Remove ActiveRecord monkey patch when it's no longer needed
config/initializers/ar_monkey_patch.rb it fixes the bug https://github.com/rails/rails/issues/26024
Check the status of the issue and if it's already fixed remove the monkey patch.
Just in case, check this tests (it's aready covered with GitLab tests though ):
require 'active_record'
require 'minitest/autorun'
require 'sqlite3'
require 'logger'
ActiveRecord::Base.establish_connection 'sqlite3::memory:'
ActiveRecord::Schema.define do
create_table :posts do |t|
t.string :name
t.integer :lock_version
end
end
class Post < ActiveRecord::Base
end
class BugTest < Minitest::Test
def test_lock_version_without_default_value
Post.destroy_all
#Post.create!(name: 'First')
ActiveRecord::Base.connection.execute("insert into posts(name) VALUES('Mark')")
p1 = Post.first
p1.name = "Michael"
p1.save
end
def test_lock_version_without_default_value1
Post.destroy_all
Post.create!(name: 'First')
p1 = Post.first
p1.update(name: "Michael")
end
def test_lock_version_without_default_value_when_form_submit
Post.destroy_all
ActiveRecord::Base.connection.execute("insert into posts(name) VALUES('Mark')")
p1 = Post.first
p1.update_attributes(name: "Bob", lock_version: 0)
p1.save!
end
def test_lock_version_without_default_value_when_form_submit1
Post.destroy_all
ActiveRecord::Base.connection.execute("insert into posts(name) VALUES('Mark')")
p1 = Post.first
p1.update_attributes(name: "Bob", lock_version: '0')
p1.save!
end
end