Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #14582 from arthurnn/blacklist_ruby_methods

Blacklist ruby keywords for scopes
Conflicts:
	activerecord/CHANGELOG.md
  • Loading branch information...
commit 1778b07dbbda2b34e3c5283315c12bfe82429b65 1 parent 8c89868
@rafaelfranca rafaelfranca authored
View
8 activerecord/CHANGELOG.md
@@ -1,3 +1,11 @@
+* Block a few default Class methods as scope name.
+
+ For instance, this will raise:
+
+ scope :public, -> { where(status: 1) }
+
+ *arthurnn*
+
* Deprecate SQLite database URLs containing an
authority.
View
4 activerecord/lib/active_record/attribute_methods.rb
@@ -29,6 +29,8 @@ def self.set_name_cache(name, value)
end
}
+ BLACKLISTED_CLASS_METHODS = %w(private public protected)
+
class AttributeMethodCache
def initialize
@module = Module.new
@@ -132,7 +134,7 @@ def method_defined_within?(name, klass, superklass = klass.superclass) # :nodoc:
# A class method is 'dangerous' if it is already (re)defined by Active Record, but
# not by any ancestors. (So 'puts' is not dangerous but 'new' is.)
def dangerous_class_method?(method_name)
- class_method_defined_within?(method_name, Base)
+ BLACKLISTED_CLASS_METHODS.include?(method_name.to_s) || class_method_defined_within?(method_name, Base)
end
def class_method_defined_within?(name, klass, superklass = klass.superclass) # :nodoc
View
1  activerecord/test/cases/enum_test.rb
@@ -194,6 +194,7 @@ class EnumTest < ActiveRecord::TestCase
:valid, # generates #valid?, which conflicts with an AR method
:save, # generates #save!, which conflicts with an AR method
:proposed, # same value as an existing enum
+ :public, :private, :protected, # generates a method that conflict with ruby words
]
conflicts.each_with_index do |value, i|
View
3  activerecord/test/cases/scoping/named_scoping_test.rb
@@ -291,6 +291,9 @@ def pro; end
:relation, # private class method on AR::Base
:new, # redefined class method on AR::Base
:all, # a default scope
+ :public,
+ :protected,
+ :private
]
non_conflicts = [
Please sign in to comment.
Something went wrong with that request. Please try again.