module ControllerHelpers

github.com/plataformatec/devise/wiki/How-To:-Stub-authentication-in-controller-specs

Public Instance Methods

sign_in(user = double('user')) click to toggle source
# File lib/generators/turbosack/templates/spec/support/controller_helper.rb, line 3
def sign_in(user = double('user'))
  if user.nil?
    allow(request.env['warden']).to receive(:authenticate!).and_throw(:warden, {:scope => :user})
    allow(controller).to receive(:current_user).and_return(nil)
  else
    allow(request.env['warden']).to receive(:authenticate!).and_return(user)
    allow(controller).to receive(:current_user).and_return(user)
  end
end