Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] test parent_works when relationships are setup with ordered_members #360

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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