| Class | FormTestHelper::Select |
| In: |
lib/form_test_helper.rb
|
| Parent: | Field |
# File lib/form_test_helper.rb, line 312
312: def initialize(tags)
313: @options = tags.first.select("option").collect {|option_tag| Option.new(self, option_tag) }
314: super
315: end
# File lib/form_test_helper.rb, line 317
317: def initial_value
318: selected_options = @options.select(&:initially_selected)
319: case selected_options.size
320: when 1
321: selected_options.first.value
322: when 0 # If no option is selected, browsers generally use the first
323: @options.first.value
324: else
325: # When multiple options selected but the multiple attribute is not specified,
326: # Firefox selects the last of the options.
327: selected_options.last.value
328: end
329: end
If value is a label, return the real value. If not an option, raise error.
# File lib/form_test_helper.rb, line 348
348: def lookup_in_options(value)
349: if options.include?(value)
350: return value
351: elsif options_are_labeled? && pair = options.detect {|option| option.include?(value.to_s) }
352: return pair.last
353: else
354: raise "Value '#{value}' isn't one of the options for #{self.name}."
355: end
356: end
# File lib/form_test_helper.rb, line 331
331: def options
332: if options_are_labeled?
333: @options.collect do |option|
334: [option.label, option.value]
335: end
336: else
337: @options.collect(&:value)
338: end
339: end