]> git.openstreetmap.org Git - rails.git/blob - test/controllers/reports_controller_test.rb
Remove the test around missing report_type, since we're not currently requiring that.
[rails.git] / test / controllers / reports_controller_test.rb
1 require "test_helper"
2
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"))
9   end
10
11   def test_new_report_after_login
12     target_user = create(:user)
13
14     session[:user] = create(:user).id
15
16     assert_equal 0, Issue.count
17
18     # Create an Issue and a report
19     get :new, :params => { :reportable_id => target_user.id, :reportable_type => "User" }
20     assert_response :success
21     assert_difference "Issue.count", 1 do
22       details = "Details of a report"
23       post :create,
24            :params => {
25              :report => {
26                :details => details,
27                :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
28              }
29            }
30     end
31     assert_equal 1, Issue.count
32     assert_response :redirect
33     assert_redirected_to root_path
34   end
35
36   def test_new_report_with_incomplete_details
37     # Test creation of a new issue and a new report
38     target_user = create(:user)
39
40     # Login
41     session[:user] = create(:user).id
42
43     assert_equal 0, Issue.count
44
45     # Create an Issue and a report
46     get :new, :params => { :reportable_id => target_user.id, :reportable_type => "User" }
47     assert_response :success
48     assert_difference "Issue.count", 1 do
49       details = "Details of a report"
50       post :create,
51            :params => {
52              :report => {
53                :details => details,
54                :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
55              }
56            }
57     end
58     assert_equal 1, Issue.count
59     assert_response :redirect
60     assert_redirected_to root_path
61
62     get :new, :params => { :reportable_id => target_user.id, :reportable_type => "User" }
63     assert_response :success
64
65     # Report without details
66     assert_no_difference "Issue.count" do
67       post :create,
68            :params => {
69              :report => {
70                :issue => { :reportable_id => 1, :reportable_type => "User" }
71              }
72            }
73     end
74     assert_response :redirect
75     assert_equal 1, Issue.find_by(:reportable_id => target_user.id, :reportable_type => "User").reports.count
76   end
77
78   def test_new_report_with_complete_details
79     # Test creation of a new issue and a new report
80     target_user = create(:user)
81
82     # Login
83     session[:user] = create(:user).id
84
85     assert_equal 0, Issue.count
86
87     # Create an Issue and a report
88     get :new, :params => { :reportable_id => target_user.id, :reportable_type => "User" }
89     assert_response :success
90     assert_difference "Issue.count", 1 do
91       details = "Details of a report"
92       post :create,
93            :params => {
94              :report => {
95                :details => details,
96                :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
97              }
98            }
99     end
100     assert_equal 1, Issue.count
101     assert_response :redirect
102     assert_redirected_to root_path
103
104     # Create a report for an existing Issue
105     get :new, :params => { :reportable_id => target_user.id, :reportable_type => "User" }
106     assert_response :success
107     assert_no_difference "Issue.count" do
108       details = "Details of another report under the same issue"
109       post :create,
110            :params => {
111              :report => {
112                :details => details,
113                :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
114              }
115            }
116     end
117     assert_response :redirect
118     report_count = Issue.find_by(:reportable_id => target_user.id, :reportable_type => "User").reports.count
119     assert_equal 2, report_count
120   end
121 end