]> git.openstreetmap.org Git - rails.git/blob - test/functional/map_bugs_controller_test.rb
Tidy up some of the map bugs code
[rails.git] / test / functional / map_bugs_controller_test.rb
1 require File.dirname(__FILE__) + '/../test_helper'
2
3 class MapBugsControllerTest < ActionController::TestCase
4   fixtures :users, :map_bugs, :map_bug_comment
5     
6   def test_map_bug_create_success
7     assert_difference('MapBug.count') do
8       assert_difference('MapBugComment.count') do
9         post :add_bug, {:lat => -1.0, :lon => -1.0, :name => "new_tester", :text => "This is a comment"}
10       end
11     end
12     assert_response :success
13     id = @response.body.sub(/ok/,"").to_i
14     get :read, {:id => id, :format => 'json'}
15     assert_response :success
16     js = @response.body
17     assert_match "\"status\":\"open\"", js
18     assert_match "\"comment\":\"This is a comment\"", js
19     assert_match "\"commenter_name\":\"new_tester (a)\"", js
20   end
21
22   def test_map_bug_comment_create_success
23     assert_difference('MapBugComment.count') do
24       post :edit_bug, {:id => 2, :name => "new_tester2", :text => "This is an additional comment"}
25     end
26     assert_response :success
27
28     get :read, {:id => 2, :format => 'json'}
29     assert_response :success
30     js = @response.body
31     assert_match "\"id\":2", js
32     assert_match "\"status\":\"open\"", js
33     assert_match "\"comment\":\"This is an additional comment\"", js
34     assert_match "\"commenter_name\":\"new_tester2 (a)\"", js
35   end
36
37   def test_map_bug_read_success
38     get :read, {:id => 1}
39     assert_response :success      
40
41     get :read, {:id => 1,  :format => 'xml'}
42     assert_response :success
43
44     get :read, {:id => 1,  :format => 'rss'}
45     assert_response :success
46
47     get :read, {:id => 1,  :format => 'json'}
48     assert_response :success
49
50     get :read, {:id => 1,  :format => 'gpx'}
51     assert_response :success
52   end
53
54   def test_map_bug_close_success
55     post :close_bug, {:id => 2}
56     assert_response :success
57
58     get :read, {:id => 2, :format => 'json'}
59     js = @response.body
60     assert_match "\"id\":2", js
61     assert_match "\"status\":\"closed\"", js
62   end
63
64   def test_get_bugs_success
65     get :get_bugs, {:bbox=>'1,1,1.2,1.2'}
66     assert_response :success
67
68     get :get_bugs, {:bbox=>'1,1,1.2,1.2', :format => 'rss'}
69     assert_response :success
70
71     get :get_bugs, {:bbox=>'1,1,1.2,1.2', :format => 'json'}
72     assert_response :success
73
74     get :get_bugs, {:bbox=>'1,1,1.2,1.2', :format => 'xml'}
75     assert_response :success
76
77     get :get_bugs, {:bbox=>'1,1,1.2,1.2', :format => 'gpx'}
78     assert_response :success
79   end
80
81   def test_get_bugs_large_area_success
82     get :get_bugs, {:bbox=>'-10,-10,12,12'}
83     assert_response :success
84   end
85
86   def test_get_bugs_closed_7_success
87     get :get_bugs, {:bbox=>'1,1,1.2,1.2', :closed => '7'}
88     assert_response :success
89   end
90
91   def test_get_bugs_closed_0_success
92     get :get_bugs, {:bbox=>'1,1,1.2,1.2', :closed => '0'}
93     assert_response :success
94   end
95
96   def test_get_bugs_closed_n1_success
97     get :get_bugs, {:bbox=>'1,1,1.2,1.2', :closed => '-1'}
98     assert_response :success
99   end
100
101
102   def test_search_success
103     get :search, {:bbox=>'1,1,1.2,1.2', :q => 'bug 1'}
104     assert_response :success
105
106     get :search, {:bbox=>'1,1,1.2,1.2', :q => 'bug 1', :format => 'xml'}
107     assert_response :success
108
109     get :search, {:bbox=>'1,1,1.2,1.2', :q => 'bug 1', :format => 'json'}
110     assert_response :success
111
112     get :search, {:bbox=>'1,1,1.2,1.2', :q => 'bug 1', :format => 'rss'}
113     assert_response :success
114
115     get :search, {:bbox=>'1,1,1.2,1.2', :q => 'bug 1', :format => 'gpx'}
116     assert_response :success
117   end
118
119   def test_rss_success
120     get :rss, {:bbox=>'1,1,1.2,1.2'}
121     assert_response :success
122         
123     get :rss
124     assert_response :success
125   end
126
127   def test_user_bugs_success
128     get :my_bugs, {:display_name=>'test'}
129     assert_response :success
130
131     get :my_bugs, {:display_name=>'pulibc_test2'}
132     assert_response :success
133
134     get :my_bugs, {:display_name=>'non-existent'}
135     assert_response :not_found  
136   end
137
138   def test_map_bug_comment_create_not_found
139     assert_no_difference('MapBugComment.count') do
140       post :edit_bug, {:id => 12345, :name => "new_tester", :text => "This is an additional comment"}
141     end
142     assert_response :not_found
143   end
144
145   def test_map_bug_close_not_found
146     post :close_bug, {:id => 12345}
147     assert_response :not_found
148   end
149
150   def test_map_bug_read_not_found
151     get :read, {:id => 12345}
152     assert_response :not_found
153   end
154
155   def test_map_bug_read_gone
156     get :read, {:id => 4}
157     assert_response :gone
158   end
159
160   def test_map_bug_hidden_comment
161     get :read, {:id => 5, :format => 'json'}
162     assert_response :success
163     js = @response.body
164     assert_match "\"id\":5", js
165     assert_match "\"comment\":\"Valid comment for bug 5\"", js
166     assert_match "\"comment\":\"Another valid comment for bug 5\"", js
167     assert_no_match /\"comment\":\"Spam for bug 5\"/, js
168   end
169 end