23

I just upgraded to Rails 5 and everything went pretty smoothy but for no apparent reason a method that is called after skip_before_action is not allowing rspec to run with this message

Before process_action callback :redirect_heroku_user has not been defined (ArgumentError)

It is super strange because it works just fine on rails 4. Here is my code:

# application_controller.rb
def redirect_heroku_user
  redirect_to root_path if heroku_user?
end 

# some_controller.rb
skip_before_action :redirect_heroku_user, only: :edit
Andrey Deineko
  • 51,333
  • 10
  • 112
  • 145
Bitwise
  • 8,021
  • 22
  • 70
  • 161
  • 1
    Do you have a before_action :redirect_heroku_user somewhere else? I think the actual error is telling you that you can't skip the before_action because the before_action was never actually set. I might be wrong, but adding rails: false as the suggested answers feels like something you shouldn't do unless you actually need it for production. – arieljuod Sep 23 '16 at 04:06

2 Answers2

32

According to this thread

ActiveSupport::Callbacks#skip_callback now raises an ArgumentError if an unrecognized callback is removed.

So your solution is to pass raise: false option to skip_before_action:

skip_before_action :redirect_heroku_user, raise: false

See the changelog for more info.

Andrey Deineko
  • 51,333
  • 10
  • 112
  • 145
6

In Rails 5, if the method redirect_heroku_user is not defined in the same controller, then it raises this exception.

You can pass raise: false to avoid it as mentioned here:

skip_before_action :redirect_heroku_user, only: :edit, raise: false
dp7
  • 6,651
  • 1
  • 18
  • 37