diff options
author | taryn <teast@globalpersonals.co.uk> | 2009-08-21 09:45:29 +0100 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2009-08-21 14:49:59 -0500 |
commit | ce61a6bd551a96205892a125c8835c4bc69c4fad (patch) | |
tree | 853cf3ffa9676d3535e49d2cd06b04033423c32b /activeresource/test | |
parent | 8bc3a147270546325458da65ae6f5e83dd260aeb (diff) | |
download | rails-ce61a6bd551a96205892a125c8835c4bc69c4fad.tar.gz rails-ce61a6bd551a96205892a125c8835c4bc69c4fad.tar.bz2 rails-ce61a6bd551a96205892a125c8835c4bc69c4fad.zip |
Added first/last/all aliases for equivalent find scopes
Just a copy from Active Record (with tests). Each is a warpper function for
the equivalent scoped call to find eg first is a wrapper for find(:first)
Signed-off-by: Joshua Peek <josh@joshpeek.com>
Diffstat (limited to 'activeresource/test')
-rw-r--r-- | activeresource/test/cases/finder_test.rb | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/activeresource/test/cases/finder_test.rb b/activeresource/test/cases/finder_test.rb index 38f7de96ac..535b6f4198 100644 --- a/activeresource/test/cases/finder_test.rb +++ b/activeresource/test/cases/finder_test.rb @@ -126,18 +126,56 @@ class FinderTest < Test::Unit::TestCase assert_equal "David", all.last.name end + def test_all + all = Person.all + assert_equal 2, all.size + assert_kind_of Person, all.first + assert_equal "Matz", all.first.name + assert_equal "David", all.last.name + end + + def test_all_with_params + all = StreetAddress.all(:params => { :person_id => 1 }) + assert_equal 1, all.size + assert_kind_of StreetAddress, all.first + end + def test_find_first matz = Person.find(:first) assert_kind_of Person, matz assert_equal "Matz", matz.name end + def test_first + matz = Person.first + assert_kind_of Person, matz + assert_equal "Matz", matz.name + end + + def test_first_with_params + addy = StreetAddress.first(:params => { :person_id => 1 }) + assert_kind_of StreetAddress, addy + assert_equal '12345 Street', addy.street + end + def test_find_last david = Person.find(:last) assert_kind_of Person, david assert_equal 'David', david.name end + def test_last + david = Person.last + assert_kind_of Person, david + assert_equal 'David', david.name + end + + def test_last_with_params + addy = StreetAddress.last(:params => { :person_id => 1 }) + assert_kind_of StreetAddress, addy + assert_equal '12345 Street', addy.street + end + def test_find_by_id_not_found assert_raise(ActiveResource::ResourceNotFound) { Person.find(99) } assert_raise(ActiveResource::ResourceNotFound) { StreetAddress.find(1) } |