Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Deprecate set_locking_column in favour of self.locking_column=

  • Loading branch information...
commit f3c84dc31692204aacac3c125dcfcc986fd961a0 1 parent 1a474cc
@jonleighton jonleighton authored
View
1  activerecord/CHANGELOG.md
@@ -6,6 +6,7 @@
* `set_inheritance_column`
* `set_sequence_name`
* `set_primary_key`
+ * `set_locking_column`
Use an assignment method instead. For example, instead of `set_table_name`, use `self.table_name=`:
View
21 activerecord/lib/active_record/locking/optimistic.rb
@@ -51,10 +51,6 @@ module Optimistic
included do
cattr_accessor :lock_optimistically, :instance_writer => false
self.lock_optimistically = true
-
- class << self
- alias_method :locking_column=, :set_locking_column
- end
end
def locking_enabled? #:nodoc:
@@ -148,15 +144,24 @@ def locking_enabled?
lock_optimistically && columns_hash[locking_column]
end
+ def locking_column=(value)
+ @original_locking_column = @locking_column if defined?(@locking_column)
+ @locking_column = value.to_s
+ end
+
# Set the column to use for optimistic locking. Defaults to +lock_version+.
def set_locking_column(value = nil, &block)
- define_attr_method :locking_column, value, &block
- value
+ deprecated_property_setter :locking_column, value, block
end
# The version column used for optimistic locking. Defaults to +lock_version+.
def locking_column
- reset_locking_column
+ reset_locking_column unless defined?(@locking_column)
+ @locking_column
+ end
+
+ def original_locking_column #:nodoc:
+ deprecated_original_property_getter :locking_column
end
# Quote the column name used for optimistic locking.
@@ -166,7 +171,7 @@ def quoted_locking_column
# Reset the column used for optimistic locking back to the +lock_version+ default.
def reset_locking_column
- set_locking_column DEFAULT_LOCKING_COLUMN
+ self.locking_column = DEFAULT_LOCKING_COLUMN
end
# Make sure the lock version column gets updated when counters are
View
42 activerecord/test/cases/locking_test.rb
@@ -11,7 +11,7 @@ class LockWithoutDefault < ActiveRecord::Base; end
class LockWithCustomColumnWithoutDefault < ActiveRecord::Base
self.table_name = :lock_without_defaults_cust
- set_locking_column :custom_lock_version
+ self.locking_column = :custom_lock_version
end
class ReadonlyFirstNamePerson < Person
@@ -226,6 +226,46 @@ def test_update_without_attributes_does_not_only_update_lock_version
end
end
+class SetLockingColumnTest < ActiveRecord::TestCase
+ def test_set_set_locking_column_with_value
+ k = Class.new( ActiveRecord::Base )
+ k.locking_column = "foo"
+ assert_equal "foo", k.locking_column
+
+ assert_deprecated do
+ k.set_locking_column "bar"
+ end
+ assert_equal "bar", k.locking_column
+ end
+
+ def test_set_locking_column_with_block
+ k = Class.new( ActiveRecord::Base )
+ k.locking_column = 'foo'
+
+ assert_deprecated do
+ k.set_locking_column { "lock_" + original_locking_column }
+ end
+ assert_equal "lock_foo", k.locking_column
+ end
+
+ def test_original_locking_column
+ k = Class.new(ActiveRecord::Base)
+ k.locking_column = "bar"
+
+ assert_deprecated do
+ assert_equal ActiveRecord::Locking::Optimistic::ClassMethods::DEFAULT_LOCKING_COLUMN, k.original_locking_column
+ end
+
+ k = Class.new(ActiveRecord::Base)
+ k.locking_column = "omg"
+ k.locking_column = "wtf"
+
+ assert_deprecated do
+ assert_equal "omg", k.original_locking_column
+ end
+ end
+end
+
class OptimisticLockingWithSchemaChangeTest < ActiveRecord::TestCase
fixtures :people, :legacy_things, :references
View
2  activerecord/test/models/legacy_thing.rb
@@ -1,3 +1,3 @@
class LegacyThing < ActiveRecord::Base
- set_locking_column :version
+ self.locking_column = :version
end
Please sign in to comment.
Something went wrong with that request. Please try again.