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:
Thorsten Eckel 2018-09-28 14:52:06 +02:00
parent 86bab028a4
commit a00f3c51a8
4 changed files with 24 additions and 19 deletions

View file

@ -6,7 +6,7 @@ RSpec.describe ::Sequencer::Sequence::Import::Ldap::Users, sequencer: :sequence
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['objectguid'] = ['user1337']
@ -99,7 +99,7 @@ RSpec.describe ::Sequencer::Sequence::Import::Ldap::Users, sequencer: :sequence
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['objectguid'] = ['user1337']

View file

@ -68,7 +68,7 @@ RSpec.describe 'Api Auth', type: :request do
expect(json_response).to be_truthy
end
it 'does token auth - admin' do
it 'does token auth - admin', last_admin_check: false do
admin_token = create(
:token,
@ -289,7 +289,7 @@ RSpec.describe 'Api Auth', type: :request do
expect(response).to have_http_status(401)
end
it 'does token auth - invalid user - admin' do
it 'does token auth - invalid user - admin', last_admin_check: false do
admin_token = create(
:token,

View 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

View file

@ -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