Skip to content

Commit

Permalink
Merge pull request #282 from SFDigitalServices/querying-publishers-by…
Browse files Browse the repository at this point in the history
…-tag

Allow querying for publishers by tag
  • Loading branch information
bigfleet committed Jul 24, 2018
2 parents cac9bf0 + 8b8c5dc commit 37b249c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/routes/publishers.rb
Expand Up @@ -12,10 +12,13 @@ class Publishers < Grape::API
params do
optional :page, type: Integer, default: 1
optional :per, type: Integer, default: 10, max: 1000
optional :tag, type: String
end

get '/publishers' do
Publisher.dataset.paginate(params[:page], params[:per]).order(Sequel.desc(:created_at))
Publisher.dataset.yield_self do |publishers|
params[:tag] ? publishers.tagged(params[:tag]) : publishers
end.paginate(params[:page], params[:per]).order(Sequel.desc(:created_at))
end

desc <<-DESC
Expand Down
7 changes: 7 additions & 0 deletions spec/routes/publishers_spec.rb
Expand Up @@ -16,6 +16,13 @@
get '/publishers', params
expect(last_response.body).to eq [publishers[2], publishers[1]].to_json
end

it 'filters by tag' do
tagged_publisher = create(:publisher, tags: ['tagged', 'foobar'])
create(:publisher, tags: ['foobar'])
get '/publishers', { tag: 'tagged' }
expect(last_response.body).to eq [tagged_publisher].to_json
end
end

describe 'GET /publishers/:publisher_id/events_count' do
Expand Down

0 comments on commit 37b249c

Please sign in to comment.