]> git.openstreetmap.org Git - rails.git/blob - test/helpers/user_roles_helper_test.rb
Fix warning on unescaped hyphen in regexp
[rails.git] / test / helpers / user_roles_helper_test.rb
1 require "test_helper"
2
3 class UserRolesHelperTest < ActionView::TestCase
4   attr_accessor :current_user
5
6   def test_role_icon_normal
7     self.current_user = create(:user)
8
9     icon = role_icon(current_user, "moderator")
10     assert_dom_equal "", icon
11
12     icon = role_icon(current_user, "importer")
13     assert_dom_equal "", icon
14
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" />
18     HTML
19     assert_dom_equal expected, icon
20
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" />
24     HTML
25     assert_dom_equal expected, icon
26   end
27
28   def test_role_icon_administrator
29     self.current_user = create(:administrator_user)
30
31     user = create(:user)
32
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&#39; to the user `#{user.display_name}&#39;?" 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" />
37       </a>
38     HTML
39     assert_dom_equal expected, icon
40
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&#39; to the user `#{user.display_name}&#39;?" 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" />
45       </a>
46     HTML
47     assert_dom_equal expected, icon
48
49     moderator_user = create(:moderator_user)
50
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&#39; from the user `#{moderator_user.display_name}&#39;?" 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" />
55       </a>
56     HTML
57     assert_dom_equal expected, icon
58
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&#39; to the user `#{user.display_name}&#39;?" 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" />
63       </a>
64     HTML
65     assert_dom_equal expected, icon
66
67     importer_user = create(:importer_user)
68
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&#39; to the user `#{user.display_name}&#39;?" 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" />
73       </a>
74     HTML
75     assert_dom_equal expected, icon
76
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&#39; from the user `#{importer_user.display_name}&#39;?" 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" />
81       </a>
82     HTML
83     assert_dom_equal expected, icon
84   end
85
86   def test_role_icons_normal
87     self.current_user = create(:user)
88
89     icons = role_icons(current_user)
90     assert_dom_equal "", icons
91
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" />
95     HTML
96     assert_dom_equal expected, icons
97
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" />
101     HTML
102     assert_dom_equal expected, icons
103
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" />
109     HTML
110     assert_dom_equal expected, icons
111   end
112
113   def test_role_icons_administrator
114     self.current_user = create(:administrator_user)
115
116     user = create(: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&#39; to the user `#{user.display_name}&#39;?" 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" />
121       </a>
122       <a data-confirm="Are you sure you want to grant the role `moderator&#39; to the user `#{user.display_name}&#39;?" 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" />
124       </a>
125       <a data-confirm="Are you sure you want to grant the role `importer&#39; to the user `#{user.display_name}&#39;?" 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" />
127       </a>
128     HTML
129     assert_dom_equal expected, icons
130
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&#39; to the user `#{moderator_user.display_name}&#39;?" 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" />
136       </a>
137       <a data-confirm="Are you sure you want to revoke the role `moderator&#39; from the user `#{moderator_user.display_name}&#39;?" 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" />
139       </a>
140       <a data-confirm="Are you sure you want to grant the role `importer&#39; to the user `#{moderator_user.display_name}&#39;?" 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" />
142       </a>
143     HTML
144     assert_dom_equal expected, icons
145
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&#39; to the user `#{importer_user.display_name}&#39;?" 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" />
151       </a>
152       <a data-confirm="Are you sure you want to grant the role `moderator&#39; to the user `#{importer_user.display_name}&#39;?" 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" />
154       </a>
155       <a data-confirm="Are you sure you want to revoke the role `importer&#39; from the user `#{importer_user.display_name}&#39;?" 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" />
157       </a>
158     HTML
159     assert_dom_equal expected, icons
160
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&#39; from the user `#{super_user.display_name}&#39;?" 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" />
166       </a>
167       <a data-confirm="Are you sure you want to revoke the role `moderator&#39; from the user `#{super_user.display_name}&#39;?" 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" />
169       </a>
170       <a data-confirm="Are you sure you want to revoke the role `importer&#39; from the user `#{super_user.display_name}&#39;?" 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" />
172       </a>
173     HTML
174     assert_dom_equal expected, icons
175   end
176 end