3 class IssuesControllerTest < ActionController::TestCase
4 fixtures :users,:user_roles
6 def test_new_issue_without_login
7 # Test creation of a new issue and a new report without logging in
8 get :new, {reportable_id: 1, reportable_type: "User", reported_user_id: 1}
9 assert_response :redirect
10 assert_redirected_to login_path(:referer => new_issue_path(:reportable_id=>1, :reportable_type=>"User",:reported_user_id=> 1))
13 def test_new_issue_after_login
14 # Test creation of a new issue and a new report
17 session[:user] = users(:normal_user).id
19 assert_equal Issue.count,0
21 # Create an Issue and a report
22 get :new, {reportable_id: 1, reportable_type: "User", reported_user_id: 2}
23 assert_response :success
24 assert_difference "Issue.count",1 do
25 details = "Details of a report"
26 post :create, { :report => { :details => details},
27 :report_type => "[OFFENSIVE]",
28 :issue => { reportable_id: 1, reportable_type: "User", reported_user_id: 2} }
30 assert_equal Issue.count,1
31 assert_response :redirect
32 assert_redirected_to root_path
35 def test_new_report_with_incomplete_details
36 # Test creation of a new issue and a new report
39 session[:user] = users(:normal_user).id
41 assert_equal Issue.count,0
43 # Create an Issue and a report
44 get :new, {reportable_id: 1, reportable_type: "User", reported_user_id: 2}
45 assert_response :success
46 assert_difference "Issue.count",1 do
47 details = "Details of a report"
48 post :create, { :report => { :details => details},
49 :report_type => "[OFFENSIVE]",
50 :issue => { reportable_id: 1, reportable_type: "User", reported_user_id: 2} }
52 assert_equal Issue.count,1
53 assert_response :redirect
54 assert_redirected_to root_path
56 get :new, {reportable_id: 1, reportable_type: "User", reported_user_id: 2}
57 assert_response :success
59 # Report without report_type
60 assert_no_difference "Issue.count" do
61 details = "Details of another report under the same issue"
62 post :create, { :report => { :details => details},
63 :issue => { reportable_id: 1, reportable_type: "User", reported_user_id: 2} }
65 assert_response :redirect
66 assert_equal Issue.find_by_reportable_id_and_reportable_type(1,"User").reports.count,1
68 # Report without details
69 assert_no_difference "Issue.count" do
70 post :create, { :report_type => "[OFFENSIVE]",
71 :issue => { reportable_id: 1, reportable_type: "User", reported_user_id: 2} }
73 assert_response :redirect
74 assert_equal Issue.find_by_reportable_id_and_reportable_type(1,"User").reports.count,1
77 def test_new_report_with_complete_details
78 # Test creation of a new issue and a new report
81 session[:user] = users(:normal_user).id
83 assert_equal Issue.count,0
85 # Create an Issue and a report
86 get :new, {reportable_id: 1, reportable_type: "User", reported_user_id: 2}
87 assert_response :success
88 assert_difference "Issue.count",1 do
89 details = "Details of a report"
90 post :create, { :report => { :details => details},
91 :report_type => "[OFFENSIVE]",
92 :issue => { reportable_id: 1, reportable_type: "User", reported_user_id: 2} }
94 assert_equal Issue.count,1
95 assert_response :redirect
96 assert_redirected_to root_path
98 # Create a report for an existing Issue
99 get :new, {reportable_id: 1, reportable_type: "User", reported_user_id: 2}
100 assert_response :success
101 assert_no_difference "Issue.count" do
102 details = "Details of another report under the same issue"
103 post :create, { :report => { :details => details},
104 :report_type => "[OFFENSIVE]",
105 :issue => { reportable_id: 1, reportable_type: "User", reported_user_id: 2} }
107 assert_response :redirect
108 assert_equal Issue.find_by_reportable_id_and_reportable_type(1,"User").reports.count,2
111 def test_change_status_by_normal_user
112 # Login as normal user
113 session[:user] = users(:normal_user).id
116 test_new_issue_after_login
117 assert_equal Issue.count,1
119 get :resolve, id: Issue.find_by_reportable_id_and_reportable_type(1,"User").id
121 assert_response :redirect
122 assert_redirected_to root_path
125 def test_change_status_by_admin
126 # Login as normal user
127 session[:user] = users(:normal_user).id
130 test_new_issue_after_login
131 assert_equal Issue.count,1
132 assert_response :redirect
134 # Login as administrator
135 session[:user] = users(:administrator_user).id
138 get :resolve, id: Issue.find_by_reportable_id_and_reportable_type(1,"User").id
139 assert_equal Issue.find_by_reportable_id_and_reportable_type(1,"User").resolved?, true
140 assert_response :redirect
143 get :reopen, id: Issue.find_by_reportable_id_and_reportable_type(1,"User").id
144 assert_equal Issue.find_by_reportable_id_and_reportable_type(1,"User").open?, true
145 assert_response :redirect
148 get :ignore, id: Issue.find_by_reportable_id_and_reportable_type(1,"User").id
149 assert_equal Issue.find_by_reportable_id_and_reportable_type(1,"User").ignored?, true
150 assert_response :redirect