Skip to content

Commit

Permalink
[Fix #1260] Fix performance regression caused by Rails/UnknownEnv o…
Browse files Browse the repository at this point in the history
…n Rails >= 7.1
  • Loading branch information
lukasfroehlich1 committed Mar 26, 2024
1 parent 37f1df8 commit 9ef6d1e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/fix_unknown_env_causing_cache_issues.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#1260](https://github.com/rubocop/rubocop-rails/issues/1260): Fix a performance regression caused by `Rails/UnknownEnv` when using Rails 7.1. ([@lukasfroehlich1][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rails/unknown_env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def unknown_env_name?(name)

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

it 'does not mutate the cop config' do
expect_no_offenses(<<~RUBY)
Rails.env.local?
Rails.env == 'local'
RUBY

expect(cop_config['Environments'].include?('local')).to be(false)
end

context 'when `Environments` is nil' do
let(:cop_config) do
{
Expand Down

0 comments on commit 9ef6d1e

Please sign in to comment.