From b9f8501f8249cdc2dc780a7a1255269c63584ef2 Mon Sep 17 00:00:00 2001 From: Gaston Ramos Date: Wed, 6 Oct 2010 19:14:12 -0300 Subject: - Fix ActiveResource::HttpMock.respond_to replace the response if it has the same request MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- activeresource/test/cases/http_mock_test.rb | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'activeresource/test') diff --git a/activeresource/test/cases/http_mock_test.rb b/activeresource/test/cases/http_mock_test.rb index d90d1e01b8..f15ad04b9a 100644 --- a/activeresource/test/cases/http_mock_test.rb +++ b/activeresource/test/cases/http_mock_test.rb @@ -69,19 +69,19 @@ class HttpMockTest < ActiveSupport::TestCase request(method, "/people/1", FORMAT_HEADER[method] => "application/json") 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") - + 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) ok_response = ActiveResource::Response.new(matz, 200, {}) - + pairs = {create_matz => created_response, get_matz => ok_response} - + ActiveResource::HttpMock.respond_to(pairs) assert_equal 2, ActiveResource::HttpMock.responses.length assert_equal "", ActiveResource::HttpMock.responses.assoc(create_matz)[1].body @@ -140,6 +140,21 @@ class HttpMockTest < ActiveSupport::TestCase assert_equal 2, ActiveResource::HttpMock.responses.length end + test "allows you to add replace the existing reponese with the same path" do + ActiveResource::HttpMock.respond_to do |mock| + mock.send(:get, "/people/1", {}, "XML1") + 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', nil) + ok_response = ActiveResource::Response.new(matz, 200, {}) + + ActiveResource::HttpMock.respond_to({get_matz => ok_response}, false) + + assert_equal 1, ActiveResource::HttpMock.responses.length + end + def request(method, path, headers = {}, body = nil) if [:put, :post].include? method @http.send(method, path, body, headers) -- cgit v1.2.3