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