aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/finder_test.rb
diff options
context:
space:
mode:
authorJosh Susser <josh@hasmanythrough.com>2011-03-23 21:52:53 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2011-03-24 09:55:51 -0700
commit5214e73850916de3c9127d35a4ecee0424d364a3 (patch)
tree74fa9ff9524a51701cfa23f708b3f777c65b7fe5 /activerecord/test/cases/finder_test.rb
parent9772de8d459960cc114c5b214343b7ce08fea21c (diff)
downloadrails-5214e73850916de3c9127d35a4ecee0424d364a3.tar.gz
rails-5214e73850916de3c9127d35a4ecee0424d364a3.tar.bz2
rails-5214e73850916de3c9127d35a4ecee0424d364a3.zip
add #first! and #last! to models & relations
Diffstat (limited to 'activerecord/test/cases/finder_test.rb')
-rw-r--r--activerecord/test/cases/finder_test.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb
index 2e620d8b03..543981b4a0 100644
--- a/activerecord/test/cases/finder_test.rb
+++ b/activerecord/test/cases/finder_test.rb
@@ -191,6 +191,30 @@ class FinderTest < ActiveRecord::TestCase
assert_nil Topic.where("title = 'The Second Topic of the day!'").first
end
+ def test_first_bang_present
+ assert_nothing_raised do
+ assert_equal topics(:second), Topic.where("title = 'The Second Topic of the day'").first!
+ end
+ end
+
+ def test_first_bang_missing
+ assert_raises ActiveRecord::RecordNotFound do
+ Topic.where("title = 'This title does not exist'").first!
+ end
+ end
+
+ def test_last_bang_present
+ assert_nothing_raised do
+ assert_equal topics(:second), Topic.where("title = 'The Second Topic of the day'").last!
+ end
+ end
+
+ def test_last_bang_missing
+ assert_raises ActiveRecord::RecordNotFound do
+ Topic.where("title = 'This title does not exist'").last!
+ end
+ end
+
def test_unexisting_record_exception_handling
assert_raise(ActiveRecord::RecordNotFound) {
Topic.find(1).parent