Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False Positive for Rails/ActionControllerFlashBeforeRender when flash is called in a case statement #1243

Open
ccutrer opened this issue Mar 1, 2024 · 0 comments

Comments

@ccutrer
Copy link
Contributor

ccutrer commented Mar 1, 2024

Expected behavior

When flash is set in a case statement, followed by a redirect_to, the cop should not register an offense.

Actual behavior

Offenses:

app/controllers/context_controller.rb:262:11: C: Rails/ActionControllerFlashBeforeRender: Use flash.now before render.
          flash[:error] = t("no_user.course", "That user does not exist or is not currently a member of this course")
          ^^^^^
app/controllers/context_controller.rb:264:11: C: Rails/ActionControllerFlashBeforeRender: Use flash.now before render.
          flash[:error] = t("no_user.group", "That user does not exist or is not currently a member of this group")
          ^^^^^

Steps to reproduce the problem

      unless @user
        case @context
        when Course
          flash[:error] = t("no_user.course", "That user does not exist or is not currently a member of this course")
        when Group
          flash[:error] = t("no_user.group", "That user does not exist or is not currently a member of this group")
        end
        redirect_to named_context_url(@context, :context_users_url)
        return
      end

RuboCop version

% rubocop -V
1.61.0 (using Parser 3.3.0.5, rubocop-ast 1.31.1, running on ruby 3.1.3) [arm64-darwin21]
  - rubocop-factory_bot 2.25.1
  - rubocop-graphql 1.5.0
  - rubocop-performance 1.20.2
  - rubocop-rails 2.23.1
  - rubocop-rake 0.6.0
  - rubocop-rspec 2.27.0```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant