From 38fc6331af1e45e077db040a317845607050d2a3 Mon Sep 17 00:00:00 2001 From: Andy Allan Date: Thu, 2 Feb 2017 12:38:19 +0000 Subject: [PATCH] Add moderator_user and administrator_user factories. --- test/factories/user.rb | 12 ++++++++++++ test/models/user_test.rb | 16 ++++++++-------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/test/factories/user.rb b/test/factories/user.rb index 79b9a2a16..6376659ab 100644 --- a/test/factories/user.rb +++ b/test/factories/user.rb @@ -8,5 +8,17 @@ FactoryGirl.define do 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 diff --git a/test/models/user_test.rb b/test/models/user_test.rb index 5eacd98b9..6632702e5 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -223,20 +223,20 @@ class UserTest < ActiveSupport::TestCase 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? - 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? - 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 -- 2.39.5