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
def href
@element["href"]
Webrat::XML.attribute(@element, "href")
end
def title
@element["title"]
Webrat::XML.attribute(@element, "title")
end
def id
@element["id"]
Webrat::XML.attribute(@element, "id")
end

View File

@ -11,10 +11,10 @@ module Webrat
def self.class_for_element(element)
if element.name == "input"
if %w[submit image].include?(element["type"])
if %w[submit image].include?(Webrat::XML.attribute(element, "type"))
field_class = "button"
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
else
field_class = element.name
@ -39,7 +39,7 @@ module Webrat
end
def id
@element["id"]
Webrat::XML.attribute(@element, "id")
end
def path
@ -50,16 +50,16 @@ module Webrat
end
end
def matches_id?(id)
if id.is_a?(Regexp)
@element["id"] =~ id
def matches_id?(expected_id)
if expected_id.is_a?(Regexp)
id =~ expected_id
else
@element["id"] == id.to_s
id == expected_id.to_s
end
end
def matches_name?(name)
@element["name"] == name.to_s
Webrat::XML.attribute(@element, "name") == name.to_s
end
def matches_label?(label_text)
@ -68,11 +68,11 @@ module Webrat
end
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
def disabled?
@element.attributes.has_key?("disabled") && @element["disabled"] != 'false'
@element.attributes.has_key?("disabled") && Webrat::XML.attribute(@element, "disabled") != 'false'
end
def raise_error_if_disabled
@ -104,7 +104,7 @@ module Webrat
protected
def name
@element["name"]
Webrat::XML.attribute(@element, "name")
end
def escaped_value
@ -136,7 +136,7 @@ module Webrat
end
def default_value
@element["value"]
Webrat::XML.attribute(@element, "value")
end
def replace_param_value(params, oval, nval)
@ -163,7 +163,7 @@ module Webrat
end
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
def to_param
@ -177,7 +177,7 @@ module Webrat
def click
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
end
@ -216,11 +216,11 @@ module Webrat
def check
raise_error_if_disabled
set(@element["value"] || "on")
set(Webrat::XML.attribute(@element, "value") || "on")
end
def checked?
@element["checked"] == "checked"
Webrat::XML.attribute(@element, "checked") == "checked"
end
def uncheck
@ -231,8 +231,8 @@ module Webrat
protected
def default_value
if @element["checked"] == "checked"
@element["value"] || "on"
if Webrat::XML.attribute(@element, "checked") == "checked"
Webrat::XML.attribute(@element, "value") || "on"
else
nil
end
@ -256,11 +256,11 @@ module Webrat
option.set(nil)
end
set(@element["value"] || "on")
set(Webrat::XML.attribute(@element, "value") || "on")
end
def checked?
@element["checked"] == "checked"
Webrat::XML.attribute(@element, "checked") == "checked"
end
protected
@ -270,8 +270,8 @@ module Webrat
end
def default_value
if @element["checked"] == "checked"
@element["value"] || "on"
if Webrat::XML.attribute(@element, "checked") == "checked"
Webrat::XML.attribute(@element, "value") || "on"
else
nil
end
@ -338,7 +338,7 @@ module Webrat
selected_options.map do |option|
return "" if option.nil?
option["value"] || option.inner_html
Webrat::XML.attribute(option, "value") || option.inner_html
end
end

View File

@ -87,7 +87,7 @@ module Webrat
end
def matches_id?(id)
@element["id"] == id.to_s
Webrat::XML.attribute(@element, "id") == id.to_s
end
protected
@ -112,11 +112,11 @@ module Webrat
end
def form_method
@element["method"].blank? ? :get : @element["method"].downcase
Webrat::XML.attribute(@element, "method").blank? ? :get : Webrat::XML.attribute(@element, "method").downcase
end
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
def merge(all_params, new_param)

View File

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

View File

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

View File

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

View File

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