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"
28 :category => category,
29 :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
33 assert_equal 1, Issue.count
34 assert_response :redirect
35 assert_redirected_to root_path
38 def test_new_report_with_incomplete_details
39 # Test creation of a new issue and a new report
40 target_user = create(:user)
43 session[:user] = create(:user).id
45 assert_equal 0, Issue.count
47 # Create an Issue and a report
48 get :new, :params => { :reportable_id => target_user.id, :reportable_type => "User" }
49 assert_response :success
50 assert_difference "Issue.count", 1 do
51 details = "Details of a report"
57 :category => category,
58 :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
62 assert_equal 1, Issue.count
63 assert_response :redirect
64 assert_redirected_to root_path
66 get :new, :params => { :reportable_id => target_user.id, :reportable_type => "User" }
67 assert_response :success
69 # Report without details
70 assert_no_difference "Issue.count" do
75 :category => category,
76 :issue => { :reportable_id => 1, :reportable_type => "User" }
80 assert_response :redirect
81 assert_equal 1, Issue.find_by(:reportable_id => target_user.id, :reportable_type => "User").reports.count
84 def test_new_report_with_complete_details
85 # Test creation of a new issue and a new report
86 target_user = create(:user)
89 session[:user] = create(:user).id
91 assert_equal 0, Issue.count
93 # Create an Issue and a report
94 get :new, :params => { :reportable_id => target_user.id, :reportable_type => "User" }
95 assert_response :success
96 assert_difference "Issue.count", 1 do
97 details = "Details of a report"
103 :category => category,
104 :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
108 assert_equal 1, Issue.count
109 assert_response :redirect
110 assert_redirected_to root_path
112 # Create a report for an existing Issue
113 get :new, :params => { :reportable_id => target_user.id, :reportable_type => "User" }
114 assert_response :success
115 assert_no_difference "Issue.count" do
116 details = "Details of another report under the same issue"
122 :category => category,
123 :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
127 assert_response :redirect
128 report_count = Issue.find_by(:reportable_id => target_user.id, :reportable_type => "User").reports.count
129 assert_equal 2, report_count