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 details
66 assert_no_difference "Issue.count" do
70 :issue => { :reportable_id => 1, :reportable_type => "User" }
74 assert_response :redirect
75 assert_equal 1, Issue.find_by(:reportable_id => target_user.id, :reportable_type => "User").reports.count
78 def test_new_report_with_complete_details
79 # Test creation of a new issue and a new report
80 target_user = create(:user)
83 session[:user] = create(:user).id
85 assert_equal 0, Issue.count
87 # Create an Issue and a report
88 get :new, :params => { :reportable_id => target_user.id, :reportable_type => "User" }
89 assert_response :success
90 assert_difference "Issue.count", 1 do
91 details = "Details of a report"
96 :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
100 assert_equal 1, Issue.count
101 assert_response :redirect
102 assert_redirected_to root_path
104 # Create a report for an existing Issue
105 get :new, :params => { :reportable_id => target_user.id, :reportable_type => "User" }
106 assert_response :success
107 assert_no_difference "Issue.count" do
108 details = "Details of another report under the same issue"
113 :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
117 assert_response :redirect
118 report_count = Issue.find_by(:reportable_id => target_user.id, :reportable_type => "User").reports.count
119 assert_equal 2, report_count