2018-12-13 09:46:01 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
require 'rubocop'
|
|
|
|
require 'rubocop/rspec/support'
|
|
|
|
require_relative '../../../rubocop/cop/inject_enterprise_edition_module'
|
|
|
|
|
|
|
|
describe RuboCop::Cop::InjectEnterpriseEditionModule do
|
|
|
|
include CopHelper
|
|
|
|
|
|
|
|
subject(:cop) { described_class.new }
|
|
|
|
|
2019-07-26 08:52:18 -04:00
|
|
|
it 'flags the use of `prepend_if_ee EE` in the middle of a file' do
|
2018-12-13 09:46:01 -05:00
|
|
|
expect_offense(<<~SOURCE)
|
|
|
|
class Foo
|
2019-07-26 08:52:18 -04:00
|
|
|
prepend_if_ee 'EE::Foo'
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^ Injecting EE modules must be done on the last line of this file, outside of any class or module definitions
|
2018-12-13 09:46:01 -05:00
|
|
|
end
|
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
|
2019-08-28 11:20:06 -04:00
|
|
|
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
|
|
|
|
|
2019-07-26 08:52:18 -04:00
|
|
|
it 'does not flag the use of `prepend_if_ee EEFoo` in the middle of a file' do
|
2019-01-16 09:21:50 -05:00
|
|
|
expect_no_offenses(<<~SOURCE)
|
|
|
|
class Foo
|
2019-07-26 08:52:18 -04:00
|
|
|
prepend_if_ee 'EEFoo'
|
2019-01-16 09:21:50 -05:00
|
|
|
end
|
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
|
2019-07-26 08:52:18 -04:00
|
|
|
it 'flags the use of `prepend_if_ee EE::Foo::Bar` in the middle of a file' do
|
2019-01-16 09:21:50 -05:00
|
|
|
expect_offense(<<~SOURCE)
|
|
|
|
class Foo
|
2019-07-26 08:52:18 -04:00
|
|
|
prepend_if_ee 'EE::Foo::Bar'
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Injecting EE modules must be done on the last line of this file, outside of any class or module definitions
|
2019-01-16 09:21:50 -05:00
|
|
|
end
|
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
|
2019-07-26 08:52:18 -04:00
|
|
|
it 'flags the use of `prepend_if_ee(EE::Foo::Bar)` in the middle of a file' do
|
2019-01-16 09:21:50 -05:00
|
|
|
expect_offense(<<~SOURCE)
|
|
|
|
class Foo
|
2019-07-26 08:52:18 -04:00
|
|
|
prepend_if_ee('EE::Foo::Bar')
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Injecting EE modules must be done on the last line of this file, outside of any class or module definitions
|
2019-01-16 09:21:50 -05:00
|
|
|
end
|
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
|
2019-07-26 08:52:18 -04:00
|
|
|
it 'flags the use of `prepend_if_ee EE::Foo::Bar::Baz` in the middle of a file' do
|
2019-01-16 09:21:50 -05:00
|
|
|
expect_offense(<<~SOURCE)
|
|
|
|
class Foo
|
2019-07-26 08:52:18 -04:00
|
|
|
prepend_if_ee 'EE::Foo::Bar::Baz'
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Injecting EE modules must be done on the last line of this file, outside of any class or module definitions
|
2019-01-16 09:21:50 -05:00
|
|
|
end
|
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
|
2019-07-26 08:52:18 -04:00
|
|
|
it 'flags the use of `prepend_if_ee ::EE` in the middle of a file' do
|
2018-12-13 09:46:01 -05:00
|
|
|
expect_offense(<<~SOURCE)
|
|
|
|
class Foo
|
2019-07-26 08:52:18 -04:00
|
|
|
prepend_if_ee '::EE::Foo'
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^ Injecting EE modules must be done on the last line of this file, outside of any class or module definitions
|
2018-12-13 09:46:01 -05:00
|
|
|
end
|
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
|
2019-07-26 08:52:18 -04:00
|
|
|
it 'flags the use of `include_if_ee EE` in the middle of a file' do
|
2018-12-13 09:46:01 -05:00
|
|
|
expect_offense(<<~SOURCE)
|
|
|
|
class Foo
|
2019-07-26 08:52:18 -04:00
|
|
|
include_if_ee 'EE::Foo'
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^ Injecting EE modules must be done on the last line of this file, outside of any class or module definitions
|
2018-12-13 09:46:01 -05:00
|
|
|
end
|
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
|
2019-07-26 08:52:18 -04:00
|
|
|
it 'flags the use of `include_if_ee ::EE` in the middle of a file' do
|
2018-12-13 09:46:01 -05:00
|
|
|
expect_offense(<<~SOURCE)
|
|
|
|
class Foo
|
2019-07-26 08:52:18 -04:00
|
|
|
include_if_ee '::EE::Foo'
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^ Injecting EE modules must be done on the last line of this file, outside of any class or module definitions
|
2018-12-13 09:46:01 -05:00
|
|
|
end
|
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
|
2019-07-26 08:52:18 -04:00
|
|
|
it 'flags the use of `extend_if_ee EE` in the middle of a file' do
|
2018-12-13 09:46:01 -05:00
|
|
|
expect_offense(<<~SOURCE)
|
|
|
|
class Foo
|
2019-07-26 08:52:18 -04:00
|
|
|
extend_if_ee 'EE::Foo'
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^ Injecting EE modules must be done on the last line of this file, outside of any class or module definitions
|
2018-12-13 09:46:01 -05:00
|
|
|
end
|
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
|
2019-07-26 08:52:18 -04:00
|
|
|
it 'flags the use of `extend_if_ee ::EE` in the middle of a file' do
|
2018-12-13 09:46:01 -05:00
|
|
|
expect_offense(<<~SOURCE)
|
|
|
|
class Foo
|
2019-07-26 08:52:18 -04:00
|
|
|
extend_if_ee '::EE::Foo'
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^ Injecting EE modules must be done on the last line of this file, outside of any class or module definitions
|
2018-12-13 09:46:01 -05:00
|
|
|
end
|
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not flag prepending of regular modules' do
|
|
|
|
expect_no_offenses(<<~SOURCE)
|
|
|
|
class Foo
|
2019-07-26 08:52:18 -04:00
|
|
|
prepend_if_ee 'Foo'
|
2018-12-13 09:46:01 -05:00
|
|
|
end
|
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not flag including of regular modules' do
|
|
|
|
expect_no_offenses(<<~SOURCE)
|
|
|
|
class Foo
|
2019-07-26 08:52:18 -04:00
|
|
|
include_if_ee 'Foo'
|
2018-12-13 09:46:01 -05:00
|
|
|
end
|
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not flag extending using regular modules' do
|
|
|
|
expect_no_offenses(<<~SOURCE)
|
|
|
|
class Foo
|
2019-07-26 08:52:18 -04:00
|
|
|
extend_if_ee 'Foo'
|
2018-12-13 09:46:01 -05:00
|
|
|
end
|
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
|
2019-07-26 08:52:18 -04:00
|
|
|
it 'does not flag the use of `prepend_if_ee EE` on the last line' do
|
2018-12-13 09:46:01 -05:00
|
|
|
expect_no_offenses(<<~SOURCE)
|
|
|
|
class Foo
|
|
|
|
end
|
|
|
|
|
2019-07-26 08:52:18 -04:00
|
|
|
Foo.prepend_if_ee('EE::Foo')
|
2018-12-13 09:46:01 -05:00
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
|
2019-07-26 08:52:18 -04:00
|
|
|
it 'does not flag the use of `include_if_ee EE` on the last line' do
|
2018-12-13 09:46:01 -05:00
|
|
|
expect_no_offenses(<<~SOURCE)
|
|
|
|
class Foo
|
|
|
|
end
|
|
|
|
|
2019-07-26 08:52:18 -04:00
|
|
|
Foo.include_if_ee('EE::Foo')
|
2018-12-13 09:46:01 -05:00
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
|
2019-07-26 08:52:18 -04:00
|
|
|
it 'does not flag the use of `extend_if_ee EE` on the last line' do
|
2018-12-13 09:46:01 -05:00
|
|
|
expect_no_offenses(<<~SOURCE)
|
|
|
|
class Foo
|
|
|
|
end
|
|
|
|
|
2019-07-26 08:52:18 -04:00
|
|
|
Foo.extend_if_ee('EE::Foo')
|
2018-12-13 09:46:01 -05:00
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'autocorrects offenses by just disabling the Cop' do
|
|
|
|
source = <<~SOURCE
|
|
|
|
class Foo
|
2019-07-26 08:52:18 -04:00
|
|
|
prepend_if_ee 'EE::Foo'
|
|
|
|
include_if_ee 'Bar'
|
2018-12-13 09:46:01 -05:00
|
|
|
end
|
|
|
|
SOURCE
|
|
|
|
|
|
|
|
expect(autocorrect_source(source)).to eq(<<~SOURCE)
|
|
|
|
class Foo
|
2019-07-26 08:52:18 -04:00
|
|
|
prepend_if_ee 'EE::Foo' # rubocop: disable Cop/InjectEnterpriseEditionModule
|
|
|
|
include_if_ee 'Bar'
|
|
|
|
end
|
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'disallows the use of prepend to inject an EE module' do
|
|
|
|
expect_offense(<<~SOURCE)
|
|
|
|
class Foo
|
|
|
|
end
|
|
|
|
|
|
|
|
Foo.prepend(EE::Foo)
|
|
|
|
^^^^^^^^^^^^^^^^^^^^ EE modules must be injected using `include_if_ee`, `extend_if_ee`, or `prepend_if_ee`
|
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
|
2019-08-28 11:20:06 -04:00
|
|
|
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
|
|
|
|
|
2019-07-26 08:52:18 -04:00
|
|
|
it 'disallows the use of extend to inject an EE module' do
|
|
|
|
expect_offense(<<~SOURCE)
|
|
|
|
class Foo
|
2018-12-13 09:46:01 -05:00
|
|
|
end
|
2019-07-26 08:52:18 -04:00
|
|
|
|
|
|
|
Foo.extend(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 include to inject an EE module' do
|
|
|
|
expect_offense(<<~SOURCE)
|
|
|
|
class Foo
|
|
|
|
end
|
|
|
|
|
|
|
|
Foo.include(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 prepend_if_ee without a String' do
|
|
|
|
expect_offense(<<~SOURCE)
|
|
|
|
class Foo
|
|
|
|
end
|
|
|
|
|
|
|
|
Foo.prepend_if_ee(EE::Foo)
|
|
|
|
^^^^^^^ EE modules to inject must be specified as a String
|
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'disallows the use of include_if_ee without a String' do
|
|
|
|
expect_offense(<<~SOURCE)
|
|
|
|
class Foo
|
|
|
|
end
|
|
|
|
|
|
|
|
Foo.include_if_ee(EE::Foo)
|
|
|
|
^^^^^^^ EE modules to inject must be specified as a String
|
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'disallows the use of extend_if_ee without a String' do
|
|
|
|
expect_offense(<<~SOURCE)
|
|
|
|
class Foo
|
|
|
|
end
|
|
|
|
|
|
|
|
Foo.extend_if_ee(EE::Foo)
|
|
|
|
^^^^^^^ EE modules to inject must be specified as a String
|
2018-12-13 09:46:01 -05:00
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
end
|