Skip to content

Commit

Permalink
Returning results past first page
Browse files Browse the repository at this point in the history
Co-authored-by: Bess Sadler <bess@users.noreply.github.com>
Co-authored-by: Jane Sandberg <sandbergja@users.noreply.github.com>
  • Loading branch information
3 people committed Sep 7, 2023
1 parent f2a2e89 commit 23cc8fa
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/controllers/guide_cards_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def index

def search
@exact_match = GuideCard.find_by(heading: params[:search_term])
@guide_cards = GuideCard.page(1)
@guide_cards = GuideCard.page(@exact_match.index_page)
end

def show
Expand Down
5 changes: 5 additions & 0 deletions app/models/guide_card.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@
class GuideCard < ApplicationRecord
paginates_per 10
include HasChildren

def index_page
number_to_check = id - 1
(number_to_check / 10) + 1
end
end
30 changes: 30 additions & 0 deletions spec/fixtures/guide_card_search_fixture.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
ID,heading,sortid,path,ID,heading,sortid,path
1,*****,1.5,14/0001/A1100,1,*****,1.5,14/0001/A1100
2,A,2.5,14/0001/B4491,2,A,2.5,14/0001/B4491
3,AALAS,3.5,14/0001/A1002,3,AALAS,3.5,14/0001/A1002
4,A.B.C.,4.5,14/0001/A1003,4,A.B.C.,4.5,14/0001/A1003
5,A.C.I.,5.5,14/0001/A1004,5,A.C.I.,5.5,14/0001/A1004
6,A-D,6.5,14/0001/A1005,6,A-D,6.5,14/0001/A1005
7,AGPA,7.5,14/0001/A1006,7,AGPA,7.5,14/0001/A1006
8,AID,8.5,14/0001/A1007,8,AID,8.5,14/0001/A1007
9,AILA,9.5,14/0002/A1008,9,AILA,9.5,14/0002/A1008
10,A.L.,10.5,14/0002/A1009,10,A.L.,10.5,14/0002/A1009
11,A.M.,11.5,14/0002/A1010,11,A.M.,11.5,14/0002/A1010
12,APL,12.5,14/0002/A1011,12,APL,12.5,14/0002/A1011
13,ARS,13.5,14/0002/A1012,13,ARS,13.5,14/0002/A1012
14,ASM,14.5,14/0002/A1013,14,ASM,14.5,14/0002/A1013
15,A.T.,15.5,14/0002/A1014,15,A.T.,15.5,14/0002/A1014
16,Aa,16.5,21/0003/A1015,16,Aa,16.5,21/0003/A1015
17,Aagaard,17.5,21/0003/A1016,17,Aagaard,17.5,21/0003/A1016
18,Aalund,18.5,21/0003/A1017,18,Aalund,18.5,21/0003/A1017
19,Aaron,19.5,21/0003/A1018,19,Aaron,19.5,21/0003/A1018
20,Aaronson,20.5,21/0003/A1019,20,Aaronson,20.5,21/0003/A1019
21,Abadan,21.5,14/0004/A1020,21,Abadan,21.5,14/0004/A1020
22,"Abailard, Pierre",22.5,sub,22,"Abailard, Pierre",22.5,sub
23,"Abailard, Pierre (Subject)",23.5,14/0004/A1026,23,"Abailard, Pierre (Subject)",23.5,14/0004/A1026
24,Abailard et Eloise,24.5,14/0004/A1047,24,Abailard et Eloise,24.5,14/0004/A1047
25,Abandoned,25.5,14/0004/A1022,25,Abandoned,25.5,14/0004/A1022
26,Abaza,26.5,14/0004/A1027,26,Abaza,26.5,14/0004/A1027
27,Abb,27.5,14/0004/A1028,27,Abb,27.5,14/0004/A1028
28,Abbas,28.5,14/0004/A1029,28,Abbas,28.5,14/0004/A1029
29,Abbasids,29.5,14/0004/A1030,29,Abbasids,29.5,14/0004/A1030
19 changes: 19 additions & 0 deletions spec/models/guide_card_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,23 @@
end
end
end

context 'knows what page of the index it should be on' do
it 'id 2 is on the first page' do
guide_card2 = GuideCard.create(id: 2)
expect(guide_card2.index_page).to eq 1
end
it 'id 11 is on the second page' do
guide_card11 = GuideCard.create(id: 11)
expect(guide_card11.index_page).to eq 2
end
it 'id 30 is on the third page' do
guide_card30 = GuideCard.create(id: 30)
expect(guide_card30.index_page).to eq 3
end
it 'id 19 is on the second page' do
guide_card19 = GuideCard.create(id: 19)
expect(guide_card19.index_page).to eq 2
end
end
end
6 changes: 3 additions & 3 deletions spec/system/search_feature_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
require 'rails_helper'

RSpec.describe 'Search Feature', type: :system, js: true do
let(:guide_card_fixture) { Rails.root.join('spec', 'fixtures', 'guide_card_fixture.csv') }
let(:guide_card_fixture) { Rails.root.join('spec', 'fixtures', 'guide_card_search_fixture.csv') }
before do
GuideCardLoadingService.new(csv_location: guide_card_fixture).import
end

describe 'search bar on front page' do
it 'returns an index of GuideCards with search term indicated' do
visit '/'
fill_in 'search_term', with: 'AID'
fill_in 'search_term', with: 'Aaron'
click_on 'Go'
expect(page).to have_link('* AID')
expect(page).to have_link('* Aaron')
end
end
end

0 comments on commit 23cc8fa

Please sign in to comment.