]> git.openstreetmap.org Git - rails.git/blob - test/controllers/reports_controller_test.rb
Remove Geonames and geocoder.ca
[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 => target_user.id, :reportable_type => "User" }
67                         })
68     end
69     assert_response :success
70     assert_template :new
71     assert_match(/Please provide the required details/, flash[:notice])
72
73     assert_equal 1, issue.reports.count
74   end
75
76   def test_new_report_with_complete_details
77     # Test creation of a new issue and a new report
78     target_user = create(:user)
79
80     # Login
81     session_for(create(:user))
82
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"
88       category = "other"
89       post reports_path(:report => {
90                           :details => details,
91                           :category => category,
92                           :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
93                         })
94     end
95     assert_response :redirect
96     assert_redirected_to user_path(target_user)
97
98     issue = Issue.last
99
100     assert_equal 1, issue.reports.count
101
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"
107       category = "other"
108       post reports_path(:report => {
109                           :details => details,
110                           :category => category,
111                           :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
112                         })
113     end
114     assert_response :redirect
115
116     assert_equal 2, issue.reports.count
117   end
118 end