diff --git a/spec/services/hyrax/custom_queries/navigators/child_file_sets_navigator_spec.rb b/spec/services/hyrax/custom_queries/navigators/child_file_sets_navigator_spec.rb index aea4e3c68e..a915bec1ea 100644 --- a/spec/services/hyrax/custom_queries/navigators/child_file_sets_navigator_spec.rb +++ b/spec/services/hyrax/custom_queries/navigators/child_file_sets_navigator_spec.rb @@ -1,42 +1,29 @@ # frozen_string_literal: true RSpec.describe Hyrax::CustomQueries::Navigators::ChildFileSetsNavigator, :clean_repo do - subject(:factory) { Wings::ModelTransformer.new(pcdm_object: pcdm_object) } - let(:resource) { subject.build } let(:custom_query_service) { Hyrax.custom_queries } - let(:work1) { build(:work, id: 'wk1', title: ['Work 1']) } - let(:work2) { build(:work, id: 'wk2', title: ['Child Work 1']) } - let(:work3) { build(:work, id: 'wk3', title: ['Child Work 2']) } - let(:fileset1) { build(:file_set, id: 'fs1', title: ['Child File Set 1']) } - let(:fileset2) { build(:file_set, id: 'fs2', title: ['Child File Set 2']) } + let(:work1) { valkyrie_create(:hyrax_work, title: ['Work 1']) } + let(:work2) { valkyrie_create(:hyrax_work, title: ['Child Work 1']) } + let(:work3) { valkyrie_create(:hyrax_work, title: ['Child Work 2']) } + let(:fileset1) { valkyrie_create(:hyrax_file_set, title: ['Child File Set 1']) } + let(:fileset2) { valkyrie_create(:hyrax_file_set, title: ['Child File Set 2']) } - describe '#find_child_file_sets' do - let(:pcdm_object) { work1 } - let(:work1_resource) { resource } - - before do - work1.members = [work2, work3, fileset1, fileset2] - work1.save! - end + before do + work1.member_ids = [work2.id, work3.id, fileset1.id, fileset2.id] + Hyrax.persister.save(resource: work1) + end + describe '#find_child_file_sets' do it 'returns only child filesets as Valkyrie resources' do - child_filesets = custom_query_service.find_child_file_sets(resource: work1_resource) - expect(child_filesets.map(&:id)).to match_valkyrie_ids_with_active_fedora_ids([fileset1.id, fileset2.id]) + child_filesets = custom_query_service.find_child_file_sets(resource: work1) + expect(child_filesets.map(&:id)).to match_array([fileset1.id, fileset2.id]) end end describe '#find_child_file_set_ids' do - let(:pcdm_object) { work1 } - let(:work1_resource) { resource } - - before do - work1.members = [work2, work3, fileset1, fileset2] - work1.save! - end - it 'returns Valkyrie ids for child filesets only' do - child_fileset_ids = custom_query_service.find_child_file_set_ids(resource: work1_resource) - expect(child_fileset_ids).to match_valkyrie_ids_with_active_fedora_ids([fileset1.id, fileset2.id]) + child_fileset_ids = custom_query_service.find_child_file_set_ids(resource: work1) + expect(child_fileset_ids).to match_array([fileset1.id, fileset2.id]) end end end diff --git a/spec/wings/services/custom_queries/navigators/child_file_sets_navigator_spec.rb b/spec/wings/services/custom_queries/navigators/child_file_sets_navigator_spec.rb new file mode 100644 index 0000000000..3bf287b26a --- /dev/null +++ b/spec/wings/services/custom_queries/navigators/child_file_sets_navigator_spec.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true +RSpec.describe Hyrax::CustomQueries::Navigators::ChildFileSetsNavigator, :active_fedora, :clean_repo do + subject(:factory) { Wings::ModelTransformer.new(pcdm_object: pcdm_object) } + let(:resource) { subject.build } + let(:custom_query_service) { Hyrax.custom_queries } + + let(:work1) { build(:work, id: 'wk1', title: ['Work 1']) } + let(:work2) { build(:work, id: 'wk2', title: ['Child Work 1']) } + let(:work3) { build(:work, id: 'wk3', title: ['Child Work 2']) } + let(:fileset1) { build(:file_set, id: 'fs1', title: ['Child File Set 1']) } + let(:fileset2) { build(:file_set, id: 'fs2', title: ['Child File Set 2']) } + + describe '#find_child_file_sets' do + let(:pcdm_object) { work1 } + let(:work1_resource) { resource } + + before do + work1.members = [work2, work3, fileset1, fileset2] + work1.save! + end + + it 'returns only child filesets as Valkyrie resources' do + child_filesets = custom_query_service.find_child_file_sets(resource: work1_resource) + expect(child_filesets.map(&:id)).to match_valkyrie_ids_with_active_fedora_ids([fileset1.id, fileset2.id]) + end + end + + describe '#find_child_file_set_ids' do + let(:pcdm_object) { work1 } + let(:work1_resource) { resource } + + before do + work1.members = [work2, work3, fileset1, fileset2] + work1.save! + end + + it 'returns Valkyrie ids for child filesets only' do + child_fileset_ids = custom_query_service.find_child_file_set_ids(resource: work1_resource) + expect(child_fileset_ids).to match_valkyrie_ids_with_active_fedora_ids([fileset1.id, fileset2.id]) + end + end +end