diff --git a/app/controllers/sub_guide_cards_controller.rb b/app/controllers/sub_guide_cards_controller.rb new file mode 100644 index 00000000..ef46914b --- /dev/null +++ b/app/controllers/sub_guide_cards_controller.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +# Controller for SubGuideCards +class SubGuideCardsController < ApplicationController + def index; end + + def show + @sub_guide_card = SubGuideCard.find(params[:id]) + end +end diff --git a/app/services/guide_card_loading_service.rb b/app/services/guide_card_loading_service.rb index 31385377..ceb3e787 100644 --- a/app/services/guide_card_loading_service.rb +++ b/app/services/guide_card_loading_service.rb @@ -24,27 +24,4 @@ def import end puts 'task completed!' end - - def scan - guide_card_data = CSV.parse(File.read(csv_location), headers: true) - heading_pairs = [[0, 4], [1, 5], [2, 6], [3, 7]] - guide_card_data.each do |card| - heading_pairs.each do |pair| - if card[pair[0]] != card[pair[1]] - Rails.logger.info("#{card[pair[0]]} does not match #{card[pair[1]]} in record #{card[0]}") - end - end - end - end - - # this method deduplicates CSV data for GuideCards - def deduplicate_csv_headings(new_csv) - guide_card_data = CSV.parse(File.read(csv_location), headers: true) - CSV.open(new_csv, 'wb') do |csv| - csv << %w[ID heading sortid path] - guide_card_data.each do |card| - csv << [card[0], card[1], card[2], card[3]] - end - end - end end diff --git a/app/views/guide_cards/show.html.erb b/app/views/guide_cards/show.html.erb index c272788d..9ba2a9ad 100644 --- a/app/views/guide_cards/show.html.erb +++ b/app/views/guide_cards/show.html.erb @@ -1,11 +1,10 @@

<%= @guide_card.heading %>

-

<%= @guide_card.sortid %>

<%= @guide_card.path %>

List of SubGuide cards

diff --git a/app/views/sub_guide_cards/index.html.erb b/app/views/sub_guide_cards/index.html.erb new file mode 100644 index 00000000..ef076490 --- /dev/null +++ b/app/views/sub_guide_cards/index.html.erb @@ -0,0 +1,2 @@ +

SubGuideCards#index

+

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

diff --git a/app/views/sub_guide_cards/show.html.erb b/app/views/sub_guide_cards/show.html.erb new file mode 100644 index 00000000..80851791 --- /dev/null +++ b/app/views/sub_guide_cards/show.html.erb @@ -0,0 +1,3 @@ +

SubGuideCards#show

+

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

+<%= @sub_guide_card.heading %> diff --git a/config/routes.rb b/config/routes.rb index 20f07039..be09a89a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,6 +6,9 @@ get 'guide_cards/', to: 'guide_cards#index' get 'guide_cards/:id', to: 'guide_cards#show' resources :guide_cards + get 'sub_guide_cards/', to: 'sub_guide_cards#index' + get 'sub_guide_cards/:id', to: 'sub_guide_cards#show' + resources :sub_guide_cards # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html # Defines the root path route ("/") diff --git a/spec/fixtures/guide_card_fixture.csv b/spec/fixtures/guide_card_fixture.csv index 53921c32..a5368d30 100644 --- a/spec/fixtures/guide_card_fixture.csv +++ b/spec/fixtures/guide_card_fixture.csv @@ -9,4 +9,5 @@ ID,heading,sortid,path,ID,heading,sortid,path 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 \ No newline at end of file +11,A.M.,11.5,14/0002/A1010,11,A.M.,11.5,14/0002/A1010 +2869,Bible,2870.5,sub,2869,Bible,2870.5,sub \ No newline at end of file diff --git a/spec/fixtures/subguide_card_fixture.csv b/spec/fixtures/subguide_card_fixture.csv index b9656dd2..e207bc80 100644 --- a/spec/fixtures/subguide_card_fixture.csv +++ b/spec/fixtures/subguide_card_fixture.csv @@ -4,4 +4,5 @@ ID,heading,sortid,parentid,path,heading,sortid,parentid,path 3,Afdeling voor ...,50351.5,50345.5,9/0091/A3038,Afdeling voor ...,50351.5,50345.5,9/0091/A3038 4,(Without subdivision),50352.5,540.5,sub,(Without subdivision),50352.5,540.5,sub 5,(As author),50353.5,50352.5,sub,(As author),50353.5,50352.5,sub -57,Nauchnyi sovet "Istoriia istoricheskoi nauki " ... 8/0097/A3100,50405.5,50358.5,8/0097/A3100,Nauchnyi sovet "Istoriia istoricheskoi nauki " ... 8/0097/A3100,50405.5,50358.5,8/0097/A3100 \ No newline at end of file +57,Nauchnyi sovet "Istoriia istoricheskoi nauki " ... 8/0097/A3100,50405.5,50358.5,8/0097/A3100,Nauchnyi sovet "Istoriia istoricheskoi nauki " ... 8/0097/A3100,50405.5,50358.5,8/0097/A3100 +1625,Manuscripts,51625.5,2870.5,sub,Manuscripts,51625.5,2870.5,sub diff --git a/spec/requests/guide_cards_spec.rb b/spec/requests/guide_cards_spec.rb index 9f08210e..52ad266c 100644 --- a/spec/requests/guide_cards_spec.rb +++ b/spec/requests/guide_cards_spec.rb @@ -21,7 +21,6 @@ it 'shows the metadata for a specific item' do get '/guide_cards/3' expect(response.body).to include('AALAS') - expect(response.body).to include('3.5') expect(response.body).to include('14/0001/A1002') end end diff --git a/spec/services/card_image_loading_service_spec.rb b/spec/services/card_image_loading_service_spec.rb index cf5e3d3e..8fd18a70 100644 --- a/spec/services/card_image_loading_service_spec.rb +++ b/spec/services/card_image_loading_service_spec.rb @@ -23,7 +23,7 @@ sgls.import expect(CardImage.count).to eq 0 cils.import - expect(CardImage.count).to eq 12 + expect(CardImage.count).to eq 14 images = CardImage.where(path: '9/0091/A3037') expect(images.map(&:image_name)).to contain_exactly('imagecat-disk9-0091-A3037-1358.0110.tif', 'imagecat-disk9-0091-A3037-1358.0111.tif') end diff --git a/spec/services/guide_card_loading_service_spec.rb b/spec/services/guide_card_loading_service_spec.rb index bcb38721..cdb6e751 100644 --- a/spec/services/guide_card_loading_service_spec.rb +++ b/spec/services/guide_card_loading_service_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require 'rails_helper' -# rubocop:disable Metrics/BlockLength describe GuideCardLoadingService do let(:fixture_file) { Rails.root.join('spec', 'fixtures', 'guide_card_fixture.csv') } let(:gcls) { described_class.new(csv_location: fixture_file) } @@ -16,42 +15,6 @@ it 'imports all data from the CSV file' do expect(GuideCard.count).to eq 0 gcls.import - expect(GuideCard.count).to eq 11 - end - - it 'does not log matching data' do - allow(Rails.logger).to receive(:info) - gcls.scan - expect(Rails.logger).not_to have_received(:info) - end - - context 'with a fixture file with non-matching data' do - let(:fixture_file) { Rails.root.join('spec', 'fixtures', 'guide_card_fixture_non_matching_data.csv') } - it 'logs non-matching data' do - allow(Rails.logger).to receive(:info) - gcls.scan - expect(Rails.logger).to have_received(:info).with('***** does not match house in record 1') - expect(Rails.logger).to have_received(:info).with('14/0001/A1002 does not match 14/0001/A1234 in record 3') - end - end - - context 'with a CSV that has duplicate headings' do - before do - File.delete(new_csv) if File.exist?(new_csv) - end - let(:fixture_file) { Rails.root.join('spec', 'fixtures', 'guide_card_fixture.csv') } - let(:new_csv) { Rails.root.join('spec', 'fixtures', 'deduplicated_guide_card_fixture.csv') } - it 'writes a new file without duplicate headings' do - expect(File.exist?(new_csv)).to eq false - guide_card_data = CSV.parse(File.read(fixture_file), headers: true) - expect(guide_card_data.headers).to contain_exactly('ID', 'heading', 'sortid', 'path', 'ID', 'heading', 'sortid', - 'path') - expect(guide_card_data.count).to eq 11 - gcls.deduplicate_csv_headings(new_csv) - deduplicate_guide_card_data = CSV.parse(File.read(new_csv), headers: true) - expect(deduplicate_guide_card_data.headers).to contain_exactly('ID', 'heading', 'sortid', 'path') - expect(deduplicate_guide_card_data.count).to eq 11 - end + expect(GuideCard.count).to eq 12 end end -# rubocop:enable Metrics/BlockLength diff --git a/spec/services/sub_guide_loading_service_spec.rb b/spec/services/sub_guide_loading_service_spec.rb index e10a50c4..94cba120 100644 --- a/spec/services/sub_guide_loading_service_spec.rb +++ b/spec/services/sub_guide_loading_service_spec.rb @@ -15,10 +15,10 @@ it 'imports all data from the CSV file' do expect(SubGuideCard.count).to eq 0 sgls.import - expect(SubGuideCard.count).to eq 6 + expect(SubGuideCard.count).to eq 7 end it 'displays progress status during import' do - expect { sgls.import }.to output("######task completed!\n").to_stdout + expect { sgls.import }.to output("#######task completed!\n").to_stdout end end diff --git a/spec/system/guide_cards_spec.rb b/spec/system/guide_cards_spec.rb index d471f01e..ea769e7f 100644 --- a/spec/system/guide_cards_spec.rb +++ b/spec/system/guide_cards_spec.rb @@ -4,8 +4,10 @@ RSpec.describe 'GuideCards', type: :system, js: true do let(:guide_card_fixture) { Rails.root.join('spec', 'fixtures', 'guide_card_fixture.csv') } + let(:subguide_card_fixture) { Rails.root.join('spec', 'fixtures', 'subguide_card_fixture.csv') } before do GuideCardLoadingService.new(csv_location: guide_card_fixture).import + SubGuideLoadingService.new(csv_location: subguide_card_fixture).import end describe 'GuideCards index page' do @@ -17,11 +19,13 @@ end end - describe 'GuideCards show page' do - it 'displays children SubGuide cards' do - SubGuideCard.create(parentid: GuideCard.find(3).sortid, heading: 'Institut fizicheskoi >') - visit '/guide_cards/3' - expect(page).to have_text 'Institut fizicheskoi >' + describe 'nested SubGuides with image display' do + it 'shows the top-level guide with subguides underneath' do + visit '/guide_cards/2869' + expect(page).to have_text 'Bible' + expect(page).to have_link 'Manuscripts' + visit '/sub_guide_cards/1625' + expect(page).to have_text 'Manuscripts' end end end diff --git a/spec/views/sub_guide_cards/index.html.erb_spec.rb b/spec/views/sub_guide_cards/index.html.erb_spec.rb new file mode 100644 index 00000000..269e243a --- /dev/null +++ b/spec/views/sub_guide_cards/index.html.erb_spec.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe 'sub_guide_cards/index.html.erb', type: :view do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/views/sub_guide_cards/show.html.erb_spec.rb b/spec/views/sub_guide_cards/show.html.erb_spec.rb new file mode 100644 index 00000000..74f8705c --- /dev/null +++ b/spec/views/sub_guide_cards/show.html.erb_spec.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe 'sub_guide_cards/show.html.erb', type: :view do + pending "add some examples to (or delete) #{__FILE__}" +end