aboutsummaryrefslogtreecommitdiffstats
path: root/activeresource/test/cases
diff options
context:
space:
mode:
authorGaston Ramos <ramos.gaston@gmail.com>2010-10-06 19:14:12 -0300
committerJosé Valim <jose.valim@gmail.com>2010-10-07 16:50:34 +0200
commitb9f8501f8249cdc2dc780a7a1255269c63584ef2 (patch)
tree3ca025558f6e6279f2d9eb1b83fb1080c3e3d862 /activeresource/test/cases
parent243513f4d17e62186ef0499edece1588c79220b2 (diff)
downloadrails-b9f8501f8249cdc2dc780a7a1255269c63584ef2.tar.gz
rails-b9f8501f8249cdc2dc780a7a1255269c63584ef2.tar.bz2
rails-b9f8501f8249cdc2dc780a7a1255269c63584ef2.zip
- Fix ActiveResource::HttpMock.respond_to replace the response
if it has the same request Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activeresource/test/cases')
-rw-r--r--activeresource/test/cases/http_mock_test.rb23
1 files changed, 19 insertions, 4 deletions
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)