Skip to content

Commit 443be66

Browse files
committed
[ESSI-2062] revise CollectionBrandingInfo model, specs
1 parent 7e063b5 commit 443be66

File tree

2 files changed

+6
-18
lines changed

2 files changed

+6
-18
lines changed

Diff for: app/models/collection_branding_info.rb

+2-7
Original file line numberDiff line numberDiff line change
@@ -96,23 +96,18 @@ def find_local_dir_name(collection_id, role)
9696
end
9797

9898
def generate_image_path!
99-
if image_path.blank? && file_set_versions.any?
100-
return unless iiif_path_service.lookup_id
99+
if image_path.blank? && iiif_path_service.lookup_id.present?
101100
self.image_path = iiif_path_service.iiif_image_url(size: ESSI.config.dig(:essi, :collection_banner_size))
102101
save
103102
end
104103
end
105104

106-
def file_set_versions
107-
file_set&.reload&.original_file&.versions || []
108-
end
109-
110105
def uploaded_files(uploaded_file_ids)
111106
return [] if uploaded_file_ids.empty?
112107
Hyrax::UploadedFile.find(uploaded_file_ids)
113108
end
114109

115110
def iiif_path_service
116-
@iiif_path_service ||= IIIFFileSetPathService.new(file_set)
111+
@iiif_path_service ||= IIIFFileSetPathService.new(file_set || {})
117112
end
118113
end

Diff for: spec/models/collection_branding_info_spec.rb

+4-11
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
RSpec.describe CollectionBrandingInfo, type: :model do
44
let(:banner) { FactoryBot.build(:collection_branding_banner) }
55
let(:file_set) { FactoryBot.create(:file_set, id: 'file_set_id', uri: 'file_set_uri') }
6-
let(:version) { double(uri: 'version_uri') }
7-
let(:versions) { double(any?: true, all: self, last: version) }
8-
6+
let(:local_file) { File.open(RSpec.configuration.fixture_path + '/world.png') }
7+
let(:local_file_set) { FactoryBot.create(:file_set, content: local_file) }
98

109
describe '#initialize' do
1110
context 'with local_path value provided' do
@@ -101,24 +100,18 @@
101100
banner.send(:image_path=, nil)
102101
end
103102
context 'and unable to generate one' do
104-
before do
105-
allow(banner).to receive(:file_set_versions).and_return([])
106-
end
107103
it 'returns nil' do
108104
expect(banner.file_set_image_path).to be_nil
109105
end
110106
end
111107
context 'but able to generate one' do
112-
before do
113-
allow(banner).to receive(:file_set_versions).and_return(versions)
114-
allow(versions).to receive(:all).and_return(versions)
115-
end
108+
let(:banner) { FactoryBot.build(:collection_branding_banner, file_set_id: local_file_set.id) }
116109
it 'sets the image_path value' do
117110
expect(banner).to receive(:image_path=)
118111
banner.file_set_image_path
119112
end
120113
it 'returns the image_path value' do
121-
expect(banner.file_set_image_path).to match version.uri
114+
expect(banner.file_set_image_path).to match /^http/
122115
end
123116
end
124117
end

0 commit comments

Comments
 (0)