aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorYuki Nishijima <mail@yukinishijima.net>2015-01-06 04:31:08 -0800
committerYuki Nishijima <mail@yukinishijima.net>2015-05-01 19:01:41 -0700
commitad5824bde0f63d5bb2e33b7fe86904d1fbd7ff95 (patch)
tree6a3dc7ce4fce9afe9e54c11d9a573bff8d3297fe /activerecord/test/cases
parent2e7fd4a8661960434ccaad71c8afb4ef26281d21 (diff)
downloadrails-ad5824bde0f63d5bb2e33b7fe86904d1fbd7ff95.tar.gz
rails-ad5824bde0f63d5bb2e33b7fe86904d1fbd7ff95.tar.bz2
rails-ad5824bde0f63d5bb2e33b7fe86904d1fbd7ff95.zip
AR::RecordNotSaved & RecordNotDestroyed should include an error message
When `AR::Base.save!` or `AR::Base.destroy!` is called and an exception is raised, the exception doesn't have any error message or has a weird message like `#<FailedBulb:0x0000000907b4b8>`. Give a better message so we can easily understand why it's failing to save/destroy.
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/associations/has_many_associations_test.rb3
-rw-r--r--activerecord/test/cases/callbacks_test.rb2
2 files changed, 4 insertions, 1 deletions
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb
index 14cdf37f46..2c4e2a875c 100644
--- a/activerecord/test/cases/associations/has_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_associations_test.rb
@@ -2131,11 +2131,12 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
car = Car.create!
original_child = FailedBulb.create!(car: car)
- assert_raise(ActiveRecord::RecordNotDestroyed) do
+ error = assert_raise(ActiveRecord::RecordNotDestroyed) do
car.failed_bulbs = [FailedBulb.create!]
end
assert_equal [original_child], car.reload.failed_bulbs
+ assert_equal "Failed to destroy the record", error.message
end
test 'updates counter cache when default scope is given' do
diff --git a/activerecord/test/cases/callbacks_test.rb b/activerecord/test/cases/callbacks_test.rb
index 3ae4a6eade..73ac30e547 100644
--- a/activerecord/test/cases/callbacks_test.rb
+++ b/activerecord/test/cases/callbacks_test.rb
@@ -451,6 +451,7 @@ class CallbacksTest < ActiveRecord::TestCase
assert !david.save
exc = assert_raise(ActiveRecord::RecordNotSaved) { david.save! }
assert_equal exc.record, david
+ assert_equal "Failed to save the record", exc.message
end
david = ImmutableDeveloper.find(1)
@@ -494,6 +495,7 @@ class CallbacksTest < ActiveRecord::TestCase
assert !david.destroy
exc = assert_raise(ActiveRecord::RecordNotDestroyed) { david.destroy! }
assert_equal exc.record, david
+ assert_equal "Failed to destroy the record", exc.message
end
assert_not_nil ImmutableDeveloper.find_by_id(1)