Skip to content

Commit

Permalink
Merge pull request #1061 from koic/fix_a_false_positive_for_rails_htt…
Browse files Browse the repository at this point in the history
…p_status

[Fix #1060] Fix a false positive for `Rails/HttpStatus`
  • Loading branch information
koic authored Aug 4, 2023
2 parents 9bb121a + ddd4a80 commit 541da7c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/fix_a_false_positive_for_rails_http_status.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#1060](https://github.com/rubocop/rubocop-rails/issues/1060): Fix a false positive for `Rails/HttpStatus` when using symbolic value that have no numeric value mapping. ([@koic][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rails/http_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def initialize(node)
end

def offensive?
!node.int_type? && !permitted_symbol?
!node.int_type? && !permitted_symbol? && number
end

def message
Expand Down
6 changes: 6 additions & 0 deletions spec/rubocop/cop/rails/http_status_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,11 @@
render :foo, status: :redirect
RUBY
end

it 'does not register an offense when using symbolic value that have no numeric value mapping' do
expect_no_offenses(<<~RUBY)
render json: { foo: 'bar' }, status: :ng
RUBY
end
end
end

0 comments on commit 541da7c

Please sign in to comment.