Skip to content

Commit

Permalink
Start display for SubGuide cards (#123)
Browse files Browse the repository at this point in the history
* Start display for SubGuide cards

Co-authored-by: Bess Sadler <[email protected]>

* remove unused methods

* remove redundant test

---------

Co-authored-by: Bess Sadler <[email protected]>
  • Loading branch information
leefaisonr and bess authored Aug 14, 2023
1 parent 4b36e92 commit 21f9bcf
Show file tree
Hide file tree
Showing 15 changed files with 50 additions and 74 deletions.
10 changes: 10 additions & 0 deletions app/controllers/sub_guide_cards_controller.rb
Original file line number Diff line number Diff line change
@@ -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
23 changes: 0 additions & 23 deletions app/services/guide_card_loading_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 1 addition & 2 deletions app/views/guide_cards/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<h1><%= @guide_card.heading %></h1>
<h2><%= @guide_card.sortid %></h2>
<h2><%= @guide_card.path %></h2>


<h2>List of SubGuide cards</h2>
<ul>
<% @sub_guide_cards.each do |sub_guide| %>
<li><%= sub_guide.heading %></li>
<li> <%= link_to sub_guide.heading, sub_guide_card_path(sub_guide.id) %> </li>
<% end %>
</ul>
2 changes: 2 additions & 0 deletions app/views/sub_guide_cards/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>SubGuideCards#index</h1>
<p>Find me in app/views/sub_guide_cards/index.html.erb</p>
3 changes: 3 additions & 0 deletions app/views/sub_guide_cards/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h1>SubGuideCards#show</h1>
<p>Find me in app/views/sub_guide_cards/show.html.erb</p>
<%= @sub_guide_card.heading %>
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 ("/")
Expand Down
3 changes: 2 additions & 1 deletion spec/fixtures/guide_card_fixture.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
3 changes: 2 additions & 1 deletion spec/fixtures/subguide_card_fixture.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
1 change: 0 additions & 1 deletion spec/requests/guide_cards_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/services/card_image_loading_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 1 addition & 38 deletions spec/services/guide_card_loading_service_spec.rb
Original file line number Diff line number Diff line change
@@ -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) }
Expand All @@ -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
4 changes: 2 additions & 2 deletions spec/services/sub_guide_loading_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 9 additions & 5 deletions spec/system/guide_cards_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
7 changes: 7 additions & 0 deletions spec/views/sub_guide_cards/index.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions spec/views/sub_guide_cards/show.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 21f9bcf

Please sign in to comment.