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 # Create an Issue and a report
17 get :new, :params => { :reportable_id => target_user.id, :reportable_type => "User" }
18 assert_response :success
19 assert_difference "Issue.count", 1 do
20 details = "Details of a report"
26 :category => category,
27 :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
31 assert_response :redirect
32 assert_redirected_to user_path(target_user.display_name)
35 def test_new_report_with_incomplete_details
36 # Test creation of a new issue and a new report
37 target_user = create(:user)
40 session[:user] = create(:user).id
42 # Create an Issue and a report
43 get :new, :params => { :reportable_id => target_user.id, :reportable_type => "User" }
44 assert_response :success
45 assert_difference "Issue.count", 1 do
46 details = "Details of a report"
52 :category => category,
53 :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
57 assert_response :redirect
58 assert_redirected_to user_path(target_user.display_name)
62 assert_equal 1, issue.reports.count
64 get :new, :params => { :reportable_id => target_user.id, :reportable_type => "User" }
65 assert_response :success
67 # Report without details
68 assert_no_difference "Issue.count" do
73 :category => category,
74 :issue => { :reportable_id => 1, :reportable_type => "User" }
78 assert_response :redirect
80 assert_equal 1, issue.reports.count
83 def test_new_report_with_complete_details
84 # Test creation of a new issue and a new report
85 target_user = create(:user)
88 session[:user] = create(:user).id
90 # Create an Issue and a report
91 get :new, :params => { :reportable_id => target_user.id, :reportable_type => "User" }
92 assert_response :success
93 assert_difference "Issue.count", 1 do
94 details = "Details of a report"
100 :category => category,
101 :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
105 assert_response :redirect
106 assert_redirected_to user_path(target_user.display_name)
110 assert_equal 1, issue.reports.count
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
129 assert_equal 2, issue.reports.count