Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a false negative for Rails/ActionControllerTestCase when class is namespaced #824

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#824](https://github.com/rubocop/rubocop-rails/pull/824): Fix a false negative for `Rails/ActionControllerTestCase` when the class is namespaced. ([@vlad-pisanov][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rails/action_controller_test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ActionControllerTestCase < Base

def_node_matcher :action_controller_test_case?, <<~PATTERN
(class
(const nil? _)
(const _ _)
(const (const {nil? cbase} :ActionController) :TestCase) _)
PATTERN

Expand Down
13 changes: 13 additions & 0 deletions spec/rubocop/cop/rails/action_controller_test_case_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ def test_foo
RUBY
end

it 'adds offense when extending `ActionController::TestCase` with a namespace' do
expect_offense(<<~RUBY)
class Foo::Bar::MyControllerTest < ActionController::TestCase
^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `ActionDispatch::IntegrationTest` instead.
end
RUBY

expect_correction(<<~RUBY)
class Foo::Bar::MyControllerTest < ActionDispatch::IntegrationTest
end
RUBY
end

it 'does not add offense when extending `ActionDispatch::IntegrationTest`' do
expect_no_offenses(<<~RUBY)
class MyControllerTest < ActionDispatch::IntegrationTest
Expand Down