Browse Source

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).

Thorsten Eckel 6 years ago
parent
commit
a00f3c51a8

+ 2 - 2
spec/lib/sequencer/sequence/import/ldap/users_spec.rb

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

+ 2 - 2
spec/requests/api_auth_spec.rb

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

+ 20 - 0
spec/support/last_admin_check.rb

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

+ 0 - 15
spec/support/system_init.rb

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