diff --git a/app/models/iiif_canvas_presenter.rb b/app/models/iiif_canvas_presenter.rb index f2c481b1f1..d0245cadf1 100644 --- a/app/models/iiif_canvas_presenter.rb +++ b/app/models/iiif_canvas_presenter.rb @@ -27,7 +27,7 @@ def initialize(master_file:, stream_info:, media_fragment: nil) delegate :derivative_ids, :id, to: :master_file def to_s - master_file.display_title + master_file.structure_title end def range diff --git a/spec/models/iiif_canvas_presenter_spec.rb b/spec/models/iiif_canvas_presenter_spec.rb index fb85b8c8dd..b8694deafe 100644 --- a/spec/models/iiif_canvas_presenter_spec.rb +++ b/spec/models/iiif_canvas_presenter_spec.rb @@ -47,6 +47,33 @@ end end + describe "#to_s" do + subject { presenter.to_s } + + context 'single-section item' do + it 'prioritizes MediaObject#title for section title' do + expect(subject).to eq master_file.structure_title + expect(subject).to eq media_object.title + expect(subject).to_not eq master_file.display_title + end + end + + context 'multi-section item' do + let(:second) { FactoryBot.build(:master_file, media_object: media_object, derivatives: [derivative]) } + + before :each do + media_object.sections = [master_file, second] + media_object.save! + end + + it 'prioritizes MasterFile#display_title for section titles' do + expect(subject).to eq master_file.structure_title + expect(subject).to eq master_file.display_title + expect(subject).to_not eq media_object.title + end + end + end + describe '#display_content' do subject { presenter.display_content.first }