diff options
author | Mikel Lindsaar <raasdnil@gmail.com> | 2010-08-30 15:35:15 +1000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2010-08-29 22:54:19 -0700 |
commit | a2996422935e46f68087b6bb11f70919b086c35f (patch) | |
tree | 5ef6d6bb5e778ae42a50b71e804b833d26a42081 /activeresource/test | |
parent | b8619426916fdad32ab743f1c0b42dd19d4ebe71 (diff) | |
download | rails-a2996422935e46f68087b6bb11f70919b086c35f.tar.gz rails-a2996422935e46f68087b6bb11f70919b086c35f.tar.bz2 rails-a2996422935e46f68087b6bb11f70919b086c35f.zip |
Updating documentation on ActiveResource HTTP Mock and also adding test coverage
Diffstat (limited to 'activeresource/test')
-rw-r--r-- | activeresource/test/cases/http_mock_test.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/activeresource/test/cases/http_mock_test.rb b/activeresource/test/cases/http_mock_test.rb index a387cd20b1..be0568b1a9 100644 --- a/activeresource/test/cases/http_mock_test.rb +++ b/activeresource/test/cases/http_mock_test.rb @@ -72,6 +72,34 @@ class HttpMockTest < ActiveSupport::TestCase 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 + assert_equal matz, ActiveResource::HttpMock.responses.assoc(get_matz)[1].body + end + + test "resets all mocked responses on each call to respond_to by default" do + ActiveResource::HttpMock.respond_to do |mock| + mock.send(:get, "/people/1", {}, "XML1") + end + assert_equal 1, ActiveResource::HttpMock.responses.length + + ActiveResource::HttpMock.respond_to do |mock| + mock.send(:get, "/people/2", {}, "XML2") + end + 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) |