Sha256: 3c9247990c5eb324ace23d82a9c6fe8ad2418f3c4e020c7bba402917f8011b2e

Contents?: true

Size: 1.6 KB

Versions: 7

Compression:

Stored size: 1.6 KB

Contents

# frozen_string_literal: true

require 'devise'
module DeviseHelpers
  # Used for accessing the action as an admin/superuser (a member of devgroup)
  def login_as_admin
    user = FactoryBot.create(:user, role: 'superuser')
    login_as(user)
  end
  # EXAMPLE: ----------------------------------------
  # describe 'GET #index' do
  #   it 'returns http success' do
  #     login_as_admin
  #     get :index
  #     expect(response).to have_http_status(:success)
  #   end
  # end

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

  # Used for hitting the user as a generic user
  def login_as_user
    user = FactoryBot.create(:user)
    login_as(user)
  end
  # EXAMPLE: ----------------------------------------
  # describe 'GET #index' do
  #   it 'returns http success' do
  #     login_as_user
  #     get :index
  #     expect(response).to have_http_status(:success)
  #   end
  # end

  # Used for simulating a login as the specified user
  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
  # EXAMPLE: ----------------------------------------
  # This is also good to use if you need to add custom paramters to test against the user
  # before do
  #   @user = FactoryBot.create(:user, superuser: false, position: 'Nurse', )
  # end
  # describe 'GET #index' do
  #   it 'returns http success' do
  #     login_as @user
  #     get :welcome
  #     expect(response).to have_http_status(:success)
  #   end
  # end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
kowl-0.0.7 lib/kowl/templates/tests/rspec/support/helpers/devise_helpers.rb
kowl-0.0.6 lib/kowl/templates/tests/rspec/support/helpers/devise_helpers.rb
kowl-0.0.5 lib/kowl/templates/tests/rspec/support/helpers/devise_helpers.rb
kowl-0.0.4 lib/kowl/templates/tests/rspec/support/helpers/devise_helpers.rb
kowl-0.0.3 lib/kowl/templates/tests/rspec/support/helpers/devise_helpers.rb
kowl-0.0.2 lib/kowl/templates/tests/rspec/support/helpers/devise_helpers.rb
kowl-0.0.1 lib/kowl/templates/tests/rspec/support/helpers/devise_helpers.rb