diff --git a/app/controllers/guide_cards_controller.rb b/app/controllers/guide_cards_controller.rb index cbd44f5..8803a24 100644 --- a/app/controllers/guide_cards_controller.rb +++ b/app/controllers/guide_cards_controller.rb @@ -23,6 +23,6 @@ def search def show @guide_card = GuideCard.find(params[:id]) @sub_guide_cards = @guide_card.children - @card_images = CardImage.where(path: @guide_card.path) + @card_images = CardImage.where(path: @guide_card.path).page(params[:page]) end end diff --git a/app/models/card_image.rb b/app/models/card_image.rb index 3bf4e97..c66c0cf 100644 --- a/app/models/card_image.rb +++ b/app/models/card_image.rb @@ -2,7 +2,7 @@ # Class for CardImage data models class CardImage < ApplicationRecord - paginates_per 8 + paginates_per 10 def iiif_url "https://puliiif.princeton.edu/iiif/2/#{image_name.gsub('.tif', '')}/full/,500/0/default.jpg" end diff --git a/app/views/guide_cards/show.html.erb b/app/views/guide_cards/show.html.erb index ce8f2ce..c7dc04b 100644 --- a/app/views/guide_cards/show.html.erb +++ b/app/views/guide_cards/show.html.erb @@ -1,16 +1,18 @@

Guide: <%= @guide_card.heading %>

-<%= render "shared/return_to_home" %> +<% if @sub_guide_cards.present? %> +

SubGuide Cards

+ +<% end %> -

List of SubGuide Cards

- - - <% @card_images.each do |image| %> +<% @card_images.each do |image| %> - <% end %> \ No newline at end of file +<% end %> + +<%= paginate @card_images %> \ No newline at end of file diff --git a/app/views/sub_guide_cards/index.html.erb b/app/views/sub_guide_cards/index.html.erb deleted file mode 100644 index 7b37c45..0000000 --- a/app/views/sub_guide_cards/index.html.erb +++ /dev/null @@ -1,2 +0,0 @@ -<%#

SubGuideCards#index

-

Find me in app/views/sub_guide_cards/index.html.erb

%> \ No newline at end of file diff --git a/app/views/sub_guide_cards/show.html.erb b/app/views/sub_guide_cards/show.html.erb index 7de4952..a8e86c9 100644 --- a/app/views/sub_guide_cards/show.html.erb +++ b/app/views/sub_guide_cards/show.html.erb @@ -1,8 +1,6 @@

SubGuide: <%= @sub_guide_card.heading %>

<%= page_entries_info @card_images, entry_name: 'card' %>

-<%= render "shared/return_to_home" %> - <%= paginate @card_images %> <% if @sub_guide_card.children.present? %> diff --git a/spec/system/card_image_pagination_spec.rb b/spec/system/card_image_pagination_spec.rb new file mode 100644 index 0000000..4a9642c --- /dev/null +++ b/spec/system/card_image_pagination_spec.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe 'Card Images Pagination', type: :system, js: true do + let(:guide_card_fixture) { Rails.root.join('spec', 'fixtures', 'guide_card_fixture.csv') } + before do + GuideCardLoadingService.new(csv_location: guide_card_fixture).import + (1..21).each do |i| + ci = CardImage.new + ci.path = '14/0001/B4491' + ci.image_name = "fake_image_#{i}.jpg" + ci.save + end + end + + describe 'GuideCards show page' do + it 'displays and paginates through card images' do + visit '/guide_cards/2' + expect(page.all('div#main-content ul img').count).to eq 10 + expect(page.all('div#main-content ul img').last[:src]).to match(/fake_image_10.jpg/) + expect(page).to have_link('Next', href: '/guide_cards/2?page=2') + click_link('Next') + expect(page.all('div#main-content ul img')[3][:src]).to match(/fake_image_14.jpg/) + end + end +end diff --git a/spec/system/guide_cards_spec.rb b/spec/system/guide_cards_spec.rb index a2c6a53..26aecad 100644 --- a/spec/system/guide_cards_spec.rb +++ b/spec/system/guide_cards_spec.rb @@ -41,4 +41,11 @@ expect(page).to have_selector('img[alt]') end end + + context 'when a GuideCard has no SubGuide cards' do + it 'displays text to that effect' do + visit '/guide_cards/2' + expect(page).not_to have_text('SubGuide Cards') + end + end end