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(current_user, "importer")
13 assert_dom_equal "", icon
15 icon = role_icon(create(:moderator_user), "moderator")
16 expected = <<~HTML.delete("\n")
17 <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
21 icon = role_icon(create(:importer_user), "importer")
22 expected = <<~HTML.delete("\n")
23 <img srcset="/images/roles/importer.svg" border="0" alt="This user is a importer" title="This user is a importer" src="/images/roles/importer.png" width="20" height="20" />
25 assert_dom_equal expected, icon
28 def test_role_icon_administrator
29 self.current_user = create(:administrator_user)
33 icon = role_icon(user, "moderator")
34 expected = <<~HTML.delete("\n")
35 <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">
36 <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" />
39 assert_dom_equal expected, icon
41 icon = role_icon(user, "importer")
42 expected = <<~HTML.delete("\n")
43 <a data-confirm="Are you sure you want to grant the role `importer' to the user `#{user.display_name}'?" rel="nofollow" data-method="post" href="/user/#{ERB::Util.u(user.display_name)}/role/importer/grant">
44 <img srcset="/images/roles/blank_importer.svg" border="0" alt="Grant importer access" title="Grant importer access" src="/images/roles/blank_importer.png" width="20" height="20" />
47 assert_dom_equal expected, icon
49 moderator_user = create(:moderator_user)
51 icon = role_icon(moderator_user, "moderator")
52 expected = <<~HTML.delete("\n")
53 <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">
54 <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" />
57 assert_dom_equal expected, icon
59 icon = role_icon(user, "importer")
60 expected = <<~HTML.delete("\n")
61 <a data-confirm="Are you sure you want to grant the role `importer' to the user `#{user.display_name}'?" rel="nofollow" data-method="post" href="/user/#{ERB::Util.u(user.display_name)}/role/importer/grant">
62 <img srcset="/images/roles/blank_importer.svg" border="0" alt="Grant importer access" title="Grant importer access" src="/images/roles/blank_importer.png" width="20" height="20" />
65 assert_dom_equal expected, icon
67 importer_user = create(:importer_user)
69 icon = role_icon(user, "moderator")
70 expected = <<~HTML.delete("\n")
71 <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">
72 <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" />
75 assert_dom_equal expected, icon
77 icon = role_icon(importer_user, "importer")
78 expected = <<~HTML.delete("\n")
79 <a data-confirm="Are you sure you want to revoke the role `importer' from the user `#{importer_user.display_name}'?" rel="nofollow" data-method="post" href="/user/#{ERB::Util.u(importer_user.display_name)}/role/importer/revoke">
80 <img srcset="/images/roles/importer.svg" border="0" alt="Revoke importer access" title="Revoke importer access" src="/images/roles/importer.png" width="20" height="20" />
83 assert_dom_equal expected, icon
86 def test_role_icons_normal
87 self.current_user = create(:user)
89 icons = role_icons(current_user)
90 assert_dom_equal "", icons
92 icons = role_icons(create(:moderator_user))
93 expected = <<~HTML.delete("\n")
94 <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" />
96 assert_dom_equal expected, icons
98 icons = role_icons(create(:importer_user))
99 expected = <<~HTML.delete("\n")
100 <img srcset="/images/roles/importer.svg" border="0" alt="This user is a importer" title="This user is a importer" src="/images/roles/importer.png" width="20" height="20" />
102 assert_dom_equal expected, icons
104 icons = role_icons(create(:super_user))
105 expected = <<~HTML.delete("\n")
106 <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" />
107 <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" />
108 <img srcset="/images/roles/importer.svg" border="0" alt="This user is a importer" title="This user is a importer" src="/images/roles/importer.png" width="20" height="20" />
110 assert_dom_equal expected, icons
113 def test_role_icons_administrator
114 self.current_user = create(:administrator_user)
117 icons = role_icons(user)
118 expected = <<~HTML.delete("\n")
119 <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">
120 <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" />
122 <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">
123 <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" />
125 <a data-confirm="Are you sure you want to grant the role `importer' to the user `#{user.display_name}'?" rel="nofollow" data-method="post" href="/user/#{ERB::Util.u(user.display_name)}/role/importer/grant">
126 <img srcset="/images/roles/blank_importer.svg" border="0" alt="Grant importer access" title="Grant importer access" src="/images/roles/blank_importer.png" width="20" height="20" />
129 assert_dom_equal expected, icons
131 moderator_user = create(:moderator_user)
132 icons = role_icons(moderator_user)
133 expected = <<~HTML.delete("\n")
134 <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">
135 <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" />
137 <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">
138 <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" />
140 <a data-confirm="Are you sure you want to grant the role `importer' to the user `#{moderator_user.display_name}'?" rel="nofollow" data-method="post" href="/user/#{ERB::Util.u(moderator_user.display_name)}/role/importer/grant">
141 <img srcset="/images/roles/blank_importer.svg" border="0" alt="Grant importer access" title="Grant importer access" src="/images/roles/blank_importer.png" width="20" height="20" />
144 assert_dom_equal expected, icons
146 importer_user = create(:importer_user)
147 icons = role_icons(importer_user)
148 expected = <<~HTML.delete("\n")
149 <a data-confirm="Are you sure you want to grant the role `administrator' to the user `#{importer_user.display_name}'?" rel="nofollow" data-method="post" href="/user/#{ERB::Util.u(importer_user.display_name)}/role/administrator/grant">
150 <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" />
152 <a data-confirm="Are you sure you want to grant the role `moderator' to the user `#{importer_user.display_name}'?" rel="nofollow" data-method="post" href="/user/#{ERB::Util.u(importer_user.display_name)}/role/moderator/grant">
153 <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" />
155 <a data-confirm="Are you sure you want to revoke the role `importer' from the user `#{importer_user.display_name}'?" rel="nofollow" data-method="post" href="/user/#{ERB::Util.u(importer_user.display_name)}/role/importer/revoke">
156 <img srcset="/images/roles/importer.svg" border="0" alt="Revoke importer access" title="Revoke importer access" src="/images/roles/importer.png" width="20" height="20" />
159 assert_dom_equal expected, icons
161 super_user = create(:super_user)
162 icons = role_icons(super_user)
163 expected = <<~HTML.delete("\n")
164 <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">
165 <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" />
167 <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">
168 <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" />
170 <a data-confirm="Are you sure you want to revoke the role `importer' from the user `#{super_user.display_name}'?" rel="nofollow" data-method="post" href="/user/#{ERB::Util.u(super_user.display_name)}/role/importer/revoke">
171 <img srcset="/images/roles/importer.svg" border="0" alt="Revoke importer access" title="Revoke importer access" src="/images/roles/importer.png" width="20" height="20" />
174 assert_dom_equal expected, icons