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 icon_dom = Rails::Dom::Testing.html_document_fragment.parse(icon)
17 assert_dom icon_dom, "svg:root", :count => 1 do
18 assert_dom "> title", :text => "This user is a moderator"
21 icon = role_icon(create(:importer_user), "importer")
22 icon_dom = Rails::Dom::Testing.html_document_fragment.parse(icon)
23 assert_dom icon_dom, "svg:root", :count => 1 do
24 assert_dom "> title", :text => "This user is a importer"
28 def test_role_icon_administrator
29 self.current_user = create(:administrator_user)
31 create(:user) do |user|
32 icon = role_icon(user, "moderator")
33 icon_dom = Rails::Dom::Testing.html_document_fragment.parse(icon)
34 assert_dom icon_dom, "a:root[href='#{user_role_path(user, 'moderator')}'][data-method='post']", :count => 1 do
35 assert_dom "> svg", :count => 1 do
36 assert_dom "> title", :text => "Grant moderator access"
40 icon = role_icon(user, "importer")
41 icon_dom = Rails::Dom::Testing.html_document_fragment.parse(icon)
42 assert_dom icon_dom, "a:root[href='#{user_role_path(user, 'importer')}'][data-method='post']", :count => 1 do
43 assert_dom "> svg", :count => 1 do
44 assert_dom "> title", :text => "Grant importer access"
49 create(:moderator_user) do |user|
50 icon = role_icon(user, "moderator")
51 icon_dom = Rails::Dom::Testing.html_document_fragment.parse(icon)
52 assert_dom icon_dom, "a:root[href='#{user_role_path(user, 'moderator')}'][data-method='delete']", :count => 1 do
53 assert_dom "> svg", :count => 1 do
54 assert_dom "> title", :text => "Revoke moderator access"
58 icon = role_icon(user, "importer")
59 icon_dom = Rails::Dom::Testing.html_document_fragment.parse(icon)
60 assert_dom icon_dom, "a:root[href='#{user_role_path(user, 'importer')}'][data-method='post']", :count => 1 do
61 assert_dom "> svg", :count => 1 do
62 assert_dom "> title", :text => "Grant importer access"
67 create(:importer_user) do |user|
68 icon = role_icon(user, "moderator")
69 icon_dom = Rails::Dom::Testing.html_document_fragment.parse(icon)
70 assert_dom icon_dom, "a:root[href='#{user_role_path(user, 'moderator')}'][data-method='post']", :count => 1 do
71 assert_dom "> svg", :count => 1 do
72 assert_dom "> title", :text => "Grant moderator access"
76 icon = role_icon(user, "importer")
77 icon_dom = Rails::Dom::Testing.html_document_fragment.parse(icon)
78 assert_dom icon_dom, "a:root[href='#{user_role_path(user, 'importer')}'][data-method='delete']", :count => 1 do
79 assert_dom "> svg", :count => 1 do
80 assert_dom "> title", :text => "Revoke importer access"
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 icons_dom = Rails::Dom::Testing.html_document_fragment.parse(icons)
94 assert_dom icons_dom, "svg:root > title", :text => "This user is a moderator"
96 icons = role_icons(create(:importer_user))
97 icons_dom = Rails::Dom::Testing.html_document_fragment.parse(icons)
98 assert_dom icons_dom, "svg:root > title", :text => "This user is a importer"
100 icons = role_icons(create(:super_user))
101 icons_dom = Rails::Dom::Testing.html_document_fragment.parse(icons)
102 assert_dom icons_dom, "svg:root", :count => 3 do
103 assert_dom "> title", :text => "This user is an administrator"
104 assert_dom "> title", :text => "This user is a moderator"
105 assert_dom "> title", :text => "This user is a importer"
109 def test_role_icons_administrator
110 self.current_user = create(:administrator_user)
112 create(:user) do |user|
113 icons = role_icons(user)
114 icons_dom = Rails::Dom::Testing.html_document_fragment.parse(icons)
115 assert_dom icons_dom, "a:root", :count => 3
116 assert_dom icons_dom, "a:root[href='#{user_role_path(user, 'administrator')}'][data-method='post']" do
117 assert_dom "> svg > title", :text => "Grant administrator access"
119 assert_dom icons_dom, "a:root[href='#{user_role_path(user, 'moderator')}'][data-method='post']" do
120 assert_dom "> svg > title", :text => "Grant moderator access"
122 assert_dom icons_dom, "a:root[href='#{user_role_path(user, 'importer')}'][data-method='post']" do
123 assert_dom "> svg > title", :text => "Grant importer access"
127 create(:moderator_user) do |user|
128 icons = role_icons(user)
129 icons_dom = Rails::Dom::Testing.html_document_fragment.parse(icons)
130 assert_dom icons_dom, "a:root", :count => 3
131 assert_dom icons_dom, "a:root[href='#{user_role_path(user, 'administrator')}'][data-method='post']" do
132 assert_dom "> svg > title", :text => "Grant administrator access"
134 assert_dom icons_dom, "a:root[href='#{user_role_path(user, 'moderator')}'][data-method='delete']" do
135 assert_dom "> svg > title", :text => "Revoke moderator access"
137 assert_dom icons_dom, "a:root[href='#{user_role_path(user, 'importer')}'][data-method='post']" do
138 assert_dom "> svg > title", :text => "Grant importer access"
142 create(:importer_user) do |user|
143 icons = role_icons(user)
144 icons_dom = Rails::Dom::Testing.html_document_fragment.parse(icons)
145 assert_dom icons_dom, "a:root", :count => 3
146 assert_dom icons_dom, "a:root[href='#{user_role_path(user, 'administrator')}'][data-method='post']" do
147 assert_dom "> svg > title", :text => "Grant administrator access"
149 assert_dom icons_dom, "a:root[href='#{user_role_path(user, 'moderator')}'][data-method='post']" do
150 assert_dom "> svg > title", :text => "Grant moderator access"
152 assert_dom icons_dom, "a:root[href='#{user_role_path(user, 'importer')}'][data-method='delete']" do
153 assert_dom "> svg > title", :text => "Revoke importer access"
157 create(:super_user) do |user|
158 icons = role_icons(user)
159 icons_dom = Rails::Dom::Testing.html_document_fragment.parse(icons)
160 assert_dom icons_dom, "a:root", :count => 3
161 assert_dom icons_dom, "a:root[href='#{user_role_path(user, 'administrator')}'][data-method='delete']" do
162 assert_dom "> svg > title", :text => "Revoke administrator access"
164 assert_dom icons_dom, "a:root[href='#{user_role_path(user, 'moderator')}'][data-method='delete']" do
165 assert_dom "> svg > title", :text => "Revoke moderator access"
167 assert_dom icons_dom, "a:root[href='#{user_role_path(user, 'importer')}'][data-method='delete']" do
168 assert_dom "> svg > title", :text => "Revoke importer access"