diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index a5ff22da35..ce615dc699 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,13 @@ +* Remove warning when overwriting existing scopes + + Removes the following unnecessary warning message that appeared when overwriting existing scopes + + ``` + Creating scope :my_scope_name. Overwriting existing method "MyClass.my_scope_name" when overwriting existing scopes + ``` + + *Weston Ganger* + * Use full precision for `updated_at` in `insert_all`/`upsert_all` `CURRENT_TIMESTAMP` provides differing precision depending on the database, diff --git a/activerecord/lib/active_record/scoping/named.rb b/activerecord/lib/active_record/scoping/named.rb index 621da4a113..92c907355b 100644 --- a/activerecord/lib/active_record/scoping/named.rb +++ b/activerecord/lib/active_record/scoping/named.rb @@ -168,7 +168,6 @@ module ActiveRecord "an instance method with the same name." end - valid_scope_name?(name) extension = Module.new(&block) if block if body.respond_to?(:to_proc) @@ -193,13 +192,6 @@ module ActiveRecord def singleton_method_added(name) generate_relation_method(name) if Kernel.respond_to?(name) && !ActiveRecord::Relation.method_defined?(name) end - - def valid_scope_name?(name) - if respond_to?(name, true) && logger - logger.warn "Creating scope :#{name}. " \ - "Overwriting existing method #{self.name}.#{name}." - end - end end end end diff --git a/activerecord/test/cases/enum_test.rb b/activerecord/test/cases/enum_test.rb index 3ddb349e91..4737588347 100644 --- a/activerecord/test/cases/enum_test.rb +++ b/activerecord/test/cases/enum_test.rb @@ -879,9 +879,6 @@ class EnumTest < ActiveRecord::TestCase " This has caused a conflict with auto generated negative scopes."\ " Avoid using enum elements starting with 'not' where the positive form is also an element." - # this message comes from ActiveRecord::Scoping::Named, but it's worth noting that both occur in this case - expected_message_2 = "Creating scope :not_sent. Overwriting existing method Book.not_sent." - Class.new(ActiveRecord::Base) do def self.name "Book" @@ -892,7 +889,6 @@ class EnumTest < ActiveRecord::TestCase end assert_includes(logger.logged(:warn), expected_message_1) - assert_includes(logger.logged(:warn), expected_message_2) ensure ActiveRecord::Base.logger = old_logger end @@ -907,9 +903,6 @@ class EnumTest < ActiveRecord::TestCase " This has caused a conflict with auto generated negative scopes."\ " Avoid using enum elements starting with 'not' where the positive form is also an element." - # this message comes from ActiveRecord::Scoping::Named, but it's worth noting that both occur in this case - expected_message_2 = "Creating scope :not_sent. Overwriting existing method Book.not_sent." - Class.new(ActiveRecord::Base) do def self.name "Book" @@ -920,7 +913,6 @@ class EnumTest < ActiveRecord::TestCase end assert_includes(logger.logged(:warn), expected_message_1) - assert_includes(logger.logged(:warn), expected_message_2) ensure ActiveRecord::Base.logger = old_logger end diff --git a/activerecord/test/cases/scoping/named_scoping_test.rb b/activerecord/test/cases/scoping/named_scoping_test.rb index a31f0d2627..997e7a4b65 100644 --- a/activerecord/test/cases/scoping/named_scoping_test.rb +++ b/activerecord/test/cases/scoping/named_scoping_test.rb @@ -512,26 +512,6 @@ class NamedScopingTest < ActiveRecord::TestCase end end - def test_scopes_with_reserved_names - class << Topic - def public_method; end - public :public_method - - def protected_method; end - protected :protected_method - - def private_method; end - private :private_method - end - - [:public_method, :protected_method, :private_method].each do |reserved_method| - assert Topic.respond_to?(reserved_method, true) - assert_called(ActiveRecord::Base.logger, :warn) do - silence_warnings { Topic.scope(reserved_method, -> { }) } - end - end - end - def test_scopes_on_relations # Topic.replied approved_topics = Topic.all.approved.order("id DESC")