ankane/pretender

Adding current_user to ApplicationController for IDE detection breaks impersonate_user

sjieg opened this issue · 2 comments

sjieg commented

Hey, first of all, thanks for this gem. We've been using it succesfully for almost 2 years now without fail.

I don't think this is a bug of Pretender really, but maybe you can help me. RubyMine doesn't understand current_user when using Devise, so I've put a function placement in my ApplicationController according to this solution:

class ApplicationController < ActionController::Base
  # @return [User]
  def current_user
    super
  end
end

When using this, all the red squiggly lines disappear and the IDE understands it's working with a User, making suggestions better. Unfortunately the impersonate_user function stops working because of this.

I've had a look at your code and my guess would be that I'm overwriting your define_method impersonated_method. WDYT?

Hey @sjieg, you can try moving impersonates :user to after the new method if it's not already. If that doesn't work, try adding debugging to see what's going on.

sjieg commented

Hah, that actually works. Thanks @ankane !

I learned something now about how these kind of methods are invoked. Much appreciated.