diff --git a/lib/webrat/core/link.rb b/lib/webrat/core/link.rb index 9e14ba6..f50420d 100644 --- a/lib/webrat/core/link.rb +++ b/lib/webrat/core/link.rb @@ -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 - - 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 def matches_text?(link_text) diff --git a/lib/webrat/core/page.rb b/lib/webrat/core/page.rb index ce964b1..0261ad7 100644 --- a/lib/webrat/core/page.rb +++ b/lib/webrat/core/page.rb @@ -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,13 +211,17 @@ module Webrat # Example: # reloads def reloads - request_page(@url, @method, @data) + load_page end def submits_form(form_id = nil) # :nodoc: end protected + + def load_page + request_page(@url, @method, @data) + end def find_select_option(option_text) forms.each do |form| diff --git a/spec/api/clicks_link_spec.rb b/spec/api/clicks_link_spec.rb index 2fedd3a..21406ba 100644 --- a/spec/api/clicks_link_spec.rb +++ b/spec/api/clicks_link_spec.rb @@ -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 + Posts + 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