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 206
206:     def initialize(tags)
207:       @tags = tags
208:       reset
209:     end

Public Instance methods

[Source]

     # File lib/form_test_helper.rb, line 215
215:     def initial_value
216:       if tag['value']
217:         tag['value']
218:       elsif tag.children
219:         tag.children.to_s
220:       end
221:     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 227
227:     def name
228:       tag['name'].gsub(/\[\]$/, '')
229:     end

[Source]

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

[Source]

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

[Source]

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

[Source]

     # File lib/form_test_helper.rb, line 235
235:     def to_s
236:       self.value.to_s
237:     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 248
248:     def update(new_value)
249:       self.value = new_value
250:     end

[Validate]