Skip to content

Commit

Permalink
Fix a false negative for Rails/ActionControllerTestCase
Browse files Browse the repository at this point in the history
  • Loading branch information
vlad-pisanov authored and koic committed Feb 25, 2023
1 parent e179054 commit c532db1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
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? cbase} _)
(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 @@ -66,6 +66,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

0 comments on commit c532db1

Please sign in to comment.