Improved RSpec suite by having dedicated last_admin_check meta attribute instead of polluting the whole suite (and adding side effects by being to assumtious).
This commit is contained in:
parent
86bab028a4
commit
a00f3c51a8
4 changed files with 24 additions and 19 deletions
|
@ -6,7 +6,7 @@ RSpec.describe ::Sequencer::Sequence::Import::Ldap::Users, sequencer: :sequence
|
||||||
|
|
||||||
context 'config "unassigned_users": "skip_sync"' do
|
context 'config "unassigned_users": "skip_sync"' do
|
||||||
|
|
||||||
it 'disables user' do
|
it 'disables user', last_admin_check: false do
|
||||||
|
|
||||||
user_entry = build(:ldap_entry)
|
user_entry = build(:ldap_entry)
|
||||||
user_entry['objectguid'] = ['user1337']
|
user_entry['objectguid'] = ['user1337']
|
||||||
|
@ -99,7 +99,7 @@ RSpec.describe ::Sequencer::Sequence::Import::Ldap::Users, sequencer: :sequence
|
||||||
|
|
||||||
context 'config "unassigned_users": nil / "sigup_roles"' do
|
context 'config "unassigned_users": nil / "sigup_roles"' do
|
||||||
|
|
||||||
it 'assigns signup roles' do
|
it 'assigns signup roles', last_admin_check: false do
|
||||||
|
|
||||||
user_entry = build(:ldap_entry)
|
user_entry = build(:ldap_entry)
|
||||||
user_entry['objectguid'] = ['user1337']
|
user_entry['objectguid'] = ['user1337']
|
||||||
|
|
|
@ -68,7 +68,7 @@ RSpec.describe 'Api Auth', type: :request do
|
||||||
expect(json_response).to be_truthy
|
expect(json_response).to be_truthy
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does token auth - admin' do
|
it 'does token auth - admin', last_admin_check: false do
|
||||||
|
|
||||||
admin_token = create(
|
admin_token = create(
|
||||||
:token,
|
:token,
|
||||||
|
@ -289,7 +289,7 @@ RSpec.describe 'Api Auth', type: :request do
|
||||||
expect(response).to have_http_status(401)
|
expect(response).to have_http_status(401)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does token auth - invalid user - admin' do
|
it 'does token auth - invalid user - admin', last_admin_check: false do
|
||||||
|
|
||||||
admin_token = create(
|
admin_token = create(
|
||||||
:token,
|
:token,
|
||||||
|
|
20
spec/support/last_admin_check.rb
Normal file
20
spec/support/last_admin_check.rb
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
RSpec.configure do |config|
|
||||||
|
|
||||||
|
config.around(:example, last_admin_check: false) do |example|
|
||||||
|
|
||||||
|
User.class_eval do
|
||||||
|
alias_method :original_last_admin_check_admin_count, :last_admin_check_admin_count
|
||||||
|
|
||||||
|
def last_admin_check_admin_count
|
||||||
|
1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
example.run
|
||||||
|
|
||||||
|
User.class_eval do
|
||||||
|
alias_method :last_admin_check_admin_count, :original_last_admin_check_admin_count
|
||||||
|
remove_method :original_last_admin_check_admin_count
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,15 +0,0 @@
|
||||||
RSpec.configure do |config|
|
|
||||||
config.before(:suite) do
|
|
||||||
|
|
||||||
email = 'admin@example.com'
|
|
||||||
if !::User.exists?(email: email)
|
|
||||||
FactoryBot.create(:user,
|
|
||||||
login: 'admin',
|
|
||||||
firstname: 'Admin',
|
|
||||||
lastname: 'Admin',
|
|
||||||
email: email,
|
|
||||||
password: 'admin',
|
|
||||||
roles: [Role.lookup(name: 'Admin')],)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
Loading…
Reference in a new issue