diff options
author | Josh Kalderimis <josh.kalderimis@gmail.com> | 2011-05-17 19:50:34 -0400 |
---|---|---|
committer | Josh Kalderimis <josh.kalderimis@gmail.com> | 2011-05-18 00:34:10 -0400 |
commit | 00958696d871da3126113be70bb858d078b86ab5 (patch) | |
tree | 6e4ce7a5389a171cf2be8d11de5aefa6e2bcc4cf /activeresource/test | |
parent | b641ab5baec0956c0135e7341ca238eff3f9d5a5 (diff) | |
download | rails-00958696d871da3126113be70bb858d078b86ab5.tar.gz rails-00958696d871da3126113be70bb858d078b86ab5.tar.bz2 rails-00958696d871da3126113be70bb858d078b86ab5.zip |
corrected some further tests and docs for the ARes change to json change
Diffstat (limited to 'activeresource/test')
-rw-r--r-- | activeresource/test/cases/authorization_test.rb | 16 | ||||
-rw-r--r-- | activeresource/test/cases/connection_test.rb | 2 | ||||
-rw-r--r-- | activeresource/test/cases/finder_test.rb | 4 | ||||
-rw-r--r-- | activeresource/test/cases/http_mock_test.rb | 56 |
4 files changed, 39 insertions, 39 deletions
diff --git a/activeresource/test/cases/authorization_test.rb b/activeresource/test/cases/authorization_test.rb index cf23f10b76..69ef9a2821 100644 --- a/activeresource/test/cases/authorization_test.rb +++ b/activeresource/test/cases/authorization_test.rb @@ -48,7 +48,7 @@ class AuthorizationTest < Test::Unit::TestCase end def test_authorization_header - authorization_header = @authenticated_conn.__send__(:authorization_header, :get, URI.parse('/people/2.xml')) + authorization_header = @authenticated_conn.__send__(:authorization_header, :get, URI.parse('/people/2.json')) assert_equal @basic_authorization_request_header['Authorization'], authorization_header['Authorization'] authorization = authorization_header["Authorization"].to_s.split @@ -58,7 +58,7 @@ class AuthorizationTest < Test::Unit::TestCase def test_authorization_header_with_username_but_no_password @conn = ActiveResource::Connection.new("http://david:@localhost") - authorization_header = @conn.__send__(:authorization_header, :get, URI.parse('/people/2.xml')) + authorization_header = @conn.__send__(:authorization_header, :get, URI.parse('/people/2.json')) authorization = authorization_header["Authorization"].to_s.split assert_equal "Basic", authorization[0] @@ -67,7 +67,7 @@ class AuthorizationTest < Test::Unit::TestCase def test_authorization_header_with_password_but_no_username @conn = ActiveResource::Connection.new("http://:test123@localhost") - authorization_header = @conn.__send__(:authorization_header, :get, URI.parse('/people/2.xml')) + authorization_header = @conn.__send__(:authorization_header, :get, URI.parse('/people/2.json')) authorization = authorization_header["Authorization"].to_s.split assert_equal "Basic", authorization[0] @@ -76,7 +76,7 @@ class AuthorizationTest < Test::Unit::TestCase def test_authorization_header_with_decoded_credentials_from_url @conn = ActiveResource::Connection.new("http://my%40email.com:%31%32%33@localhost") - authorization_header = @conn.__send__(:authorization_header, :get, URI.parse('/people/2.xml')) + authorization_header = @conn.__send__(:authorization_header, :get, URI.parse('/people/2.json')) authorization = authorization_header["Authorization"].to_s.split assert_equal "Basic", authorization[0] @@ -87,7 +87,7 @@ class AuthorizationTest < Test::Unit::TestCase @authenticated_conn = ActiveResource::Connection.new("http://@localhost") @authenticated_conn.user = 'david' @authenticated_conn.password = 'test123' - authorization_header = @authenticated_conn.__send__(:authorization_header, :get, URI.parse('/people/2.xml')) + authorization_header = @authenticated_conn.__send__(:authorization_header, :get, URI.parse('/people/2.json')) assert_equal @basic_authorization_request_header['Authorization'], authorization_header['Authorization'] authorization = authorization_header["Authorization"].to_s.split @@ -98,7 +98,7 @@ class AuthorizationTest < Test::Unit::TestCase def test_authorization_header_explicitly_setting_username_but_no_password @conn = ActiveResource::Connection.new("http://@localhost") @conn.user = "david" - authorization_header = @conn.__send__(:authorization_header, :get, URI.parse('/people/2.xml')) + authorization_header = @conn.__send__(:authorization_header, :get, URI.parse('/people/2.json')) authorization = authorization_header["Authorization"].to_s.split assert_equal "Basic", authorization[0] @@ -108,7 +108,7 @@ class AuthorizationTest < Test::Unit::TestCase def test_authorization_header_explicitly_setting_password_but_no_username @conn = ActiveResource::Connection.new("http://@localhost") @conn.password = "test123" - authorization_header = @conn.__send__(:authorization_header, :get, URI.parse('/people/2.xml')) + authorization_header = @conn.__send__(:authorization_header, :get, URI.parse('/people/2.json')) authorization = authorization_header["Authorization"].to_s.split assert_equal "Basic", authorization[0] @@ -117,7 +117,7 @@ class AuthorizationTest < Test::Unit::TestCase def test_authorization_header_if_credentials_supplied_and_auth_type_is_basic @authenticated_conn.auth_type = :basic - authorization_header = @authenticated_conn.__send__(:authorization_header, :get, URI.parse('/people/2.xml')) + authorization_header = @authenticated_conn.__send__(:authorization_header, :get, URI.parse('/people/2.json')) assert_equal @basic_authorization_request_header['Authorization'], authorization_header['Authorization'] authorization = authorization_header["Authorization"].to_s.split diff --git a/activeresource/test/cases/connection_test.rb b/activeresource/test/cases/connection_test.rb index cac8710d97..09df0fb678 100644 --- a/activeresource/test/cases/connection_test.rb +++ b/activeresource/test/cases/connection_test.rb @@ -14,7 +14,7 @@ class ConnectionTest < Test::Unit::TestCase @david = david.to_json @header = { 'key' => 'value' }.freeze - @default_request_headers = { 'Content-Type' => 'application/xml' } + @default_request_headers = { 'Content-Type' => 'application/json' } ActiveResource::HttpMock.respond_to do |mock| mock.get "/people/2.json", @header, @david mock.get "/people.json", {}, @people diff --git a/activeresource/test/cases/finder_test.rb b/activeresource/test/cases/finder_test.rb index 73030339a9..9c51f2a390 100644 --- a/activeresource/test/cases/finder_test.rb +++ b/activeresource/test/cases/finder_test.rb @@ -108,9 +108,9 @@ class FinderTest < Test::Unit::TestCase end def test_find_all_by_from_with_options - ActiveResource::HttpMock.respond_to { |m| m.get "/companies/1/people.xml", {}, @people_david } + ActiveResource::HttpMock.respond_to { |m| m.get "/companies/1/people.json", {}, @people_david } - people = Person.find(:all, :from => "/companies/1/people.xml") + people = Person.find(:all, :from => "/companies/1/people.json") assert_equal 1, people.size assert_equal "David", people.first.name end diff --git a/activeresource/test/cases/http_mock_test.rb b/activeresource/test/cases/http_mock_test.rb index cd5155924a..d2fd911314 100644 --- a/activeresource/test/cases/http_mock_test.rb +++ b/activeresource/test/cases/http_mock_test.rb @@ -11,10 +11,10 @@ class HttpMockTest < ActiveSupport::TestCase [:post, :put, :get, :delete, :head].each do |method| test "responds to simple #{method} request" do ActiveResource::HttpMock.respond_to do |mock| - mock.send(method, "/people/1", {FORMAT_HEADER[method] => "application/xml"}, "Response") + mock.send(method, "/people/1", { FORMAT_HEADER[method] => "application/json" }, "Response") end - assert_equal "Response", request(method, "/people/1", FORMAT_HEADER[method] => "application/xml").body + assert_equal "Response", request(method, "/people/1", FORMAT_HEADER[method] => "application/json").body end test "adds format header by default to #{method} request" do @@ -22,7 +22,7 @@ class HttpMockTest < ActiveSupport::TestCase mock.send(method, "/people/1", {}, "Response") end - assert_equal "Response", request(method, "/people/1", FORMAT_HEADER[method] => "application/xml").body + assert_equal "Response", request(method, "/people/1", FORMAT_HEADER[method] => "application/json").body end test "respond only when headers match header by default to #{method} request" do @@ -53,8 +53,8 @@ class HttpMockTest < ActiveSupport::TestCase test "responds correctly when format header is given to #{method} request" do ActiveResource::HttpMock.respond_to do |mock| - mock.send(method, "/people/1", {FORMAT_HEADER[method] => "application/xml"}, "XML") - mock.send(method, "/people/1", {FORMAT_HEADER[method] => "application/json"}, "Json") + mock.send(method, "/people/1", { FORMAT_HEADER[method] => "application/xml" }, "XML") + mock.send(method, "/people/1", { FORMAT_HEADER[method] => "application/json" }, "Json") end assert_equal "XML", request(method, "/people/1", FORMAT_HEADER[method] => "application/xml").body @@ -63,22 +63,22 @@ class HttpMockTest < ActiveSupport::TestCase test "raises InvalidRequestError if no response found for the #{method} request" do ActiveResource::HttpMock.respond_to do |mock| - mock.send(method, "/people/1", {FORMAT_HEADER[method] => "application/xml"}, "XML") + mock.send(method, "/people/1", { FORMAT_HEADER[method] => "application/json" }, "json") end assert_raise(::ActiveResource::InvalidRequestError) do - request(method, "/people/1", FORMAT_HEADER[method] => "application/json") + request(method, "/people/1", FORMAT_HEADER[method] => "application/xml") end end end test "allows you to send in pairs directly to the respond_to method" do - matz = { :id => 1, :name => "Matz" }.to_xml(:root => "person") + matz = { :person => { :id => 1, :name => "Matz" } }.to_json - create_matz = ActiveResource::Request.new(:post, '/people.xml', matz, {}) - created_response = ActiveResource::Response.new("", 201, {"Location" => "/people/1.xml"}) - get_matz = ActiveResource::Request.new(:get, '/people/1.xml', nil) + create_matz = ActiveResource::Request.new(:post, '/people.json', matz, {}) + created_response = ActiveResource::Response.new("", 201, { "Location" => "/people/1.json" }) + get_matz = ActiveResource::Request.new(:get, '/people/1.json', nil) ok_response = ActiveResource::Response.new(matz, 200, {}) pairs = {create_matz => created_response, get_matz => ok_response} @@ -91,24 +91,24 @@ class HttpMockTest < ActiveSupport::TestCase test "resets all mocked responses on each call to respond_to with a block by default" do ActiveResource::HttpMock.respond_to do |mock| - mock.send(:get, "/people/1", {}, "XML1") + mock.send(:get, "/people/1", {}, "JSON1") end assert_equal 1, ActiveResource::HttpMock.responses.length ActiveResource::HttpMock.respond_to do |mock| - mock.send(:get, "/people/2", {}, "XML2") + mock.send(:get, "/people/2", {}, "JSON2") end assert_equal 1, ActiveResource::HttpMock.responses.length end test "resets all mocked responses on each call to respond_to by passing pairs by default" do ActiveResource::HttpMock.respond_to do |mock| - mock.send(:get, "/people/1", {}, "XML1") + mock.send(:get, "/people/1", {}, "JSON1") end assert_equal 1, ActiveResource::HttpMock.responses.length - matz = { :id => 1, :name => "Matz" }.to_xml(:root => "person") - get_matz = ActiveResource::Request.new(:get, '/people/1.xml', nil) + matz = { :person => { :id => 1, :name => "Matz" } }.to_json + get_matz = ActiveResource::Request.new(:get, '/people/1.json', nil) ok_response = ActiveResource::Response.new(matz, 200, {}) ActiveResource::HttpMock.respond_to({get_matz => ok_response}) @@ -117,24 +117,24 @@ class HttpMockTest < ActiveSupport::TestCase test "allows you to add new responses to the existing responses by calling a block" do ActiveResource::HttpMock.respond_to do |mock| - mock.send(:get, "/people/1", {}, "XML1") + mock.send(:get, "/people/1", {}, "JSON1") end assert_equal 1, ActiveResource::HttpMock.responses.length ActiveResource::HttpMock.respond_to(false) do |mock| - mock.send(:get, "/people/2", {}, "XML2") + mock.send(:get, "/people/2", {}, "JSON2") end assert_equal 2, ActiveResource::HttpMock.responses.length end test "allows you to add new responses to the existing responses by passing pairs" do ActiveResource::HttpMock.respond_to do |mock| - mock.send(:get, "/people/1", {}, "XML1") + mock.send(:get, "/people/1", {}, "JSON1") end assert_equal 1, ActiveResource::HttpMock.responses.length - matz = { :id => 1, :name => "Matz" }.to_xml(:root => "person") - get_matz = ActiveResource::Request.new(:get, '/people/1.xml', nil) + matz = { :person => { :id => 1, :name => "Matz" } }.to_json + get_matz = ActiveResource::Request.new(:get, '/people/1.json', nil) ok_response = ActiveResource::Response.new(matz, 200, {}) ActiveResource::HttpMock.respond_to({get_matz => ok_response}, false) @@ -143,23 +143,23 @@ class HttpMockTest < ActiveSupport::TestCase test "allows you to replace the existing reponse with the same request by calling a block" do ActiveResource::HttpMock.respond_to do |mock| - mock.send(:get, "/people/1", {}, "XML1") + mock.send(:get, "/people/1", {}, "JSON1") end assert_equal 1, ActiveResource::HttpMock.responses.length ActiveResource::HttpMock.respond_to(false) do |mock| - mock.send(:get, "/people/1", {}, "XML2") + mock.send(:get, "/people/1", {}, "JSON2") end assert_equal 1, ActiveResource::HttpMock.responses.length end test "allows you to replace the existing reponse with the same request by passing pairs" do ActiveResource::HttpMock.respond_to do |mock| - mock.send(:get, "/people/1", {}, "XML1") + mock.send(:get, "/people/1", {}, "JSON1") end assert_equal 1, ActiveResource::HttpMock.responses.length - matz = { :id => 1, :name => "Matz" }.to_xml(:root => "person") + matz = { :person => { :id => 1, :name => "Matz" } }.to_json get_matz = ActiveResource::Request.new(:get, '/people/1', nil) ok_response = ActiveResource::Response.new(matz, 200, {}) @@ -169,19 +169,19 @@ class HttpMockTest < ActiveSupport::TestCase test "do not replace the response with the same path but different method by calling a block" do ActiveResource::HttpMock.respond_to do |mock| - mock.send(:get, "/people/1", {}, "XML1") + mock.send(:get, "/people/1", {}, "JSON1") end assert_equal 1, ActiveResource::HttpMock.responses.length ActiveResource::HttpMock.respond_to(false) do |mock| - mock.send(:put, "/people/1", {}, "XML2") + mock.send(:put, "/people/1", {}, "JSON2") end assert_equal 2, ActiveResource::HttpMock.responses.length end test "do not replace the response with the same path but different method by passing pairs" do ActiveResource::HttpMock.respond_to do |mock| - mock.send(:get, "/people/1", {}, "XML1") + mock.send(:get, "/people/1", {}, "JSON1") end assert_equal 1, ActiveResource::HttpMock.responses.length |