Module: DeviseHelpers

Defined in:
lib/kowl/templates/tests/rspec/support/helpers/devise_helpers.rb,
lib/kowl/templates/tests/minitest/support/helpers/devise_helper.rb

Instance Method Summary collapse

Instance Method Details

#login_as(user) ⇒ Object

Used for simulating a login as the specified user



39
40
41
42
43
# File 'lib/kowl/templates/tests/rspec/support/helpers/devise_helpers.rb', line 39

def (user)
  user = FactoryBot.create(:user) if user.nil?
  allow(controller).to receive(:authenticate_user!).and_return(true)
  allow(controller).to receive(:current_user).and_return(user)
end

#login_as_adminObject

Used for accessing the action as an admin/superuser (a member of devgroup)



6
7
8
9
# File 'lib/kowl/templates/tests/rspec/support/helpers/devise_helpers.rb', line 6

def 
  user = FactoryBot.create(:user, role: 'superuser')
  (user)
end

#login_as_staffObject

EXAMPLE: —————————————- describe ‘GET #index’ do

it 'returns http success' do
  
  get :index
  expect(response).to have_http_status(:success)
end

end



19
20
21
22
# File 'lib/kowl/templates/tests/rspec/support/helpers/devise_helpers.rb', line 19

def 
  user = FactoryBot.create(:user, role: :staff)
  (user)
end

#login_as_userObject

Used for hitting the user as a generic user



25
26
27
28
# File 'lib/kowl/templates/tests/rspec/support/helpers/devise_helpers.rb', line 25

def 
  user = FactoryBot.create(:user)
  (user)
end