]> git.openstreetmap.org Git - rails.git/blob - test/functional/map_bugs_controller_test.rb
b701e244e2e3b3f5569e8a3a9d42a538d02ad44d
[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
36   end
37
38   def test_map_bug_read_success
39     get :read, {:id => 1}
40     assert_response :success      
41
42     get :read, {:id => 1,  :format => 'xml'}
43     assert_response :success
44
45     get :read, {:id => 1,  :format => 'rss'}
46     assert_response :success
47
48     get :read, {:id => 1,  :format => 'json'}
49     assert_response :success
50
51     get :read, {:id => 1,  :format => 'gpx'}
52     assert_response :success
53   end
54
55   def test_map_bug_close_success
56         post :close_bug, {:id => 2}
57     assert_response :success
58
59         get :read, {:id => 2, :format => 'json'}
60         js = @response.body
61         assert_match "\"id\":2", js
62         assert_match "\"status\":\"closed\"", js
63   end
64
65   def test_get_bugs_success
66         get :get_bugs, {:bbox=>'1,1,1.2,1.2'}
67         assert_response :success
68
69         get :get_bugs, {:bbox=>'1,1,1.2,1.2', :format => 'rss'}
70         assert_response :success
71
72         get :get_bugs, {:bbox=>'1,1,1.2,1.2', :format => 'json'}
73         assert_response :success
74
75         get :get_bugs, {:bbox=>'1,1,1.2,1.2', :format => 'xml'}
76         assert_response :success
77
78         get :get_bugs, {:bbox=>'1,1,1.2,1.2', :format => 'gpx'}
79         assert_response :success
80   end
81
82   def test_get_bugs_large_area_success
83         get :get_bugs, {:bbox=>'-10,-10,12,12'}
84         assert_response :success
85   end
86
87   def test_get_bugs_closed_7_success
88         get :get_bugs, {:bbox=>'1,1,1.2,1.2', :closed => '7'}
89         assert_response :success
90   end
91
92   def test_get_bugs_closed_0_success
93         get :get_bugs, {:bbox=>'1,1,1.2,1.2', :closed => '0'}
94         assert_response :success
95   end
96
97   def test_get_bugs_closed_n1_success
98         get :get_bugs, {:bbox=>'1,1,1.2,1.2', :closed => '-1'}
99         assert_response :success
100   end
101
102
103   def test_search_success
104         get :search, {:bbox=>'1,1,1.2,1.2', :q => 'bug 1'}
105         assert_response :success
106
107         get :search, {:bbox=>'1,1,1.2,1.2', :q => 'bug 1', :format => 'xml'}
108         assert_response :success
109
110         get :search, {:bbox=>'1,1,1.2,1.2', :q => 'bug 1', :format => 'json'}
111         assert_response :success
112
113         get :search, {:bbox=>'1,1,1.2,1.2', :q => 'bug 1', :format => 'rss'}
114         assert_response :success
115
116         get :search, {:bbox=>'1,1,1.2,1.2', :q => 'bug 1', :format => 'gpx'}
117         assert_response :success
118   end
119
120   def test_rss_success
121         get :rss, {:bbox=>'1,1,1.2,1.2'}
122         assert_response :success
123         
124         get :rss
125         assert_response :success
126   end
127
128   def test_map_bug_comment_create_not_found
129     assert_no_difference('MapBugComment.count') do
130         post :edit_bug, {:id => 12345, :name => "new_tester", :text => "This is an additional comment"}
131     end
132     assert_response :not_found
133   end
134
135   def test_map_bug_close_not_found
136         post :close_bug, {:id => 12345}
137     assert_response :not_found
138   end
139
140   def test_map_bug_read_not_found
141         get :read, {:id => 12345}
142     assert_response :not_found
143   end
144
145   def test_map_bug_read_gone
146         get :read, {:id => 4}
147     assert_response :gone
148   end
149
150   def test_map_bug_hidden_comment
151         get :read, {:id => 5, :format => 'json'}
152         assert_response :success
153         js = @response.body
154         assert_match "\"id\":5", js
155         assert_match "\"comment\":\"Valid comment for bug 5\"", js
156         assert_match "\"comment\":\"Another valid comment for bug 5\"", js
157         assert_no_match /\"comment\":\"Spam for bug 5\"/, js
158   end
159   
160
161   
162 end