Skip to content

Commit

Permalink
test parent_works when relationships are setup with ordered_members
Browse files Browse the repository at this point in the history
  • Loading branch information
elrayle committed Mar 28, 2019
1 parent b6d1183 commit 6af0811
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
29 changes: 25 additions & 4 deletions spec/hydra/works/models/file_set_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,34 +101,55 @@
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

context 'when child works know about parent works' do
# 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
Expand Down
15 changes: 15 additions & 0 deletions spec/hydra/works/models/work_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6af0811

Please sign in to comment.