Class FormTestHelper::Field
In: lib/form_test_helper.rb
Parent: Object

Methods

initial_value   name   new   proxy   reset   tag   to_s   update  

Included Modules

TagProxy

Attributes

name  [R] 
tags  [R] 
value  [RW] 

Public Class methods

[Source]

     # File lib/form_test_helper.rb, line 205
205:     def initialize(tags)
206:       @tags = tags
207:       reset
208:     end

Public Instance methods

[Source]

     # File lib/form_test_helper.rb, line 214
214:     def initial_value
215:       if tag['value']
216:         tag['value']
217:       elsif tag.children
218:         tag.children.to_s
219:       end
220:     end

The name for the field (which may have multiple values) Multiple form elements with the same name are considered only one field. Fields that return multiple values when submitted are indicated with square brackets at the end of their name in HTML, but have no such ending internal to this class.

[Source]

     # File lib/form_test_helper.rb, line 226
226:     def name
227:       tag['name'].gsub(/\[\]$/, '')
228:     end

[Source]

     # File lib/form_test_helper.rb, line 238
238:     def proxy
239:       returning @value do |value| 
240:         value.extend(FieldProxy)
241:         value.field = self
242:       end
243:     end

[Source]

     # File lib/form_test_helper.rb, line 230
230:     def reset
231:       @value = initial_value
232:     end

[Source]

     # File lib/form_test_helper.rb, line 210
210:     def tag
211:       tags.first
212:     end

[Source]

     # File lib/form_test_helper.rb, line 234
234:     def to_s
235:       self.value.to_s
236:     end

Update the value of the field. This enables updates to be done recursively through FieldsHashes until a form is reached

[Source]

     # File lib/form_test_helper.rb, line 247
247:     def update(new_value)
248:       self.value = new_value
249:     end

[Validate]