3 class IssuesControllerTest < ActionController::TestCase
5 # cleanup any emails set off by the test
6 ActionMailer::Base.deliveries.clear
9 def test_view_dashboard_without_auth
10 # Access issues_path without login
12 assert_response :redirect
13 assert_redirected_to login_path(:referer => issues_path)
15 # Access issues_path as normal user
16 session[:user] = create(:user).id
18 assert_response :redirect
19 assert_redirected_to root_path
21 # Access issues_path by admin
22 session[:user] = create(:administrator_user).id
24 # this is redirected because there are no issues?!
25 assert_response :redirect
26 assert_redirected_to issues_path
28 # Access issues_path by moderator
29 session[:user] = create(:moderator_user).id
31 # this is redirected because there are no issues?!
32 assert_response :redirect
33 assert_redirected_to issues_path
36 def test_new_issue_without_login
37 # Test creation of a new issue and a new report without logging in
38 get :new, :params => { :reportable_id => 1, :reportable_type => "User", :reported_user_id => 1 }
39 assert_response :redirect
40 assert_redirected_to login_path(:referer => new_issue_path(:reportable_id => 1, :reportable_type => "User", :reported_user_id => 1))
43 def test_new_issue_after_login
44 # Test creation of a new issue and a new report
45 target_user = create(:user)
48 session[:user] = create(:user).id
50 assert_equal Issue.count, 0
52 # Create an Issue and a report
53 get :new, :params => { :reportable_id => target_user.id, :reportable_type => "User", :reported_user_id => target_user.id }
54 assert_response :success
55 assert_difference "Issue.count", 1 do
56 details = "Details of a report"
59 :report => { :details => details },
60 :report_type => "[OFFENSIVE]",
61 :issue => { :reportable_id => target_user.id, :reportable_type => "User", :reported_user_id => target_user.id }
64 assert_equal Issue.count, 1
65 assert_response :redirect
66 assert_redirected_to root_path
69 def test_new_report_with_incomplete_details
70 # Test creation of a new issue and a new report
71 target_user = create(:user)
74 session[:user] = create(:user).id
76 assert_equal Issue.count, 0
78 # Create an Issue and a report
79 get :new, :params => { :reportable_id => target_user.id, :reportable_type => "User", :reported_user_id => target_user.id }
80 assert_response :success
81 assert_difference "Issue.count", 1 do
82 details = "Details of a report"
85 :report => { :details => details },
86 :report_type => "[OFFENSIVE]",
87 :issue => { :reportable_id => target_user.id, :reportable_type => "User", :reported_user_id => target_user.id }
90 assert_equal Issue.count, 1
91 assert_response :redirect
92 assert_redirected_to root_path
94 get :new, :params => { :reportable_id => target_user.id, :reportable_type => "User", :reported_user_id => target_user.id }
95 assert_response :success
97 # Report without report_type
98 assert_no_difference "Issue.count" do
99 details = "Details of another report under the same issue"
102 :report => { :details => details },
103 :issue => { :reportable_id => target_user.id, :reportable_type => "User", :reported_user_id => target_user.id }
106 assert_response :redirect
107 assert_equal Issue.find_by(:reportable_id => target_user.id, :reportable_type => "User").reports.count, 1
109 # Report without details
110 assert_no_difference "Issue.count" do
113 :report_type => "[OFFENSIVE]",
114 :issue => { :reportable_id => 1, :reportable_type => "User", :reported_user_id => 2 }
117 assert_response :redirect
118 assert_equal Issue.find_by(:reportable_id => target_user.id, :reportable_type => "User").reports.count, 1
121 def test_new_report_with_complete_details
122 # Test creation of a new issue and a new report
123 target_user = create(:user)
126 session[:user] = create(:user).id
128 assert_equal Issue.count, 0
130 # Create an Issue and a report
131 get :new, :params => { :reportable_id => target_user.id, :reportable_type => "User", :reported_user_id => target_user.id }
132 assert_response :success
133 assert_difference "Issue.count", 1 do
134 details = "Details of a report"
137 :report => { :details => details },
138 :report_type => "[OFFENSIVE]",
139 :issue => { :reportable_id => target_user.id, :reportable_type => "User", :reported_user_id => target_user.id }
142 assert_equal Issue.count, 1
143 assert_response :redirect
144 assert_redirected_to root_path
146 # Create a report for an existing Issue
147 get :new, :params => { :reportable_id => target_user.id, :reportable_type => "User", :reported_user_id => target_user.id }
148 assert_response :success
149 assert_no_difference "Issue.count" do
150 details = "Details of another report under the same issue"
153 :report => { :details => details },
154 :report_type => "[OFFENSIVE]",
155 :issue => { :reportable_id => target_user.id, :reportable_type => "User", :reported_user_id => target_user.id }
158 assert_response :redirect
159 report_count = Issue.find_by(:reportable_id => target_user.id, :reportable_type => "User").reports.count
160 assert_equal report_count, 2
163 def test_change_status_by_normal_user
164 target_user = create(:user)
165 issue = create(:issue, :reportable => target_user, :reported_user => target_user)
167 # Login as normal user
168 session[:user] = create(:user).id
170 assert_equal Issue.count, 1
172 get :resolve, :params => { :id => issue.id }
174 assert_response :redirect
175 assert_redirected_to root_path
178 def test_change_status_by_admin
179 target_user = create(:user)
180 issue = create(:issue, :reportable => target_user, :reported_user => target_user)
182 # Login as administrator
183 session[:user] = create(:administrator_user).id
186 get :resolve, :params => { :id => issue.id }
187 assert_equal Issue.find_by(:reportable_id => target_user.id, :reportable_type => "User").resolved?, true
188 assert_response :redirect
191 get :reopen, :params => { :id => issue.id }
192 assert_equal Issue.find_by(:reportable_id => target_user.id, :reportable_type => "User").open?, true
193 assert_response :redirect
196 get :ignore, :params => { :id => issue.id }
197 assert_equal Issue.find_by(:reportable_id => target_user, :reportable_type => "User").ignored?, true
198 assert_response :redirect
201 def test_search_issues
202 good_user = create(:user)
203 bad_user = create(:user)
204 create(:issue, :reportable => bad_user, :reported_user => bad_user, :issue_type => "administrator")
205 # Login as administrator
206 session[:user] = create(:administrator_user).id
208 # No issues against the user
209 get :index, :params => { :search_by_user => good_user.display_name }
210 assert_response :redirect
211 assert_redirected_to issues_path
214 get :index, :params => { :search_by_user => "test1000" }
215 assert_response :redirect
216 assert_redirected_to issues_path
218 # Find Issue against bad_user
219 get :index, :params => { :search_by_user => bad_user.display_name }
220 assert_response :success