From 6af0811f96c90874a9366a938cda346f3473a776 Mon Sep 17 00:00:00 2001 From: "E. Lynette Rayle" Date: Thu, 28 Mar 2019 08:07:36 -0400 Subject: [PATCH] test parent_works when relationships are setup with ordered_members --- spec/hydra/works/models/file_set_spec.rb | 29 ++++++++++++++++++++---- spec/hydra/works/models/work_spec.rb | 15 ++++++++++++ 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/spec/hydra/works/models/file_set_spec.rb b/spec/hydra/works/models/file_set_spec.rb index 36c0a084..70345544 100644 --- a/spec/hydra/works/models/file_set_spec.rb +++ b/spec/hydra/works/models/file_set_spec.rb @@ -101,20 +101,23 @@ context 'relationships' do context '#parent_works and #parent_work_ids' do let(:parent_work) { Hydra::Works::Work.new(id: 'parent_work') } + let(:parent_work2) { Hydra::Works::Work.new(id: 'parent_work2') } let(:child_file_set1) { described_class.new(id: 'child_file_set1') } let(:child_file_set2) { described_class.new(id: 'child_file_set2') } context 'when parent work knows about child file sets' do before do parent_work.members = [child_file_set1, child_file_set2] + parent_work2.members = [child_file_set1] child_file_set1.save child_file_set2.save parent_work.save + parent_work2.save end it 'gets parent work' do - expect(child_file_set1.parent_works).to match_array [parent_work] - expect(child_file_set1.parent_work_ids).to match_array [parent_work.id] + expect(child_file_set1.parent_works).to match_array [parent_work, parent_work2] + expect(child_file_set1.parent_work_ids).to match_array [parent_work.id, parent_work2.id] end end @@ -122,13 +125,31 @@ # before do # # NOOP: The :member_of relationship is not defined for works. It only uses the :members relationship. # child_file_set1.member_of = [parent_work] + # child_file_set1.member_of = [parent_work2] # child_file_set2.member_of = [parent_work] + # child_file_set1.save + # child_file_set2.save # end it 'gets parent work' do skip 'Pending implementation of the :member_of relationship for works' - expect(child_file_set1.parent_works).to match_array [parent_work] - expect(child_file_set1.parent_work_ids).to match_array [parent_work.id] + expect(child_file_set1.parent_works).to match_array [parent_work, parent_work2] + expect(child_file_set1.parent_work_ids).to match_array [parent_work.id, parent_work2.id] + end + end + + context 'when child works know about parent works as ordered members' do + before do + parent_work.ordered_members = [child_file_set1] + parent_work2.ordered_members = [child_file_set1] + child_file_set1.save + parent_work.save + parent_work2.save + end + + it 'gets parent work' do + expect(child_file_set1.parent_works).to match_array [parent_work, parent_work2] + expect(child_file_set1.parent_work_ids).to match_array [parent_work.id, parent_work2.id] end end end diff --git a/spec/hydra/works/models/work_spec.rb b/spec/hydra/works/models/work_spec.rb index 520933fc..584649aa 100644 --- a/spec/hydra/works/models/work_spec.rb +++ b/spec/hydra/works/models/work_spec.rb @@ -379,6 +379,21 @@ class DummyExtWork < Hydra::Works::Work expect(child_work.parent_work_ids).to match_array [parent_work1.id, parent_work2.id] end end + + context 'when child works know about parent works as ordered members' do + before do + parent_work1.ordered_members = [child_work] + parent_work2.ordered_members = [child_work] + child_work.save + parent_work1.save + parent_work2.save + end + + it 'gets parent work' do + expect(child_work.parent_work_ids).to match_array [parent_work1.id, parent_work2.id] + expect(child_work.parent_works).to match_array [parent_work1, parent_work2] + end + end end context '#child_works and #child_work_ids' do