]> git.openstreetmap.org Git - rails.git/blob - test/controllers/reports_controller_test.rb
Merge remote-tracking branch 'upstream/pull/2994'
[rails.git] / test / controllers / reports_controller_test.rb
1 require "test_helper"
2
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"))
9   end
10
11   def test_new_report_after_login
12     target_user = create(:user)
13
14     session_for(create(:user))
15
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"
21       category = "other"
22       post reports_path(:report => {
23                           :details => details,
24                           :category => category,
25                           :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
26                         })
27     end
28     assert_response :redirect
29     assert_redirected_to user_path(target_user)
30   end
31
32   def test_new_report_with_incomplete_details
33     # Test creation of a new issue and a new report
34     target_user = create(:user)
35
36     # Login
37     session_for(create(:user))
38
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"
44       category = "other"
45       post reports_path(:report => {
46                           :details => details,
47                           :category => category,
48                           :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
49                         })
50     end
51     assert_response :redirect
52     assert_redirected_to user_path(target_user)
53
54     issue = Issue.last
55
56     assert_equal 1, issue.reports.count
57
58     get new_report_path(:reportable_id => target_user.id, :reportable_type => "User")
59     assert_response :success
60
61     # Report without details
62     assert_no_difference "Issue.count" do
63       category = "other"
64       post reports_path(:report => {
65                           :category => category,
66                           :issue => { :reportable_id => 1, :reportable_type => "User" }
67                         })
68     end
69     assert_response :redirect
70
71     assert_equal 1, issue.reports.count
72   end
73
74   def test_new_report_with_complete_details
75     # Test creation of a new issue and a new report
76     target_user = create(:user)
77
78     # Login
79     session_for(create(:user))
80
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"
86       category = "other"
87       post reports_path(:report => {
88                           :details => details,
89                           :category => category,
90                           :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
91                         })
92     end
93     assert_response :redirect
94     assert_redirected_to user_path(target_user)
95
96     issue = Issue.last
97
98     assert_equal 1, issue.reports.count
99
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"
105       category = "other"
106       post reports_path(:report => {
107                           :details => details,
108                           :category => category,
109                           :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
110                         })
111     end
112     assert_response :redirect
113
114     assert_equal 2, issue.reports.count
115   end
116 end