From: Tom Hughes Date: Thu, 9 Mar 2017 18:35:57 +0000 (+0000) Subject: Merge remote-tracking branch 'openstreetmap/pull/1483' X-Git-Tag: live~4111 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/685df702ef6f3e8feac2dca08808cd9ace066a0d?hp=da57077c0b7879f83a8881dc4e7ee115abfac906 Merge remote-tracking branch 'openstreetmap/pull/1483' --- diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 4232b0574..68a7566d9 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -74,7 +74,7 @@ Metrics/CyclomaticComplexity: # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives. # URISchemes: http, https Metrics/LineLength: - Max: 962 + Max: 1072 # Offense count: 612 # Configuration parameters: CountComments. 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 diff --git a/test/helpers/user_roles_helper_test.rb b/test/helpers/user_roles_helper_test.rb index 53169b75a..880c16e59 100644 --- a/test/helpers/user_roles_helper_test.rb +++ b/test/helpers/user_roles_helper_test.rb @@ -1,51 +1,56 @@ require "test_helper" class UserRolesHelperTest < ActionView::TestCase - fixtures :users, :user_roles - def test_role_icon_normal - @user = users(:normal_user) + user = create(:user) + @user = user - icon = role_icon(users(:normal_user), "moderator") + icon = role_icon(user, "moderator") assert_dom_equal "", icon - icon = role_icon(users(:moderator_user), "moderator") + icon = role_icon(create(:moderator_user), "moderator") assert_dom_equal 'This user is a moderator', icon end def test_role_icon_administrator - @user = users(:administrator_user) + @user = create(:administrator_user) - icon = role_icon(users(:normal_user), "moderator") - assert_dom_equal 'Grant moderator access', icon + user = create(:user) + icon = role_icon(user, "moderator") + assert_dom_equal %(Grant moderator access), icon - icon = role_icon(users(:moderator_user), "moderator") - assert_dom_equal 'Revoke moderator access', icon + moderator_user = create(:moderator_user) + icon = role_icon(moderator_user, "moderator") + assert_dom_equal %(Revoke moderator access), icon end def test_role_icons_normal - @user = users(:normal_user) + user = create(:user) + @user = user - icons = role_icons(users(:normal_user)) + icons = role_icons(user) assert_dom_equal " ", icons - icons = role_icons(users(:moderator_user)) + icons = role_icons(create(:moderator_user)) assert_dom_equal ' This user is a moderator', icons - icons = role_icons(users(:super_user)) + icons = role_icons(create(:super_user)) assert_dom_equal ' This user is an administrator This user is a moderator', icons end def test_role_icons_administrator - @user = users(:administrator_user) + @user = create(:administrator_user) - icons = role_icons(users(:normal_user)) - assert_dom_equal ' Grant administrator access Grant moderator access', icons + user = create(:user) + icons = role_icons(user) + assert_dom_equal %( Grant administrator access Grant moderator access), icons - icons = role_icons(users(:moderator_user)) - assert_dom_equal ' Grant administrator access Revoke moderator access', icons + moderator_user = create(:moderator_user) + icons = role_icons(moderator_user) + assert_dom_equal %( Grant administrator access Revoke moderator access), icons - icons = role_icons(users(:super_user)) - assert_dom_equal ' Revoke administrator access Revoke moderator access', icons + super_user = create(:super_user) + icons = role_icons(super_user) + assert_dom_equal %( Revoke administrator access Revoke moderator access), icons end end