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
-
#login_as(user) ⇒ Object
Used for simulating a login as the specified user.
-
#login_as_admin ⇒ Object
Used for accessing the action as an admin/superuser (a member of devgroup).
-
#login_as_staff ⇒ Object
EXAMPLE: —————————————- describe ‘GET #index’ do it ‘returns http success’ do login_as_admin get :index expect(response).to have_http_status(:success) end end.
-
#login_as_user ⇒ Object
Used for hitting the user as a generic user.
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 login_as(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_admin ⇒ Object
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 login_as_admin user = FactoryBot.create(:user, role: 'superuser') login_as(user) end |
#login_as_staff ⇒ Object
EXAMPLE: —————————————- describe ‘GET #index’ do
it 'returns http success' do
login_as_admin
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 login_as_staff user = FactoryBot.create(:user, role: :staff) login_as(user) end |
#login_as_user ⇒ Object
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 login_as_user user = FactoryBot.create(:user) login_as(user) end |