Merge pull request #43204 from westonganger/remove_scope_overwrite_warning

Remove warning when overwriting existing scopes
This commit is contained in:
Guillermo Iguaran 2021-09-15 09:03:26 -07:00 committed by GitHub
commit f832fa58d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 36 deletions

View File

@ -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,

View File

@ -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

View File

@ -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

View File

@ -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")