- def test_search_by_user_success
- user = create(:user)
-
- create(:note) do |note|
- create(:note_comment, :note => note, :author => user)
- end
-
- get :search, :params => { :user => user.id, :format => "xml" }
- assert_response :success
- assert_equal "application/xml", @response.content_type
- assert_select "osm", :count => 1 do
- assert_select "note", :count => 1
- end
-
- get :search, :params => { :user => user.id, :format => "json" }
- assert_response :success
- assert_equal "application/json", @response.content_type
- js = ActiveSupport::JSON.decode(@response.body)
- assert_not_nil js
- assert_equal "FeatureCollection", js["type"]
- assert_equal 1, js["features"].count
-
- get :search, :params => { :user => user.id, :format => "rss" }
- assert_response :success
- assert_equal "application/rss+xml", @response.content_type
- assert_select "rss", :count => 1 do
- assert_select "channel", :count => 1 do
- assert_select "item", :count => 1
- end
- end
-
- get :search, :params => { :user => user.id, :format => "gpx" }
- assert_response :success
- assert_equal "application/gpx+xml", @response.content_type
- assert_select "gpx", :count => 1 do
- assert_select "wpt", :count => 1
- end
- end
-
- def test_search_no_match
- create(:note_with_comments)
-
- get :search, :params => { :q => "no match", :format => "xml" }
- assert_response :success
- assert_equal "application/xml", @response.content_type
- assert_select "osm", :count => 1 do
- assert_select "note", :count => 0
- end
-
- get :search, :params => { :q => "no match", :format => "json" }
- assert_response :success
- assert_equal "application/json", @response.content_type
- js = ActiveSupport::JSON.decode(@response.body)
- assert_not_nil js
- assert_equal "FeatureCollection", js["type"]
- assert_equal 0, js["features"].count
-
- get :search, :params => { :q => "no match", :format => "rss" }
- assert_response :success
- assert_equal "application/rss+xml", @response.content_type
- assert_select "rss", :count => 1 do
- assert_select "channel", :count => 1 do
- assert_select "item", :count => 0
- end
- end
-
- get :search, :params => { :q => "no match", :format => "gpx" }
- assert_response :success
- assert_equal "application/gpx+xml", @response.content_type
- assert_select "gpx", :count => 1 do
- assert_select "wpt", :count => 0
- end
- end
-
- def test_search_by_time_no_match
- create(:note_with_comments)
-
- get :search, :params => { :from => "01.01.2010", :to => "01.10.2010", :format => "xml" }
- assert_response :success
- assert_equal "application/xml", @response.content_type
- assert_select "osm", :count => 1 do
- assert_select "note", :count => 0
- end
-
- get :search, :params => { :from => "01.01.2010", :to => "01.10.2010", :format => "json" }
- assert_response :success
- assert_equal "application/json", @response.content_type
- js = ActiveSupport::JSON.decode(@response.body)
- assert_not_nil js
- assert_equal "FeatureCollection", js["type"]
- assert_equal 0, js["features"].count
-
- get :search, :params => { :from => "01.01.2010", :to => "01.10.2010", :format => "rss" }
- assert_response :success
- assert_equal "application/rss+xml", @response.content_type
- assert_select "rss", :count => 1 do
- assert_select "channel", :count => 1 do
- assert_select "item", :count => 0
- end
- end
-
- get :search, :params => { :from => "01.01.2010", :to => "01.10.2010", :format => "gpx" }
- assert_response :success
- assert_equal "application/gpx+xml", @response.content_type
- assert_select "gpx", :count => 1 do
- assert_select "wpt", :count => 0
- end
- end
-
- def test_search_bad_params
- get :search, :params => { :q => "no match", :limit => "0", :format => "json" }
- assert_response :bad_request
-
- get :search, :params => { :q => "no match", :limit => "10001", :format => "json" }
- assert_response :bad_request
-
- get :search, :params => { :display_name => "non-existent" }
- assert_response :bad_request
-
- get :search, :params => { :user => "-1" }
- assert_response :bad_request
-
- get :search, :params => { :from => "wrong-date", :to => "wrong-date" }
- assert_response :bad_request
-
- get :search, :params => { :from => "01.01.2010", :to => "2010.01.2010" }
- assert_response :bad_request
- end
-
- def test_feed_success
- position = (1.1 * GeoRecord::SCALE).to_i
- create(:note_with_comments, :latitude => position, :longitude => position)
- create(:note_with_comments, :latitude => position, :longitude => position)
- position = (1.5 * GeoRecord::SCALE).to_i
- create(:note_with_comments, :latitude => position, :longitude => position)
- create(:note_with_comments, :latitude => position, :longitude => position)
-
- get :feed, :params => { :format => "rss" }
- assert_response :success
- assert_equal "application/rss+xml", @response.content_type
- assert_select "rss", :count => 1 do
- assert_select "channel", :count => 1 do
- assert_select "item", :count => 4
- end
- end
-
- get :feed, :params => { :bbox => "1,1,1.2,1.2", :format => "rss" }
- assert_response :success
- assert_equal "application/rss+xml", @response.content_type
- assert_select "rss", :count => 1 do
- assert_select "channel", :count => 1 do
- assert_select "item", :count => 2
- end
- end
- end
-
- def test_feed_fail
- get :feed, :params => { :bbox => "1,1,1.2", :format => "rss" }
- assert_response :bad_request
-
- get :feed, :params => { :bbox => "1,1,1.2,1.2,1.2", :format => "rss" }
- assert_response :bad_request
-
- get :feed, :params => { :bbox => "1,1,1.2,1.2", :limit => "0", :format => "rss" }
- assert_response :bad_request
-
- get :feed, :params => { :bbox => "1,1,1.2,1.2", :limit => "10001", :format => "rss" }
- assert_response :bad_request
- end
-
- def test_mine_success
- first_user = create(:user)
- second_user = create(:user)
- moderator_user = create(:moderator_user)
-
- create(:note) do |note|
- create(:note_comment, :note => note, :author => first_user)
- end
- create(:note) do |note|
- create(:note_comment, :note => note, :author => second_user)
- end
- create(:note, :status => "hidden") do |note|
- create(:note_comment, :note => note, :author => second_user)
- end
-
- # Note that the table rows include a header row
- get :mine, :params => { :display_name => first_user.display_name }
- assert_response :success
- assert_select "table.note_list tr", :count => 2
-
- get :mine, :params => { :display_name => second_user.display_name }
- assert_response :success
- assert_select "table.note_list tr", :count => 2
-
- get :mine, :params => { :display_name => "non-existent" }
- assert_response :not_found
-
- session[:user] = moderator_user.id
-
- get :mine, :params => { :display_name => first_user.display_name }
- assert_response :success
- assert_select "table.note_list tr", :count => 2
-
- get :mine, :params => { :display_name => second_user.display_name }
- assert_response :success
- assert_select "table.note_list tr", :count => 3
-
- get :mine, :params => { :display_name => "non-existent" }
- assert_response :not_found
- end
-
- def test_mine_paged
- user = create(:user)
-
- create_list(:note, 50) do |note|
- create(:note_comment, :note => note, :author => user)
- end
-
- get :mine, :params => { :display_name => user.display_name }
- assert_response :success
- assert_select "table.note_list tr", :count => 11
-
- get :mine, :params => { :display_name => user.display_name, :page => 2 }