-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring log_in_as spec to use user factories to eliminate DB lock…
… errors.
- Loading branch information
1 parent
b811fa8
commit 656ba28
Showing
1 changed file
with
21 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,29 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.feature 'Switch User' do | ||
let(:user_attributes) do | ||
{ email: 'test@example.com' } | ||
end | ||
let(:user) do | ||
User.new(user_attributes) { |u| u.save(validate: false) } | ||
end | ||
|
||
before do | ||
login_as user | ||
end | ||
let(:user) { FactoryBot.create(:user) } | ||
let(:admin_user) { FactoryBot.create(:admin)} | ||
|
||
scenario 'Non-admin user is not allowed to see switch user form' do | ||
visit '/users/sessions/log_in_as' | ||
expect(page).to have_no_selector('select#switch_user_identifier') | ||
context 'Non-admin user' do | ||
before do | ||
login_as user | ||
end | ||
scenario 'is not allowed to see switch user form' do | ||
visit '/users/sessions/log_in_as' | ||
expect(page).to have_no_selector('select#switch_user_identifier') | ||
logout | ||
end | ||
end | ||
|
||
scenario 'Admin user is allowed to see switch user form' do | ||
admin = Role.where(name: 'admin').first_or_create | ||
admin.users << user | ||
visit '/users/sessions/log_in_as' | ||
expect(page).to have_css('select#switch_user_identifier') | ||
context 'Admin user' do | ||
before do | ||
login_as admin_user | ||
allow(admin_user).to receive(:admin?).and_return(true) | ||
end | ||
scenario 'is allowed to see switch user form' do | ||
visit '/users/sessions/log_in_as' | ||
expect(page).to have_css('select#switch_user_identifier') | ||
logout | ||
end | ||
end | ||
end |