| 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 147
147: def initialize(constructor = {})
148: if constructor.is_a?(Hash)
149: # super()
150: merge!(constructor)
151: else
152: super(constructor)
153: end
154: end
# File lib/form_test_helper.rb, line 172
172: def [](key)
173: raise(FieldNotFoundError, "Field named '#{key.to_s}' not found in FieldsHash.") unless self.has_key?(key)
174: super
175: 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 167
167: def update(other_hash)
168: other_hash.each_pair { |key, value| self[key].update(value) }
169: self
170: end
# File lib/form_test_helper.rb, line 178
178: def convert_value(value)
179: value.is_a?(Hash) ? FieldsHash.new(value) : value
180: end