]> git.openstreetmap.org Git - rails.git/commitdiff
Add moderator_user and administrator_user factories.
authorAndy Allan <git@gravitystorm.co.uk>
Thu, 2 Feb 2017 12:38:19 +0000 (12:38 +0000)
committerAndy Allan <git@gravitystorm.co.uk>
Thu, 2 Feb 2017 12:38:19 +0000 (12:38 +0000)
test/factories/user.rb
test/models/user_test.rb

index 79b9a2a1664b84941293500ab5e10b8672132f23..6376659ab0b9ec76c696f156cbe1cb0fa0bb7d75 100644 (file)
@@ -8,5 +8,17 @@ FactoryGirl.define do
       home_lat { rand(-90.0...90.0) }
       home_lon { rand(-180.0...180.0) }
     end
       home_lat { rand(-90.0...90.0) }
       home_lon { rand(-180.0...180.0) }
     end
+
+    factory :moderator_user do
+      after(:create) do |user, _evaluator|
+        create(:user_role, :role => "moderator", :user => user)
+      end
+    end
+
+    factory :administrator_user do
+      after(:create) do |user, _evaluator|
+        create(:user_role, :role => "administrator", :user => user)
+      end
+    end
   end
 end
   end
 end
index 5eacd98b9ca5143b33bdeb6365951ff2152356e2..6632702e59518867c8e8af1049fa7ca43e8d4276 100644 (file)
@@ -223,20 +223,20 @@ class UserTest < ActiveSupport::TestCase
   end
 
   def test_moderator?
   end
 
   def test_moderator?
-    assert_equal false, users(:normal_user).moderator?
-    assert_equal true, users(:moderator_user).moderator?
+    assert_equal false, create(:user).moderator?
+    assert_equal true, create(:moderator_user).moderator?
   end
 
   def test_administrator?
   end
 
   def test_administrator?
-    assert_equal false, users(:normal_user).administrator?
-    assert_equal true, users(:administrator_user).administrator?
+    assert_equal false, create(:user).administrator?
+    assert_equal true, create(:administrator_user).administrator?
   end
 
   def test_has_role?
   end
 
   def test_has_role?
-    assert_equal false, users(:normal_user).has_role?("administrator")
-    assert_equal false, users(:normal_user).has_role?("moderator")
-    assert_equal true, users(:administrator_user).has_role?("administrator")
-    assert_equal true, users(:moderator_user).has_role?("moderator")
+    assert_equal false, create(:user).has_role?("administrator")
+    assert_equal false, create(:user).has_role?("moderator")
+    assert_equal true, create(:administrator_user).has_role?("administrator")
+    assert_equal true, create(:moderator_user).has_role?("moderator")
   end
 
   def test_delete
   end
 
   def test_delete