Merge 003a665155
into a0768a4d04
This commit is contained in:
commit
b3528715e1
2 changed files with 32 additions and 0 deletions
|
@ -255,6 +255,14 @@ module Api
|
|||
@notes = closed_condition(Note.all)
|
||||
@notes = bbox_condition(@notes)
|
||||
|
||||
# Add ids filter
|
||||
if params[:notes]
|
||||
ids = params["notes"].split(",").collect(&:to_i)
|
||||
raise OSM::APIBadUserInput, "No notes were given to search for" if ids.empty?
|
||||
|
||||
@notes = @notes.where(:id => ids)
|
||||
end
|
||||
|
||||
# Add any user filter
|
||||
user = query_conditions_user_value
|
||||
@notes = @notes.joins(:comments).where(:note_comments => { :author_id => user }) if user
|
||||
|
|
|
@ -1207,6 +1207,30 @@ module Api
|
|||
assert_response :bad_request
|
||||
end
|
||||
|
||||
def test_search_by_ids_success
|
||||
note1 = create(:note, :created_at => "2020-01-01T00:00:00Z")
|
||||
note2 = create(:note, :created_at => "2020-02-01T00:00:00Z")
|
||||
note3 = create(:note, :created_at => "2020-03-01T00:00:00Z", :status => "hidden")
|
||||
note4 = create(:note, :created_at => "2020-04-01T00:00:00Z")
|
||||
create(:note, :created_at => "2020-05-01T00:00:00Z")
|
||||
|
||||
get search_api_notes_path(:notes => "#{note4.id},#{note2.id},#{note3.id},#{note1.id}", :format => "json")
|
||||
assert_response :success
|
||||
assert_equal "application/json", @response.media_type
|
||||
js = ActiveSupport::JSON.decode(@response.body)
|
||||
assert_not_nil js
|
||||
assert_equal "FeatureCollection", js["type"]
|
||||
assert_equal 3, js["features"].count
|
||||
assert_equal note4.id, js["features"][0]["properties"]["id"]
|
||||
assert_equal note2.id, js["features"][1]["properties"]["id"]
|
||||
assert_equal note1.id, js["features"][2]["properties"]["id"]
|
||||
end
|
||||
|
||||
def test_search_by_ids_bad_params
|
||||
get search_api_notes_path, :params => { :notes => "" }
|
||||
assert_response :bad_request
|
||||
end
|
||||
|
||||
def test_feed_success
|
||||
position = (1.1 * GeoRecord::SCALE).to_i
|
||||
create(:note_with_comments, :latitude => position, :longitude => position)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue