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")
15 <source srcset="/images/roles/moderator.svg" type="image/svg+xml">
16 <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" />
19 assert_dom_equal expected, icon
22 def test_role_icon_administrator
23 self.current_user = create(:administrator_user)
26 icon = role_icon(user, "moderator")
27 expected = <<~HTML.delete("\n")
28 <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">
30 <source srcset="/images/roles/blank_moderator.svg" type="image/svg+xml">
31 <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" />
35 assert_dom_equal expected, icon
37 moderator_user = create(:moderator_user)
38 icon = role_icon(moderator_user, "moderator")
39 expected = <<~HTML.delete("\n")
40 <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">
42 <source srcset="/images/roles/moderator.svg" type="image/svg+xml">
43 <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" />
47 assert_dom_equal expected, icon
50 def test_role_icons_normal
51 self.current_user = create(:user)
53 icons = role_icons(current_user)
54 assert_dom_equal "", icons
56 icons = role_icons(create(:moderator_user))
57 expected = <<~HTML.delete("\n")
59 <source srcset="/images/roles/moderator.svg" type="image/svg+xml">
60 <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" />
63 assert_dom_equal expected, icons
65 icons = role_icons(create(:super_user))
66 expected = <<~HTML.delete("\n")
68 <source srcset="/images/roles/administrator.svg" type="image/svg+xml">
69 <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" />
72 <source srcset="/images/roles/moderator.svg" type="image/svg+xml">
73 <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" />
76 assert_dom_equal expected, icons
79 def test_role_icons_administrator
80 self.current_user = create(:administrator_user)
83 icons = role_icons(user)
84 expected = <<~HTML.delete("\n")
85 <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">
87 <source srcset="/images/roles/blank_administrator.svg" type="image/svg+xml">
88 <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" />
91 <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">
93 <source srcset="/images/roles/blank_moderator.svg" type="image/svg+xml">
94 <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" />
98 assert_dom_equal expected, icons
100 moderator_user = create(:moderator_user)
101 icons = role_icons(moderator_user)
102 expected = <<~HTML.delete("\n")
103 <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">
105 <source srcset="/images/roles/blank_administrator.svg" type="image/svg+xml">
106 <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" />
109 <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">
111 <source srcset="/images/roles/moderator.svg" type="image/svg+xml">
112 <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" />
116 assert_dom_equal expected, icons
118 super_user = create(:super_user)
119 icons = role_icons(super_user)
120 expected = <<~HTML.delete("\n")
121 <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">
123 <source srcset="/images/roles/administrator.svg" type="image/svg+xml">
124 <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" />
127 <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">
129 <source srcset="/images/roles/moderator.svg" type="image/svg+xml">
130 <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" />
134 assert_dom_equal expected, icons