3 class IssuesControllerTest < ActionDispatch::IntegrationTest
5 # Access issues list without login
7 assert_redirected_to login_path(:referer => issues_path)
9 # Access issues list as normal user
10 session_for(create(:user))
12 assert_redirected_to :controller => :errors, :action => :forbidden
14 # Access issues list as administrator
15 session_for(create(:administrator_user))
17 assert_response :success
19 # Access issues list as moderator
20 session_for(create(:moderator_user))
22 assert_response :success
25 def test_show_moderator
26 target_user = create(:user)
27 issue = create(:issue, :reportable => target_user, :reported_user => target_user, :assigned_role => "moderator")
29 # Access issue without login
31 assert_redirected_to login_path(:referer => issue_path(issue))
33 # Access issue as normal user
34 session_for(create(:user))
36 assert_redirected_to :controller => :errors, :action => :forbidden
38 # Access issue as administrator
39 session_for(create(:administrator_user))
41 assert_redirected_to :controller => :errors, :action => :not_found
43 # Access issue as moderator
44 session_for(create(:moderator_user))
46 assert_response :success
49 def test_show_administrator
50 target_user = create(:user)
51 issue = create(:issue, :reportable => target_user, :reported_user => target_user, :assigned_role => "administrator")
53 # Access issue without login
55 assert_redirected_to login_path(:referer => issue_path(issue))
57 # Access issue as normal user
58 session_for(create(:user))
60 assert_redirected_to :controller => :errors, :action => :forbidden
62 # Access issue as moderator
63 session_for(create(:moderator_user))
65 assert_redirected_to :controller => :errors, :action => :not_found
67 # Access issue as administrator
68 session_for(create(:administrator_user))
70 assert_response :success
73 def test_resolve_moderator
74 target_user = create(:user)
75 issue = create(:issue, :reportable => target_user, :reported_user => target_user, :assigned_role => "moderator")
77 # Resolve issue without login
78 post resolve_issue_path(issue)
79 assert_response :forbidden
81 # Resolve issue as normal user
82 session_for(create(:user))
83 post resolve_issue_path(issue)
84 assert_redirected_to :controller => :errors, :action => :forbidden
86 # Resolve issue as administrator
87 session_for(create(:administrator_user))
88 post resolve_issue_path(issue)
89 assert_redirected_to :controller => :errors, :action => :not_found
90 assert_not_predicate issue.reload, :resolved?
92 # Resolve issue as moderator
93 session_for(create(:moderator_user))
94 post resolve_issue_path(issue)
95 assert_response :redirect
96 assert_predicate issue.reload, :resolved?
99 def test_resolve_administrator
100 target_user = create(:user)
101 issue = create(:issue, :reportable => target_user, :reported_user => target_user, :assigned_role => "administrator")
103 # Resolve issue without login
104 post resolve_issue_path(issue)
105 assert_response :forbidden
107 # Resolve issue as normal user
108 session_for(create(:user))
109 post resolve_issue_path(issue)
110 assert_redirected_to :controller => :errors, :action => :forbidden
112 # Resolve issue as moderator
113 session_for(create(:moderator_user))
114 post resolve_issue_path(issue)
115 assert_redirected_to :controller => :errors, :action => :not_found
116 assert_not_predicate issue.reload, :resolved?
118 # Resolve issue as administrator
119 session_for(create(:administrator_user))
120 post resolve_issue_path(issue)
121 assert_response :redirect
122 assert_predicate issue.reload, :resolved?
125 def test_ignore_moderator
126 target_user = create(:user)
127 issue = create(:issue, :reportable => target_user, :reported_user => target_user, :assigned_role => "moderator")
129 # Ignore issue without login
130 post ignore_issue_path(issue)
131 assert_response :forbidden
133 # Ignore issue as normal user
134 session_for(create(:user))
135 post ignore_issue_path(issue)
136 assert_redirected_to :controller => :errors, :action => :forbidden
138 # Ignore issue as administrator
139 session_for(create(:administrator_user))
140 post ignore_issue_path(issue)
141 assert_redirected_to :controller => :errors, :action => :not_found
142 assert_not_predicate issue.reload, :ignored?
144 # Ignore issue as moderator
145 session_for(create(:moderator_user))
146 post ignore_issue_path(issue)
147 assert_response :redirect
148 assert_predicate issue.reload, :ignored?
151 def test_ignore_administrator
152 target_user = create(:user)
153 issue = create(:issue, :reportable => target_user, :reported_user => target_user, :assigned_role => "administrator")
155 # Ignore issue without login
156 post ignore_issue_path(issue)
157 assert_response :forbidden
159 # Ignore issue as normal user
160 session_for(create(:user))
161 post ignore_issue_path(issue)
162 assert_redirected_to :controller => :errors, :action => :forbidden
164 # Ignore issue as moderator
165 session_for(create(:moderator_user))
166 post ignore_issue_path(issue)
167 assert_redirected_to :controller => :errors, :action => :not_found
168 assert_not_predicate issue.reload, :ignored?
170 # Ignore issue as administrator
171 session_for(create(:administrator_user))
172 post ignore_issue_path(issue)
173 assert_response :redirect
174 assert_predicate issue.reload, :ignored?
177 def test_reopen_moderator
178 target_user = create(:user)
179 issue = create(:issue, :reportable => target_user, :reported_user => target_user, :assigned_role => "moderator")
183 # Reopen issue without login
184 post reopen_issue_path(issue)
185 assert_response :forbidden
187 # Reopen issue as normal user
188 session_for(create(:user))
189 post reopen_issue_path(issue)
190 assert_redirected_to :controller => :errors, :action => :forbidden
192 # Reopen issue as administrator
193 session_for(create(:administrator_user))
194 post reopen_issue_path(issue)
195 assert_redirected_to :controller => :errors, :action => :not_found
196 assert_not_predicate issue.reload, :open?
198 # Reopen issue as moderator
199 session_for(create(:moderator_user))
200 post reopen_issue_path(issue)
201 assert_response :redirect
202 assert_predicate issue.reload, :open?
205 def test_reopen_administrator
206 target_user = create(:user)
207 issue = create(:issue, :reportable => target_user, :reported_user => target_user, :assigned_role => "administrator")
211 # Reopen issue without login
212 post reopen_issue_path(issue)
213 assert_response :forbidden
215 # Reopen issue as normal user
216 session_for(create(:user))
217 post reopen_issue_path(issue)
218 assert_redirected_to :controller => :errors, :action => :forbidden
220 # Reopen issue as moderator
221 session_for(create(:moderator_user))
222 post reopen_issue_path(issue)
223 assert_redirected_to :controller => :errors, :action => :not_found
224 assert_not_predicate issue.reload, :open?
226 # Reopen issue as administrator
227 session_for(create(:administrator_user))
228 post reopen_issue_path(issue)
229 assert_response :redirect
230 assert_predicate issue.reload, :open?