3 class IssuesControllerTest < ActionController::TestCase
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[:user] = create(:user).id
13 assert_response :redirect
14 assert_redirected_to :controller => :errors, :action => :forbidden
16 # Access issues list as administrator
17 session[:user] = create(:administrator_user).id
19 assert_response :success
21 # Access issues list as moderator
22 session[:user] = create(:moderator_user).id
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 :show, :params => { :id => issue.id }
33 assert_response :redirect
34 assert_redirected_to login_path(:referer => issue_path(issue))
36 # Access issue as normal user
37 session[:user] = create(:user).id
38 get :show, :params => { :id => issue.id }
39 assert_response :redirect
40 assert_redirected_to :controller => :errors, :action => :forbidden
42 # Access issue as administrator
43 session[:user] = create(:administrator_user).id
44 get :show, :params => { :id => issue.id }
45 assert_redirected_to :controller => :errors, :action => :not_found
47 # Access issue as moderator
48 session[:user] = create(:moderator_user).id
49 get :show, :params => { :id => issue.id }
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 :show, :params => { :id => issue.id }
59 assert_response :redirect
60 assert_redirected_to login_path(:referer => issue_path(issue))
62 # Access issue as normal user
63 session[:user] = create(:user).id
64 get :show, :params => { :id => issue.id }
65 assert_response :redirect
66 assert_redirected_to :controller => :errors, :action => :forbidden
68 # Access issue as moderator
69 session[:user] = create(:moderator_user).id
70 get :show, :params => { :id => issue.id }
71 assert_redirected_to :controller => :errors, :action => :not_found
73 # Access issue as administrator
74 session[:user] = create(:administrator_user).id
75 get :show, :params => { :id => issue.id }
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 get :resolve, :params => { :id => issue.id }
85 assert_response :redirect
86 assert_redirected_to login_path(:referer => resolve_issue_path(issue))
88 # Resolve issue as normal user
89 session[:user] = create(:user).id
90 get :resolve, :params => { :id => issue.id }
91 assert_response :redirect
92 assert_redirected_to :controller => :errors, :action => :forbidden
94 # Resolve issue as administrator
95 session[:user] = create(:administrator_user).id
96 get :resolve, :params => { :id => issue.id }
97 assert_redirected_to :controller => :errors, :action => :not_found
98 assert_not issue.reload.resolved?
100 # Resolve issue as moderator
101 session[:user] = create(:moderator_user).id
102 get :resolve, :params => { :id => issue.id }
103 assert_response :redirect
104 assert issue.reload.resolved?
107 def test_resolve_administrator
108 target_user = create(:user)
109 issue = create(:issue, :reportable => target_user, :reported_user => target_user, :assigned_role => "administrator")
111 # Resolve issue without login
112 get :resolve, :params => { :id => issue.id }
113 assert_response :redirect
114 assert_redirected_to login_path(:referer => resolve_issue_path(issue))
116 # Resolve issue as normal user
117 session[:user] = create(:user).id
118 get :resolve, :params => { :id => issue.id }
119 assert_response :redirect
120 assert_redirected_to :controller => :errors, :action => :forbidden
122 # Resolve issue as moderator
123 session[:user] = create(:moderator_user).id
124 get :resolve, :params => { :id => issue.id }
125 assert_redirected_to :controller => :errors, :action => :not_found
126 assert_not issue.reload.resolved?
128 # Resolve issue as administrator
129 session[:user] = create(:administrator_user).id
130 get :resolve, :params => { :id => issue.id }
131 assert_response :redirect
132 assert issue.reload.resolved?
135 def test_ignore_moderator
136 target_user = create(:user)
137 issue = create(:issue, :reportable => target_user, :reported_user => target_user, :assigned_role => "moderator")
139 # Ignore issue without login
140 get :ignore, :params => { :id => issue.id }
141 assert_response :redirect
142 assert_redirected_to login_path(:referer => ignore_issue_path(issue))
144 # Ignore issue as normal user
145 session[:user] = create(:user).id
146 get :ignore, :params => { :id => issue.id }
147 assert_response :redirect
148 assert_redirected_to :controller => :errors, :action => :forbidden
150 # Ignore issue as administrator
151 session[:user] = create(:administrator_user).id
152 get :ignore, :params => { :id => issue.id }
153 assert_redirected_to :controller => :errors, :action => :not_found
154 assert_not issue.reload.ignored?
156 # Ignore issue as moderator
157 session[:user] = create(:moderator_user).id
158 get :ignore, :params => { :id => issue.id }
159 assert_response :redirect
160 assert issue.reload.ignored?
163 def test_ignore_administrator
164 target_user = create(:user)
165 issue = create(:issue, :reportable => target_user, :reported_user => target_user, :assigned_role => "administrator")
167 # Ignore issue without login
168 get :ignore, :params => { :id => issue.id }
169 assert_response :redirect
170 assert_redirected_to login_path(:referer => ignore_issue_path(issue))
172 # Ignore issue as normal user
173 session[:user] = create(:user).id
174 get :ignore, :params => { :id => issue.id }
175 assert_response :redirect
176 assert_redirected_to :controller => :errors, :action => :forbidden
178 # Ignore issue as moderator
179 session[:user] = create(:moderator_user).id
180 get :ignore, :params => { :id => issue.id }
181 assert_redirected_to :controller => :errors, :action => :not_found
182 assert_not issue.reload.ignored?
184 # Ignore issue as administrator
185 session[:user] = create(:administrator_user).id
186 get :ignore, :params => { :id => issue.id }
187 assert_response :redirect
188 assert issue.reload.ignored?
191 def test_reopen_moderator
192 target_user = create(:user)
193 issue = create(:issue, :reportable => target_user, :reported_user => target_user, :assigned_role => "moderator")
197 # Reopen issue without login
198 get :reopen, :params => { :id => issue.id }
199 assert_response :redirect
200 assert_redirected_to login_path(:referer => reopen_issue_path(issue))
202 # Reopen issue as normal user
203 session[:user] = create(:user).id
204 get :reopen, :params => { :id => issue.id }
205 assert_response :redirect
206 assert_redirected_to :controller => :errors, :action => :forbidden
208 # Reopen issue as administrator
209 session[:user] = create(:administrator_user).id
210 get :reopen, :params => { :id => issue.id }
211 assert_redirected_to :controller => :errors, :action => :not_found
212 assert_not issue.reload.open?
214 # Reopen issue as moderator
215 session[:user] = create(:moderator_user).id
216 get :reopen, :params => { :id => issue.id }
217 assert_response :redirect
218 assert issue.reload.open?
221 def test_reopen_administrator
222 target_user = create(:user)
223 issue = create(:issue, :reportable => target_user, :reported_user => target_user, :assigned_role => "administrator")
227 # Reopen issue without login
228 get :reopen, :params => { :id => issue.id }
229 assert_response :redirect
230 assert_redirected_to login_path(:referer => reopen_issue_path(issue))
232 # Reopen issue as normal user
233 session[:user] = create(:user).id
234 get :reopen, :params => { :id => issue.id }
235 assert_response :redirect
236 assert_redirected_to :controller => :errors, :action => :forbidden
238 # Reopen issue as moderator
239 session[:user] = create(:moderator_user).id
240 get :reopen, :params => { :id => issue.id }
241 assert_redirected_to :controller => :errors, :action => :not_found
242 assert_not issue.reload.open?
244 # Reopen issue as administrator
245 session[:user] = create(:administrator_user).id
246 get :reopen, :params => { :id => issue.id }
247 assert_response :redirect
248 assert issue.reload.open?