diff options
author | Rick Olson <technoweenie@gmail.com> | 2007-04-29 03:14:36 +0000 |
---|---|---|
committer | Rick Olson <technoweenie@gmail.com> | 2007-04-29 03:14:36 +0000 |
commit | bd50d82f701c55d89b891ebd216ec84008b486c1 (patch) | |
tree | 5d9a4fc7dbf8e48088e66d2dc4de7ec76955f440 /activeresource/test | |
parent | 1162c29e308eb064c305a06262b8a47e2e0f1b48 (diff) | |
download | rails-bd50d82f701c55d89b891ebd216ec84008b486c1.tar.gz rails-bd50d82f701c55d89b891ebd216ec84008b486c1.tar.bz2 rails-bd50d82f701c55d89b891ebd216ec84008b486c1.zip |
Add support for setting custom headers per ActiveResource model [Rick]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6624 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activeresource/test')
-rw-r--r-- | activeresource/test/base_test.rb | 8 | ||||
-rw-r--r-- | activeresource/test/connection_test.rb | 25 |
2 files changed, 33 insertions, 0 deletions
diff --git a/activeresource/test/base_test.rb b/activeresource/test/base_test.rb index 51e1dd3c04..2c823e8e69 100644 --- a/activeresource/test/base_test.rb +++ b/activeresource/test/base_test.rb @@ -13,6 +13,7 @@ class BaseTest < Test::Unit::TestCase ActiveResource::HttpMock.respond_to do |mock| mock.get "/people/1.xml", {}, @matz mock.get "/people/2.xml", {}, @david + mock.get "/people/3.xml", {'key' => 'value'}, nil, 404 mock.put "/people/1.xml", {}, nil, 204 mock.delete "/people/1.xml", {}, nil, 200 mock.delete "/people/2.xml", {}, nil, 400 @@ -198,6 +199,13 @@ class BaseTest < Test::Unit::TestCase assert_equal "Matz", matz.name end + def test_custom_header + Person.custom_headers['key'] = 'value' + assert_raises(ActiveResource::ResourceNotFound) { Person.find(3) } + ensure + Person.custom_headers.delete('key') + end + def test_find_by_id_not_found assert_raises(ActiveResource::ResourceNotFound) { Person.find(99) } assert_raises(ActiveResource::ResourceNotFound) { StreetAddress.find(1) } diff --git a/activeresource/test/connection_test.rb b/activeresource/test/connection_test.rb index b434dd4012..67d5553e72 100644 --- a/activeresource/test/connection_test.rb +++ b/activeresource/test/connection_test.rb @@ -13,16 +13,21 @@ class ConnectionTest < Test::Unit::TestCase @people_empty = [ ].to_xml(:root => 'people-empty-elements') @matz = @matz.to_xml(:root => 'person') @david = @david.to_xml(:root => 'person') + @header = {'key' => 'value'} @default_request_headers = { 'Content-Type' => 'application/xml' } ActiveResource::HttpMock.respond_to do |mock| + mock.get "/people/2.xml", @header, @david mock.get "/people.xml", {}, @people mock.get "/people_single_elements.xml", {}, @people_single mock.get "/people_empty_elements.xml", {}, @people_empty mock.get "/people/1.xml", {}, @matz mock.put "/people/1.xml", {}, nil, 204 + mock.put "/people/2.xml", {}, @header, 204 mock.delete "/people/1.xml", {}, nil, 200 + mock.delete "/people/2.xml", @header, nil, 200 mock.post "/people.xml", {}, nil, 201, 'Location' => '/people/5.xml' + mock.post "/members.xml", {}, @header, 201, 'Location' => '/people/6.xml' end end @@ -79,6 +84,11 @@ class ConnectionTest < Test::Unit::TestCase assert_equal "Matz", matz["name"] end + def test_get_with_header + david = @conn.get("/people/2.xml", @header) + assert_equal "David", david["name"] + end + def test_get_collection people = @conn.get("/people.xml") assert_equal "Matz", people[0]["name"] @@ -100,16 +110,31 @@ class ConnectionTest < Test::Unit::TestCase assert_equal "/people/5.xml", response["Location"] end + def test_post_with_header + response = @conn.post("/members.xml", @header) + assert_equal "/people/6.xml", response["Location"] + end + def test_put response = @conn.put("/people/1.xml") assert_equal 204, response.code end + def test_put_with_header + response = @conn.put("/people/2.xml", @header) + assert_equal 204, response.code + end + def test_delete response = @conn.delete("/people/1.xml") assert_equal 200, response.code end + def test_delete_with_header + response = @conn.delete("/people/2.xml", @header) + assert_equal 200, response.code + end + protected def assert_response_raises(klass, code) assert_raise(klass, "Expected response code #{code} to raise #{klass}") do |