3 class ReportsControllerTest < ActionDispatch::IntegrationTest
4 def test_new_report_without_login
5 target_user = create(:user)
6 get new_report_path(: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_for(create(:user))
16 # Create an Issue and a report
17 get new_report_path(: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"
22 post reports_path(:report => {
24 :category => category,
25 :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
28 assert_response :redirect
29 assert_redirected_to user_path(target_user)
32 def test_new_report_with_incomplete_details
33 # Test creation of a new issue and a new report
34 target_user = create(:user)
37 session_for(create(:user))
39 # Create an Issue and a report
40 get new_report_path(:reportable_id => target_user.id, :reportable_type => "User")
41 assert_response :success
42 assert_difference "Issue.count", 1 do
43 details = "Details of a report"
45 post reports_path(:report => {
47 :category => category,
48 :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
51 assert_response :redirect
52 assert_redirected_to user_path(target_user)
56 assert_equal 1, issue.reports.count
58 get new_report_path(:reportable_id => target_user.id, :reportable_type => "User")
59 assert_response :success
61 # Report without details
62 assert_no_difference "Issue.count" do
64 post reports_path(:report => {
65 :category => category,
66 :issue => { :reportable_id => 1, :reportable_type => "User" }
69 assert_response :redirect
71 assert_equal 1, issue.reports.count
74 def test_new_report_with_complete_details
75 # Test creation of a new issue and a new report
76 target_user = create(:user)
79 session_for(create(:user))
81 # Create an Issue and a report
82 get new_report_path(:reportable_id => target_user.id, :reportable_type => "User")
83 assert_response :success
84 assert_difference "Issue.count", 1 do
85 details = "Details of a report"
87 post reports_path(:report => {
89 :category => category,
90 :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
93 assert_response :redirect
94 assert_redirected_to user_path(target_user)
98 assert_equal 1, issue.reports.count
100 # Create a report for an existing Issue
101 get new_report_path(:reportable_id => target_user.id, :reportable_type => "User")
102 assert_response :success
103 assert_no_difference "Issue.count" do
104 details = "Details of another report under the same issue"
106 post reports_path(:report => {
108 :category => category,
109 :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
112 assert_response :redirect
114 assert_equal 2, issue.reports.count