| Class | FormTestHelper::FieldsHash |
| In: |
lib/form_test_helper.rb
|
| Parent: | HashWithIndifferentAccess |
A hash of fields to allow infinite nesting of fields named like ‘person[address][street]’
Uses merge! instead of update when creating a new FieldsHash so update can update field values, not the field objects themselves.
# File lib/form_test_helper.rb, line 146
146: def initialize(constructor = {})
147: if constructor.is_a?(Hash)
148: # super()
149: merge!(constructor)
150: else
151: super(constructor)
152: end
153: end
# File lib/form_test_helper.rb, line 171
171: def [](key)
172: raise(FieldNotFoundError, "Field named '#{key.to_s}' not found in FieldsHash.") unless self.has_key?(key)
173: super
174: end
Allow field values to be merged in from a hash. Example:
new_book = {
:name => 'Pickaxe',
:category => 'Programming',
:classic => true,
}
form.book.update(new_book)
# File lib/form_test_helper.rb, line 166
166: def update(other_hash)
167: other_hash.each_pair { |key, value| self[key].update(value) }
168: self
169: end
# File lib/form_test_helper.rb, line 177
177: def convert_value(value)
178: value.is_a?(Hash) ? FieldsHash.new(value) : value
179: end