diff --git a/lib/webrat/core/elements/field.rb b/lib/webrat/core/elements/field.rb index c11330b..12aa87c 100644 --- a/lib/webrat/core/elements/field.rb +++ b/lib/webrat/core/elements/field.rb @@ -365,11 +365,11 @@ module Webrat def self.xpath_search ".//select" end - - def find_option(text) - options.detect { |o| o.matches_text?(text) } - end + def options + @options ||= SelectOption.load_all(@session, @element) + end + protected def default_value @@ -382,9 +382,5 @@ module Webrat end end - def options - @options ||= SelectOption.load_all(@session, @element) - end - end end diff --git a/lib/webrat/core/elements/form.rb b/lib/webrat/core/elements/form.rb index 9102298..81859da 100644 --- a/lib/webrat/core/elements/form.rb +++ b/lib/webrat/core/elements/form.rb @@ -11,14 +11,6 @@ module Webrat def self.xpath_search ".//form" end - - def find_select_option(option_text) - select_fields = fields_by_type([SelectField]) - - select_fields.detect_mapped do |select_field| - select_field.find_option(option_text) - end - end def fields @fields ||= Field.load_all(@session, @element) diff --git a/lib/webrat/core/locators/select_option_locator.rb b/lib/webrat/core/locators/select_option_locator.rb index b90ed7f..a471690 100644 --- a/lib/webrat/core/locators/select_option_locator.rb +++ b/lib/webrat/core/locators/select_option_locator.rb @@ -17,7 +17,7 @@ module Webrat if @id_or_name_or_label field = FieldLocator.new(@session, @dom, @id_or_name_or_label, SelectField).locate! - field.send(:options).detect do |o| + field.options.detect do |o| if @option_text.is_a?(Regexp) Webrat::XML.inner_html(o.element) =~ @option_text else @@ -51,7 +51,7 @@ module Webrat end - def find_select_option(option_text, id_or_name_or_label) #:nodoc: + def select_option(option_text, id_or_name_or_label = nil) #:nodoc: SelectOptionLocator.new(@session, dom, option_text, id_or_name_or_label).locate! end diff --git a/lib/webrat/core/methods.rb b/lib/webrat/core/methods.rb index e75e96c..f430cea 100644 --- a/lib/webrat/core/methods.rb +++ b/lib/webrat/core/methods.rb @@ -40,6 +40,7 @@ module Webrat :reload, :reloads, :clicks_link_within, :click_link_within, :field_labeled, + :select_option, :set_hidden_field, :submit_form, :request_page, :current_dom, :selects_date, :selects_time, :selects_datetime, diff --git a/lib/webrat/core/scope.rb b/lib/webrat/core/scope.rb index ea3ac0f..fc85203 100644 --- a/lib/webrat/core/scope.rb +++ b/lib/webrat/core/scope.rb @@ -98,8 +98,7 @@ module Webrat # select "February", :from => "event_month" # select "February", :from => "Event Month" def select(option_text, options = {}) - option = find_select_option(option_text, options[:from]) - option.choose + select_option(option_text, options[:from]).choose end webrat_deprecate :selects, :select diff --git a/lib/webrat/core/session.rb b/lib/webrat/core/session.rb index 71a2129..054d638 100644 --- a/lib/webrat/core/session.rb +++ b/lib/webrat/core/session.rb @@ -223,6 +223,7 @@ module Webrat def_delegators :current_scope, :field_labeled def_delegators :current_scope, :field_by_xpath def_delegators :current_scope, :field_with_id + def_delegators :current_scope, :select_option private