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 245
245:     def initialize(tags)
246:       @tags = tags
247:       reset
248:     end

Public Instance methods

[Source]

     # File lib/form_test_helper.rb, line 254
254:     def initial_value
255:       if tag['value']
256:         tag['value']
257:       elsif tag.children
258:         tag.children.to_s
259:       end
260:     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 266
266:     def name
267:       tag['name'].gsub(/\[\]$/, '')
268:     end

[Source]

     # File lib/form_test_helper.rb, line 278
278:     def proxy
279:       returning @value do |value| 
280:         value.extend(FieldProxy)
281:         value.field = self
282:       end
283:     end

[Source]

     # File lib/form_test_helper.rb, line 270
270:     def reset
271:       @value = initial_value
272:     end

[Source]

     # File lib/form_test_helper.rb, line 250
250:     def tag
251:       tags.first
252:     end

[Source]

     # File lib/form_test_helper.rb, line 274
274:     def to_s
275:       self.value.to_s
276:     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 287
287:     def update(new_value)
288:       self.value = new_value
289:     end

[Validate]