-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
82902df
commit e83a09c
Showing
10 changed files
with
85 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# frozen_string_literal: true | ||
|
||
class CardImage < ApplicationRecord | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |