Commit 5445f71e authored by Yorick Peterse's avatar Yorick Peterse

Fix InjectEnterpriseEditionModule cop for qa/

This ensures the InjectEnterpriseEditionModule cop is able to detect the
prepend patterns used in the qa/ directory. Previously it would not
detect them as all EE QA modules reside in QA::EE, and not the top-level
EE namespace.
parent 4b23faab
...@@ -24,7 +24,7 @@ module RuboCop ...@@ -24,7 +24,7 @@ module RuboCop
# We use `match?` here instead of RuboCop's AST matching, as this makes # We use `match?` here instead of RuboCop's AST matching, as this makes
# it far easier to handle nested constants such as `EE::Foo::Bar::Baz`. # it far easier to handle nested constants such as `EE::Foo::Bar::Baz`.
line.match?(/(\s|\()('|")?(::)?EE::/) line.match?(/(\s|\()('|")?(::)?(QA::)?EE::/)
end end
def on_send(node) def on_send(node)
......
...@@ -19,6 +19,15 @@ describe RuboCop::Cop::InjectEnterpriseEditionModule do ...@@ -19,6 +19,15 @@ describe RuboCop::Cop::InjectEnterpriseEditionModule do
SOURCE SOURCE
end end
it 'flags the use of `prepend_if_ee QA::EE` in the middle of a file' do
expect_offense(<<~SOURCE)
class Foo
prepend_if_ee 'QA::EE::Foo'
^^^^^^^^^^^^^^^^^^^^^^^^^^^ Injecting EE modules must be done on the last line of this file, outside of any class or module definitions
end
SOURCE
end
it 'does not flag the use of `prepend_if_ee EEFoo` in the middle of a file' do it 'does not flag the use of `prepend_if_ee EEFoo` in the middle of a file' do
expect_no_offenses(<<~SOURCE) expect_no_offenses(<<~SOURCE)
class Foo class Foo
...@@ -176,6 +185,16 @@ describe RuboCop::Cop::InjectEnterpriseEditionModule do ...@@ -176,6 +185,16 @@ describe RuboCop::Cop::InjectEnterpriseEditionModule do
SOURCE SOURCE
end end
it 'disallows the use of prepend to inject a QA::EE module' do
expect_offense(<<~SOURCE)
class Foo
end
Foo.prepend(QA::EE::Foo)
^^^^^^^^^^^^^^^^^^^^^^^^ EE modules must be injected using `include_if_ee`, `extend_if_ee`, or `prepend_if_ee`
SOURCE
end
it 'disallows the use of extend to inject an EE module' do it 'disallows the use of extend to inject an EE module' do
expect_offense(<<~SOURCE) expect_offense(<<~SOURCE)
class Foo class 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