3 class IssuesControllerTest < ActionDispatch::IntegrationTest
5 # Access issues list without login
7 assert_response :redirect
8 assert_redirected_to login_path(:referer => issues_path)
10 # Access issues list as normal user
11 session_for(create(:user))
13 assert_response :redirect
14 assert_redirected_to :controller => :errors, :action => :forbidden
16 # Access issues list as administrator
17 session_for(create(:administrator_user))
19 assert_response :success
21 # Access issues list as moderator
22 session_for(create(:moderator_user))
24 assert_response :success
27 def test_show_moderator
28 target_user = create(:user)
29 issue = create(:issue, :reportable => target_user, :reported_user => target_user, :assigned_role => "moderator")
31 # Access issue without login
32 get issue_path(:id => issue)
33 assert_response :redirect
34 assert_redirected_to login_path(:referer => issue_path(issue))
36 # Access issue as normal user
37 session_for(create(:user))
38 get issue_path(:id => issue)
39 assert_response :redirect
40 assert_redirected_to :controller => :errors, :action => :forbidden
42 # Access issue as administrator
43 session_for(create(:administrator_user))
44 get issue_path(:id => issue)
45 assert_redirected_to :controller => :errors, :action => :not_found
47 # Access issue as moderator
48 session_for(create(:moderator_user))
49 get issue_path(:id => issue)
50 assert_response :success
53 def test_show_administrator
54 target_user = create(:user)
55 issue = create(:issue, :reportable => target_user, :reported_user => target_user, :assigned_role => "administrator")
57 # Access issue without login
58 get issue_path(:id => issue)
59 assert_response :redirect
60 assert_redirected_to login_path(:referer => issue_path(issue))
62 # Access issue as normal user
63 session_for(create(:user))
64 get issue_path(:id => issue)
65 assert_response :redirect
66 assert_redirected_to :controller => :errors, :action => :forbidden
68 # Access issue as moderator
69 session_for(create(:moderator_user))
70 get issue_path(:id => issue)
71 assert_redirected_to :controller => :errors, :action => :not_found
73 # Access issue as administrator
74 session_for(create(:administrator_user))
75 get issue_path(:id => issue)
76 assert_response :success
79 def test_resolve_moderator
80 target_user = create(:user)
81 issue = create(:issue, :reportable => target_user, :reported_user => target_user, :assigned_role => "moderator")
83 # Resolve issue without login
84 post resolve_issue_path(:id => issue)
85 assert_response :forbidden
87 # Resolve issue as normal user
88 session_for(create(:user))
89 post resolve_issue_path(:id => issue)
90 assert_response :redirect
91 assert_redirected_to :controller => :errors, :action => :forbidden
93 # Resolve issue as administrator
94 session_for(create(:administrator_user))
95 post resolve_issue_path(:id => issue)
96 assert_redirected_to :controller => :errors, :action => :not_found
97 assert_not issue.reload.resolved?
99 # Resolve issue as moderator
100 session_for(create(:moderator_user))
101 post resolve_issue_path(:id => issue)
102 assert_response :redirect
103 assert_predicate issue.reload, :resolved?
106 def test_resolve_administrator
107 target_user = create(:user)
108 issue = create(:issue, :reportable => target_user, :reported_user => target_user, :assigned_role => "administrator")
110 # Resolve issue without login
111 post resolve_issue_path(:id => issue)
112 assert_response :forbidden
114 # Resolve issue as normal user
115 session_for(create(:user))
116 post resolve_issue_path(:id => issue)
117 assert_response :redirect
118 assert_redirected_to :controller => :errors, :action => :forbidden
120 # Resolve issue as moderator
121 session_for(create(:moderator_user))
122 post resolve_issue_path(:id => issue)
123 assert_redirected_to :controller => :errors, :action => :not_found
124 assert_not issue.reload.resolved?
126 # Resolve issue as administrator
127 session_for(create(:administrator_user))
128 post resolve_issue_path(:id => issue)
129 assert_response :redirect
130 assert_predicate issue.reload, :resolved?
133 def test_ignore_moderator
134 target_user = create(:user)
135 issue = create(:issue, :reportable => target_user, :reported_user => target_user, :assigned_role => "moderator")
137 # Ignore issue without login
138 post ignore_issue_path(:id => issue)
139 assert_response :forbidden
141 # Ignore issue as normal user
142 session_for(create(:user))
143 post ignore_issue_path(:id => issue)
144 assert_response :redirect
145 assert_redirected_to :controller => :errors, :action => :forbidden
147 # Ignore issue as administrator
148 session_for(create(:administrator_user))
149 post ignore_issue_path(:id => issue)
150 assert_redirected_to :controller => :errors, :action => :not_found
151 assert_not issue.reload.ignored?
153 # Ignore issue as moderator
154 session_for(create(:moderator_user))
155 post ignore_issue_path(:id => issue)
156 assert_response :redirect
157 assert_predicate issue.reload, :ignored?
160 def test_ignore_administrator
161 target_user = create(:user)
162 issue = create(:issue, :reportable => target_user, :reported_user => target_user, :assigned_role => "administrator")
164 # Ignore issue without login
165 post ignore_issue_path(:id => issue)
166 assert_response :forbidden
168 # Ignore issue as normal user
169 session_for(create(:user))
170 post ignore_issue_path(:id => issue)
171 assert_response :redirect
172 assert_redirected_to :controller => :errors, :action => :forbidden
174 # Ignore issue as moderator
175 session_for(create(:moderator_user))
176 post ignore_issue_path(:id => issue)
177 assert_redirected_to :controller => :errors, :action => :not_found
178 assert_not issue.reload.ignored?
180 # Ignore issue as administrator
181 session_for(create(:administrator_user))
182 post ignore_issue_path(:id => issue)
183 assert_response :redirect
184 assert_predicate issue.reload, :ignored?
187 def test_reopen_moderator
188 target_user = create(:user)
189 issue = create(:issue, :reportable => target_user, :reported_user => target_user, :assigned_role => "moderator")
193 # Reopen issue without login
194 post reopen_issue_path(:id => issue)
195 assert_response :forbidden
197 # Reopen issue as normal user
198 session_for(create(:user))
199 post reopen_issue_path(:id => issue)
200 assert_response :redirect
201 assert_redirected_to :controller => :errors, :action => :forbidden
203 # Reopen issue as administrator
204 session_for(create(:administrator_user))
205 post reopen_issue_path(:id => issue)
206 assert_redirected_to :controller => :errors, :action => :not_found
207 assert_not issue.reload.open?
209 # Reopen issue as moderator
210 session_for(create(:moderator_user))
211 post reopen_issue_path(:id => issue)
212 assert_response :redirect
213 assert_predicate issue.reload, :open?
216 def test_reopen_administrator
217 target_user = create(:user)
218 issue = create(:issue, :reportable => target_user, :reported_user => target_user, :assigned_role => "administrator")
222 # Reopen issue without login
223 post reopen_issue_path(:id => issue)
224 assert_response :forbidden
226 # Reopen issue as normal user
227 session_for(create(:user))
228 post reopen_issue_path(:id => issue)
229 assert_response :redirect
230 assert_redirected_to :controller => :errors, :action => :forbidden
232 # Reopen issue as moderator
233 session_for(create(:moderator_user))
234 post reopen_issue_path(:id => issue)
235 assert_redirected_to :controller => :errors, :action => :not_found
236 assert_not issue.reload.open?
238 # Reopen issue as administrator
239 session_for(create(:administrator_user))
240 post reopen_issue_path(:id => issue)
241 assert_response :redirect
242 assert_predicate issue.reload, :open?