From: Andy Allan Date: Thu, 9 Mar 2017 16:21:51 +0000 (+0000) Subject: Create a super_user factory. X-Git-Tag: live~3533^2~1 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/eac26c9a2ca1a5fa3a85f1196416a7d324ba7663 Create a super_user factory. --- diff --git a/test/controllers/user_roles_controller_test.rb b/test/controllers/user_roles_controller_test.rb index ef1a57cbe..c7e5926ad 100644 --- a/test/controllers/user_roles_controller_test.rb +++ b/test/controllers/user_roles_controller_test.rb @@ -20,11 +20,7 @@ class UserRolesControllerTest < ActionController::TestCase target_user = create(:user) normal_user = create(:user) administrator_user = create(:administrator_user) - # Create a super user which has all known roles - super_user = create(:user) - UserRole::ALL_ROLES.each do |role| - create(:user_role, :user => super_user, :granter => administrator_user, :role => role) - end + super_user = create(:super_user) # Granting should fail when not logged in post :grant, :display_name => target_user.display_name, :role => "moderator" @@ -85,11 +81,7 @@ class UserRolesControllerTest < ActionController::TestCase target_user = create(:user) normal_user = create(:user) administrator_user = create(:administrator_user) - # Create a super user which has all known roles - super_user = create(:user) - UserRole::ALL_ROLES.each do |role| - create(:user_role, :user => super_user, :granter => administrator_user, :role => role) - end + super_user = create(:super_user) # Revoking should fail when not logged in post :revoke, :display_name => target_user.display_name, :role => "moderator" diff --git a/test/factories/user.rb b/test/factories/user.rb index 802fedd91..8fe768410 100644 --- a/test/factories/user.rb +++ b/test/factories/user.rb @@ -46,5 +46,13 @@ FactoryGirl.define do create(:user_role, :role => "administrator", :user => user) end end + + factory :super_user do + after(:create) do |user, _evaluator| + UserRole::ALL_ROLES.each do |role| + create(:user_role, :role => role, :user => user) + end + end + end end end