Skip to content

Commit

Permalink
Expose select_option through Webrat::Methods. Minor refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
brynary committed Dec 1, 2008
1 parent f5ed57e commit d576a72
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 20 deletions.
12 changes: 4 additions & 8 deletions lib/webrat/core/elements/field.rb
Expand Up @@ -365,11 +365,11 @@ class SelectField < Field #:nodoc:
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
Expand All @@ -382,9 +382,5 @@ def default_value
end
end

def options
@options ||= SelectOption.load_all(@session, @element)
end

end
end
8 changes: 0 additions & 8 deletions lib/webrat/core/elements/form.rb
Expand Up @@ -11,14 +11,6 @@ class Form < Element #:nodoc:
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)
Expand Down
4 changes: 2 additions & 2 deletions lib/webrat/core/locators/select_option_locator.rb
Expand Up @@ -17,7 +17,7 @@ def locate
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
Expand Down Expand Up @@ -51,7 +51,7 @@ def error_message

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

Expand Down
1 change: 1 addition & 0 deletions lib/webrat/core/methods.rb
Expand Up @@ -40,6 +40,7 @@ def webrat_session
: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,
Expand Down
3 changes: 1 addition & 2 deletions lib/webrat/core/scope.rb
Expand Up @@ -98,8 +98,7 @@ def choose(field_locator)
# 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
Expand Down
1 change: 1 addition & 0 deletions lib/webrat/core/session.rb
Expand Up @@ -223,6 +223,7 @@ def dom
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

Expand Down

0 comments on commit d576a72

Please sign in to comment.