Expose select_option through Webrat::Methods. Minor refactorings
This commit is contained in:
parent
f5ed57e042
commit
d576a72120
@ -366,8 +366,8 @@ module Webrat
|
|||||||
".//select"
|
".//select"
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_option(text)
|
def options
|
||||||
options.detect { |o| o.matches_text?(text) }
|
@options ||= SelectOption.load_all(@session, @element)
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
@ -382,9 +382,5 @@ module Webrat
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def options
|
|
||||||
@options ||= SelectOption.load_all(@session, @element)
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -12,14 +12,6 @@ module Webrat
|
|||||||
".//form"
|
".//form"
|
||||||
end
|
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
|
def fields
|
||||||
@fields ||= Field.load_all(@session, @element)
|
@fields ||= Field.load_all(@session, @element)
|
||||||
end
|
end
|
||||||
|
@ -17,7 +17,7 @@ module Webrat
|
|||||||
if @id_or_name_or_label
|
if @id_or_name_or_label
|
||||||
field = FieldLocator.new(@session, @dom, @id_or_name_or_label, SelectField).locate!
|
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)
|
if @option_text.is_a?(Regexp)
|
||||||
Webrat::XML.inner_html(o.element) =~ @option_text
|
Webrat::XML.inner_html(o.element) =~ @option_text
|
||||||
else
|
else
|
||||||
@ -51,7 +51,7 @@ module Webrat
|
|||||||
|
|
||||||
end
|
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!
|
SelectOptionLocator.new(@session, dom, option_text, id_or_name_or_label).locate!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -40,6 +40,7 @@ module Webrat
|
|||||||
:reload, :reloads,
|
:reload, :reloads,
|
||||||
:clicks_link_within, :click_link_within,
|
:clicks_link_within, :click_link_within,
|
||||||
:field_labeled,
|
:field_labeled,
|
||||||
|
:select_option,
|
||||||
:set_hidden_field, :submit_form,
|
:set_hidden_field, :submit_form,
|
||||||
:request_page, :current_dom,
|
:request_page, :current_dom,
|
||||||
:selects_date, :selects_time, :selects_datetime,
|
:selects_date, :selects_time, :selects_datetime,
|
||||||
|
@ -98,8 +98,7 @@ module Webrat
|
|||||||
# select "February", :from => "event_month"
|
# select "February", :from => "event_month"
|
||||||
# select "February", :from => "Event Month"
|
# select "February", :from => "Event Month"
|
||||||
def select(option_text, options = {})
|
def select(option_text, options = {})
|
||||||
option = find_select_option(option_text, options[:from])
|
select_option(option_text, options[:from]).choose
|
||||||
option.choose
|
|
||||||
end
|
end
|
||||||
|
|
||||||
webrat_deprecate :selects, :select
|
webrat_deprecate :selects, :select
|
||||||
|
@ -223,6 +223,7 @@ module Webrat
|
|||||||
def_delegators :current_scope, :field_labeled
|
def_delegators :current_scope, :field_labeled
|
||||||
def_delegators :current_scope, :field_by_xpath
|
def_delegators :current_scope, :field_by_xpath
|
||||||
def_delegators :current_scope, :field_with_id
|
def_delegators :current_scope, :field_with_id
|
||||||
|
def_delegators :current_scope, :select_option
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user