Commit e3e74662 authored by Jacopo's avatar Jacopo

Handles when ClassMethods is used inside a class

parent a1cad13b
...@@ -48,7 +48,7 @@ module RuboCop ...@@ -48,7 +48,7 @@ module RuboCop
private private
def extends_activesupport_concern?(node) def extends_activesupport_concern?(node)
container_module = container_module_of(node.parent) container_module = container_module_of(node)
return false unless container_module return false unless container_module
container_module.descendants.any? do |descendant| container_module.descendants.any? do |descendant|
...@@ -57,7 +57,9 @@ module RuboCop ...@@ -57,7 +57,9 @@ module RuboCop
end end
def container_module_of(node) def container_module_of(node)
node = node.parent until node.type == :module while node = node.parent
break if node.type == :module
end
node node
end end
......
...@@ -48,6 +48,17 @@ describe RuboCop::Cop::PreferClassMethodsOverModule do ...@@ -48,6 +48,17 @@ describe RuboCop::Cop::PreferClassMethodsOverModule do
RUBY RUBY
end end
it "doesn't flag violation when ClassMethods is used inside a class" do
expect_no_offenses(<<~RUBY)
class Foo
module ClassMethods
def a_class_method
end
end
end
RUBY
end
it "doesn't flag violation when not using either class_methods or ClassMethods" do it "doesn't flag violation when not using either class_methods or ClassMethods" do
expect_no_offenses(<<~RUBY) expect_no_offenses(<<~RUBY)
module Foo module Foo
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment