Remove deprecated ActiveModel::Dirty#reset_#{attribute}
and ActiveModel::Dirty#reset_changes
.
This commit is contained in:
parent
4be859f0fd
commit
37175a24bd
@ -1,3 +1,8 @@
|
||||
* Remove deprecated `ActiveModel::Dirty#reset_#{attribute}` and
|
||||
`ActiveModel::Dirty#reset_changes`.
|
||||
|
||||
*Rafael Mendonça França*
|
||||
|
||||
* Change the way in which callback chains can be halted.
|
||||
|
||||
The preferred method to halt a callback chain from now on is to explicitly
|
||||
|
@ -116,7 +116,6 @@ module Dirty
|
||||
|
||||
included do
|
||||
attribute_method_suffix '_changed?', '_change', '_will_change!', '_was'
|
||||
attribute_method_affix prefix: 'reset_', suffix: '!'
|
||||
attribute_method_affix prefix: 'restore_', suffix: '!'
|
||||
end
|
||||
|
||||
@ -204,15 +203,6 @@ def clear_changes_information # :doc:
|
||||
@changed_attributes = ActiveSupport::HashWithIndifferentAccess.new
|
||||
end
|
||||
|
||||
def reset_changes
|
||||
ActiveSupport::Deprecation.warn(<<-MSG.squish)
|
||||
`#reset_changes` is deprecated and will be removed on Rails 5.
|
||||
Please use `#clear_changes_information` instead.
|
||||
MSG
|
||||
|
||||
clear_changes_information
|
||||
end
|
||||
|
||||
# Handle <tt>*_change</tt> for +method_missing+.
|
||||
def attribute_change(attr)
|
||||
[changed_attributes[attr], __send__(attr)] if attribute_changed?(attr)
|
||||
@ -231,16 +221,6 @@ def attribute_will_change!(attr)
|
||||
set_attribute_was(attr, value)
|
||||
end
|
||||
|
||||
# Handle <tt>reset_*!</tt> for +method_missing+.
|
||||
def reset_attribute!(attr)
|
||||
ActiveSupport::Deprecation.warn(<<-MSG.squish)
|
||||
`#reset_#{attr}!` is deprecated and will be removed on Rails 5.
|
||||
Please use `#restore_#{attr}!` instead.
|
||||
MSG
|
||||
|
||||
restore_attribute!(attr)
|
||||
end
|
||||
|
||||
# Handle <tt>restore_*!</tt> for +method_missing+.
|
||||
def restore_attribute!(attr)
|
||||
if attribute_changed?(attr)
|
||||
|
@ -181,23 +181,6 @@ def deprecated_reload
|
||||
assert_equal ActiveSupport::HashWithIndifferentAccess.new, @model.changed_attributes
|
||||
end
|
||||
|
||||
test "reset_changes is deprecated" do
|
||||
@model.name = 'Dmitry'
|
||||
@model.name_changed?
|
||||
@model.save
|
||||
@model.name = 'Bob'
|
||||
|
||||
assert_equal [nil, 'Dmitry'], @model.previous_changes['name']
|
||||
assert_equal 'Dmitry', @model.changed_attributes['name']
|
||||
|
||||
assert_deprecated do
|
||||
@model.deprecated_reload
|
||||
end
|
||||
|
||||
assert_equal ActiveSupport::HashWithIndifferentAccess.new, @model.previous_changes
|
||||
assert_equal ActiveSupport::HashWithIndifferentAccess.new, @model.changed_attributes
|
||||
end
|
||||
|
||||
test "restore_attributes should restore all previous data" do
|
||||
@model.name = 'Dmitry'
|
||||
@model.color = 'Red'
|
||||
|
@ -165,18 +165,6 @@ def test_aliased_attribute_changes
|
||||
assert_equal parrot.name_change, parrot.title_change
|
||||
end
|
||||
|
||||
def test_reset_attribute!
|
||||
pirate = Pirate.create!(:catchphrase => 'Yar!')
|
||||
pirate.catchphrase = 'Ahoy!'
|
||||
|
||||
assert_deprecated do
|
||||
pirate.reset_catchphrase!
|
||||
end
|
||||
assert_equal "Yar!", pirate.catchphrase
|
||||
assert_equal Hash.new, pirate.changes
|
||||
assert !pirate.catchphrase_changed?
|
||||
end
|
||||
|
||||
def test_restore_attribute!
|
||||
pirate = Pirate.create!(:catchphrase => 'Yar!')
|
||||
pirate.catchphrase = 'Ahoy!'
|
||||
|
Loading…
Reference in New Issue
Block a user