Skip to content

Commit

Permalink
Image url part 2 (#118)
Browse files Browse the repository at this point in the history
* Create card image loading spec

Co-authored-by: Anna Headley <hackartisan@users.noreply.github.com>
Co-authored-by: Bess Sadler <bess@users.noreply.github.com>

* rubocop corrections

* Start to import image files as CardImage objects

Co-authored-by: Bess Sadler <bess@users.noreply.github.com>

* add rubocop exception

---------

Co-authored-by: Anna Headley <hackartisan@users.noreply.github.com>
Co-authored-by: Bess Sadler <bess@users.noreply.github.com>
  • Loading branch information
3 people committed Aug 10, 2023
1 parent 82902df commit e83a09c
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 12 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Rails/FilePath:
Layout/LineLength:
Exclude:
- "config/initializers/content_security_policy.rb"
- "spec/services/card_image_loading_service_spec.rb"

Metrics/BlockLength:
Exclude:
Expand Down
4 changes: 4 additions & 0 deletions app/models/card_image.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class CardImage < ApplicationRecord
end
4 changes: 1 addition & 3 deletions app/models/sub_guide_card.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@ def parent
GuideCard.find_by(sortid: parentid) || SubGuideCard.find_by(sortid: parentid)
end
include HasChildren
def url
'https://puliiif.princeton.edu/iiif/2/imagecat-disk5-0338-A5977-0000.0073/full/,500/0/default.jpg'
end
def image_urls; end
end
15 changes: 15 additions & 0 deletions app/services/card_image_loading_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

# Class for card image loading service
class CardImageLoadingService
# For each SubGuideCard, take its path and query s3 to get all of the image names
# for that path. For each image file, create a CardImage object with the path and
# image name.
def import
SubGuideCard.all.each do |sgc|
ci = CardImage.new
ci.path = sgc.path
ci.save
end
end
end
13 changes: 13 additions & 0 deletions db/migrate/20230810192642_create_card_images.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

# db migration for card image loading service
class CreateCardImages < ActiveRecord::Migration[7.0]
def change
create_table :card_images do |t|
t.text :path
t.text :image_name

t.timestamps
end
end
end
9 changes: 8 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
12 changes: 12 additions & 0 deletions spec/models/card_image_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe CardImage, type: :model do
it 'can be instantiated' do
ci = CardImage.new
ci.path = '5/0338/A5977'
ci.image_name = 'imagecat-disk5-0338-A5977-0000.0001.tif'
ci.save
end
end
16 changes: 8 additions & 8 deletions spec/models/sub_guide_card_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@
end
end

context 'when we use a card from disk5 with path 5/0338/A5977' do
it 'returns a URL' do
sub_guide_image = SubGuideCard.create(path: '5/0338/A5977')
expect(sub_guide_image.url).to eq 'https://puliiif.princeton.edu/iiif/2/imagecat-disk5-0338-A5977-0000.0073/full/,500/0/default.jpg'
context 'when we display a subguide whose path is 5/0338/A5977' do
xit 'has an array of image urls' do
sub_guide_card = SubGuideCard.create(path: '5/0338/A5977')
expect(sub_guide_card.image_urls.count).to eq 169
end
end

context 'when we use a card from disk4 with path 4/1466/B5962' do
xit 'returns a URL' do
sub_guide_image = SubGuideCard.create(path: '4/1466/B5962')
expect(sub_guide_image.url).to eq 'https://puliiif.princeton.edu/iiif/2/imagecat-disk4-1466-B5962-0000.0064/full/,500/0/default.jpg'
context 'when we display a subguide whose path is 4/1466/B5962' do
xit 'has an array of image urls' do
sub_guide_card = SubGuideCard.create(path: '4/1466/B5962')
expect(sub_guide_card.image_urls.count).to eq 102
end
end
end
23 changes: 23 additions & 0 deletions spec/services/card_image_loading_service_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

require 'rails_helper'

describe CardImageLoadingService do
let(:cils) { described_class.new }
let(:sgls) do
SubGuideLoadingService.new(csv_location: Rails.root.join('spec', 'fixtures', 'subguide_card_fixture.csv'))
end
let(:s3_response) do
"2023-07-19 14:39:38 3422 imagecat-disk9-0091-A3037-1358.0110.tif\n2023-07-19 14:39:38 7010 imagecat-disk9-0091-A3037-1358.0111.tif\n"
end
it 'can instantiate' do
expect(cils).to be_instance_of described_class
end

it 'imports all card images' do
sgls.import
expect(CardImage.count).to eq 0
cils.import
expect(CardImage.count).to eq 6
end
end

0 comments on commit e83a09c

Please sign in to comment.