File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -101,6 +101,46 @@ class NonController < ApplicationRecord
101
101
end
102
102
end
103
103
104
+ context 'with a condition' do
105
+ %w[ ActionController::Base ApplicationController ] . each do |parent_class |
106
+ context "within a class inherited from #{ parent_class } " do
107
+ it 'registers an offense and corrects' do
108
+ expect_offense ( <<~RUBY )
109
+ class HomeController < #{ parent_class }
110
+ def create
111
+ flash[:alert] = "msg" if condition
112
+ ^^^^^ Use `flash.now` before `render`.
113
+ render :index
114
+ end
115
+ end
116
+ RUBY
117
+
118
+ expect_correction ( <<~RUBY )
119
+ class HomeController < #{ parent_class }
120
+ def create
121
+ flash.now[:alert] = "msg" if condition
122
+ render :index
123
+ end
124
+ end
125
+ RUBY
126
+ end
127
+ end
128
+ end
129
+
130
+ context 'within a non Rails controller class' do
131
+ it 'does not register an offense' do
132
+ expect_no_offenses ( <<~RUBY )
133
+ class NonController < ApplicationRecord
134
+ before_action do
135
+ flash[:alert] = "msg"
136
+ render :index
137
+ end
138
+ end
139
+ RUBY
140
+ end
141
+ end
142
+ end
143
+
104
144
context 'within a class method' do
105
145
it 'does not register an offense' do
106
146
expect_no_offenses ( <<~RUBY )
You can’t perform that action at this time.
0 commit comments