aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/finder_test.rb
diff options
context:
space:
mode:
authorZev Blut <zblut@cerego.co.jp>2014-06-18 11:44:00 +0900
committerZev Blut <zblut@cerego.co.jp>2014-06-18 11:44:00 +0900
commit2ea51a1ae69083c1a2712f6b2bc47130249e02cb (patch)
tree5de5b3390cbf27620756c180c838a5ba285cd527 /activerecord/test/cases/finder_test.rb
parentfcd0ac066e0959a9f4fa4459a27e041abe8eb52a (diff)
downloadrails-2ea51a1ae69083c1a2712f6b2bc47130249e02cb.tar.gz
rails-2ea51a1ae69083c1a2712f6b2bc47130249e02cb.tar.bz2
rails-2ea51a1ae69083c1a2712f6b2bc47130249e02cb.zip
Update RecordNotFound exception cases to include a message with the
Model that the Record was not found in.
Diffstat (limited to 'activerecord/test/cases/finder_test.rb')
-rw-r--r--activerecord/test/cases/finder_test.rb28
1 files changed, 18 insertions, 10 deletions
diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb
index 0f52f2c0fc..2657774291 100644
--- a/activerecord/test/cases/finder_test.rb
+++ b/activerecord/test/cases/finder_test.rb
@@ -248,7 +248,7 @@ class FinderTest < ActiveRecord::TestCase
end
def test_take_bang_missing
- assert_raises ActiveRecord::RecordNotFound do
+ assert_raises_with_message ActiveRecord::RecordNotFound, "Couldn't find Topic" do
Topic.where("title = 'This title does not exist'").take!
end
end
@@ -268,7 +268,7 @@ class FinderTest < ActiveRecord::TestCase
end
def test_first_bang_missing
- assert_raises ActiveRecord::RecordNotFound do
+ assert_raises_with_message ActiveRecord::RecordNotFound, "Couldn't find Topic" do
Topic.where("title = 'This title does not exist'").first!
end
end
@@ -282,7 +282,7 @@ class FinderTest < ActiveRecord::TestCase
def test_model_class_responds_to_first_bang
assert Topic.first!
Topic.delete_all
- assert_raises ActiveRecord::RecordNotFound do
+ assert_raises_with_message ActiveRecord::RecordNotFound, "Couldn't find Topic" do
Topic.first!
end
end
@@ -304,7 +304,7 @@ class FinderTest < ActiveRecord::TestCase
def test_model_class_responds_to_second_bang
assert Topic.second!
Topic.delete_all
- assert_raises ActiveRecord::RecordNotFound do
+ assert_raises_with_message ActiveRecord::RecordNotFound, "Couldn't find Topic" do
Topic.second!
end
end
@@ -326,7 +326,7 @@ class FinderTest < ActiveRecord::TestCase
def test_model_class_responds_to_third_bang
assert Topic.third!
Topic.delete_all
- assert_raises ActiveRecord::RecordNotFound do
+ assert_raises_with_message ActiveRecord::RecordNotFound, "Couldn't find Topic" do
Topic.third!
end
end
@@ -348,7 +348,7 @@ class FinderTest < ActiveRecord::TestCase
def test_model_class_responds_to_fourth_bang
assert Topic.fourth!
Topic.delete_all
- assert_raises ActiveRecord::RecordNotFound do
+ assert_raises_with_message ActiveRecord::RecordNotFound, "Couldn't find Topic" do
Topic.fourth!
end
end
@@ -370,7 +370,7 @@ class FinderTest < ActiveRecord::TestCase
def test_model_class_responds_to_fifth_bang
assert Topic.fifth!
Topic.delete_all
- assert_raises ActiveRecord::RecordNotFound do
+ assert_raises_with_message ActiveRecord::RecordNotFound, "Couldn't find Topic" do
Topic.fifth!
end
end
@@ -382,14 +382,14 @@ class FinderTest < ActiveRecord::TestCase
end
def test_last_bang_missing
- assert_raises ActiveRecord::RecordNotFound do
+ assert_raises_with_message ActiveRecord::RecordNotFound, "Couldn't find Topic" do
Topic.where("title = 'This title does not exist'").last!
end
end
def test_model_class_responds_to_last_bang
assert_equal topics(:fifth), Topic.last!
- assert_raises ActiveRecord::RecordNotFound do
+ assert_raises_with_message ActiveRecord::RecordNotFound, "Couldn't find Topic" do
Topic.delete_all
Topic.last!
end
@@ -760,7 +760,9 @@ class FinderTest < ActiveRecord::TestCase
def test_find_by_one_attribute_bang
assert_equal topics(:first), Topic.find_by_title!("The First Topic")
- assert_raise(ActiveRecord::RecordNotFound) { Topic.find_by_title!("The First Topic!") }
+ assert_raises_with_message(ActiveRecord::RecordNotFound, "Couldn't find Topic") do
+ Topic.find_by_title!("The First Topic!")
+ end
end
def test_find_by_on_attribute_that_is_a_reserved_word
@@ -1029,4 +1031,10 @@ class FinderTest < ActiveRecord::TestCase
end
end)
end
+
+ def assert_raises_with_message(exception_class, message, &block)
+ err = assert_raises(exception_class) { block.call }
+ assert_match message, err.message
+ end
+
end