| 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 169
169: def initialize(constructor = {})
170: if constructor.is_a?(Hash)
171: # super()
172: merge!(constructor)
173: else
174: super(constructor)
175: end
176: end
# File lib/form_test_helper.rb, line 194
194: def [](key)
195: unless self.has_key?(key)
196: raise(FieldNotFoundError, "Field named '#{key.to_s}' not found in FieldsHash.")
197: end
198: super
199: end
Allows setting form field values using key access to form fields: Examples:
form = select_form
form.user['name'] = 'joe'
submit_form do |form|
form.user['name'] = 'joe'
end
# File lib/form_test_helper.rb, line 210
210: def []=(key, value)
211: self[key].value = value
212: 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 189
189: def update(other_hash)
190: other_hash.each_pair { |key, value| self[key].update(value) }
191: self
192: end
# File lib/form_test_helper.rb, line 217
217: def convert_value(value)
218: value.is_a?(Hash) ? FieldsHash.new(value) : value
219: end