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 => target_user.id, :reportable_type => "User" }
69 assert_response :success
71 assert_match(/Please provide the required details/, flash[:notice])
73 assert_equal 1, issue.reports.count
76 def test_new_report_with_complete_details
77 # Test creation of a new issue and a new report
78 target_user = create(:user)
81 session_for(create(:user))
83 # Create an Issue and a report
84 get new_report_path(:reportable_id => target_user.id, :reportable_type => "User")
85 assert_response :success
86 assert_difference "Issue.count", 1 do
87 details = "Details of a report"
89 post reports_path(:report => {
91 :category => category,
92 :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
95 assert_response :redirect
96 assert_redirected_to user_path(target_user)
100 assert_equal 1, issue.reports.count
102 # Create a report for an existing Issue
103 get new_report_path(:reportable_id => target_user.id, :reportable_type => "User")
104 assert_response :success
105 assert_no_difference "Issue.count" do
106 details = "Details of another report under the same issue"
108 post reports_path(:report => {
110 :category => category,
111 :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
114 assert_response :redirect
116 assert_equal 2, issue.reports.count