Skip to content

Commit

Permalink
Merge pull request #1015 from transitland/query-for-feed-by-url
Browse files Browse the repository at this point in the history
feeds API endpoint: allow filtering by URL
  • Loading branch information
drewda committed Mar 10, 2017
2 parents 2a5c34f + dc90677 commit b16d73f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/controllers/api/v1/feeds_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def index
@feeds = AllowFiltering.by_onestop_id(@feeds, params)
@feeds = AllowFiltering.by_tag_keys_and_values(@feeds, params)
@feeds = AllowFiltering.by_updated_since(@feeds, params)
@feeds = AllowFiltering.by_attribute_array(@feeds, params, :url, case_sensitive: true)

# Geometry
if [params[:lat], params[:lon]].map(&:present?).all?
Expand Down
19 changes: 19 additions & 0 deletions spec/controllers/api/v1/feeds_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,25 @@
expect(feeds.first[:issues]).to be_nil
}})
end

it 'query: by one source URL' do
feeds = create_list(:feed, 3)
feed_to_find = feeds.second
get :index, url: feed_to_find.url
expect_json({feeds: -> (feeds) {
expect(feeds.size).to eq 1
expect(feeds.first[:onestop_id]).to eq feed_to_find.onestop_id
}})
end

it 'query: by two source URLs' do
feeds = create_list(:feed, 3)
feeds_to_find = [feeds.second, feeds.third]
get :index, url: [feeds_to_find.first.url, feeds_to_find.second.url]
expect_json({feeds: -> (feeds) {
expect(feeds.size).to eq 2
}})
end
end

context 'as GeoJSON' do
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/feed_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

FactoryGirl.define do
factory :feed do
url 'http://www.ridemetro.org/News/Downloads/DataFiles/google_transit.zip'
sequence (:url) { |n| "http://www.ridemetro.org/News/Downloads/DataFiles/google_transit#{n}.zip" }
onestop_id { Faker::OnestopId.feed }
geometry { {
"type": "Polygon",
Expand Down

0 comments on commit b16d73f

Please sign in to comment.