aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2017-06-20 17:41:00 -0400
committerGitHub <noreply@github.com>2017-06-20 17:41:00 -0400
commit890de7705257323d05c8831b8c1ab43433b0ba89 (patch)
tree1359497c4fe8798416dc51acd96de4456c7b890c /activerecord/test
parentec8e38943b360312c8db97ca5d1ad4b09eba6683 (diff)
parentf08bc757ebe108df46d76d6fd0029546539f817f (diff)
downloadrails-890de7705257323d05c8831b8c1ab43433b0ba89.tar.gz
rails-890de7705257323d05c8831b8c1ab43433b0ba89.tar.bz2
rails-890de7705257323d05c8831b8c1ab43433b0ba89.zip
Merge pull request #28926 from bogdanvlviv/fix-destroy-with-locking_column-value-null
Fix destroy with locking_column value null
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/locking_test.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/activerecord/test/cases/locking_test.rb b/activerecord/test/cases/locking_test.rb
index 2b139a5da4..703487db35 100644
--- a/activerecord/test/cases/locking_test.rb
+++ b/activerecord/test/cases/locking_test.rb
@@ -453,6 +453,31 @@ class OptimisticLockingWithSchemaChangeTest < ActiveRecord::TestCase
PersonalLegacyThing.reset_column_information
end
+ def test_destroy_existing_object_with_locking_column_value_null_in_the_database
+ ActiveRecord::Base.connection.execute("INSERT INTO lock_without_defaults(title) VALUES('title1')")
+ t1 = LockWithoutDefault.last
+
+ assert_equal 0, t1.lock_version
+ assert_nil t1.lock_version_before_type_cast
+
+ t1.destroy
+
+ assert t1.destroyed?
+ end
+
+ def test_destroy_stale_object
+ t1 = LockWithoutDefault.create!(title: "title1")
+ stale_object = LockWithoutDefault.find(t1.id)
+
+ t1.update!(title: "title2")
+
+ assert_raises(ActiveRecord::StaleObjectError) do
+ stale_object.destroy!
+ end
+
+ refute stale_object.destroyed?
+ end
+
private
def add_counter_column_to(model, col = "test_count")