aboutsummaryrefslogtreecommitdiffstats
path: root/activeresource/test
diff options
context:
space:
mode:
authorJacques Crocker <railsjedi@gmail.com>2010-09-18 03:09:37 -0700
committerJosé Valim <jose.valim@gmail.com>2010-09-25 13:54:09 +0200
commit51f1f550dab47c6ec3dcdba7b153258e2a0feb69 (patch)
tree8502e35b46ddff65795db6c20edcf0768b56dc7f /activeresource/test
parentee5ef67c443407f616feef3a8cade8ba3a9d6ef0 (diff)
downloadrails-51f1f550dab47c6ec3dcdba7b153258e2a0feb69.tar.gz
rails-51f1f550dab47c6ec3dcdba7b153258e2a0feb69.tar.bz2
rails-51f1f550dab47c6ec3dcdba7b153258e2a0feb69.zip
Allow per Resource format settings
Previously, ActiveResource was using the connection level formatter for get requests. This made it impossible to use custom formatters per resource. Additionally this commit makes the Connection request methods more consistent. It always returns a Response. The base will then decode it each the response using its format setting. Merging this commit will allow users to add custom formatters on a per Resource basis. This enables handling pagination responses from the server side, a very common use case that was previously impossible without monkeypatching XmlFormat. Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activeresource/test')
-rw-r--r--activeresource/test/cases/authorization_test.rb12
-rw-r--r--activeresource/test/connection_test.rb14
2 files changed, 17 insertions, 9 deletions
diff --git a/activeresource/test/cases/authorization_test.rb b/activeresource/test/cases/authorization_test.rb
index 1a7c9ec8a4..a6797643e1 100644
--- a/activeresource/test/cases/authorization_test.rb
+++ b/activeresource/test/cases/authorization_test.rb
@@ -132,7 +132,7 @@ class AuthorizationTest < Test::Unit::TestCase
end
def test_get
- david = @authenticated_conn.get("/people/2.xml")
+ david = decode(@authenticated_conn.get("/people/2.xml"))
assert_equal "David", david["name"]
end
@@ -159,7 +159,7 @@ class AuthorizationTest < Test::Unit::TestCase
def test_get_with_digest_auth_handles_initial_401_response_and_retries
@authenticated_conn.auth_type = :digest
response = @authenticated_conn.get("/people/2.xml")
- assert_equal "David", response["name"]
+ assert_equal "David", decode(response)["name"]
end
def test_post_with_digest_auth_handles_initial_401_response_and_retries
@@ -190,11 +190,11 @@ class AuthorizationTest < Test::Unit::TestCase
def test_get_with_digest_auth_caches_nonce
@authenticated_conn.auth_type = :digest
response = @authenticated_conn.get("/people/2.xml")
- assert_equal "David", response["name"]
+ assert_equal "David", decode(response)["name"]
# There is no mock for this request with a non-cached nonce.
response = @authenticated_conn.get("/people/1.xml")
- assert_equal "Matz", response["name"]
+ assert_equal "Matz", decode(response)["name"]
end
def test_retry_on_401_only_happens_with_digest_auth
@@ -241,4 +241,8 @@ class AuthorizationTest < Test::Unit::TestCase
def response_digest_auth_header
%Q(Digest realm="RailsTestApp", qop="auth", algorithm=MD5, nonce="#{@nonce}", opaque="ef6dfb078ba22298d366f99567814ffb")
end
+
+ def decode(response)
+ @authenticated_conn.format.decode(response.body)
+ end
end
diff --git a/activeresource/test/connection_test.rb b/activeresource/test/connection_test.rb
index 1b4b61899d..fe80cdf2e5 100644
--- a/activeresource/test/connection_test.rb
+++ b/activeresource/test/connection_test.rb
@@ -120,7 +120,7 @@ class ConnectionTest < Test::Unit::TestCase
end
def test_get
- matz = @conn.get("/people/1.xml")
+ matz = decode(@conn.get("/people/1.xml"))
assert_equal "Matz", matz["name"]
end
@@ -131,23 +131,23 @@ class ConnectionTest < Test::Unit::TestCase
end
def test_get_with_header
- david = @conn.get("/people/2.xml", @header)
+ david = decode(@conn.get("/people/2.xml", @header))
assert_equal "David", david["name"]
end
def test_get_collection
- people = @conn.get("/people.xml")
+ people = decode(@conn.get("/people.xml"))
assert_equal "Matz", people[0]["name"]
assert_equal "David", people[1]["name"]
end
def test_get_collection_single
- people = @conn.get("/people_single_elements.xml")
+ people = decode(@conn.get("/people_single_elements.xml"))
assert_equal "Matz", people[0]["name"]
end
def test_get_collection_empty
- people = @conn.get("/people_empty_elements.xml")
+ people = decode(@conn.get("/people_empty_elements.xml"))
assert_equal [], people
end
@@ -250,4 +250,8 @@ class ConnectionTest < Test::Unit::TestCase
def handle_response(response)
@conn.__send__(:handle_response, response)
end
+
+ def decode(response)
+ @conn.format.decode(response.body)
+ end
end