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 "\"body\":\"This is a comment\"", js
 
  19     assert_match "\"author_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 "\"body\":\"This is an additional comment\"", js
 
  34     assert_match "\"author_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=>'-2.5,-2.5,2.5,2.5'}
 
  83     assert_response :success
 
  86   def test_get_bugs_large_area_bad_request
 
  87     get :get_bugs, {:bbox=>'-10,-10,12,12'}
 
  88     assert_response :bad_request
 
  91   def test_get_bugs_closed_7_success
 
  92     get :get_bugs, {:bbox=>'1,1,1.2,1.2', :closed => '7'}
 
  93     assert_response :success
 
  96   def test_get_bugs_closed_0_success
 
  97     get :get_bugs, {:bbox=>'1,1,1.2,1.2', :closed => '0'}
 
  98     assert_response :success
 
 101   def test_get_bugs_closed_n1_success
 
 102     get :get_bugs, {:bbox=>'1,1,1.2,1.2', :closed => '-1'}
 
 103     assert_response :success
 
 107   def test_search_success
 
 108     get :search, {:bbox=>'1,1,1.2,1.2', :q => 'bug 1'}
 
 109     assert_response :success
 
 111     get :search, {:bbox=>'1,1,1.2,1.2', :q => 'bug 1', :format => 'xml'}
 
 112     assert_response :success
 
 114     get :search, {:bbox=>'1,1,1.2,1.2', :q => 'bug 1', :format => 'json'}
 
 115     assert_response :success
 
 117     get :search, {:bbox=>'1,1,1.2,1.2', :q => 'bug 1', :format => 'rss'}
 
 118     assert_response :success
 
 120     get :search, {:bbox=>'1,1,1.2,1.2', :q => 'bug 1', :format => 'gpx'}
 
 121     assert_response :success
 
 125     get :rss, {:bbox=>'1,1,1.2,1.2'}
 
 126     assert_response :success
 
 129     assert_response :success
 
 132   def test_user_bugs_success
 
 133     get :my_bugs, {:display_name=>'test'}
 
 134     assert_response :success
 
 136     get :my_bugs, {:display_name=>'pulibc_test2'}
 
 137     assert_response :success
 
 139     get :my_bugs, {:display_name=>'non-existent'}
 
 140     assert_response :not_found  
 
 143   def test_map_bug_comment_create_not_found
 
 144     assert_no_difference('MapBugComment.count') do
 
 145       post :edit_bug, {:id => 12345, :name => "new_tester", :text => "This is an additional comment"}
 
 147     assert_response :not_found
 
 150   def test_map_bug_close_not_found
 
 151     post :close_bug, {:id => 12345}
 
 152     assert_response :not_found
 
 155   def test_map_bug_read_not_found
 
 156     get :read, {:id => 12345}
 
 157     assert_response :not_found
 
 160   def test_map_bug_read_gone
 
 161     get :read, {:id => 4}
 
 162     assert_response :gone
 
 165   def test_map_bug_hidden_comment
 
 166     get :read, {:id => 5, :format => 'json'}
 
 167     assert_response :success
 
 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