Skip to content

Commit

Permalink
Merge pull request #1175 from koic/fix_an_error_for_rails_unknown_env
Browse files Browse the repository at this point in the history
[Fix #1172] Fix an error for `Rails/UnknownEnv`
  • Loading branch information
koic committed Nov 1, 2023
2 parents 1be8d21 + c2dc319 commit ce796cc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog/fix_an_error_for_rails_unknown_env.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#1172](https://github.com/rubocop/rubocop-rails/issues/1172): Fix an error for `Rails/UnknownEnv` when using Rails 7.1. ([@koic][])
6 changes: 3 additions & 3 deletions lib/rubocop/cop/rails/unknown_env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ def unknown_env_name?(name)

def environments
@environments ||= begin
e = cop_config['Environments']
e += ['local'] if target_rails_version >= 7.1
e
environments = cop_config['Environments'] || []
environments << 'local' if target_rails_version >= 7.1
environments
end
end
end
Expand Down
15 changes: 15 additions & 0 deletions spec/rubocop/cop/rails/unknown_env_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,20 @@
Rails.env == 'local'
RUBY
end

context 'when `Environments` is nil' do
let(:cop_config) do
{
'Environments' => nil
}
end

it 'accepts local as an environment name' do
expect_no_offenses(<<~RUBY)
Rails.env.local?
Rails.env == 'local'
RUBY
end
end
end
end

0 comments on commit ce796cc

Please sign in to comment.