From 0b17495446eac62f7694ceb88c823724f30aaeca Mon Sep 17 00:00:00 2001 From: Jeremy Burks Date: Mon, 27 Oct 2008 21:29:22 -0500 Subject: [PATCH 1/9] move merb/param_parser to core so it can be used for other sessions other than merb (i.e. mechanize) --- Manifest.txt | 4 ++-- lib/webrat/{merb => core}/param_parser.rb | 0 lib/webrat/{merb => core}/url_encoded_pair_parser.rb | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename lib/webrat/{merb => core}/param_parser.rb (100%) rename lib/webrat/{merb => core}/url_encoded_pair_parser.rb (100%) diff --git a/Manifest.txt b/Manifest.txt index 08b0319..e76f6cc 100644 --- a/Manifest.txt +++ b/Manifest.txt @@ -16,16 +16,16 @@ lib/webrat/core/form.rb lib/webrat/core/label.rb lib/webrat/core/link.rb lib/webrat/core/logging.rb +lib/webrat/core/param_parser.rb lib/webrat/core/scope.rb lib/webrat/core/select_option.rb lib/webrat/core/session.rb +lib/webrat/core/url_encoded_pair_parser.rb lib/webrat/mechanize.rb lib/webrat/mechanize/mechanize_session.rb lib/webrat/merb.rb lib/webrat/merb/indifferent_access.rb -lib/webrat/merb/param_parser.rb lib/webrat/merb/support.rb -lib/webrat/merb/url_encoded_pair_parser.rb lib/webrat/rack/rack_session.rb lib/webrat/rails.rb lib/webrat/rails/rails_session.rb diff --git a/lib/webrat/merb/param_parser.rb b/lib/webrat/core/param_parser.rb similarity index 100% rename from lib/webrat/merb/param_parser.rb rename to lib/webrat/core/param_parser.rb diff --git a/lib/webrat/merb/url_encoded_pair_parser.rb b/lib/webrat/core/url_encoded_pair_parser.rb similarity index 100% rename from lib/webrat/merb/url_encoded_pair_parser.rb rename to lib/webrat/core/url_encoded_pair_parser.rb From 5efa47aa530b64e6b17b9ecdb9282a15498d0d1c Mon Sep 17 00:00:00 2001 From: Jeremy Burks Date: Mon, 27 Oct 2008 21:58:21 -0500 Subject: [PATCH 2/9] fixed requires and manifest --- Manifest.txt | 11 +++-------- lib/webrat/core.rb | 1 + lib/webrat/core/field.rb | 1 - lib/webrat/core/param_parser.rb | 2 +- 4 files changed, 5 insertions(+), 10 deletions(-) diff --git a/Manifest.txt b/Manifest.txt index 90c67d6..a811ec6 100644 --- a/Manifest.txt +++ b/Manifest.txt @@ -7,6 +7,9 @@ TODO.txt init.rb install.rb lib/webrat.rb +lib/webrat/core_extensions/blank.rb +lib/webrat/core_extensions/hash_with_indifferent_access.rb +lib/webrat/core_extensions/nil_to_param.rb lib/webrat/core.rb lib/webrat/core/area.rb lib/webrat/core/assertions.rb @@ -24,8 +27,6 @@ lib/webrat/core/url_encoded_pair_parser.rb lib/webrat/mechanize.rb lib/webrat/mechanize/mechanize_session.rb lib/webrat/merb.rb -lib/webrat/merb/indifferent_access.rb -lib/webrat/merb/support.rb lib/webrat/rack/rack_session.rb lib/webrat/rails.rb lib/webrat/rails/rails_session.rb @@ -40,10 +41,6 @@ lib/webrat/selenium/location_strategy_javascript/webratlinkwithin.js lib/webrat/selenium/location_strategy_javascript/webratselectwithoption.js lib/webrat/selenium/selenium_session.rb lib/webrat/sinatra/sinatra_session.rb -manifest.diff -mechanize_spike.rb -selenium_spike.rb -spec/api/attaches_file_spec.rb spec/api/basic_auth_spec.rb spec/api/checks_spec.rb spec/api/chooses_spec.rb @@ -53,14 +50,12 @@ spec/api/clicks_link_spec.rb spec/api/fills_in_spec.rb spec/api/reloads_spec.rb spec/api/save_and_open_spec.rb -spec/api/selects_date_spec.rb spec/api/selects_spec.rb spec/api/should_not_see_spec.rb spec/api/should_see_spec.rb spec/api/visits_spec.rb spec/api/within_spec.rb spec/fakes/test_session.rb -spec/integration/rails_spec.rb spec/rcov.opts spec/spec_helper.rb spec/webrat/core/logging_spec.rb diff --git a/lib/webrat/core.rb b/lib/webrat/core.rb index b7aaf4f..8a3ae30 100644 --- a/lib/webrat/core.rb +++ b/lib/webrat/core.rb @@ -1,5 +1,6 @@ require "webrat/core/logging" require "webrat/core/flunk" +require "webrat/core/param_parser" require "webrat/core/form" require "webrat/core/scope" require "webrat/core/link" diff --git a/lib/webrat/core/field.rb b/lib/webrat/core/field.rb index 31e244b..b94ec2b 100644 --- a/lib/webrat/core/field.rb +++ b/lib/webrat/core/field.rb @@ -1,7 +1,6 @@ require "cgi" require "webrat/core_extensions/blank" require "webrat/core_extensions/nil_to_param" -require "webrat/merb/param_parser" module Webrat class Field diff --git a/lib/webrat/core/param_parser.rb b/lib/webrat/core/param_parser.rb index d2b55c7..c570039 100644 --- a/lib/webrat/core/param_parser.rb +++ b/lib/webrat/core/param_parser.rb @@ -1,6 +1,6 @@ require "cgi" require "webrat/core_extensions/blank" -require "webrat/merb/url_encoded_pair_parser" +require "webrat/core/url_encoded_pair_parser" module Webrat class ParamParser From 71adad4ada338289f8773a786a959b34101c50ac Mon Sep 17 00:00:00 2001 From: Jeremy Burks Date: Mon, 27 Oct 2008 22:01:27 -0500 Subject: [PATCH 3/9] the manifest was missing core/mime.rb --- Manifest.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/Manifest.txt b/Manifest.txt index a811ec6..f18d97e 100644 --- a/Manifest.txt +++ b/Manifest.txt @@ -19,6 +19,7 @@ lib/webrat/core/form.rb lib/webrat/core/label.rb lib/webrat/core/link.rb lib/webrat/core/logging.rb +lib/webrat/core/mime.rb lib/webrat/core/param_parser.rb lib/webrat/core/scope.rb lib/webrat/core/select_option.rb From 40c6b6ed4495d0534e81286d70c37c058f11d193 Mon Sep 17 00:00:00 2001 From: Jeremy Burks Date: Mon, 27 Oct 2008 22:01:48 -0500 Subject: [PATCH 4/9] "fixed" MechanizeSession, Session expects get and post to have 3 arguments --- lib/webrat/mechanize/mechanize_session.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/webrat/mechanize/mechanize_session.rb b/lib/webrat/mechanize/mechanize_session.rb index 7a817c4..fe607a6 100644 --- a/lib/webrat/mechanize/mechanize_session.rb +++ b/lib/webrat/mechanize/mechanize_session.rb @@ -6,11 +6,11 @@ module Webrat @mechanize = mechanize end - def get(url, data) + def get(url, data, headers_argument_not_used = nil) @mechanize_page = @mechanize.get(url, data) end - def post(url, data) + def post(url, data, headers_argument_not_used = nil) @mechanize_page = @mechanize.post(url, data) end From 5623643b534f26e73974752e2455551938a41c4d Mon Sep 17 00:00:00 2001 From: Jeremy Burks Date: Mon, 3 Nov 2008 20:44:33 -0600 Subject: [PATCH 5/9] exposed the mechanize page --- lib/webrat/mechanize/mechanize_session.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/webrat/mechanize/mechanize_session.rb b/lib/webrat/mechanize/mechanize_session.rb index fe607a6..cc8e241 100644 --- a/lib/webrat/mechanize/mechanize_session.rb +++ b/lib/webrat/mechanize/mechanize_session.rb @@ -6,6 +6,10 @@ module Webrat @mechanize = mechanize end + def page + @mechanize_page + end + def get(url, data, headers_argument_not_used = nil) @mechanize_page = @mechanize.get(url, data) end From d039c9590f4d4aac18dca033e40150bd61c8f6b9 Mon Sep 17 00:00:00 2001 From: Jeremy Burks Date: Sat, 8 Nov 2008 08:45:51 -0600 Subject: [PATCH 6/9] ignore the log dir --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 1e26df0..61c5eb1 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ pkg doc ri email.txt +log From 7dfd59c29cd3eee6e42d0866fc84f10ce200ae93 Mon Sep 17 00:00:00 2001 From: Jeremy Burks Date: Sat, 8 Nov 2008 08:46:14 -0600 Subject: [PATCH 7/9] the mechanize session must specially handle params {:user => {:name => "Nancy"}} now becomes {"user[name]" => "Nancy"} --- lib/webrat/mechanize/mechanize_session.rb | 11 +++++++++- .../mechanize/mechanize_session_spec.rb | 21 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/lib/webrat/mechanize/mechanize_session.rb b/lib/webrat/mechanize/mechanize_session.rb index cc8e241..fdd731b 100644 --- a/lib/webrat/mechanize/mechanize_session.rb +++ b/lib/webrat/mechanize/mechanize_session.rb @@ -15,7 +15,16 @@ module Webrat end def post(url, data, headers_argument_not_used = nil) - @mechanize_page = @mechanize.post(url, data) + post_data = data.inject({}) do |memo, param| + case param.last + when Hash + param.last.each {|attribute, value| memo["#{param.first}[#{attribute}]"] = value } + else + memo[param.first] = param.last + end + memo + end + @mechanize_page = @mechanize.post(url, post_data) end def response_body diff --git a/spec/webrat/mechanize/mechanize_session_spec.rb b/spec/webrat/mechanize/mechanize_session_spec.rb index aa5077e..452d3b7 100644 --- a/spec/webrat/mechanize/mechanize_session_spec.rb +++ b/spec/webrat/mechanize/mechanize_session_spec.rb @@ -12,4 +12,25 @@ describe Webrat::MechanizeSession do @mech.headers.should == {} end end + + describe "post" do + def url + 'http://test.host/users' + end + + def data + {:user => {:first_name => 'Nancy', :last_name => 'Callahan'}} + end + + def flattened_data + {'user[first_name]' => 'Nancy', 'user[last_name]' => 'Callahan'} + end + + it "should flatten model post data" do + mechanize = mock :mechanize + mechanize.should_receive(:post).with(url, flattened_data) + + Webrat::MechanizeSession.new(mechanize).post(url, data) + end + end end \ No newline at end of file From 255788e14b85da9aad094d3fdeb03f2df12e500c Mon Sep 17 00:00:00 2001 From: Jeremy Burks Date: Tue, 11 Nov 2008 19:38:30 -0600 Subject: [PATCH 8/9] spec.opts --- spec/spec.opts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/spec.opts b/spec/spec.opts index e69de29..c49b982 100644 --- a/spec/spec.opts +++ b/spec/spec.opts @@ -0,0 +1,2 @@ +--diff +--color \ No newline at end of file From a570d40f7056e977a4583a4baecb8444a7ffcce0 Mon Sep 17 00:00:00 2001 From: Jeremy Burks Date: Tue, 11 Nov 2008 20:08:17 -0600 Subject: [PATCH 9/9] core expects a response so mechanize got one --- lib/webrat/mechanize.rb | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/webrat/mechanize.rb b/lib/webrat/mechanize.rb index e60b020..77d0f77 100644 --- a/lib/webrat/mechanize.rb +++ b/lib/webrat/mechanize.rb @@ -3,17 +3,16 @@ require "mechanize" module Webrat class MechanizeSession < Session + attr_accessor :response + alias :page :response + def initialize(mechanize = WWW::Mechanize.new) super() @mechanize = mechanize end - def page - @mechanize_page - end - def get(url, data, headers_argument_not_used = nil) - @mechanize_page = @mechanize.get(url, data) + @response = @mechanize.get(url, data) end def post(url, data, headers_argument_not_used = nil) @@ -26,15 +25,15 @@ module Webrat end memo end - @mechanize_page = @mechanize.post(url, post_data) + @response = @mechanize.post(url, post_data) end def response_body - @mechanize_page.content + @response.content end def response_code - @mechanize_page.code.to_i + @response.code.to_i end end