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
|
||||
end
|
||||
|
||||
def click(method = nil)
|
||||
def click(method = nil, options = {})
|
||||
method ||= http_method
|
||||
return if href =~ /^#/ && method == :get
|
||||
|
||||
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
|
||||
|
||||
def matches_text?(link_text)
|
||||
|
|
|
@ -16,7 +16,7 @@ module Webrat
|
|||
@data = data
|
||||
|
||||
reset_dom
|
||||
reloads if @url
|
||||
load_page if @url
|
||||
|
||||
session.current_page = self
|
||||
end
|
||||
|
@ -128,11 +128,15 @@ module Webrat
|
|||
# JavaScript onclick handlers for PUT, POST and DELETE links, as well as
|
||||
# CSRF authenticity tokens if they are present.
|
||||
#
|
||||
# Javascript imitation can be disabled by passing the option :javascript => false
|
||||
#
|
||||
# Example:
|
||||
# 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.click
|
||||
link.click(nil, options)
|
||||
end
|
||||
|
||||
# Works like clicks_link, but only looks for the link text within a given selector
|
||||
|
@ -207,7 +211,7 @@ module Webrat
|
|||
# Example:
|
||||
# reloads
|
||||
def reloads
|
||||
request_page(@url, @method, @data)
|
||||
load_page
|
||||
end
|
||||
|
||||
def submits_form(form_id = nil) # :nodoc:
|
||||
|
@ -215,6 +219,10 @@ module Webrat
|
|||
|
||||
protected
|
||||
|
||||
def load_page
|
||||
request_page(@url, @method, @data)
|
||||
end
|
||||
|
||||
def find_select_option(option_text)
|
||||
forms.each do |form|
|
||||
result = form.find_select_option(option_text)
|
||||
|
|
|
@ -97,6 +97,20 @@ describe "clicks_link" do
|
|||
@session.clicks_link "Posts"
|
||||
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
|
||||
@session.response_body = <<-EOS
|
||||
<a href="/posts" onclick="var f = document.createElement('form');
|
||||
|
|
Loading…
Reference in New Issue