Merge branch 'master' into 14965-arv-mount-py-three
[arvados.git] / services / api / test / factories / user.rb
index 7c48fc0ccc57c22944f2170c281ac52e51ac16b4..91d939516485328ba492717b55d60ba9de216793 100644 (file)
@@ -1,23 +1,39 @@
-include CurrentApiClient
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
 
-FactoryGirl.define do
+class CurrentApiClientHelper
+  extend CurrentApiClient
+end
+
+FactoryBot.define do
   factory :user do
-    before :create do
-      Thread.current[:user_was] = Thread.current[:user]
-      Thread.current[:user] = system_user
+    transient do
+      join_groups { [] }
     end
-    after :create do
-      Thread.current[:user] = Thread.current[:user_was]
+    after :create do |user, evaluator|
+      CurrentApiClientHelper.act_as_system_user do
+        evaluator.join_groups.each do |g|
+          Link.create!(tail_uuid: user.uuid,
+                       head_uuid: g.uuid,
+                       link_class: 'permission',
+                       name: 'can_read')
+          Link.create!(tail_uuid: g.uuid,
+                       head_uuid: user.uuid,
+                       link_class: 'permission',
+                       name: 'can_read')
+        end
+      end
     end
-    first_name "Factory"
-    last_name "Factory"
+    first_name { "Factory" }
+    last_name { "Factory" }
     identity_url do
       "https://example.com/#{rand(2**24).to_s(36)}"
     end
     factory :active_user do
-      is_active true
+      is_active { true }
       after :create do |user|
-        act_as_system_user do
+        CurrentApiClientHelper.act_as_system_user do
           Link.create!(tail_uuid: user.uuid,
                        head_uuid: Group.where('uuid ~ ?', '-f+$').first.uuid,
                        link_class: 'permission',
@@ -25,5 +41,10 @@ FactoryGirl.define do
         end
       end
     end
+    to_create do |instance|
+      CurrentApiClientHelper.act_as_system_user do
+        instance.save!
+      end
+    end
   end
 end