From c0d8f587757670b3b717f196ba024be9ee60aef6 Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Tue, 18 Jul 2017 10:37:31 -0400 Subject: Remove deprecated code concerning non-attributes and `*_will_change!` --- activerecord/lib/active_record/attribute_methods/dirty.rb | 12 +----------- activerecord/lib/active_record/attribute_mutation_tracker.rb | 9 ++------- activerecord/test/cases/dirty_test.rb | 8 +++----- activerecord/test/models/parrot.rb | 2 +- 4 files changed, 7 insertions(+), 24 deletions(-) diff --git a/activerecord/lib/active_record/attribute_methods/dirty.rb b/activerecord/lib/active_record/attribute_methods/dirty.rb index 1931a58ec8..5efe051125 100644 --- a/activerecord/lib/active_record/attribute_methods/dirty.rb +++ b/activerecord/lib/active_record/attribute_methods/dirty.rb @@ -209,17 +209,7 @@ module ActiveRecord def attribute_will_change!(attr_name) super - if self.class.has_attribute?(attr_name) - mutations_from_database.force_change(attr_name) - else - ActiveSupport::Deprecation.warn(<<-EOW.squish) - #{attr_name} is not an attribute known to Active Record. - This behavior is deprecated and will be removed in the next - version of Rails. If you'd like #{attr_name} to be managed - by Active Record, add `attribute :#{attr_name}` to your class. - EOW - mutations_from_database.deprecated_force_change(attr_name) - end + mutations_from_database.force_change(attr_name) end def _update_record(*) diff --git a/activerecord/lib/active_record/attribute_mutation_tracker.rb b/activerecord/lib/active_record/attribute_mutation_tracker.rb index a01a58f8a5..e275ae72ba 100644 --- a/activerecord/lib/active_record/attribute_mutation_tracker.rb +++ b/activerecord/lib/active_record/attribute_mutation_tracker.rb @@ -5,7 +5,6 @@ module ActiveRecord def initialize(attributes) @attributes = attributes @forced_changes = Set.new - @deprecated_forced_changes = Set.new end def changed_values @@ -33,7 +32,7 @@ module ActiveRecord end def any_changes? - attr_names.any? { |attr| changed?(attr) } || deprecated_forced_changes.any? + attr_names.any? { |attr| changed?(attr) } end def changed?(attr_name, from: OPTION_NOT_GIVEN, to: OPTION_NOT_GIVEN) @@ -62,15 +61,11 @@ module ActiveRecord forced_changes << attr_name.to_s end - def deprecated_force_change(attr_name) - deprecated_forced_changes << attr_name.to_s - end - # TODO Change this to private once we've dropped Ruby 2.2 support. # Workaround for Ruby 2.2 "private attribute?" warning. protected - attr_reader :attributes, :forced_changes, :deprecated_forced_changes + attr_reader :attributes, :forced_changes private diff --git a/activerecord/test/cases/dirty_test.rb b/activerecord/test/cases/dirty_test.rb index 6a5ec8214e..9f57bd5e7f 100644 --- a/activerecord/test/cases/dirty_test.rb +++ b/activerecord/test/cases/dirty_test.rb @@ -299,11 +299,9 @@ class DirtyTest < ActiveRecord::TestCase end def test_virtual_attribute_will_change - assert_deprecated do - parrot = Parrot.create!(name: "Ruby") - parrot.send(:attribute_will_change!, :cancel_save_from_callback) - assert parrot.has_changes_to_save? - end + parrot = Parrot.create!(name: "Ruby") + parrot.send(:attribute_will_change!, :cancel_save_from_callback) + assert parrot.has_changes_to_save? end def test_association_assignment_changes_foreign_key diff --git a/activerecord/test/models/parrot.rb b/activerecord/test/models/parrot.rb index 1e5f9285a8..255ac19365 100644 --- a/activerecord/test/models/parrot.rb +++ b/activerecord/test/models/parrot.rb @@ -8,7 +8,7 @@ class Parrot < ActiveRecord::Base validates_presence_of :name - attr_accessor :cancel_save_from_callback + attribute :cancel_save_from_callback before_save :cancel_save_callback_method, if: :cancel_save_from_callback def cancel_save_callback_method throw(:abort) -- cgit v1.2.3