From c647ae98bb6a18311aadb203fdfd4854567c3c44 Mon Sep 17 00:00:00 2001 From: Mark Menard Date: Thu, 5 Mar 2009 17:45:56 -0500 Subject: [PATCH 1/2] Memoize WWW::Mechanize instance. --- lib/webrat/mechanize.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/webrat/mechanize.rb b/lib/webrat/mechanize.rb index 41fe41b..d82c397 100644 --- a/lib/webrat/mechanize.rb +++ b/lib/webrat/mechanize.rb @@ -36,7 +36,7 @@ module Webrat #:nodoc: end def mechanize - @mechanize = WWW::Mechanize.new + @mechanize ||= WWW::Mechanize.new end def_delegators :mechanize, :basic_auth From 0c2261d869ef988612eed290221633f27feb609c Mon Sep 17 00:00:00 2001 From: Mark Menard Date: Thu, 12 Mar 2009 15:42:20 -0400 Subject: [PATCH 2/2] Add support for Rails javascript post links. --- lib/webrat/core/elements/link.rb | 2 ++ spec/public/click_link_spec.rb | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/lib/webrat/core/elements/link.rb b/lib/webrat/core/elements/link.rb index 3204db5..a11b689 100644 --- a/lib/webrat/core/elements/link.rb +++ b/lib/webrat/core/elements/link.rb @@ -81,6 +81,8 @@ module Webrat :delete elsif onclick.include?("m.setAttribute('value', 'put')") :put + elsif onclick.include?("m.setAttribute('value', 'post')") + :post else raise Webrat::WebratError.new("No HTTP method for _method param in #{onclick.inspect}") end diff --git a/spec/public/click_link_spec.rb b/spec/public/click_link_spec.rb index a00549c..1a8c111 100644 --- a/spec/public/click_link_spec.rb +++ b/spec/public/click_link_spec.rb @@ -176,6 +176,27 @@ describe "click_link" do click_link "Posts", :javascript => false end + it "should click rails javascript post links" do + with_html <<-HTML + + Post + + HTML + webrat_session.should_receive(:post).with("/posts", {}) + click_link "Post" + end + it "should click rails javascript put links" do with_html <<-HTML