aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/transactions_test.rb
diff options
context:
space:
mode:
authorGodfrey Chan <godfreykfc@gmail.com>2012-05-21 14:57:04 -0700
committerGodfrey Chan <godfreykfc@gmail.com>2012-05-21 14:57:04 -0700
commitcb847b9f2e56eeff737323d9a42a2a0a6c23804d (patch)
treec22d2cf52201134bea2e32bc15706b0d998d8133 /activerecord/test/cases/transactions_test.rb
parent03886d817307e091024ff3bd26844447abd8c408 (diff)
downloadrails-cb847b9f2e56eeff737323d9a42a2a0a6c23804d.tar.gz
rails-cb847b9f2e56eeff737323d9a42a2a0a6c23804d.tar.bz2
rails-cb847b9f2e56eeff737323d9a42a2a0a6c23804d.zip
Restore the frozen state on rollback. Fixes #6417.
Currently, when saving a frozen record, an exception would be thrown which causes a rollback. However, there is a bug in active record that "defrost" the record as a side effect: >> t = Topic.new => #<Topic id: nil, ...> >> t.freeze => #<Topic id: nil, ...> >> t.save RuntimeError: can't modify a frozen Hash >> t.frozen? => false >> t.save => true This patch fixes the bug by explictly restoring the frozen state on the attributes Hash after every rollback.
Diffstat (limited to 'activerecord/test/cases/transactions_test.rb')
-rw-r--r--activerecord/test/cases/transactions_test.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/activerecord/test/cases/transactions_test.rb b/activerecord/test/cases/transactions_test.rb
index 203dd054f1..a9ccd00fac 100644
--- a/activerecord/test/cases/transactions_test.rb
+++ b/activerecord/test/cases/transactions_test.rb
@@ -362,6 +362,16 @@ class TransactionTest < ActiveRecord::TestCase
end
end
+ def test_rollback_when_saving_a_frozen_record
+ topic = Topic.new(:title => 'test')
+ topic.freeze
+ e = assert_raise(RuntimeError) { topic.save }
+ assert_equal "can't modify frozen Hash", e.message
+ assert !topic.persisted?, 'not persisted'
+ assert_nil topic.id
+ assert topic.frozen?, 'not frozen'
+ end
+
def test_restore_active_record_state_for_all_records_in_a_transaction
topic_1 = Topic.new(:title => 'test_1')
topic_2 = Topic.new(:title => 'test_2')