]> git.openstreetmap.org Git - rails.git/blob - test/functional/map_bugs_controller_test.rb
Tidy up the note_comment model a bit
[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 :create, {: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 "\"body\":\"This is a comment\"", js
19     assert_match "\"author_name\":\"new_tester (a)\"", js
20   end
21
22   def test_map_bug_comment_create_success
23     assert_difference('MapBugComment.count') do
24       post :update, {: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 "\"body\":\"This is an additional comment\"", js
34     assert_match "\"author_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, {: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 :list, {:bbox=>'1,1,1.2,1.2'}
66     assert_response :success
67
68     get :list, {:bbox=>'1,1,1.2,1.2', :format => 'rss'}
69     assert_response :success
70
71     get :list, {:bbox=>'1,1,1.2,1.2', :format => 'json'}
72     assert_response :success
73
74     get :list, {:bbox=>'1,1,1.2,1.2', :format => 'xml'}
75     assert_response :success
76
77     get :list, {: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 :list, {:bbox=>'-2.5,-2.5,2.5,2.5'}
83     assert_response :success
84   end
85
86   def test_get_bugs_large_area_bad_request
87     get :list, {:bbox=>'-10,-10,12,12'}
88     assert_response :bad_request
89   end
90
91   def test_get_bugs_closed_7_success
92     get :list, {:bbox=>'1,1,1.2,1.2', :closed => '7'}
93     assert_response :success
94   end
95
96   def test_get_bugs_closed_0_success
97     get :list, {:bbox=>'1,1,1.2,1.2', :closed => '0'}
98     assert_response :success
99   end
100
101   def test_get_bugs_closed_n1_success
102     get :list, {:bbox=>'1,1,1.2,1.2', :closed => '-1'}
103     assert_response :success
104   end
105
106
107   def test_search_success
108     get :search, {:bbox=>'1,1,1.2,1.2', :q => 'bug 1'}
109     assert_response :success
110
111     get :search, {:bbox=>'1,1,1.2,1.2', :q => 'bug 1', :format => 'xml'}
112     assert_response :success
113
114     get :search, {:bbox=>'1,1,1.2,1.2', :q => 'bug 1', :format => 'json'}
115     assert_response :success
116
117     get :search, {:bbox=>'1,1,1.2,1.2', :q => 'bug 1', :format => 'rss'}
118     assert_response :success
119
120     get :search, {:bbox=>'1,1,1.2,1.2', :q => 'bug 1', :format => 'gpx'}
121     assert_response :success
122   end
123
124   def test_rss_success
125     get :rss, {:bbox=>'1,1,1.2,1.2'}
126     assert_response :success
127         
128     get :rss
129     assert_response :success
130   end
131
132   def test_user_bugs_success
133     get :mine, {:display_name=>'test'}
134     assert_response :success
135
136     get :mine, {:display_name=>'pulibc_test2'}
137     assert_response :success
138
139     get :mine, {:display_name=>'non-existent'}
140     assert_response :not_found  
141   end
142
143   def test_map_bug_comment_create_not_found
144     assert_no_difference('MapBugComment.count') do
145       post :update, {:id => 12345, :name => "new_tester", :text => "This is an additional comment"}
146     end
147     assert_response :not_found
148   end
149
150   def test_map_bug_close_not_found
151     post :close, {:id => 12345}
152     assert_response :not_found
153   end
154
155   def test_map_bug_read_not_found
156     get :read, {:id => 12345}
157     assert_response :not_found
158   end
159
160   def test_map_bug_read_gone
161     get :read, {:id => 4}
162     assert_response :gone
163   end
164
165   def test_map_bug_hidden_comment
166     get :read, {:id => 5, :format => 'json'}
167     assert_response :success
168     js = @response.body
169     assert_match "\"id\":5", js
170     assert_match "\"body\":\"Valid comment for bug 5\"", js
171     assert_match "\"body\":\"Another valid comment for bug 5\"", js
172     assert_no_match /\"body\":\"Spam for bug 5\"/, js
173   end
174 end