Converting usages of element attributes to use a Webrat::XML method

This commit is contained in:
Bryan Helmkamp 2008-11-27 00:52:17 -05:00
parent 7ef8fdf7ba
commit 9a344fdc2b
7 changed files with 39 additions and 35 deletions

View File

@ -18,15 +18,15 @@ module Webrat
protected protected
def href def href
@element["href"] Webrat::XML.attribute(@element, "href")
end end
def title def title
@element["title"] Webrat::XML.attribute(@element, "title")
end end
def id def id
@element["id"] Webrat::XML.attribute(@element, "id")
end end

View File

@ -11,10 +11,10 @@ module Webrat
def self.class_for_element(element) def self.class_for_element(element)
if element.name == "input" if element.name == "input"
if %w[submit image].include?(element["type"]) if %w[submit image].include?(Webrat::XML.attribute(element, "type"))
field_class = "button" field_class = "button"
else else
field_class = element["type"] || "text" #default type; 'type' attribute is not mandatory field_class = Webrat::XML.attribute(element, "type") || "text" #default type; 'type' attribute is not mandatory
end end
else else
field_class = element.name field_class = element.name
@ -39,7 +39,7 @@ module Webrat
end end
def id def id
@element["id"] Webrat::XML.attribute(@element, "id")
end end
def path def path
@ -50,16 +50,16 @@ module Webrat
end end
end end
def matches_id?(id) def matches_id?(expected_id)
if id.is_a?(Regexp) if expected_id.is_a?(Regexp)
@element["id"] =~ id id =~ expected_id
else else
@element["id"] == id.to_s id == expected_id.to_s
end end
end end
def matches_name?(name) def matches_name?(name)
@element["name"] == name.to_s Webrat::XML.attribute(@element, "name") == name.to_s
end end
def matches_label?(label_text) def matches_label?(label_text)
@ -68,11 +68,11 @@ module Webrat
end end
def matches_alt?(alt) def matches_alt?(alt)
@element["alt"] =~ /^\W*#{Regexp.escape(alt.to_s)}/i Webrat::XML.attribute(@element, "alt") =~ /^\W*#{Regexp.escape(alt.to_s)}/i
end end
def disabled? def disabled?
@element.attributes.has_key?("disabled") && @element["disabled"] != 'false' @element.attributes.has_key?("disabled") && Webrat::XML.attribute(@element, "disabled") != 'false'
end end
def raise_error_if_disabled def raise_error_if_disabled
@ -104,7 +104,7 @@ module Webrat
protected protected
def name def name
@element["name"] Webrat::XML.attribute(@element, "name")
end end
def escaped_value def escaped_value
@ -136,7 +136,7 @@ module Webrat
end end
def default_value def default_value
@element["value"] Webrat::XML.attribute(@element, "value")
end end
def replace_param_value(params, oval, nval) def replace_param_value(params, oval, nval)
@ -163,7 +163,7 @@ module Webrat
end end
def matches_value?(value) def matches_value?(value)
@element["value"] =~ /^\W*#{Regexp.escape(value.to_s)}/i || matches_text?(value) || matches_alt?(value) Webrat::XML.attribute(@element, "value") =~ /^\W*#{Regexp.escape(value.to_s)}/i || matches_text?(value) || matches_alt?(value)
end end
def to_param def to_param
@ -177,7 +177,7 @@ module Webrat
def click def click
raise_error_if_disabled raise_error_if_disabled
set(@element["value"]) unless @element["name"].blank? set(Webrat::XML.attribute(@element, "value")) unless Webrat::XML.attribute(@element, "name").blank?
@form.submit @form.submit
end end
@ -216,11 +216,11 @@ module Webrat
def check def check
raise_error_if_disabled raise_error_if_disabled
set(@element["value"] || "on") set(Webrat::XML.attribute(@element, "value") || "on")
end end
def checked? def checked?
@element["checked"] == "checked" Webrat::XML.attribute(@element, "checked") == "checked"
end end
def uncheck def uncheck
@ -231,8 +231,8 @@ module Webrat
protected protected
def default_value def default_value
if @element["checked"] == "checked" if Webrat::XML.attribute(@element, "checked") == "checked"
@element["value"] || "on" Webrat::XML.attribute(@element, "value") || "on"
else else
nil nil
end end
@ -256,11 +256,11 @@ module Webrat
option.set(nil) option.set(nil)
end end
set(@element["value"] || "on") set(Webrat::XML.attribute(@element, "value") || "on")
end end
def checked? def checked?
@element["checked"] == "checked" Webrat::XML.attribute(@element, "checked") == "checked"
end end
protected protected
@ -270,8 +270,8 @@ module Webrat
end end
def default_value def default_value
if @element["checked"] == "checked" if Webrat::XML.attribute(@element, "checked") == "checked"
@element["value"] || "on" Webrat::XML.attribute(@element, "value") || "on"
else else
nil nil
end end
@ -338,7 +338,7 @@ module Webrat
selected_options.map do |option| selected_options.map do |option|
return "" if option.nil? return "" if option.nil?
option["value"] || option.inner_html Webrat::XML.attribute(option, "value") || option.inner_html
end end
end end

View File

@ -87,7 +87,7 @@ module Webrat
end end
def matches_id?(id) def matches_id?(id)
@element["id"] == id.to_s Webrat::XML.attribute(@element, "id") == id.to_s
end end
protected protected
@ -112,11 +112,11 @@ module Webrat
end end
def form_method def form_method
@element["method"].blank? ? :get : @element["method"].downcase Webrat::XML.attribute(@element, "method").blank? ? :get : Webrat::XML.attribute(@element, "method").downcase
end end
def form_action def form_action
@element["action"].blank? ? @session.current_url : @element["action"] Webrat::XML.attribute(@element, "action").blank? ? @session.current_url : Webrat::XML.attribute(@element, "action")
end end
def merge(all_params, new_param) def merge(all_params, new_param)

View File

@ -19,7 +19,7 @@ module Webrat
end end
def for_id def for_id
@element['for'] Webrat::XML.attribute(@element, "for")
end end
end end

View File

@ -49,7 +49,7 @@ module Webrat
protected protected
def id def id
@element['id'] Webrat::XML.attribute(@element, "id")
end end
def data def data
@ -57,11 +57,11 @@ module Webrat
end end
def title def title
@element['title'] Webrat::XML.attribute(@element, "title")
end end
def href def href
@element["href"] Webrat::XML.attribute(@element, "href")
end end
def absolute_href def absolute_href
@ -81,7 +81,7 @@ module Webrat
end end
def onclick def onclick
@element["onclick"] Webrat::XML.attribute(@element, "onclick")
end end
def http_method def http_method

View File

@ -22,7 +22,7 @@ module Webrat
protected protected
def value def value
@element["value"] || @element.inner_html Webrat::XML.attribute(@element, "value") || @element.inner_html
end end
end end

View File

@ -24,6 +24,10 @@ module Webrat #:nodoc:
Hpricot(stringlike.to_s) Hpricot(stringlike.to_s)
end end
end end
def self.attribute(element, attribute_name)
element[attribute_name]
end
def self.xpath_search(element, *searches) def self.xpath_search(element, *searches)
searches.flatten.map do |search| searches.flatten.map do |search|