3 class UserRolesHelperTest < ActionView::TestCase
4 attr_accessor :current_user
6 def test_role_icon_normal
7 self.current_user = create(:user)
9 icon = role_icon(current_user, "moderator")
10 assert_dom_equal "", icon
12 icon = role_icon(create(:moderator_user), "moderator")
13 expected = <<~HTML.delete("\n")
14 <img srcset="/images/roles/moderator.svg" border="0" alt="This user is a moderator" title="This user is a moderator" src="/images/roles/moderator.png" width="20" height="20" />
16 assert_dom_equal expected, icon
19 def test_role_icon_administrator
20 self.current_user = create(:administrator_user)
23 icon = role_icon(user, "moderator")
24 expected = <<~HTML.delete("\n")
25 <a data-confirm="Are you sure you want to grant the role `moderator' to the user `#{user.display_name}'?" rel="nofollow" data-method="post" href="/user/#{ERB::Util.u(user.display_name)}/role/moderator/grant">
26 <img srcset="/images/roles/blank_moderator.svg" border="0" alt="Grant moderator access" title="Grant moderator access" src="/images/roles/blank_moderator.png" width="20" height="20" />
29 assert_dom_equal expected, icon
31 moderator_user = create(:moderator_user)
32 icon = role_icon(moderator_user, "moderator")
33 expected = <<~HTML.delete("\n")
34 <a data-confirm="Are you sure you want to revoke the role `moderator' from the user `#{moderator_user.display_name}'?" rel="nofollow" data-method="post" href="/user/#{ERB::Util.u(moderator_user.display_name)}/role/moderator/revoke">
35 <img srcset="/images/roles/moderator.svg" border="0" alt="Revoke moderator access" title="Revoke moderator access" src="/images/roles/moderator.png" width="20" height="20" />
38 assert_dom_equal expected, icon
41 def test_role_icons_normal
42 self.current_user = create(:user)
44 icons = role_icons(current_user)
45 assert_dom_equal "", icons
47 icons = role_icons(create(:moderator_user))
48 expected = <<~HTML.delete("\n")
49 <img srcset="/images/roles/moderator.svg" border="0" alt="This user is a moderator" title="This user is a moderator" src="/images/roles/moderator.png" width="20" height="20" />
51 assert_dom_equal expected, icons
53 icons = role_icons(create(:super_user))
54 expected = <<~HTML.delete("\n")
55 <img srcset="/images/roles/administrator.svg" border="0" alt="This user is an administrator" title="This user is an administrator" src="/images/roles/administrator.png" width="20" height="20" />
56 <img srcset="/images/roles/moderator.svg" border="0" alt="This user is a moderator" title="This user is a moderator" src="/images/roles/moderator.png" width="20" height="20" />
58 assert_dom_equal expected, icons
61 def test_role_icons_administrator
62 self.current_user = create(:administrator_user)
65 icons = role_icons(user)
66 expected = <<~HTML.delete("\n")
67 <a data-confirm="Are you sure you want to grant the role `administrator' to the user `#{user.display_name}'?" rel="nofollow" data-method="post" href="/user/#{ERB::Util.u(user.display_name)}/role/administrator/grant">
68 <img srcset="/images/roles/blank_administrator.svg" border="0" alt="Grant administrator access" title="Grant administrator access" src="/images/roles/blank_administrator.png" width="20" height="20" />
70 <a data-confirm="Are you sure you want to grant the role `moderator' to the user `#{user.display_name}'?" rel="nofollow" data-method="post" href="/user/#{ERB::Util.u(user.display_name)}/role/moderator/grant">
71 <img srcset="/images/roles/blank_moderator.svg" border="0" alt="Grant moderator access" title="Grant moderator access" src="/images/roles/blank_moderator.png" width="20" height="20" />
74 assert_dom_equal expected, icons
76 moderator_user = create(:moderator_user)
77 icons = role_icons(moderator_user)
78 expected = <<~HTML.delete("\n")
79 <a data-confirm="Are you sure you want to grant the role `administrator' to the user `#{moderator_user.display_name}'?" rel="nofollow" data-method="post" href="/user/#{ERB::Util.u(moderator_user.display_name)}/role/administrator/grant">
80 <img srcset="/images/roles/blank_administrator.svg" border="0" alt="Grant administrator access" title="Grant administrator access" src="/images/roles/blank_administrator.png" width="20" height="20" />
82 <a data-confirm="Are you sure you want to revoke the role `moderator' from the user `#{moderator_user.display_name}'?" rel="nofollow" data-method="post" href="/user/#{ERB::Util.u(moderator_user.display_name)}/role/moderator/revoke">
83 <img srcset="/images/roles/moderator.svg" border="0" alt="Revoke moderator access" title="Revoke moderator access" src="/images/roles/moderator.png" width="20" height="20" />
86 assert_dom_equal expected, icons
88 super_user = create(:super_user)
89 icons = role_icons(super_user)
90 expected = <<~HTML.delete("\n")
91 <a data-confirm="Are you sure you want to revoke the role `administrator' from the user `#{super_user.display_name}'?" rel="nofollow" data-method="post" href="/user/#{ERB::Util.u(super_user.display_name)}/role/administrator/revoke">
92 <img srcset="/images/roles/administrator.svg" border="0" alt="Revoke administrator access" title="Revoke administrator access" src="/images/roles/administrator.png" width="20" height="20" />
94 <a data-confirm="Are you sure you want to revoke the role `moderator' from the user `#{super_user.display_name}'?" rel="nofollow" data-method="post" href="/user/#{ERB::Util.u(super_user.display_name)}/role/moderator/revoke">
95 <img srcset="/images/roles/moderator.svg" border="0" alt="Revoke moderator access" title="Revoke moderator access" src="/images/roles/moderator.png" width="20" height="20" />
98 assert_dom_equal expected, icons