1 require File.dirname(__FILE__) + '/../test_helper'
3 class MapBugsControllerTest < ActionController::TestCase
4 fixtures :users, :map_bugs, :map_bug_comment
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"}
12 assert_response :success
13 id = @response.body.sub(/ok/,"").to_i
14 get :read, {:id => id, :format => 'json'}
15 assert_response :success
17 assert_match "\"status\":\"open\"", js
18 assert_match "\"comment\":\"This is a comment\"", js
19 assert_match "\"commenter_name\":\"new_tester (a)\"", js
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"}
26 assert_response :success
28 get :read, {:id => 2, :format => 'json'}
29 assert_response :success
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
38 def test_map_bug_read_success
40 assert_response :success
42 get :read, {:id => 1, :format => 'xml'}
43 assert_response :success
45 get :read, {:id => 1, :format => 'rss'}
46 assert_response :success
48 get :read, {:id => 1, :format => 'json'}
49 assert_response :success
51 get :read, {:id => 1, :format => 'gpx'}
52 assert_response :success
55 def test_map_bug_close_success
56 post :close_bug, {:id => 2}
57 assert_response :success
59 get :read, {:id => 2, :format => 'json'}
61 assert_match "\"id\":2", js
62 assert_match "\"status\":\"closed\"", js
65 def test_get_bugs_success
66 get :get_bugs, {:bbox=>'1,1,1.2,1.2'}
67 assert_response :success
69 get :get_bugs, {:bbox=>'1,1,1.2,1.2', :format => 'rss'}
70 assert_response :success
72 get :get_bugs, {:bbox=>'1,1,1.2,1.2', :format => 'json'}
73 assert_response :success
75 get :get_bugs, {:bbox=>'1,1,1.2,1.2', :format => 'xml'}
76 assert_response :success
78 get :get_bugs, {:bbox=>'1,1,1.2,1.2', :format => 'gpx'}
79 assert_response :success
82 def test_get_bugs_large_area_success
83 get :get_bugs, {:bbox=>'-10,-10,12,12'}
84 assert_response :success
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
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
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
103 def test_search_success
104 get :search, {:bbox=>'1,1,1.2,1.2', :q => 'bug 1'}
105 assert_response :success
107 get :search, {:bbox=>'1,1,1.2,1.2', :q => 'bug 1', :format => 'xml'}
108 assert_response :success
110 get :search, {:bbox=>'1,1,1.2,1.2', :q => 'bug 1', :format => 'json'}
111 assert_response :success
113 get :search, {:bbox=>'1,1,1.2,1.2', :q => 'bug 1', :format => 'rss'}
114 assert_response :success
116 get :search, {:bbox=>'1,1,1.2,1.2', :q => 'bug 1', :format => 'gpx'}
117 assert_response :success
121 get :rss, {:bbox=>'1,1,1.2,1.2'}
122 assert_response :success
125 assert_response :success
128 def test_user_bugs_success
129 get :my_bugs, {:display_name=>'test'}
130 assert_response :success
132 get :my_bugs, {:display_name=>'pulibc_test2'}
133 assert_response :success
135 get :my_bugs, {:display_name=>'non-existent'}
136 assert_response :not_found
140 def test_map_bug_comment_create_not_found
141 assert_no_difference('MapBugComment.count') do
142 post :edit_bug, {:id => 12345, :name => "new_tester", :text => "This is an additional comment"}
144 assert_response :not_found
147 def test_map_bug_close_not_found
148 post :close_bug, {:id => 12345}
149 assert_response :not_found
152 def test_map_bug_read_not_found
153 get :read, {:id => 12345}
154 assert_response :not_found
157 def test_map_bug_read_gone
158 get :read, {:id => 4}
159 assert_response :gone
162 def test_map_bug_hidden_comment
163 get :read, {:id => 5, :format => 'json'}
164 assert_response :success
166 assert_match "\"id\":5", js
167 assert_match "\"comment\":\"Valid comment for bug 5\"", js
168 assert_match "\"comment\":\"Another valid comment for bug 5\"", js
169 assert_no_match /\"comment\":\"Spam for bug 5\"/, js