3 class ReportsControllerTest < ActionController::TestCase
4 def test_new_report_without_login
5 target_user = create(:user)
6 get :new, :params => { :reportable_id => target_user.id, :reportable_type => "User" }
7 assert_response :redirect
8 assert_redirected_to login_path(:referer => new_report_path(:reportable_id => target_user.id, :reportable_type => "User"))
11 def test_new_report_after_login
12 target_user = create(:user)
14 session[:user] = create(:user).id
16 assert_equal 0, Issue.count
18 # Create an Issue and a report
19 get :new, :params => { :reportable_id => target_user.id, :reportable_type => "User" }
20 assert_response :success
21 assert_difference "Issue.count", 1 do
22 details = "Details of a report"
27 :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
31 assert_equal 1, Issue.count
32 assert_response :redirect
33 assert_redirected_to root_path
36 def test_new_report_with_incomplete_details
37 # Test creation of a new issue and a new report
38 target_user = create(:user)
41 session[:user] = create(:user).id
43 assert_equal 0, Issue.count
45 # Create an Issue and a report
46 get :new, :params => { :reportable_id => target_user.id, :reportable_type => "User" }
47 assert_response :success
48 assert_difference "Issue.count", 1 do
49 details = "Details of a report"
54 :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
58 assert_equal 1, Issue.count
59 assert_response :redirect
60 assert_redirected_to root_path
62 get :new, :params => { :reportable_id => target_user.id, :reportable_type => "User" }
63 assert_response :success
65 # Report without report_type
66 assert_no_difference "Issue.count" do
67 details = "Details of another report under the same issue"
72 :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
76 assert_response :redirect
77 assert_equal 1, Issue.find_by(:reportable_id => target_user.id, :reportable_type => "User").reports.count
79 # Report without details
80 assert_no_difference "Issue.count" do
84 :issue => { :reportable_id => 1, :reportable_type => "User" }
88 assert_response :redirect
89 assert_equal 1, Issue.find_by(:reportable_id => target_user.id, :reportable_type => "User").reports.count
92 def test_new_report_with_complete_details
93 # Test creation of a new issue and a new report
94 target_user = create(:user)
97 session[:user] = create(:user).id
99 assert_equal 0, Issue.count
101 # Create an Issue and a report
102 get :new, :params => { :reportable_id => target_user.id, :reportable_type => "User" }
103 assert_response :success
104 assert_difference "Issue.count", 1 do
105 details = "Details of a report"
110 :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
114 assert_equal 1, Issue.count
115 assert_response :redirect
116 assert_redirected_to root_path
118 # Create a report for an existing Issue
119 get :new, :params => { :reportable_id => target_user.id, :reportable_type => "User" }
120 assert_response :success
121 assert_no_difference "Issue.count" do
122 details = "Details of another report under the same issue"
127 :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
131 assert_response :redirect
132 report_count = Issue.find_by(:reportable_id => target_user.id, :reportable_type => "User").reports.count
133 assert_equal 2, report_count