File tree Expand file tree Collapse file tree 3 files changed +43
-1
lines changed Expand file tree Collapse file tree 3 files changed +43
-1
lines changed Original file line number Diff line number Diff line change
1
+ * [ #893 ] ( https://github.com/rubocop/rubocop-rails/issues/893 ) : Support ` local ` as an environment for ` Rails/UnknownEnv ` from Rails 7.1 onward. ([ @ghiculescu ] [ ] )
Original file line number Diff line number Diff line change @@ -86,7 +86,11 @@ def unknown_env_name?(name)
86
86
end
87
87
88
88
def environments
89
- cop_config [ 'Environments' ]
89
+ @environments ||= begin
90
+ e = cop_config [ 'Environments' ]
91
+ e += [ 'local' ] if target_rails_version >= 7.1
92
+ e
93
+ end
90
94
end
91
95
end
92
96
end
Original file line number Diff line number Diff line change 24
24
^^^^^^^^^^^^^ Unknown environment `developpment`. Did you mean `development`?
25
25
Rails.env.something?
26
26
^^^^^^^^^^ Unknown environment `something`.
27
+ Rails.env.local?
28
+ ^^^^^^ Unknown environment `local`.
27
29
RUBY
28
30
end
29
31
36
38
37
39
'something' === Rails.env
38
40
^^^^^^^^^^^ Unknown environment `something`.
41
+
42
+ 'local' === Rails.env
43
+ ^^^^^^^ Unknown environment `local`.
39
44
RUBY
40
45
end
41
46
end
49
54
^^^^^^^^^^^^^ Unknown environment `developpment`.
50
55
Rails.env.something?
51
56
^^^^^^^^^^ Unknown environment `something`.
57
+
58
+ Rails.env.local?
59
+ ^^^^^^ Unknown environment `local`.
52
60
RUBY
53
61
end
54
62
61
69
62
70
'something' === Rails.env
63
71
^^^^^^^^^^^ Unknown environment `something`.
72
+
73
+ 'local' === Rails.env
74
+ ^^^^^^^ Unknown environment `local`.
64
75
RUBY
65
76
end
66
77
end
72
83
Rails.env == 'production'
73
84
RUBY
74
85
end
86
+
87
+ context 'Rails 7.1' do
88
+ let ( :config ) do
89
+ RuboCop ::Config . new (
90
+ {
91
+ 'AllCops' => {
92
+ 'TargetRailsVersion' => '7.1'
93
+ } ,
94
+ 'Rails/UnknownEnv' => {
95
+ 'Environments' => %w[
96
+ development
97
+ production
98
+ test
99
+ ]
100
+ }
101
+ }
102
+ )
103
+ end
104
+
105
+ it 'accepts local as an environment name on Rails 7.1' do
106
+ expect_no_offenses ( <<~RUBY )
107
+ Rails.env.local?
108
+ Rails.env == 'local'
109
+ RUBY
110
+ end
111
+ end
75
112
end
You can’t perform that action at this time.
0 commit comments