|
1 | | -# Contributing new Flex attributes |
| 1 | +# Contributing new Strata attributes |
2 | 2 |
|
3 | | -This document describes how to create new Flex attributes |
| 3 | +This document describes how to create new Strata attributes |
4 | 4 |
|
5 | 5 | ## Design |
6 | 6 |
|
7 | | -1. Decide whether or not to create a new value object in app/models/flex/ |
8 | | - By default, Flex attributes will require creating a new value object. The exception is if the type of the attribute is already a native Ruby type, such as the memorable_date attribute which represents a Date object. |
| 7 | +1. Decide whether or not to create a new value object in app/models/strata/ |
| 8 | + By default, Strata attributes will require creating a new value object. The exception is if the type of the attribute is already a native Ruby type, such as the memorable_date attribute which represents a Date object. |
9 | 9 |
|
10 | 10 | 2. Determine if the attribute is composed of multiple nested attributes: |
11 | 11 |
|
@@ -67,19 +67,19 @@ This document describes how to create new Flex attributes |
67 | 67 | ``` |
68 | 68 |
|
69 | 69 | 3. Decide if there are validations that need to be added by default. |
70 | | - Note: Do not add presence option or validation. By default all Flex attributes allow nil. |
| 70 | + Note: Do not add presence option or validation. By default all Strata attributes allow nil. |
71 | 71 |
|
72 | 72 | ## Implementation |
73 | 73 |
|
74 | 74 | 1. Create the value object |
75 | | -2. Create a Concern `{FlexAttributeType}Attribute` in `app/lib/strata/attributes/` with a class method `{flex_attribute_type}_attribute` that takes the attribute `name` and an `options` hash and defines the new flex_attribute type on the including class, then include the module in Strata::Attributes in `app/lib/strata/attributes.rb` |
76 | | - 1. **Important**: The `flex_attribute` method in `app/lib/strata/attributes.rb` dynamically calls `#{type}_attribute`, so following the naming convention for the class method is required for the attribute to work properly. |
77 | | -3. Extend the `flex:migration` generator in `migration_generator.rb` to include the new Flex attribute. |
78 | | -4. For testing, add the new flex attribute to TestRecord in `spec/dummy/app/models/test_record.rb`. Try using the flex migration generator to generate this migration by running `cd spec/dummy && bin/rails generate flex:migration Add<AttributeName>ToTestRecords <attribute_name>:<flex_attribute_type>` and then run the migration with `bin/rails db:migrate` |
79 | | -5. Add tests to spec/dummy/spec/lib/flex/attributes_spec.rb leveraging the new flex attribute. Make sure to test: |
| 75 | +2. Create a Concern `{StrataAttributeType}Attribute` in `app/lib/strata/attributes/` with a class method `{strata_attribute_type}_attribute` that takes the attribute `name` and an `options` hash and defines the new strata_attribute type on the including class, then include the module in Strata::Attributes in `app/lib/strata/attributes.rb` |
| 76 | + 1. **Important**: The `strata_attribute` method in `app/lib/strata/attributes.rb` dynamically calls `#{type}_attribute`, so following the naming convention for the class method is required for the attribute to work properly. |
| 77 | +3. Extend the `strata:migration` generator in `migration_generator.rb` to include the new Strata attribute. |
| 78 | +4. For testing, add the new strata attribute to TestRecord in `spec/dummy/app/models/test_record.rb`. Try using the strata migration generator to generate this migration by running `cd spec/dummy && bin/rails generate strata:migration Add<AttributeName>ToTestRecords <attribute_name>:<strata_attribute_type>` and then run the migration with `bin/rails db:migrate` |
| 79 | +5. Add tests to spec/dummy/spec/lib/strata/attributes_spec.rb leveraging the new strata attribute. Make sure to test: |
80 | 80 | a. Assign a Hash to the attribute and make sure the attribute is cast to the value object type and has the correct value |
81 | 81 | b. Load the attribute from the database and make sure the attribute is correctly cast from the database record to the value object type and has the correct value |
82 | 82 | c. Test validation logic if relevant. When testing validation logic, check that the appropriate error objects are present and that the original uncast values are present so that they can be shown to the user to be fixed. |
83 | | -1. Create the associated FormBuilder helper method for rendering the form fields associated with the Flex attribute. (See [Contributing FormBuilder helper methods](/docs/contributing/contributing-form-builder-helper-methods.md)) |
| 83 | +1. Create the associated FormBuilder helper method for rendering the form fields associated with the Strata attribute. (See [Contributing FormBuilder helper methods](/docs/contributing/contributing-form-builder-helper-methods.md)) |
84 | 84 |
|
85 | 85 | See the existing attribute tests in the codebase for examples. |
0 commit comments