Add support for disabling JavaScript when clicking a link to enable testing of both JS and non-JS implementations LM/BH
This commit is contained in:
parent
856b6cb17e
commit
6074ec3e35
@ -6,11 +6,17 @@ module Webrat
|
|||||||
@element = element
|
@element = element
|
||||||
end
|
end
|
||||||
|
|
||||||
def click(method = nil)
|
def click(method = nil, options = {})
|
||||||
method ||= http_method
|
method ||= http_method
|
||||||
return if href =~ /^#/ && method == :get
|
return if href =~ /^#/ && method == :get
|
||||||
|
|
||||||
Page.new(@page.session, absolute_href, method, data)
|
options[:javascript] = true if options[:javascript].nil?
|
||||||
|
|
||||||
|
if options[:javascript]
|
||||||
|
Page.new(@page.session, absolute_href, method, data)
|
||||||
|
else
|
||||||
|
Page.new(@page.session, absolute_href, :get, {})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def matches_text?(link_text)
|
def matches_text?(link_text)
|
||||||
|
@ -16,7 +16,7 @@ module Webrat
|
|||||||
@data = data
|
@data = data
|
||||||
|
|
||||||
reset_dom
|
reset_dom
|
||||||
reloads if @url
|
load_page if @url
|
||||||
|
|
||||||
session.current_page = self
|
session.current_page = self
|
||||||
end
|
end
|
||||||
@ -128,11 +128,15 @@ module Webrat
|
|||||||
# JavaScript onclick handlers for PUT, POST and DELETE links, as well as
|
# JavaScript onclick handlers for PUT, POST and DELETE links, as well as
|
||||||
# CSRF authenticity tokens if they are present.
|
# CSRF authenticity tokens if they are present.
|
||||||
#
|
#
|
||||||
|
# Javascript imitation can be disabled by passing the option :javascript => false
|
||||||
|
#
|
||||||
# Example:
|
# Example:
|
||||||
# clicks_link "Sign up"
|
# clicks_link "Sign up"
|
||||||
def clicks_link(link_text)
|
#
|
||||||
|
# clicks_link "Sign up", :javascript => false
|
||||||
|
def clicks_link(link_text, options = {})
|
||||||
link = find_link(link_text)
|
link = find_link(link_text)
|
||||||
link.click
|
link.click(nil, options)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Works like clicks_link, but only looks for the link text within a given selector
|
# Works like clicks_link, but only looks for the link text within a given selector
|
||||||
@ -207,13 +211,17 @@ module Webrat
|
|||||||
# Example:
|
# Example:
|
||||||
# reloads
|
# reloads
|
||||||
def reloads
|
def reloads
|
||||||
request_page(@url, @method, @data)
|
load_page
|
||||||
end
|
end
|
||||||
|
|
||||||
def submits_form(form_id = nil) # :nodoc:
|
def submits_form(form_id = nil) # :nodoc:
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
|
def load_page
|
||||||
|
request_page(@url, @method, @data)
|
||||||
|
end
|
||||||
|
|
||||||
def find_select_option(option_text)
|
def find_select_option(option_text)
|
||||||
forms.each do |form|
|
forms.each do |form|
|
||||||
|
@ -97,6 +97,20 @@ describe "clicks_link" do
|
|||||||
@session.clicks_link "Posts"
|
@session.clicks_link "Posts"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should click rails javascript post links without javascript" do
|
||||||
|
@session.response_body = <<-EOS
|
||||||
|
<a href="/posts" onclick="var f = document.createElement('form');
|
||||||
|
f.style.display = 'none';
|
||||||
|
this.parentNode.appendChild(f);
|
||||||
|
f.method = 'POST';
|
||||||
|
f.action = this.href;
|
||||||
|
f.submit();
|
||||||
|
return false;">Posts</a>
|
||||||
|
EOS
|
||||||
|
@session.expects(:get).with("/posts", {})
|
||||||
|
@session.clicks_link "Posts", :javascript => false
|
||||||
|
end
|
||||||
|
|
||||||
it "should click rails javascript put links" do
|
it "should click rails javascript put links" do
|
||||||
@session.response_body = <<-EOS
|
@session.response_body = <<-EOS
|
||||||
<a href="/posts" onclick="var f = document.createElement('form');
|
<a href="/posts" onclick="var f = document.createElement('form');
|
||||||
|
Loading…
Reference in New Issue
Block a user