aboutsummaryrefslogtreecommitdiffstats
path: root/activeresource/test
diff options
context:
space:
mode:
authortaryn <teast@globalpersonals.co.uk>2009-08-19 12:20:30 +0100
committerJoshua Peek <josh@joshpeek.com>2009-08-19 09:04:48 -0500
commit4dc05bc8a9824b9404cebecaba28f9f248f9995e (patch)
tree99d222d011c9564d33787dd433d18c0e52d808c2 /activeresource/test
parent079ed8fc43b22529f456ef26599099ae1ed6337d (diff)
downloadrails-4dc05bc8a9824b9404cebecaba28f9f248f9995e.tar.gz
rails-4dc05bc8a9824b9404cebecaba28f9f248f9995e.tar.bz2
rails-4dc05bc8a9824b9404cebecaba28f9f248f9995e.zip
Swallow ResourceNotFound error on find_every
Active Record does not explode with RecordNotFound if you go looking for a collection of objects - it just returns nil. Thus Active Resource should also not explode. After all - finding no objects that match a set of conditions is not exceptional behaviour - unlike looking for a specific object with a given id (which you'd expect to exist). I've also added documentation to +find+ to reflect this. Signed-off-by: Joshua Peek <josh@joshpeek.com>
Diffstat (limited to 'activeresource/test')
-rw-r--r--activeresource/test/cases/finder_test.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/activeresource/test/cases/finder_test.rb b/activeresource/test/cases/finder_test.rb
index a3083101db..38f7de96ac 100644
--- a/activeresource/test/cases/finder_test.rb
+++ b/activeresource/test/cases/finder_test.rb
@@ -79,6 +79,7 @@ class FinderTest < Test::Unit::TestCase
mock.get "/people/1/addresses.xml", {}, @addresses
mock.get "/people/1/addresses/1.xml", {}, @addy
mock.get "/people/1/addresses/2.xml", {}, nil, 404
+ mock.get "/people/2/addresses.xml", {}, nil, 404
mock.get "/people/2/addresses/1.xml", {}, nil, 404
mock.get "/people/Greg/addresses/1.xml", {}, @addy
mock.put "/people/1/addresses/1.xml", {}, nil, 204
@@ -142,6 +143,18 @@ class FinderTest < Test::Unit::TestCase
assert_raise(ActiveResource::ResourceNotFound) { StreetAddress.find(1) }
end
+ def test_find_all_sub_objects
+ all = StreetAddress.find(:all, :params => { :person_id => 1 })
+ assert_equal 1, all.size
+ assert_kind_of StreetAddress, all.first
+ end
+
+ def test_find_all_sub_objects_not_found
+ assert_nothing_raised do
+ addys = StreetAddress.find(:all, :params => { :person_id => 2 })
+ end
+ end
+
def test_find_all_by_from
ActiveResource::HttpMock.respond_to { |m| m.get "/companies/1/people.xml", {}, @people_david }