Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#1182](https://github.com/rubocop/rubocop-rails/issues/1182): Fix a false positive for `Rails/ActionControllerFlashBeforeRender` when flash is called in a block. ([@5hun-s][])
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def followed_by_render?(flash_node)
return false if use_redirect_to?(context)

context = node
elsif context.right_siblings.empty?
elsif context.right_siblings.empty? && !use_redirect_to?(context.parent)
return true
end
context = context.right_siblings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,4 +395,36 @@ def create
RUBY
end
end

context 'when using `flash` in a one-line iteration block before `redirect_to`' do
it 'does not register an offense' do
expect_no_offenses(<<~RUBY)
class HomeController < ApplicationController
def create
messages = %w[foo bar baz]
messages.each { |message| flash[:alert] = message }

redirect_to :index
end
end
RUBY
end
end

context 'when using `flash` in a multi-line block before `redirect_to`' do
it 'does not register an offense' do
expect_no_offenses(<<~RUBY)
class HomeController < ApplicationController
def create
messages = %w[foo bar baz]
messages.each do |message|
flash[:alert] = message
end

redirect_to :index
end
end
RUBY
end
end
end