From 2bb33bbd590b1217f0a6576de34105ab1db3510c Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 12 Jan 2007 07:20:05 +0000 Subject: 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 --- activeresource/test/base_test.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'activeresource/test') 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", {}, "#{@matz}#{@david}" mock.get "/people/1/addresses.xml", {}, "#{@addy}" 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 -- cgit v1.2.3