Skip to content

Commit

Permalink
Honor pages parameter in public json API? (issue #251)
Browse files Browse the repository at this point in the history
* does this work with api pagination?
  • Loading branch information
manno committed Sep 26, 2017
1 parent 0b36e43 commit c327c80
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/controllers/public/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def show
end

def search
@events = paginate(Frontend::Event.query(params[:q]).records, per_page: 50, max_per_page: 256)
@events = paginate(Frontend::Event.query(params[:q]).page(params[:page]).records, per_page: 50, max_per_page: 256)
respond_to { |format| format.json }
end
end
9 changes: 7 additions & 2 deletions test/controllers/public/events_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,18 @@ class Public::EventsControllerTest < ActionController::TestCase

test 'search for events return multiple results' do
Event.__elasticsearch__.create_index! force: true
create_list(:event, 11, title: 'fake-event')
create_list(:event, 26, title: 'fake-event')
Event.import
Event.__elasticsearch__.refresh_index!

get :search, params: { q: 'fake-event' }, format: :json
assert_response :success
json = JSON.parse(response.body)
assert_equal 11, json['events'].count
assert_equal 25, json['events'].count

get :search, params: { q: 'fake-event', page: '2' }, format: :json
assert_response :success
json = JSON.parse(response.body)
assert_equal 1, json['events'].count
end
end

0 comments on commit c327c80

Please sign in to comment.