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
37 def test_map_bug_read_success
39 assert_response :success
41 get :read, {:id => 1, :format => 'xml'}
42 assert_response :success
44 get :read, {:id => 1, :format => 'rss'}
45 assert_response :success
47 get :read, {:id => 1, :format => 'json'}
48 assert_response :success
50 get :read, {:id => 1, :format => 'gpx'}
51 assert_response :success
54 def test_map_bug_close_success
55 post :close_bug, {:id => 2}
56 assert_response :success
58 get :read, {:id => 2, :format => 'json'}
60 assert_match "\"id\":2", js
61 assert_match "\"status\":\"closed\"", js
64 def test_get_bugs_success
65 get :get_bugs, {:bbox=>'1,1,1.2,1.2'}
66 assert_response :success
68 get :get_bugs, {:bbox=>'1,1,1.2,1.2', :format => 'rss'}
69 assert_response :success
71 get :get_bugs, {:bbox=>'1,1,1.2,1.2', :format => 'json'}
72 assert_response :success
74 get :get_bugs, {:bbox=>'1,1,1.2,1.2', :format => 'xml'}
75 assert_response :success
77 get :get_bugs, {:bbox=>'1,1,1.2,1.2', :format => 'gpx'}
78 assert_response :success
81 def test_get_bugs_large_area_success
82 get :get_bugs, {:bbox=>'-10,-10,12,12'}
83 assert_response :success
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
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
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
102 def test_search_success
103 get :search, {:bbox=>'1,1,1.2,1.2', :q => 'bug 1'}
104 assert_response :success
106 get :search, {:bbox=>'1,1,1.2,1.2', :q => 'bug 1', :format => 'xml'}
107 assert_response :success
109 get :search, {:bbox=>'1,1,1.2,1.2', :q => 'bug 1', :format => 'json'}
110 assert_response :success
112 get :search, {:bbox=>'1,1,1.2,1.2', :q => 'bug 1', :format => 'rss'}
113 assert_response :success
115 get :search, {:bbox=>'1,1,1.2,1.2', :q => 'bug 1', :format => 'gpx'}
116 assert_response :success
120 get :rss, {:bbox=>'1,1,1.2,1.2'}
121 assert_response :success
124 assert_response :success
127 def test_user_bugs_success
128 get :my_bugs, {:display_name=>'test'}
129 assert_response :success
131 get :my_bugs, {:display_name=>'pulibc_test2'}
132 assert_response :success
134 get :my_bugs, {:display_name=>'non-existent'}
135 assert_response :not_found
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"}
142 assert_response :not_found
145 def test_map_bug_close_not_found
146 post :close_bug, {:id => 12345}
147 assert_response :not_found
150 def test_map_bug_read_not_found
151 get :read, {:id => 12345}
152 assert_response :not_found
155 def test_map_bug_read_gone
156 get :read, {:id => 4}
157 assert_response :gone
160 def test_map_bug_hidden_comment
161 get :read, {:id => 5, :format => 'json'}
162 assert_response :success
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