Module: ControllerHelpers

Defined in:
lib/generators/happy_seed/base/templates/spec/support/controller_helpers.rb

Instance Method Summary collapse

Instance Method Details

#login_with(user = double('user'), scope = :user) ⇒ Object



2
3
4
5
6
7
8
9
10
11
# File 'lib/generators/happy_seed/base/templates/spec/support/controller_helpers.rb', line 2

def (user = double('user'), scope = :user)
  current_user = "current_#{scope}".to_sym
  if user.nil?
    allow(request.env['warden']).to receive(:authenticate!).and_throw(:warden, {:scope => scope})
    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