Skip to content
Merged
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
1 change: 1 addition & 0 deletions changelog/fix_an_error_for_rails_env.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#1556](https://github.com/rubocop/rubocop-rails/pull/1556): Fix an error for `Rails/Env` when assigning `Rails.env`. ([@koic][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rails/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def on_send(node)
return unless node.receiver&.const_name == 'Rails'

parent = node.parent
return unless parent&.predicate_method?
return unless parent.respond_to?(:predicate_method?) && parent.predicate_method?

return if ALLOWED_LIST.include?(parent.method_name)

Expand Down
6 changes: 6 additions & 0 deletions spec/rubocop/cop/rails/env_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
RUBY
end

it 'does not register an offense when assigning `Rails.env`' do
expect_no_offenses(<<~RUBY)
rails_env = Rails.env
RUBY
end

it 'does not register an offense for valid Rails.env methods' do
expect_no_offenses(<<~RUBY)
Rails.env.capitalize
Expand Down