aboutsummaryrefslogtreecommitdiffstats
path: root/activeresource/test
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2007-01-12 07:20:05 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2007-01-12 07:20:05 +0000
commit2bb33bbd590b1217f0a6576de34105ab1db3510c (patch)
tree4133c16561bfdb8f9c99b7e6f15b6b074826515e /activeresource/test
parentfa619b051b5e12c6b1e8b91a32d6738edafcc3af (diff)
downloadrails-2bb33bbd590b1217f0a6576de34105ab1db3510c.tar.gz
rails-2bb33bbd590b1217f0a6576de34105ab1db3510c.tar.bz2
rails-2bb33bbd590b1217f0a6576de34105ab1db3510c.zip
Base.exists?(id, options) and Base#exists? check whether the resource is found. Closes #6970.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5898 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activeresource/test')
-rw-r--r--activeresource/test/base_test.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/activeresource/test/base_test.rb b/activeresource/test/base_test.rb
index a8c9454476..f9f2b24c72 100644
--- a/activeresource/test/base_test.rb
+++ b/activeresource/test/base_test.rb
@@ -21,6 +21,8 @@ class BaseTest < Test::Unit::TestCase
mock.get "/people.xml", {}, "<people>#{@matz}#{@david}</people>"
mock.get "/people/1/addresses.xml", {}, "<addresses>#{@addy}</addresses>"
mock.get "/people/1/addresses/1.xml", {}, @addy
+ mock.get "/people/1/addresses/2.xml", {}, nil, 404
+ mock.get "/people/2/addresses/1.xml", {}, nil, 404
mock.put "/people/1/addresses/1.xml", {}, nil, 204
mock.delete "/people/1/addresses/1.xml", {}, nil, 200
mock.post "/people/1/addresses.xml", {}, nil, 201, 'Location' => '/people/1/addresses/5'
@@ -237,4 +239,26 @@ class BaseTest < Test::Unit::TestCase
def test_delete
assert Person.delete(1)
end
+
+ def test_exists
+ # Class method.
+ assert !Person.exists?(nil)
+ assert Person.exists?(1)
+ assert !Person.exists?(99)
+
+ # Instance method.
+ assert !Person.new.exists?
+ assert Person.find(1).exists?
+ assert !Person.new(:id => 99).exists?
+
+ # Nested class method.
+ assert StreetAddress.exists?(1, :person_id => 1)
+ assert !StreetAddress.exists?(1, :person_id => 2)
+ assert !StreetAddress.exists?(2, :person_id => 1)
+
+ # Nested instance method.
+ assert StreetAddress.find(1, :person_id => 1).exists?
+ assert !StreetAddress.new({:id => 1}, {:person_id => 2}).exists?
+ assert !StreetAddress.new({:id => 2}, {:person_id => 1}).exists?
+ end
end