From 6ea9f798e601631b9bddbe5f7a176ad3cab04a0f Mon Sep 17 00:00:00 2001 From: "E. Lynette Rayle" Date: Mon, 20 Jul 2015 11:50:32 -0400 Subject: [PATCH] First optimization pass to change create to new whenever possible Partial fix for issue #156 - optimize tests Also includes fix for issue #151 - remove usage of AddObjectToObject --- Gemfile | 4 +- .../services/generic_file/add_generic_file.rb | 3 +- .../services/generic_work/add_generic_file.rb | 3 +- .../services/generic_work/add_generic_work.rb | 3 +- spec/hydra/works/models/collection_spec.rb | 19 ++--- spec/hydra/works/models/generic_file_spec.rb | 12 ++- spec/hydra/works/models/generic_work_spec.rb | 21 +++-- .../collection/add_collection_spec.rb | 74 ++++-------------- .../collection/add_generic_work_spec.rb | 72 ++++------------- .../collection/add_related_object_spec.rb | 69 ++++------------- .../collection/get_collections_spec.rb | 12 ++- .../collection/get_generic_works_spec.rb | 12 ++- .../collection/get_related_objects_spec.rb | 17 ++-- .../collection/remove_collection_spec.rb | 68 ++++------------ .../collection/remove_generic_work_spec.rb | 68 ++++------------ .../collection/remove_related_object_spec.rb | 66 +++------------- .../add_file_to_generic_file_spec.rb | 3 +- .../generic_file/add_generic_file_spec.rb | 75 ++++-------------- .../generic_file/add_related_object_spec.rb | 67 ++++------------ .../generic_file/get_generic_files_spec.rb | 7 +- .../generic_file/get_related_objects_spec.rb | 13 ++-- .../generic_file/persist_derivative_spec.rb | 2 +- .../generic_file/remove_generic_file_spec.rb | 64 +++------------ .../remove_related_object_spec.rb | 64 +++------------ .../services/generic_file/upload_file_spec.rb | 4 +- .../generic_work/add_generic_file_spec.rb | 73 ++++-------------- .../generic_work/add_generic_work_spec.rb | 77 ++++--------------- .../generic_work/add_related_object_spec.rb | 67 +++------------- .../generic_work/get_generic_files_spec.rb | 12 ++- .../generic_work/get_generic_works_spec.rb | 12 ++- .../generic_work/get_related_objects_spec.rb | 13 ++-- .../generic_work/move_generic_file_spec.rb | 8 +- .../generic_work/remove_generic_file_spec.rb | 68 ++++------------ .../generic_work/remove_generic_work_spec.rb | 68 ++++------------ .../remove_related_object_spec.rb | 66 +++------------- spec/hydra/works_spec.rb | 10 +-- 36 files changed, 288 insertions(+), 1008 deletions(-) diff --git a/Gemfile b/Gemfile index d98e8709..d55c95e2 100644 --- a/Gemfile +++ b/Gemfile @@ -3,8 +3,8 @@ source 'https://rubygems.org' # Specify your gem's dependencies in hydra-works.gemspec gemspec -gem 'activefedora-aggregation', github: 'projecthydra-labs/activefedora-aggregation', ref: '0dfe4f4' -gem 'hydra-pcdm', github: 'projecthydra-labs/hydra-pcdm', ref: '11f46014' +gem 'activefedora-aggregation', github: 'projecthydra-labs/activefedora-aggregation', ref: 'master' +gem 'hydra-pcdm', github: 'projecthydra-labs/hydra-pcdm', ref: 'master' gem 'hydra-derivatives', github: 'projecthydra/hydra-derivatives', ref: '7a8377c' gem 'slop', '~> 3.6' # For byebug diff --git a/lib/hydra/works/services/generic_file/add_generic_file.rb b/lib/hydra/works/services/generic_file/add_generic_file.rb index cd8c6c73..408eb325 100644 --- a/lib/hydra/works/services/generic_file/add_generic_file.rb +++ b/lib/hydra/works/services/generic_file/add_generic_file.rb @@ -12,8 +12,7 @@ class AddGenericFileToGenericFile def self.call( parent_generic_file, child_generic_file ) raise ArgumentError, 'parent_generic_file must be a hydra-works generic file' unless Hydra::Works.generic_file? parent_generic_file raise ArgumentError, 'child_generic_file must be a hydra-works generic file' unless Hydra::Works.generic_file? child_generic_file - Hydra::PCDM::AddObjectToObject.call( parent_generic_file, child_generic_file ) + parent_generic_file.members << child_generic_file end - end end diff --git a/lib/hydra/works/services/generic_work/add_generic_file.rb b/lib/hydra/works/services/generic_work/add_generic_file.rb index 1f2b6baa..1851721c 100644 --- a/lib/hydra/works/services/generic_work/add_generic_file.rb +++ b/lib/hydra/works/services/generic_work/add_generic_file.rb @@ -12,8 +12,7 @@ class AddGenericFileToGenericWork def self.call( parent_generic_work, child_generic_file ) raise ArgumentError, 'parent_generic_work must be a hydra-works generic work' unless Hydra::Works.generic_work? parent_generic_work raise ArgumentError, 'child_generic_file must be a hydra-works generic file' unless Hydra::Works.generic_file? child_generic_file - Hydra::PCDM::AddObjectToObject.call( parent_generic_work, child_generic_file ) + parent_generic_work.members << child_generic_file end - end end diff --git a/lib/hydra/works/services/generic_work/add_generic_work.rb b/lib/hydra/works/services/generic_work/add_generic_work.rb index 2c187f3e..dc08ea80 100644 --- a/lib/hydra/works/services/generic_work/add_generic_work.rb +++ b/lib/hydra/works/services/generic_work/add_generic_work.rb @@ -12,8 +12,7 @@ class AddGenericWorkToGenericWork def self.call( parent_generic_work, child_generic_work ) raise ArgumentError, 'parent_generic_work must be a hydra-works generic work' unless Hydra::Works.generic_work? parent_generic_work raise ArgumentError, 'child_generic_work must be a hydra-works generic work' unless Hydra::Works.generic_work? child_generic_work - Hydra::PCDM::AddObjectToObject.call( parent_generic_work, child_generic_work ) + parent_generic_work.members << child_generic_work end - end end diff --git a/spec/hydra/works/models/collection_spec.rb b/spec/hydra/works/models/collection_spec.rb index 2e229f5e..68077c54 100644 --- a/spec/hydra/works/models/collection_spec.rb +++ b/spec/hydra/works/models/collection_spec.rb @@ -2,17 +2,16 @@ describe Hydra::Works::Collection do - let(:collection1) { Hydra::Works::Collection.create } - let(:collection2) { Hydra::Works::Collection.create } - let(:collection3) { Hydra::Works::Collection.create } + let(:collection1) { Hydra::Works::Collection.new } + let(:collection2) { Hydra::Works::Collection.new } + let(:collection3) { Hydra::Works::Collection.new } - let(:generic_work1) { Hydra::Works::GenericWork::Base.create } - let(:generic_work2) { Hydra::Works::GenericWork::Base.create } + let(:generic_work1) { Hydra::Works::GenericWork::Base.new } + let(:generic_work2) { Hydra::Works::GenericWork::Base.new } describe '#collections=' do it 'should aggregate collections' do collection1.collections = [collection2, collection3] - collection1.save expect(collection1.collections).to eq [collection2, collection3] end end @@ -20,22 +19,20 @@ describe '#generic_works=' do it 'should aggregate generic_works' do collection1.generic_works = [generic_work1,generic_work2] - collection1.save expect(collection1.generic_works).to eq [generic_work1,generic_work2] end end describe 'Related objects' do - let(:object) { Hydra::PCDM::Object.create } - let(:collection) { Hydra::Works::Collection.create } + let(:object) { Hydra::PCDM::Object.new } + let(:collection) { Hydra::Works::Collection.new } before do collection.related_objects = [object] - collection.save end it 'persists' do - expect(collection.reload.related_objects).to eq [object] + expect(collection.related_objects).to eq [object] end end end diff --git a/spec/hydra/works/models/generic_file_spec.rb b/spec/hydra/works/models/generic_file_spec.rb index 79c6504b..ded756ce 100644 --- a/spec/hydra/works/models/generic_file_spec.rb +++ b/spec/hydra/works/models/generic_file_spec.rb @@ -2,28 +2,26 @@ describe Hydra::Works::GenericFile::Base do - let(:generic_file1) { Hydra::Works::GenericFile::Base.create } - let(:generic_file2) { Hydra::Works::GenericFile::Base.create } - let(:generic_file3) { Hydra::Works::GenericFile::Base.create } + let(:generic_file1) { Hydra::Works::GenericFile::Base.new } + let(:generic_file2) { Hydra::Works::GenericFile::Base.new } + let(:generic_file3) { Hydra::Works::GenericFile::Base.new } describe '#generic_files=' do it 'should aggregate generic_files' do generic_file1.generic_files = [generic_file2, generic_file3] - generic_file1.save expect(generic_file1.generic_files).to eq [generic_file2, generic_file3] end end describe 'Related objects' do - let(:object1) { Hydra::PCDM::Object.create } + let(:object1) { Hydra::PCDM::Object.new } before do generic_file1.related_objects = [object1] - generic_file1.save end it 'persists' do - expect(generic_file1.reload.related_objects).to eq [object1] + expect(generic_file1.related_objects).to eq [object1] end end diff --git a/spec/hydra/works/models/generic_work_spec.rb b/spec/hydra/works/models/generic_work_spec.rb index 143afe17..65f98253 100644 --- a/spec/hydra/works/models/generic_work_spec.rb +++ b/spec/hydra/works/models/generic_work_spec.rb @@ -2,19 +2,18 @@ describe Hydra::Works::GenericWork do - let(:generic_work1) { Hydra::Works::GenericWork::Base.create } - let(:generic_work2) { Hydra::Works::GenericWork::Base.create } - let(:generic_work3) { Hydra::Works::GenericWork::Base.create } + let(:generic_work1) { Hydra::Works::GenericWork::Base.new } + let(:generic_work2) { Hydra::Works::GenericWork::Base.new } + let(:generic_work3) { Hydra::Works::GenericWork::Base.new } - let(:generic_file1) { Hydra::Works::GenericFile::Base.create } - let(:generic_file2) { Hydra::Works::GenericFile::Base.create } + let(:generic_file1) { Hydra::Works::GenericFile::Base.new } + let(:generic_file2) { Hydra::Works::GenericFile::Base.new } let(:pcdm_file1) { Hydra::PCDM::File.new } describe '#generic_works=' do it 'should aggregate generic_works' do generic_work1.generic_works = [generic_work2, generic_work3] - generic_work1.save expect(generic_work1.generic_works).to eq [generic_work2, generic_work3] end end @@ -22,7 +21,6 @@ describe '#generic_files=' do it 'should aggregate generic_files' do generic_work1.generic_files = [generic_file1, generic_file2] - generic_work1.save expect(generic_work1.generic_files).to eq [generic_file1, generic_file2] end end @@ -33,7 +31,7 @@ class TestWork < Hydra::Works::GenericWork::Base end end - subject { TestWork.create(generic_files: [generic_file1]) } + subject { TestWork.new(generic_files: [generic_file1]) } it "should have many generic files" do expect(subject.generic_files).to eq [generic_file1] @@ -47,16 +45,15 @@ class TestWork < Hydra::Works::GenericWork::Base end describe 'Related objects' do - let(:generic_work1) { Hydra::Works::GenericWork::Base.create } - let(:object1) { Hydra::PCDM::Object.create } + let(:generic_work1) { Hydra::Works::GenericWork::Base.new } + let(:object1) { Hydra::PCDM::Object.new } before do generic_work1.related_objects = [object1] - generic_work1.save end it 'persists' do - expect(generic_work1.reload.related_objects).to eq [object1] + expect(generic_work1.related_objects).to eq [object1] end end diff --git a/spec/hydra/works/services/collection/add_collection_spec.rb b/spec/hydra/works/services/collection/add_collection_spec.rb index 23d1b0d6..b70c74ec 100644 --- a/spec/hydra/works/services/collection/add_collection_spec.rb +++ b/spec/hydra/works/services/collection/add_collection_spec.rb @@ -2,15 +2,15 @@ describe Hydra::Works::AddCollectionToCollection do - subject { Hydra::Works::Collection.create } + subject { Hydra::Works::Collection.new } describe '#call' do context 'with acceptable collections' do - let(:collection1) { Hydra::Works::Collection.create } - let(:collection2) { Hydra::Works::Collection.create } - let(:collection3) { Hydra::Works::Collection.create } - let(:generic_work1) { Hydra::Works::GenericWork::Base.create } - let(:generic_work2) { Hydra::Works::GenericWork::Base.create } + let(:collection1) { Hydra::Works::Collection.new } + let(:collection2) { Hydra::Works::Collection.new } + let(:collection3) { Hydra::Works::Collection.new } + let(:generic_work1) { Hydra::Works::GenericWork::Base.new } + let(:generic_work2) { Hydra::Works::GenericWork::Base.new } context 'with collections and generic_works' do before do @@ -18,7 +18,6 @@ Hydra::Works::AddCollectionToCollection.call( subject, collection2 ) Hydra::Works::AddGenericWorkToCollection.call( subject, generic_work1 ) Hydra::Works::AddGenericWorkToCollection.call( subject, generic_work2 ) - subject.save end it 'should add an generic_work to collection with collections and generic_works' do @@ -43,17 +42,15 @@ class Kollection < ActiveFedora::Base end end after { Object.send(:remove_const, :Kollection) } - let(:kollection1) { Kollection.create } + let(:kollection1) { Kollection.new } it 'should accept implementing collection as a child' do Hydra::Works::AddCollectionToCollection.call( subject, kollection1 ) - subject.save expect( Hydra::Works::GetCollectionsFromCollection.call( subject ) ).to eq [kollection1] end it 'should accept implementing collection as a parent' do Hydra::Works::AddCollectionToCollection.call( kollection1, collection1 ) - subject.save expect( Hydra::Works::GetCollectionsFromCollection.call( kollection1 ) ).to eq [collection1] end end @@ -64,30 +61,28 @@ class Cullection < Hydra::Works::Collection end end after { Object.send(:remove_const, :Cullection) } - let(:cullection1) { Cullection.create } + let(:cullection1) { Cullection.new } it 'should accept extending collection as a child' do Hydra::Works::AddCollectionToCollection.call( subject, cullection1 ) - subject.save expect( Hydra::Works::GetCollectionsFromCollection.call( subject ) ).to eq [cullection1] end it 'should accept extending collection as a parent' do Hydra::Works::AddCollectionToCollection.call( cullection1, collection1 ) - subject.save expect( Hydra::Works::GetCollectionsFromCollection.call( cullection1 ) ).to eq [collection1] end end end context 'with unacceptable child collections' do - let(:generic_work1) { Hydra::Works::GenericWork::Base.create } - let(:generic_file1) { Hydra::Works::GenericFile::Base.create } - let(:pcdm_collection1) { Hydra::PCDM::Collection.create } - let(:pcdm_object1) { Hydra::PCDM::Object.create } + let(:generic_work1) { Hydra::Works::GenericWork::Base.new } + let(:generic_file1) { Hydra::Works::GenericFile::Base.new } + let(:pcdm_collection1) { Hydra::PCDM::Collection.new } + let(:pcdm_object1) { Hydra::PCDM::Object.new } let(:pcdm_file1) { Hydra::PCDM::File.new } let(:non_PCDM_object) { "I'm not a PCDM object" } - let(:af_base_object) { ActiveFedora::Base.create } + let(:af_base_object) { ActiveFedora::Base.new } let(:error_message) { 'child_collection must be a hydra-works collection' } @@ -119,48 +114,5 @@ class Cullection < Hydra::Works::Collection expect{ Hydra::Works::AddCollectionToCollection.call( subject, af_base_object ) }.to raise_error(ArgumentError,error_message) end end - - context 'with unacceptable parent collections' do - let(:collection1) { Hydra::Works::Collection.create } - let(:generic_work1) { Hydra::Works::GenericWork::Base.create } - let(:generic_file1) { Hydra::Works::GenericFile::Base.create } - let(:pcdm_collection1) { Hydra::PCDM::Collection.create } - let(:pcdm_object1) { Hydra::PCDM::Object.create } - let(:pcdm_file1) { Hydra::PCDM::File.new } - let(:non_PCDM_object) { "I'm not a PCDM object" } - let(:af_base_object) { ActiveFedora::Base.create } - - let(:error_message) { 'parent_collection must be a hydra-works collection' } - - it 'should NOT accept Hydra::Works::GenericWork as parent collection' do - expect{ Hydra::Works::AddCollectionToCollection.call( generic_work1, collection1 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::Works::GenericFile as parent collection' do - expect{ Hydra::Works::AddCollectionToCollection.call( generic_file1, collection1 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::PCDM::Collections as parent collection' do - expect{ Hydra::Works::AddCollectionToCollection.call( pcdm_collection1, collection1 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::PCDM::Objects as parent collection' do - expect{ Hydra::Works::AddCollectionToCollection.call( pcdm_object1, collection1 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::PCDM::Files as parent collection' do - expect{ Hydra::Works::AddCollectionToCollection.call( pcdm_file1, collection1 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept non-PCDM objects as parent collection' do - expect{ Hydra::Works::AddCollectionToCollection.call( non_PCDM_object, collection1 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept AF::Base objects as parent collection' do - expect{ Hydra::Works::AddCollectionToCollection.call( af_base_object, collection1 ) }.to raise_error(ArgumentError,error_message) - end - end - end - end diff --git a/spec/hydra/works/services/collection/add_generic_work_spec.rb b/spec/hydra/works/services/collection/add_generic_work_spec.rb index 7bb25988..7f0c025f 100644 --- a/spec/hydra/works/services/collection/add_generic_work_spec.rb +++ b/spec/hydra/works/services/collection/add_generic_work_spec.rb @@ -2,15 +2,15 @@ describe Hydra::Works::AddGenericWorkToCollection do - let(:subject) { Hydra::Works::Collection.create } + let(:subject) { Hydra::Works::Collection.new } describe '#call' do context 'with acceptable generic_works' do - let(:generic_work1) { Hydra::Works::GenericWork::Base.create } - let(:generic_work2) { Hydra::Works::GenericWork::Base.create } - let(:generic_work3) { Hydra::Works::GenericWork::Base.create } - let(:collection1) { Hydra::Works::Collection.create } - let(:collection2) { Hydra::Works::Collection.create } + let(:generic_work1) { Hydra::Works::GenericWork::Base.new } + let(:generic_work2) { Hydra::Works::GenericWork::Base.new } + let(:generic_work3) { Hydra::Works::GenericWork::Base.new } + let(:collection1) { Hydra::Works::Collection.new } + let(:collection2) { Hydra::Works::Collection.new } context 'with collections and generic_works' do before do @@ -18,7 +18,6 @@ Hydra::Works::AddCollectionToCollection.call( subject, collection2 ) Hydra::Works::AddGenericWorkToCollection.call( subject, generic_work1 ) Hydra::Works::AddGenericWorkToCollection.call( subject, generic_work2 ) - subject.save end it 'should add generic_work to collection with collections and generic_works' do @@ -43,11 +42,10 @@ class DummyIncWork < ActiveFedora::Base end end after { Object.send(:remove_const, :DummyIncWork) } - let(:iwork1) { DummyIncWork.create } + let(:iwork1) { DummyIncWork.new } it 'should accept implementing generic_work as a child' do Hydra::Works::AddGenericWorkToCollection.call( subject, iwork1 ) - subject.save expect( Hydra::Works::GetGenericWorksFromCollection.call( subject ) ).to eq [iwork1] end @@ -59,24 +57,23 @@ class DummyExtWork < Hydra::Works::GenericWork::Base end end after { Object.send(:remove_const, :DummyExtWork) } - let(:ework1) { DummyExtWork.create } + let(:ework1) { DummyExtWork.new } it 'should accept extending generic_work as a child' do Hydra::Works::AddGenericWorkToCollection.call( subject, ework1 ) - subject.save expect( Hydra::Works::GetGenericWorksFromCollection.call( subject ) ).to eq [ework1] end end end context 'with unacceptable child generic_works' do - let(:collection1) { Hydra::Works::Collection.create } - let(:generic_file1) { Hydra::Works::GenericFile::Base.create } - let(:pcdm_collection1) { Hydra::PCDM::Collection.create } - let(:pcdm_object1) { Hydra::PCDM::Object.create } + let(:collection1) { Hydra::Works::Collection.new } + let(:generic_file1) { Hydra::Works::GenericFile::Base.new } + let(:pcdm_collection1) { Hydra::PCDM::Collection.new } + let(:pcdm_object1) { Hydra::PCDM::Object.new } let(:pcdm_file1) { Hydra::PCDM::File.new } let(:non_PCDM_object) { "I'm not a PCDM object" } - let(:af_base_object) { ActiveFedora::Base.create } + let(:af_base_object) { ActiveFedora::Base.new } let(:error_message) { 'child_generic_work must be a hydra-works generic work' } @@ -108,48 +105,5 @@ class DummyExtWork < Hydra::Works::GenericWork::Base expect{ Hydra::Works::AddGenericWorkToCollection.call( subject, af_base_object ) }.to raise_error(ArgumentError,error_message) end end - - context 'with unacceptable parent collections' do - let(:generic_work1) { Hydra::Works::GenericWork::Base.create } - let(:generic_work2) { Hydra::Works::GenericWork::Base.create } - let(:generic_file1) { Hydra::Works::GenericFile::Base.create } - let(:pcdm_collection1) { Hydra::PCDM::Collection.create } - let(:pcdm_object1) { Hydra::PCDM::Object.create } - let(:pcdm_file1) { Hydra::PCDM::File.new } - let(:non_PCDM_object) { "I'm not a PCDM object" } - let(:af_base_object) { ActiveFedora::Base.create } - - let(:error_message) { 'parent_collection must be a hydra-works collection' } - - it 'should NOT accept Hydra::Works::GenericWork as parent collection' do - expect{ Hydra::Works::AddGenericWorkToCollection.call( generic_work1, generic_work2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::Works::GenericFile as parent collection' do - expect{ Hydra::Works::AddGenericWorkToCollection.call( generic_file1, generic_work2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::PCDM::Collections as parent collection' do - expect{ Hydra::Works::AddGenericWorkToCollection.call( pcdm_collection1, generic_work2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::PCDM::Objects as parent collection' do - expect{ Hydra::Works::AddGenericWorkToCollection.call( pcdm_object1, generic_work2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::PCDM::Files as parent collection' do - expect{ Hydra::Works::AddGenericWorkToCollection.call( pcdm_file1, generic_work2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept non-PCDM objects as parent collection' do - expect{ Hydra::Works::AddGenericWorkToCollection.call( non_PCDM_object, generic_work2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept AF::Base objects as parent collection' do - expect{ Hydra::Works::AddGenericWorkToCollection.call( af_base_object, generic_work2 ) }.to raise_error(ArgumentError,error_message) - end - end - end - end diff --git a/spec/hydra/works/services/collection/add_related_object_spec.rb b/spec/hydra/works/services/collection/add_related_object_spec.rb index a25b22fd..99b32df3 100644 --- a/spec/hydra/works/services/collection/add_related_object_spec.rb +++ b/spec/hydra/works/services/collection/add_related_object_spec.rb @@ -2,18 +2,18 @@ describe Hydra::Works::AddRelatedObjectToCollection do - let(:subject) { Hydra::Works::Collection.create } + let(:subject) { Hydra::Works::Collection.new } describe '#call' do context 'with acceptable related objects' do - let(:object1) { Hydra::PCDM::Object.create } - let(:object2) { Hydra::PCDM::Object.create } - let(:collection1) { Hydra::Works::Collection.create } - let(:collection2) { Hydra::Works::Collection.create } - let(:generic_work1) { Hydra::Works::GenericWork::Base.create } - let(:generic_work2) { Hydra::Works::GenericWork::Base.create } - let(:generic_file1) { Hydra::Works::GenericFile::Base.create } + let(:object1) { Hydra::PCDM::Object.new } + let(:object2) { Hydra::PCDM::Object.new } + let(:collection1) { Hydra::Works::Collection.new } + let(:collection2) { Hydra::Works::Collection.new } + let(:generic_work1) { Hydra::Works::GenericWork::Base.new } + let(:generic_work2) { Hydra::Works::GenericWork::Base.new } + let(:generic_file1) { Hydra::Works::GenericFile::Base.new } it 'should add various types of related objects to collection' do Hydra::Works::AddRelatedObjectToCollection.call( subject, generic_work1 ) @@ -33,7 +33,6 @@ Hydra::Works::AddGenericWorkToCollection.call( subject, generic_work1 ) Hydra::Works::AddGenericWorkToCollection.call( subject, generic_work2 ) Hydra::Works::AddRelatedObjectToCollection.call( subject, object1 ) - subject.save end it 'should add a related object to collection with collections and generic_works' do @@ -58,11 +57,11 @@ end context 'with unacceptable child related objects' do - let(:collection1) { Hydra::Works::Collection.create } - let(:pcdm_collection1) { Hydra::PCDM::Collection.create } + let(:collection1) { Hydra::Works::Collection.new } + let(:pcdm_collection1) { Hydra::PCDM::Collection.new } let(:pcdm_file1) { Hydra::PCDM::File.new } let(:non_PCDM_object) { "I'm not a PCDM object" } - let(:af_base_object) { ActiveFedora::Base.create } + let(:af_base_object) { ActiveFedora::Base.new } let(:error_message) { 'child_related_object must be a pcdm object' } @@ -87,51 +86,9 @@ end end - context 'with unacceptable parent collections' do - let(:pcdm_object2) { Hydra::PCDM::Object.create } - let(:generic_work1) { Hydra::Works::GenericWork::Base.create } - let(:generic_file1) { Hydra::Works::GenericFile::Base.create } - let(:pcdm_collection1) { Hydra::PCDM::Collection.create } - let(:pcdm_object1) { Hydra::PCDM::Object.create } - let(:pcdm_file1) { Hydra::PCDM::File.new } - let(:non_PCDM_object) { "I'm not a PCDM object" } - let(:af_base_object) { ActiveFedora::Base.create } - - let(:error_message) { 'parent_collection must be a hydra-works collection' } - - it 'should NOT accept Hydra::Works::GenericWork as parent collection' do - expect{ Hydra::Works::AddRelatedObjectToCollection.call( generic_work1, pcdm_object2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::Works::GenericFile as parent collection' do - expect{ Hydra::Works::AddRelatedObjectToCollection.call( generic_file1, pcdm_object2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::PCDM::Collections as parent collection' do - expect{ Hydra::Works::AddRelatedObjectToCollection.call( pcdm_collection1, pcdm_object2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::PCDM::Objects as parent collection' do - expect{ Hydra::Works::AddRelatedObjectToCollection.call( pcdm_object1, pcdm_object2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::PCDM::Files as parent collection' do - expect{ Hydra::Works::AddRelatedObjectToCollection.call( pcdm_file1, pcdm_object2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept non-PCDM objects as parent collection' do - expect{ Hydra::Works::AddRelatedObjectToCollection.call( non_PCDM_object, pcdm_object2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept AF::Base objects as parent collection' do - expect{ Hydra::Works::AddRelatedObjectToCollection.call( af_base_object, pcdm_object2 ) }.to raise_error(ArgumentError,error_message) - end - end - - context 'with invalid behaviors' do - let(:object1) { Hydra::PCDM::Object.create } - let(:object2) { Hydra::PCDM::Object.create } + let(:object1) { Hydra::PCDM::Object.new } + let(:object2) { Hydra::PCDM::Object.new } it 'should NOT allow related objects to repeat' do skip 'skipping this test because issue pcdm#92 needs to be addressed' do diff --git a/spec/hydra/works/services/collection/get_collections_spec.rb b/spec/hydra/works/services/collection/get_collections_spec.rb index e77cf2ba..1f281ae4 100644 --- a/spec/hydra/works/services/collection/get_collections_spec.rb +++ b/spec/hydra/works/services/collection/get_collections_spec.rb @@ -2,19 +2,18 @@ describe Hydra::Works::GetCollectionsFromCollection do - subject { Hydra::Works::Collection.create } + subject { Hydra::Works::Collection.new } - let(:collection1) { Hydra::Works::Collection.create } - let(:collection2) { Hydra::Works::Collection.create } + let(:collection1) { Hydra::Works::Collection.new } + let(:collection2) { Hydra::Works::Collection.new } - let(:generic_work1) { Hydra::Works::GenericWork::Base.create } - let(:generic_work2) { Hydra::Works::GenericWork::Base.create } + let(:generic_work1) { Hydra::Works::GenericWork::Base.new } + let(:generic_work2) { Hydra::Works::GenericWork::Base.new } describe '#call' do it 'should return empty array when only generic_works are aggregated' do Hydra::Works::AddGenericWorkToCollection.call( subject, generic_work1 ) Hydra::Works::AddGenericWorkToCollection.call( subject, generic_work2 ) - subject.save expect(Hydra::Works::GetCollectionsFromCollection.call( subject )).to eq [] end @@ -24,7 +23,6 @@ Hydra::Works::AddCollectionToCollection.call( subject, collection2 ) Hydra::Works::AddGenericWorkToCollection.call( subject, generic_work1 ) Hydra::Works::AddGenericWorkToCollection.call( subject, generic_work2 ) - subject.save end it 'should only return collections' do diff --git a/spec/hydra/works/services/collection/get_generic_works_spec.rb b/spec/hydra/works/services/collection/get_generic_works_spec.rb index 63184ba9..ef63135c 100644 --- a/spec/hydra/works/services/collection/get_generic_works_spec.rb +++ b/spec/hydra/works/services/collection/get_generic_works_spec.rb @@ -2,19 +2,18 @@ describe Hydra::Works::GetGenericWorksFromCollection do - subject { Hydra::Works::Collection.create } + subject { Hydra::Works::Collection.new } - let(:collection1) { Hydra::Works::Collection.create } - let(:collection2) { Hydra::Works::Collection.create } + let(:collection1) { Hydra::Works::Collection.new } + let(:collection2) { Hydra::Works::Collection.new } - let(:generic_work1) { Hydra::Works::GenericWork::Base.create } - let(:generic_work2) { Hydra::Works::GenericWork::Base.create } + let(:generic_work1) { Hydra::Works::GenericWork::Base.new } + let(:generic_work2) { Hydra::Works::GenericWork::Base.new } describe '#call' do it 'should return empty array when only collections are aggregated' do Hydra::Works::AddCollectionToCollection.call( subject, collection1 ) Hydra::Works::AddCollectionToCollection.call( subject, collection2 ) - subject.save expect(Hydra::Works::GetGenericWorksFromCollection.call( subject )).to eq [] end @@ -24,7 +23,6 @@ Hydra::Works::AddCollectionToCollection.call( subject, collection2 ) Hydra::Works::AddGenericWorkToCollection.call( subject, generic_work1 ) Hydra::Works::AddGenericWorkToCollection.call( subject, generic_work2 ) - subject.save end it 'should only return generic works' do diff --git a/spec/hydra/works/services/collection/get_related_objects_spec.rb b/spec/hydra/works/services/collection/get_related_objects_spec.rb index da9c368a..ec08a92e 100644 --- a/spec/hydra/works/services/collection/get_related_objects_spec.rb +++ b/spec/hydra/works/services/collection/get_related_objects_spec.rb @@ -2,17 +2,17 @@ describe Hydra::Works::GetRelatedObjectsFromCollection do - subject { Hydra::Works::Collection.create } + subject { Hydra::Works::Collection.new } - let(:collection1) { Hydra::Works::Collection.create } - let(:collection2) { Hydra::Works::Collection.create } + let(:collection1) { Hydra::Works::Collection.new } + let(:collection2) { Hydra::Works::Collection.new } - let(:object1) { Hydra::PCDM::Object.create } - let(:object2) { Hydra::PCDM::Object.create } + let(:object1) { Hydra::PCDM::Object.new } + let(:object2) { Hydra::PCDM::Object.new } - let(:generic_work1) { Hydra::Works::GenericWork::Base.create } - let(:generic_work2) { Hydra::Works::GenericWork::Base.create } - let(:generic_file1) { Hydra::Works::GenericFile::Base.create } + let(:generic_work1) { Hydra::Works::GenericWork::Base.new } + let(:generic_work2) { Hydra::Works::GenericWork::Base.new } + let(:generic_file1) { Hydra::Works::GenericFile::Base.new } describe '#call' do context 'with collections and generic works' do @@ -20,7 +20,6 @@ Hydra::Works::AddCollectionToCollection.call( subject, collection1 ) Hydra::Works::AddCollectionToCollection.call( subject, collection2 ) Hydra::Works::AddGenericWorkToCollection.call( subject, generic_work1 ) - subject.save end it 'should return empty array when only collections and generic works are aggregated' do diff --git a/spec/hydra/works/services/collection/remove_collection_spec.rb b/spec/hydra/works/services/collection/remove_collection_spec.rb index fde05713..1faaeb1c 100644 --- a/spec/hydra/works/services/collection/remove_collection_spec.rb +++ b/spec/hydra/works/services/collection/remove_collection_spec.rb @@ -2,16 +2,16 @@ describe Hydra::Works::RemoveCollectionFromCollection do - subject { Hydra::Works::Collection.create } + subject { Hydra::Works::Collection.new } - let(:collection1) { Hydra::Works::Collection.create } - let(:collection2) { Hydra::Works::Collection.create } - let(:collection3) { Hydra::Works::Collection.create } - let(:collection4) { Hydra::Works::Collection.create } - let(:collection5) { Hydra::Works::Collection.create } + let(:collection1) { Hydra::Works::Collection.new } + let(:collection2) { Hydra::Works::Collection.new } + let(:collection3) { Hydra::Works::Collection.new } + let(:collection4) { Hydra::Works::Collection.new } + let(:collection5) { Hydra::Works::Collection.new } - let(:generic_work1) { Hydra::Works::GenericWork::Base.create } - let(:generic_work2) { Hydra::Works::GenericWork::Base.create } + let(:generic_work1) { Hydra::Works::GenericWork::Base.new } + let(:generic_work2) { Hydra::Works::GenericWork::Base.new } describe '#call' do @@ -49,13 +49,13 @@ end context 'with unacceptable collections' do - let(:generic_work1) { Hydra::Works::GenericWork::Base.create } - let(:generic_file1) { Hydra::Works::GenericFile::Base.create } - let(:pcdm_collection1) { Hydra::PCDM::Collection.create } - let(:pcdm_object1) { Hydra::PCDM::Object.create } + let(:generic_work1) { Hydra::Works::GenericWork::Base.new } + let(:generic_file1) { Hydra::Works::GenericFile::Base.new } + let(:pcdm_collection1) { Hydra::PCDM::Collection.new } + let(:pcdm_object1) { Hydra::PCDM::Object.new } let(:pcdm_file1) { Hydra::PCDM::File.new } let(:non_PCDM_object) { "I'm not a PCDM object" } - let(:af_base_object) { ActiveFedora::Base.create } + let(:af_base_object) { ActiveFedora::Base.new } let(:error_type) { ArgumentError } let(:error_message) { 'child_collection must be a hydra-works collection' } @@ -88,46 +88,4 @@ expect{ Hydra::Works::RemoveCollectionFromCollection.call( subject, af_base_object ) }.to raise_error(error_type,error_message) end end - - context 'with unacceptable parent collection' do - let(:collection2) { Hydra::Works::Collection.create } - let(:generic_work1) { Hydra::Works::GenericWork::Base.create } - let(:generic_file1) { Hydra::Works::GenericFile::Base.create } - let(:pcdm_collection1) { Hydra::PCDM::Collection.create } - let(:pcdm_object1) { Hydra::PCDM::Object.create } - let(:pcdm_file1) { Hydra::PCDM::File.new } - let(:non_PCDM_object) { "I'm not a PCDM object" } - let(:af_base_object) { ActiveFedora::Base.create } - - let(:error_type) { ArgumentError } - let(:error_message) { 'parent_collection must be a hydra-works collection' } - - it 'should NOT accept Hydra::Works::GenericWork as parent collection' do - expect{ Hydra::Works::RemoveCollectionFromCollection.call( generic_work1, collection2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::Works::GenericFile as parent collection' do - expect{ Hydra::Works::RemoveCollectionFromCollection.call( generic_file1, collection2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::PCDM::Collections as parent collection' do - expect{ Hydra::Works::RemoveCollectionFromCollection.call( pcdm_collection1, collection2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::PCDM::Objects as parent collection' do - expect{ Hydra::Works::RemoveCollectionFromCollection.call( pcdm_object1, collection2 ) }.to raise_error(error_type,error_message) - end - - it 'should NOT accept Hydra::PCDM::Files as parent collection' do - expect{ Hydra::Works::RemoveCollectionFromCollection.call( pcdm_file1, collection2 ) }.to raise_error(error_type,error_message) - end - - it 'should NOT accept non-PCDM objects as parent collection' do - expect{ Hydra::Works::RemoveCollectionFromCollection.call( non_PCDM_object, collection2 ) }.to raise_error(error_type,error_message) - end - - it 'should NOT accept AF::Base objects as parent collection' do - expect{ Hydra::Works::RemoveCollectionFromCollection.call( af_base_object, collection2 ) }.to raise_error(error_type,error_message) - end - end end diff --git a/spec/hydra/works/services/collection/remove_generic_work_spec.rb b/spec/hydra/works/services/collection/remove_generic_work_spec.rb index 6a08d6bd..1035b162 100644 --- a/spec/hydra/works/services/collection/remove_generic_work_spec.rb +++ b/spec/hydra/works/services/collection/remove_generic_work_spec.rb @@ -2,16 +2,16 @@ describe Hydra::Works::RemoveGenericWorkFromCollection do - subject { Hydra::Works::Collection.create } + subject { Hydra::Works::Collection.new } - let(:generic_work1) { Hydra::Works::GenericWork::Base.create } - let(:generic_work2) { Hydra::Works::GenericWork::Base.create } - let(:generic_work3) { Hydra::Works::GenericWork::Base.create } - let(:generic_work4) { Hydra::Works::GenericWork::Base.create } - let(:generic_work5) { Hydra::Works::GenericWork::Base.create } + let(:generic_work1) { Hydra::Works::GenericWork::Base.new } + let(:generic_work2) { Hydra::Works::GenericWork::Base.new } + let(:generic_work3) { Hydra::Works::GenericWork::Base.new } + let(:generic_work4) { Hydra::Works::GenericWork::Base.new } + let(:generic_work5) { Hydra::Works::GenericWork::Base.new } - let(:collection1) { Hydra::Works::Collection.create } - let(:collection2) { Hydra::Works::Collection.create } + let(:collection1) { Hydra::Works::Collection.new } + let(:collection2) { Hydra::Works::Collection.new } describe '#call' do @@ -49,13 +49,13 @@ end context 'with unacceptable generic works' do - let(:collection1) { Hydra::Works::Collection.create } - let(:generic_file1) { Hydra::Works::GenericFile::Base.create } - let(:pcdm_collection1) { Hydra::PCDM::Collection.create } - let(:pcdm_object1) { Hydra::PCDM::Object.create } + let(:collection1) { Hydra::Works::Collection.new } + let(:generic_file1) { Hydra::Works::GenericFile::Base.new } + let(:pcdm_collection1) { Hydra::PCDM::Collection.new } + let(:pcdm_object1) { Hydra::PCDM::Object.new } let(:pcdm_file1) { Hydra::PCDM::File.new } let(:non_PCDM_object) { "I'm not a PCDM object" } - let(:af_base_object) { ActiveFedora::Base.create } + let(:af_base_object) { ActiveFedora::Base.new } let(:error_type) { ArgumentError } let(:error_message) { 'child_generic_work must be a hydra-works generic work' } @@ -88,46 +88,4 @@ expect{ Hydra::Works::RemoveGenericWorkFromCollection.call( subject, af_base_object ) }.to raise_error(error_type,error_message) end end - - context 'with unacceptable parent collection' do - let(:generic_work2) { Hydra::Works::GenericWork::Base.create } - let(:generic_work1) { Hydra::Works::GenericWork::Base.create } - let(:generic_file1) { Hydra::Works::GenericFile::Base.create } - let(:pcdm_collection1) { Hydra::PCDM::Collection.create } - let(:pcdm_object1) { Hydra::PCDM::Object.create } - let(:pcdm_file1) { Hydra::PCDM::File.new } - let(:non_PCDM_object) { "I'm not a PCDM object" } - let(:af_base_object) { ActiveFedora::Base.create } - - let(:error_type) { ArgumentError } - let(:error_message) { 'parent_collection must be a hydra-works collection' } - - it 'should NOT accept Hydra::Works::GenericWork as parent collection' do - expect{ Hydra::Works::RemoveGenericWorkFromCollection.call( generic_work1, generic_work2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::Works::GenericFile as parent collection' do - expect{ Hydra::Works::RemoveGenericWorkFromCollection.call( generic_file1, generic_work2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::PCDM::Collections as parent collection' do - expect{ Hydra::Works::RemoveGenericWorkFromCollection.call( pcdm_collection1, generic_work2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::PCDM::Objects as parent collection' do - expect{ Hydra::Works::RemoveGenericWorkFromCollection.call( pcdm_object1, generic_work2 ) }.to raise_error(error_type,error_message) - end - - it 'should NOT accept Hydra::PCDM::Files as parent collection' do - expect{ Hydra::Works::RemoveGenericWorkFromCollection.call( pcdm_file1, generic_work2 ) }.to raise_error(error_type,error_message) - end - - it 'should NOT accept non-PCDM objects as parent collection' do - expect{ Hydra::Works::RemoveGenericWorkFromCollection.call( non_PCDM_object, generic_work2 ) }.to raise_error(error_type,error_message) - end - - it 'should NOT accept AF::Base objects as parent collection' do - expect{ Hydra::Works::RemoveGenericWorkFromCollection.call( af_base_object, generic_work2 ) }.to raise_error(error_type,error_message) - end - end end diff --git a/spec/hydra/works/services/collection/remove_related_object_spec.rb b/spec/hydra/works/services/collection/remove_related_object_spec.rb index 3a6ceb8e..e7770c9a 100644 --- a/spec/hydra/works/services/collection/remove_related_object_spec.rb +++ b/spec/hydra/works/services/collection/remove_related_object_spec.rb @@ -2,17 +2,17 @@ describe Hydra::Works::RemoveRelatedObjectFromCollection do - subject { Hydra::Works::Collection.create } + subject { Hydra::Works::Collection.new } - let(:related_object1) { Hydra::PCDM::Object.create } - let(:related_work2) { Hydra::Works::GenericWork::Base.create } - let(:related_file3) { Hydra::Works::GenericFile::Base.create } - let(:related_object4) { Hydra::PCDM::Object.create } - let(:related_work5) { Hydra::Works::GenericWork::Base.create } + let(:related_object1) { Hydra::PCDM::Object.new } + let(:related_work2) { Hydra::Works::GenericWork::Base.new } + let(:related_file3) { Hydra::Works::GenericFile::Base.new } + let(:related_object4) { Hydra::PCDM::Object.new } + let(:related_work5) { Hydra::Works::GenericWork::Base.new } - let(:collection1) { Hydra::Works::Collection.create } - let(:collection2) { Hydra::Works::Collection.create } - let(:generic_work1) { Hydra::Works::GenericWork::Base.create } + let(:collection1) { Hydra::Works::Collection.new } + let(:collection2) { Hydra::Works::Collection.new } + let(:generic_work1) { Hydra::Works::GenericWork::Base.new } describe '#call' do @@ -54,11 +54,11 @@ end context 'with unacceptable related object' do - let(:collection1) { Hydra::Works::Collection.create } - let(:pcdm_collection1) { Hydra::PCDM::Collection.create } + let(:collection1) { Hydra::Works::Collection.new } + let(:pcdm_collection1) { Hydra::PCDM::Collection.new } let(:pcdm_file1) { Hydra::PCDM::File.new } let(:non_PCDM_object) { "I'm not a PCDM object" } - let(:af_base_object) { ActiveFedora::Base.create } + let(:af_base_object) { ActiveFedora::Base.new } let(:error_type) { ArgumentError } let(:error_message) { 'child_related_object must be a pcdm object' } @@ -83,46 +83,4 @@ expect{ Hydra::Works::RemoveRelatedObjectFromCollection.call( subject, af_base_object ) }.to raise_error(error_type,error_message) end end - - context 'with unacceptable parent collection' do - let(:related_object2) { Hydra::PCDM::Object.create } - let(:generic_work1) { Hydra::Works::GenericWork::Base.create } - let(:generic_file1) { Hydra::Works::GenericFile::Base.create } - let(:pcdm_collection1) { Hydra::PCDM::Collection.create } - let(:pcdm_object1) { Hydra::PCDM::Object.create } - let(:pcdm_file1) { Hydra::PCDM::File.new } - let(:non_PCDM_object) { "I'm not a PCDM object" } - let(:af_base_object) { ActiveFedora::Base.create } - - let(:error_type) { ArgumentError } - let(:error_message) { 'parent_collection must be a hydra-works collection' } - - it 'should NOT accept Hydra::Works::GenericWork as parent collection' do - expect{ Hydra::Works::RemoveRelatedObjectFromCollection.call( generic_work1, related_object2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::Works::GenericFile as parent collection' do - expect{ Hydra::Works::RemoveRelatedObjectFromCollection.call( generic_file1, related_object2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::PCDM::Collections as parent collection' do - expect{ Hydra::Works::RemoveRelatedObjectFromCollection.call( pcdm_collection1, related_object2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::PCDM::Objects as parent collection' do - expect{ Hydra::Works::RemoveRelatedObjectFromCollection.call( pcdm_object1, related_object2 ) }.to raise_error(error_type,error_message) - end - - it 'should NOT accept Hydra::PCDM::Files as parent collection' do - expect{ Hydra::Works::RemoveRelatedObjectFromCollection.call( pcdm_file1, related_object2 ) }.to raise_error(error_type,error_message) - end - - it 'should NOT accept non-PCDM objects as parent collection' do - expect{ Hydra::Works::RemoveRelatedObjectFromCollection.call( non_PCDM_object, related_object2 ) }.to raise_error(error_type,error_message) - end - - it 'should NOT accept AF::Base objects as parent collection' do - expect{ Hydra::Works::RemoveRelatedObjectFromCollection.call( af_base_object, related_work2 ) }.to raise_error(error_type,error_message) - end - end end diff --git a/spec/hydra/works/services/generic_file/add_file_to_generic_file_spec.rb b/spec/hydra/works/services/generic_file/add_file_to_generic_file_spec.rb index 8013d6f1..5554a30d 100644 --- a/spec/hydra/works/services/generic_file/add_file_to_generic_file_spec.rb +++ b/spec/hydra/works/services/generic_file/add_file_to_generic_file_spec.rb @@ -2,7 +2,7 @@ describe Hydra::Works::AddFileToGenericFile do - let(:generic_file) { Hydra::Works::GenericFile::Base.create } + let(:generic_file) { Hydra::Works::GenericFile::Base.new } let(:reloaded) { generic_file.reload } let(:filename) { "sample-file.pdf" } let(:path) { File.join(fixture_path, filename) } @@ -20,6 +20,7 @@ context "when generic_file is not valid" do before do + generic_file.save allow(generic_file).to receive(:valid?).and_return(false) end it "returns false" do diff --git a/spec/hydra/works/services/generic_file/add_generic_file_spec.rb b/spec/hydra/works/services/generic_file/add_generic_file_spec.rb index 65376b1d..2e57a4eb 100644 --- a/spec/hydra/works/services/generic_file/add_generic_file_spec.rb +++ b/spec/hydra/works/services/generic_file/add_generic_file_spec.rb @@ -2,21 +2,19 @@ describe Hydra::Works::AddGenericFileToGenericFile do - let(:subject) { Hydra::Works::GenericFile::Base.create } + let(:subject) { Hydra::Works::GenericFile::Base.new } describe '#call' do context 'with acceptable generic_files' do - let(:generic_file1) { Hydra::Works::GenericFile::Base.create } - let(:generic_file2) { Hydra::Works::GenericFile::Base.create } - let(:generic_file3) { Hydra::Works::GenericFile::Base.create } - let(:generic_file4) { Hydra::Works::GenericFile::Base.create } - let(:generic_file5) { Hydra::Works::GenericFile::Base.create } + let(:generic_file1) { Hydra::Works::GenericFile::Base.new } + let(:generic_file2) { Hydra::Works::GenericFile::Base.new } + let(:generic_file3) { Hydra::Works::GenericFile::Base.new } + let(:generic_file4) { Hydra::Works::GenericFile::Base.new } + let(:generic_file5) { Hydra::Works::GenericFile::Base.new } it 'should aggregate generic_files in a sub-generic_file of a generic_file' do Hydra::Works::AddGenericFileToGenericFile.call( generic_file1, generic_file2 ) - generic_file1.save Hydra::Works::AddGenericFileToGenericFile.call( generic_file2, generic_file3 ) - generic_file2.save expect( Hydra::Works::GetGenericFilesFromGenericFile.call( generic_file1 ) ).to eq [generic_file2] expect( Hydra::Works::GetGenericFilesFromGenericFile.call( generic_file2 ) ).to eq [generic_file3] end @@ -33,6 +31,7 @@ let(:file2) { subject.files.build } before do + subject.save file1.content = "I'm a file" file2.content = "I am too" Hydra::Works::AddGenericFileToGenericFile.call( subject, generic_file1 ) @@ -62,11 +61,10 @@ class DummyIncFile < ActiveFedora::Base end end after { Object.send(:remove_const, :DummyIncFile) } - let(:ifile1) { DummyIncFile.create } + let(:ifile1) { DummyIncFile.new } it 'should accept implementing generic_file as a child' do Hydra::Works::AddGenericFileToGenericFile.call( subject, ifile1 ) - subject.save expect( Hydra::Works::GetGenericFilesFromGenericFile.call( subject ) ).to eq [ifile1] end end @@ -77,24 +75,23 @@ class DummyExtFile < Hydra::Works::GenericFile::Base end end after { Object.send(:remove_const, :DummyExtFile) } - let(:efile1) { DummyExtFile.create } + let(:efile1) { DummyExtFile.new } it 'should accept extending generic_file as a child' do Hydra::Works::AddGenericFileToGenericFile.call( subject, efile1 ) - subject.save expect( Hydra::Works::GetGenericFilesFromGenericFile.call( subject ) ).to eq [efile1] end end end context 'with unacceptable child generic_files' do - let(:collection1) { Hydra::Works::Collection.create } - let(:generic_work1) { Hydra::Works::GenericWork::Base.create } - let(:pcdm_collection1) { Hydra::PCDM::Collection.create } - let(:pcdm_object1) { Hydra::PCDM::Object.create } + let(:collection1) { Hydra::Works::Collection.new } + let(:generic_work1) { Hydra::Works::GenericWork::Base.new } + let(:pcdm_collection1) { Hydra::PCDM::Collection.new } + let(:pcdm_object1) { Hydra::PCDM::Object.new } let(:pcdm_file1) { Hydra::PCDM::File.new } let(:non_PCDM_object) { "I'm not a PCDM object" } - let(:af_base_object) { ActiveFedora::Base.create } + let(:af_base_object) { ActiveFedora::Base.new } let(:error_message) { 'child_generic_file must be a hydra-works generic file' } @@ -126,49 +123,5 @@ class DummyExtFile < Hydra::Works::GenericFile::Base expect{ Hydra::Works::AddGenericFileToGenericFile.call( subject, af_base_object ) }.to raise_error(ArgumentError,error_message) end end - - context 'with unacceptable parent generic works' do - let(:collection1) { Hydra::Works::Collection.create } - let(:generic_work1) { Hydra::Works::GenericWork::Base.create } - let(:generic_file1) { Hydra::Works::GenericFile::Base.create } - let(:generic_file2) { Hydra::Works::GenericFile::Base.create } - let(:pcdm_collection1) { Hydra::PCDM::Collection.create } - let(:pcdm_object1) { Hydra::PCDM::Object.create } - let(:pcdm_file1) { Hydra::PCDM::File.new } - let(:non_PCDM_object) { "I'm not a PCDM object" } - let(:af_base_object) { ActiveFedora::Base.create } - - let(:error_message) { 'parent_generic_file must be a hydra-works generic file' } - - it 'should NOT accept Hydra::Works::Collection as parent generic file' do - expect{ Hydra::Works::AddGenericFileToGenericFile.call( collection1, generic_file2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::Works::GenericWork as parent generic file' do - expect{ Hydra::Works::AddGenericFileToGenericFile.call( generic_work1, generic_file2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::PCDM::Collections as parent generic file' do - expect{ Hydra::Works::AddGenericFileToGenericFile.call( pcdm_collection1, generic_file2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::PCDM::Objects as parent generic file' do - expect{ Hydra::Works::AddGenericFileToGenericFile.call( pcdm_object1, generic_file2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::PCDM::Files as parent generic file' do - expect{ Hydra::Works::AddGenericFileToGenericFile.call( pcdm_file1, generic_file2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept non-PCDM objects as parent generic file' do - expect{ Hydra::Works::AddGenericFileToGenericFile.call( non_PCDM_object, generic_file2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept AF::Base objects as parent generic file' do - expect{ Hydra::Works::AddGenericFileToGenericFile.call( af_base_object, generic_file2 ) }.to raise_error(ArgumentError,error_message) - end - end - end - end diff --git a/spec/hydra/works/services/generic_file/add_related_object_spec.rb b/spec/hydra/works/services/generic_file/add_related_object_spec.rb index bc19344c..1bbb9257 100644 --- a/spec/hydra/works/services/generic_file/add_related_object_spec.rb +++ b/spec/hydra/works/services/generic_file/add_related_object_spec.rb @@ -2,17 +2,17 @@ describe Hydra::Works::AddRelatedObjectToGenericFile do - let(:subject) { Hydra::Works::GenericFile::Base.create } + let(:subject) { Hydra::Works::GenericFile::Base.new } describe '#call' do context 'with acceptable related objects' do - let(:object1) { Hydra::PCDM::Object.create } - let(:object2) { Hydra::PCDM::Object.create } - let(:generic_work1) { Hydra::Works::GenericWork::Base.create } - let(:generic_work2) { Hydra::Works::GenericWork::Base.create } - let(:generic_file1) { Hydra::Works::GenericFile::Base.create } - let(:generic_file2) { Hydra::Works::GenericFile::Base.create } + let(:object1) { Hydra::PCDM::Object.new } + let(:object2) { Hydra::PCDM::Object.new } + let(:generic_work1) { Hydra::Works::GenericWork::Base.new } + let(:generic_work2) { Hydra::Works::GenericWork::Base.new } + let(:generic_file1) { Hydra::Works::GenericFile::Base.new } + let(:generic_file2) { Hydra::Works::GenericFile::Base.new } it 'should add various types of related objects to generic_file' do Hydra::Works::AddRelatedObjectToGenericFile.call( subject, generic_work1 ) @@ -30,6 +30,7 @@ let(:file2) { subject.files.build } before do + subject.save file1.content = "I'm a file" file2.content = "I am too" Hydra::Works::AddGenericFileToGenericFile.call( subject, generic_file1 ) @@ -59,11 +60,11 @@ end context 'with unacceptable child related objects' do - let(:collection1) { Hydra::Works::Collection.create } - let(:pcdm_collection1) { Hydra::PCDM::Collection.create } + let(:collection1) { Hydra::Works::Collection.new } + let(:pcdm_collection1) { Hydra::PCDM::Collection.new } let(:pcdm_file1) { Hydra::PCDM::File.new } let(:non_PCDM_object) { "I'm not a PCDM object" } - let(:af_base_object) { ActiveFedora::Base.create } + let(:af_base_object) { ActiveFedora::Base.new } let(:error_message) { 'child_related_object must be a pcdm object' } @@ -88,51 +89,9 @@ end end - context 'with unacceptable parent generic work' do - let(:collection1) { Hydra::Works::Collection.create } - let(:generic_work1) { Hydra::Works::GenericWork::Base.create } - let(:pcdm_collection1) { Hydra::PCDM::Collection.create } - let(:pcdm_object1) { Hydra::PCDM::Object.create } - let(:pcdm_object2) { Hydra::PCDM::Object.create } - let(:pcdm_file1) { Hydra::PCDM::File.new } - let(:non_PCDM_object) { "I'm not a PCDM object" } - let(:af_base_object) { ActiveFedora::Base.create } - - let(:error_message) { 'parent_generic_file must be a hydra-works generic file' } - - it 'should NOT accept Hydra::Works::Collection as parent generic file' do - expect{ Hydra::Works::AddRelatedObjectToGenericFile.call( collection1, pcdm_object2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::Works::GenericWork as parent generic file' do - expect{ Hydra::Works::AddRelatedObjectToGenericFile.call( generic_work1, pcdm_object2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::PCDM::Collections as parent generic file' do - expect{ Hydra::Works::AddRelatedObjectToGenericFile.call( pcdm_collection1, pcdm_object2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::PCDM::Objects as parent generic file' do - expect{ Hydra::Works::AddRelatedObjectToGenericFile.call( pcdm_object1, pcdm_object2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::PCDM::Files as parent generic file' do - expect{ Hydra::Works::AddRelatedObjectToGenericFile.call( pcdm_file1, pcdm_object2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept non-PCDM objects as parent generic file' do - expect{ Hydra::Works::AddRelatedObjectToGenericFile.call( non_PCDM_object, pcdm_object2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept AF::Base objects as parent generic file' do - expect{ Hydra::Works::AddRelatedObjectToGenericFile.call( af_base_object, pcdm_object2 ) }.to raise_error(ArgumentError,error_message) - end - end - - context 'with invalid behaviors' do - let(:object1) { Hydra::PCDM::Object.create } - let(:object2) { Hydra::PCDM::Object.create } + let(:object1) { Hydra::PCDM::Object.new } + let(:object2) { Hydra::PCDM::Object.new } it 'should NOT allow related objects to repeat' do skip 'skipping this test because issue pcdm#92 needs to be addressed' do diff --git a/spec/hydra/works/services/generic_file/get_generic_files_spec.rb b/spec/hydra/works/services/generic_file/get_generic_files_spec.rb index 1050cdbc..c231b154 100644 --- a/spec/hydra/works/services/generic_file/get_generic_files_spec.rb +++ b/spec/hydra/works/services/generic_file/get_generic_files_spec.rb @@ -2,16 +2,15 @@ describe Hydra::Works::GetGenericFilesFromGenericFile do - subject { Hydra::Works::GenericFile::Base.create } + subject { Hydra::Works::GenericFile::Base.new } - let(:generic_file1) { Hydra::Works::GenericFile::Base.create } - let(:generic_file2) { Hydra::Works::GenericFile::Base.create } + let(:generic_file1) { Hydra::Works::GenericFile::Base.new } + let(:generic_file2) { Hydra::Works::GenericFile::Base.new } describe '#call' do it 'should return generic_files when generic_files are aggregated' do Hydra::Works::AddGenericFileToGenericFile.call( subject, generic_file1 ) Hydra::Works::AddGenericFileToGenericFile.call( subject, generic_file2 ) - subject.save expect(Hydra::Works::GetGenericFilesFromGenericFile.call( subject )).to eq [generic_file1,generic_file2] end diff --git a/spec/hydra/works/services/generic_file/get_related_objects_spec.rb b/spec/hydra/works/services/generic_file/get_related_objects_spec.rb index eef1077f..d19f7bd5 100644 --- a/spec/hydra/works/services/generic_file/get_related_objects_spec.rb +++ b/spec/hydra/works/services/generic_file/get_related_objects_spec.rb @@ -2,21 +2,20 @@ describe Hydra::Works::GetRelatedObjectsFromGenericFile do - subject { Hydra::Works::GenericFile::Base.create } + subject { Hydra::Works::GenericFile::Base.new } - let(:object1) { Hydra::PCDM::Object.create } - let(:object2) { Hydra::PCDM::Object.create } + let(:object1) { Hydra::PCDM::Object.new } + let(:object2) { Hydra::PCDM::Object.new } - let(:generic_work1) { Hydra::Works::GenericWork::Base.create } - let(:generic_file1) { Hydra::Works::GenericFile::Base.create } - let(:generic_file2) { Hydra::Works::GenericFile::Base.create } + let(:generic_work1) { Hydra::Works::GenericWork::Base.new } + let(:generic_file1) { Hydra::Works::GenericFile::Base.new } + let(:generic_file2) { Hydra::Works::GenericFile::Base.new } describe '#call' do context 'with generic files' do before do Hydra::Works::AddGenericFileToGenericFile.call( subject, generic_file1 ) Hydra::Works::AddGenericFileToGenericFile.call( subject, generic_file2 ) - subject.save end it 'should return empty array when only generic files are aggregated' do diff --git a/spec/hydra/works/services/generic_file/persist_derivative_spec.rb b/spec/hydra/works/services/generic_file/persist_derivative_spec.rb index 02ef76bf..9248d532 100644 --- a/spec/hydra/works/services/generic_file/persist_derivative_spec.rb +++ b/spec/hydra/works/services/generic_file/persist_derivative_spec.rb @@ -2,7 +2,7 @@ describe Hydra::Works::PersistDerivative do - let(:generic_file) { Hydra::Works::GenericFile::Base.create } + let(:generic_file) { Hydra::Works::GenericFile::Base.new } let(:filename) { "sample-file.pdf" } let(:destination_name) { File.join(fixture_path, filename) } let(:file) { File.new(destination_name) } diff --git a/spec/hydra/works/services/generic_file/remove_generic_file_spec.rb b/spec/hydra/works/services/generic_file/remove_generic_file_spec.rb index 8a6a4ffe..5032b567 100644 --- a/spec/hydra/works/services/generic_file/remove_generic_file_spec.rb +++ b/spec/hydra/works/services/generic_file/remove_generic_file_spec.rb @@ -2,13 +2,13 @@ describe Hydra::Works::RemoveGenericFileFromGenericFile do - subject { Hydra::Works::GenericFile::Base.create } + subject { Hydra::Works::GenericFile::Base.new } - let(:generic_file1) { Hydra::Works::GenericFile::Base.create } - let(:generic_file2) { Hydra::Works::GenericFile::Base.create } - let(:generic_file3) { Hydra::Works::GenericFile::Base.create } - let(:generic_file4) { Hydra::Works::GenericFile::Base.create } - let(:generic_file5) { Hydra::Works::GenericFile::Base.create } + let(:generic_file1) { Hydra::Works::GenericFile::Base.new } + let(:generic_file2) { Hydra::Works::GenericFile::Base.new } + let(:generic_file3) { Hydra::Works::GenericFile::Base.new } + let(:generic_file4) { Hydra::Works::GenericFile::Base.new } + let(:generic_file5) { Hydra::Works::GenericFile::Base.new } describe '#call' do context 'when multiple collections' do @@ -40,13 +40,13 @@ end context 'with unacceptable generic files' do - let(:collection1) { Hydra::Works::Collection.create } - let(:generic_work1) { Hydra::Works::GenericWork::Base.create } - let(:pcdm_collection1) { Hydra::PCDM::Collection.create } - let(:pcdm_object1) { Hydra::PCDM::Object.create } + let(:collection1) { Hydra::Works::Collection.new } + let(:generic_work1) { Hydra::Works::GenericWork::Base.new } + let(:pcdm_collection1) { Hydra::PCDM::Collection.new } + let(:pcdm_object1) { Hydra::PCDM::Object.new } let(:pcdm_file1) { Hydra::PCDM::File.new } let(:non_PCDM_object) { "I'm not a PCDM object" } - let(:af_base_object) { ActiveFedora::Base.create } + let(:af_base_object) { ActiveFedora::Base.new } let(:error_type) { ArgumentError } let(:error_message) { 'child_generic_file must be a hydra-works generic file' } @@ -79,46 +79,4 @@ expect{ Hydra::Works::RemoveGenericFileFromGenericFile.call( subject, af_base_object ) }.to raise_error(error_type,error_message) end end - - context 'with unacceptable parent generic file' do - let(:generic_file2) { Hydra::Works::GenericFile::Base.create } - let(:collection1) { Hydra::Works::Collection.create } - let(:generic_work1) { Hydra::Works::GenericWork::Base.create } - let(:pcdm_collection1) { Hydra::PCDM::Collection.create } - let(:pcdm_object1) { Hydra::PCDM::Object.create } - let(:pcdm_file1) { Hydra::PCDM::File.new } - let(:non_PCDM_object) { "I'm not a PCDM object" } - let(:af_base_object) { ActiveFedora::Base.create } - - let(:error_type) { ArgumentError } - let(:error_message) { 'parent_generic_file must be a hydra-works generic file' } - - it 'should NOT accept Hydra::Works::Collection as parent generic file' do - expect{ Hydra::Works::RemoveGenericFileFromGenericFile.call( collection1, generic_file2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::Works::GenericWork as parent generic file' do - expect{ Hydra::Works::RemoveGenericFileFromGenericFile.call( generic_work1, generic_file2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::PCDM::Collections as parent generic file' do - expect{ Hydra::Works::RemoveGenericFileFromGenericFile.call( pcdm_collection1, generic_file2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::PCDM::Objects as parent generic file' do - expect{ Hydra::Works::RemoveGenericFileFromGenericFile.call( pcdm_object1, generic_file2 ) }.to raise_error(error_type,error_message) - end - - it 'should NOT accept Hydra::PCDM::Files as parent generic file' do - expect{ Hydra::Works::RemoveGenericFileFromGenericFile.call( pcdm_file1, generic_file2 ) }.to raise_error(error_type,error_message) - end - - it 'should NOT accept non-PCDM objects as parent generic file' do - expect{ Hydra::Works::RemoveGenericFileFromGenericFile.call( non_PCDM_object, generic_file2 ) }.to raise_error(error_type,error_message) - end - - it 'should NOT accept AF::Base objects as parent generic file' do - expect{ Hydra::Works::RemoveGenericFileFromGenericFile.call( af_base_object, generic_file2 ) }.to raise_error(error_type,error_message) - end - end end diff --git a/spec/hydra/works/services/generic_file/remove_related_object_spec.rb b/spec/hydra/works/services/generic_file/remove_related_object_spec.rb index 5965969e..93175e9a 100644 --- a/spec/hydra/works/services/generic_file/remove_related_object_spec.rb +++ b/spec/hydra/works/services/generic_file/remove_related_object_spec.rb @@ -2,16 +2,16 @@ describe Hydra::Works::RemoveRelatedObjectFromGenericFile do - subject { Hydra::Works::GenericFile::Base.create } + subject { Hydra::Works::GenericFile::Base.new } - let(:related_object1) { Hydra::PCDM::Object.create } - let(:related_work2) { Hydra::Works::GenericWork::Base.create } - let(:related_file3) { Hydra::Works::GenericFile::Base.create } - let(:related_object4) { Hydra::PCDM::Object.create } - let(:related_work5) { Hydra::Works::GenericWork::Base.create } + let(:related_object1) { Hydra::PCDM::Object.new } + let(:related_work2) { Hydra::Works::GenericWork::Base.new } + let(:related_file3) { Hydra::Works::GenericFile::Base.new } + let(:related_object4) { Hydra::PCDM::Object.new } + let(:related_work5) { Hydra::Works::GenericWork::Base.new } - let(:generic_file1) { Hydra::Works::GenericFile::Base.create } - let(:generic_file2) { Hydra::Works::GenericFile::Base.create } + let(:generic_file1) { Hydra::Works::GenericFile::Base.new } + let(:generic_file2) { Hydra::Works::GenericFile::Base.new } describe '#call' do @@ -49,11 +49,11 @@ end context 'with unacceptable related object' do - let(:collection1) { Hydra::Works::Collection.create } - let(:pcdm_collection1) { Hydra::PCDM::Collection.create } + let(:collection1) { Hydra::Works::Collection.new } + let(:pcdm_collection1) { Hydra::PCDM::Collection.new } let(:pcdm_file1) { Hydra::PCDM::File.new } let(:non_PCDM_object) { "I'm not a PCDM object" } - let(:af_base_object) { ActiveFedora::Base.create } + let(:af_base_object) { ActiveFedora::Base.new } let(:error_type) { ArgumentError } let(:error_message) { 'child_related_object must be a pcdm object' } @@ -78,46 +78,4 @@ expect{ Hydra::Works::RemoveRelatedObjectFromGenericFile.call( subject, af_base_object ) }.to raise_error(error_type,error_message) end end - - context 'with unacceptable parent generic file' do - let(:related_object2) { Hydra::PCDM::Object.create } - let(:collection1) { Hydra::Works::Collection.create } - let(:generic_work1) { Hydra::Works::GenericWork::Base.create } - let(:pcdm_collection1) { Hydra::PCDM::Collection.create } - let(:pcdm_object1) { Hydra::PCDM::Object.create } - let(:pcdm_file1) { Hydra::PCDM::File.new } - let(:non_PCDM_object) { "I'm not a PCDM object" } - let(:af_base_object) { ActiveFedora::Base.create } - - let(:error_type) { ArgumentError } - let(:error_message) { 'parent_generic_file must be a hydra-works generic file' } - - it 'should NOT accept Hydra::Works::Collection as parent generic file' do - expect{ Hydra::Works::RemoveRelatedObjectFromGenericFile.call( collection1, related_object2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::Works::GenericWork as parent generic file' do - expect{ Hydra::Works::RemoveRelatedObjectFromGenericFile.call( generic_work1, related_object2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::PCDM::Collections as parent generic file' do - expect{ Hydra::Works::RemoveRelatedObjectFromGenericFile.call( pcdm_collection1, related_object2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::PCDM::Objects as parent generic file' do - expect{ Hydra::Works::RemoveRelatedObjectFromGenericFile.call( pcdm_object1, related_object2 ) }.to raise_error(error_type,error_message) - end - - it 'should NOT accept Hydra::PCDM::Files as parent generic file' do - expect{ Hydra::Works::RemoveRelatedObjectFromGenericFile.call( pcdm_file1, related_object2 ) }.to raise_error(error_type,error_message) - end - - it 'should NOT accept non-PCDM objects as parent generic file' do - expect{ Hydra::Works::RemoveRelatedObjectFromGenericFile.call( non_PCDM_object, related_object2 ) }.to raise_error(error_type,error_message) - end - - it 'should NOT accept AF::Base objects as parent generic file' do - expect{ Hydra::Works::RemoveRelatedObjectFromGenericFile.call( af_base_object, related_work2 ) }.to raise_error(error_type,error_message) - end - end end diff --git a/spec/hydra/works/services/generic_file/upload_file_spec.rb b/spec/hydra/works/services/generic_file/upload_file_spec.rb index f08ef1bf..89113157 100644 --- a/spec/hydra/works/services/generic_file/upload_file_spec.rb +++ b/spec/hydra/works/services/generic_file/upload_file_spec.rb @@ -2,8 +2,8 @@ describe Hydra::Works::UploadFileToGenericFile do - let(:generic_work) { Hydra::Works::GenericWork::Base.create } - let(:generic_file) { Hydra::Works::GenericFile::Base.create } + let(:generic_work) { Hydra::Works::GenericWork::Base.new } + let(:generic_file) { Hydra::Works::GenericFile::Base.new } let(:filename) { "sample-file.pdf" } let(:file) { File.join(fixture_path, filename) } let(:updated_filename) { "updated-file.txt"} diff --git a/spec/hydra/works/services/generic_work/add_generic_file_spec.rb b/spec/hydra/works/services/generic_work/add_generic_file_spec.rb index 8b78c332..1c99151c 100644 --- a/spec/hydra/works/services/generic_work/add_generic_file_spec.rb +++ b/spec/hydra/works/services/generic_work/add_generic_file_spec.rb @@ -2,15 +2,15 @@ describe Hydra::Works::AddGenericFileToGenericWork do - let(:subject) { Hydra::Works::GenericWork::Base.create } + let(:subject) { Hydra::Works::GenericWork::Base.new } describe '#call' do context 'with acceptable generic_works' do - let(:generic_work1) { Hydra::Works::GenericWork::Base.create } - let(:generic_work2) { Hydra::Works::GenericWork::Base.create } - let(:generic_file1) { Hydra::Works::GenericFile::Base.create } - let(:generic_file2) { Hydra::Works::GenericFile::Base.create } - let(:generic_file3) { Hydra::Works::GenericFile::Base.create } + let(:generic_work1) { Hydra::Works::GenericWork::Base.new } + let(:generic_work2) { Hydra::Works::GenericWork::Base.new } + let(:generic_file1) { Hydra::Works::GenericFile::Base.new } + let(:generic_file2) { Hydra::Works::GenericFile::Base.new } + let(:generic_file3) { Hydra::Works::GenericFile::Base.new } context 'with generic_files and generic_works' do before do @@ -18,7 +18,6 @@ Hydra::Works::AddGenericFileToGenericWork.call( subject, generic_file2 ) Hydra::Works::AddGenericWorkToGenericWork.call( subject, generic_work1 ) Hydra::Works::AddGenericWorkToGenericWork.call( subject, generic_work2 ) - subject.save end it 'should add generic_file to generic_work with generic_files and generic_works' do @@ -43,11 +42,10 @@ class DummyIncFile < ActiveFedora::Base end end after { Object.send(:remove_const, :DummyIncFile) } - let(:ifile1) { DummyIncFile.create } + let(:ifile1) { DummyIncFile.new } it 'should accept implementing generic_file as a child' do Hydra::Works::AddGenericFileToGenericWork.call( subject, ifile1 ) - subject.save expect( Hydra::Works::GetGenericFilesFromGenericWork.call( subject ) ).to eq [ifile1] end @@ -59,24 +57,23 @@ class DummyExtFile < Hydra::Works::GenericFile::Base end end after { Object.send(:remove_const, :DummyExtFile) } - let(:efile1) { DummyExtFile.create } + let(:efile1) { DummyExtFile.new } it 'should accept extending generic_file as a child' do Hydra::Works::AddGenericFileToGenericWork.call( subject, efile1 ) - subject.save expect( Hydra::Works::GetGenericFilesFromGenericWork.call( subject ) ).to eq [efile1] end end end context 'with unacceptable child generic_files' do - let(:collection1) { Hydra::Works::Collection.create } - let(:generic_work1) { Hydra::Works::GenericWork::Base.create } - let(:pcdm_collection1) { Hydra::PCDM::Collection.create } - let(:pcdm_object1) { Hydra::PCDM::Object.create } + let(:collection1) { Hydra::Works::Collection.new } + let(:generic_work1) { Hydra::Works::GenericWork::Base.new } + let(:pcdm_collection1) { Hydra::PCDM::Collection.new } + let(:pcdm_object1) { Hydra::PCDM::Object.new } let(:pcdm_file1) { Hydra::PCDM::File.new } let(:non_PCDM_object) { "I'm not a PCDM object" } - let(:af_base_object) { ActiveFedora::Base.create } + let(:af_base_object) { ActiveFedora::Base.new } let(:error_message) { 'child_generic_file must be a hydra-works generic file' } @@ -108,49 +105,5 @@ class DummyExtFile < Hydra::Works::GenericFile::Base expect{ Hydra::Works::AddGenericFileToGenericWork.call( subject, af_base_object ) }.to raise_error(ArgumentError,error_message) end end - - context 'with unacceptable parent generic works' do - let(:collection1) { Hydra::Works::Collection.create } - let(:generic_work1) { Hydra::Works::GenericWork::Base.create } - let(:generic_work2) { Hydra::Works::GenericWork::Base.create } - let(:generic_file1) { Hydra::Works::GenericFile::Base.create } - let(:pcdm_collection1) { Hydra::PCDM::Collection.create } - let(:pcdm_object1) { Hydra::PCDM::Object.create } - let(:pcdm_file1) { Hydra::PCDM::File.new } - let(:non_PCDM_object) { "I'm not a PCDM object" } - let(:af_base_object) { ActiveFedora::Base.create } - - let(:error_message) { 'parent_generic_work must be a hydra-works generic work' } - - it 'should NOT accept Hydra::Works::Collection as parent generic work' do - expect{ Hydra::Works::AddGenericFileToGenericWork.call( collection1, generic_work2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::Works::GenericFile as parent generic work' do - expect{ Hydra::Works::AddGenericFileToGenericWork.call( generic_file1, generic_work2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::PCDM::Collections as parent generic work' do - expect{ Hydra::Works::AddGenericFileToGenericWork.call( pcdm_collection1, generic_work2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::PCDM::Objects as parent generic work' do - expect{ Hydra::Works::AddGenericFileToGenericWork.call( pcdm_object1, generic_work2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::PCDM::Files as parent generic work' do - expect{ Hydra::Works::AddGenericFileToGenericWork.call( pcdm_file1, generic_work2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept non-PCDM objects as parent generic work' do - expect{ Hydra::Works::AddGenericFileToGenericWork.call( non_PCDM_object, generic_work2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept AF::Base objects as parent generic work' do - expect{ Hydra::Works::AddGenericFileToGenericWork.call( af_base_object, generic_work2 ) }.to raise_error(ArgumentError,error_message) - end - end - end - end diff --git a/spec/hydra/works/services/generic_work/add_generic_work_spec.rb b/spec/hydra/works/services/generic_work/add_generic_work_spec.rb index 5b10b366..6f6385a9 100644 --- a/spec/hydra/works/services/generic_work/add_generic_work_spec.rb +++ b/spec/hydra/works/services/generic_work/add_generic_work_spec.rb @@ -2,17 +2,17 @@ describe Hydra::Works::AddGenericWorkToGenericWork do - let(:subject) { Hydra::Works::GenericWork::Base.create } + let(:subject) { Hydra::Works::GenericWork::Base.new } describe '#call' do context 'with acceptable generic_works' do - let(:generic_work1) { Hydra::Works::GenericWork::Base.create } - let(:generic_work2) { Hydra::Works::GenericWork::Base.create } - let(:generic_work3) { Hydra::Works::GenericWork::Base.create } - let(:generic_work4) { Hydra::Works::GenericWork::Base.create } - let(:generic_work5) { Hydra::Works::GenericWork::Base.create } - let(:generic_file1) { Hydra::Works::GenericFile::Base.create } - let(:generic_file2) { Hydra::Works::GenericFile::Base.create } + let(:generic_work1) { Hydra::Works::GenericWork::Base.new } + let(:generic_work2) { Hydra::Works::GenericWork::Base.new } + let(:generic_work3) { Hydra::Works::GenericWork::Base.new } + let(:generic_work4) { Hydra::Works::GenericWork::Base.new } + let(:generic_work5) { Hydra::Works::GenericWork::Base.new } + let(:generic_file1) { Hydra::Works::GenericFile::Base.new } + let(:generic_file2) { Hydra::Works::GenericFile::Base.new } context 'with generic_files and generic_works' do before do @@ -20,7 +20,6 @@ Hydra::Works::AddGenericFileToGenericWork.call( subject, generic_file2 ) Hydra::Works::AddGenericWorkToGenericWork.call( subject, generic_work1 ) Hydra::Works::AddGenericWorkToGenericWork.call( subject, generic_work2 ) - subject.save end it 'should add generic_work to generic_work with generic_files and generic_works' do @@ -45,11 +44,10 @@ class DummyIncWork < ActiveFedora::Base end end after { Object.send(:remove_const, :DummyIncWork) } - let(:iwork1) { DummyIncWork.create } + let(:iwork1) { DummyIncWork.new } it 'should accept implementing generic_work as a child' do Hydra::Works::AddGenericWorkToGenericWork.call( subject, iwork1 ) - subject.save expect( Hydra::Works::GetGenericWorksFromGenericWork.call( subject ) ).to eq [iwork1] end end @@ -60,24 +58,23 @@ class DummyExtWork < Hydra::Works::GenericWork::Base end end after { Object.send(:remove_const, :DummyExtWork) } - let(:ework1) { DummyExtWork.create } + let(:ework1) { DummyExtWork.new } it 'should accept extending generic_work as a child' do Hydra::Works::AddGenericWorkToGenericWork.call( subject, ework1 ) - subject.save expect( Hydra::Works::GetGenericWorksFromGenericWork.call( subject ) ).to eq [ework1] end end end context 'with unacceptable child generic_works' do - let(:collection1) { Hydra::Works::Collection.create } - let(:generic_file1) { Hydra::Works::GenericFile::Base.create } - let(:pcdm_collection1) { Hydra::PCDM::Collection.create } - let(:pcdm_object1) { Hydra::PCDM::Object.create } + let(:collection1) { Hydra::Works::Collection.new } + let(:generic_file1) { Hydra::Works::GenericFile::Base.new } + let(:pcdm_collection1) { Hydra::PCDM::Collection.new } + let(:pcdm_object1) { Hydra::PCDM::Object.new } let(:pcdm_file1) { Hydra::PCDM::File.new } let(:non_PCDM_object) { "I'm not a PCDM object" } - let(:af_base_object) { ActiveFedora::Base.create } + let(:af_base_object) { ActiveFedora::Base.new } let(:error_message) { 'child_generic_work must be a hydra-works generic work' } @@ -109,49 +106,5 @@ class DummyExtWork < Hydra::Works::GenericWork::Base expect{ Hydra::Works::AddGenericWorkToGenericWork.call( subject, af_base_object ) }.to raise_error(ArgumentError,error_message) end end - - context 'with unacceptable parent generic works' do - let(:collection1) { Hydra::Works::Collection.create } - let(:generic_work1) { Hydra::Works::GenericWork::Base.create } - let(:generic_work2) { Hydra::Works::GenericWork::Base.create } - let(:generic_file1) { Hydra::Works::GenericFile::Base.create } - let(:pcdm_collection1) { Hydra::PCDM::Collection.create } - let(:pcdm_object1) { Hydra::PCDM::Object.create } - let(:pcdm_file1) { Hydra::PCDM::File.new } - let(:non_PCDM_object) { "I'm not a PCDM object" } - let(:af_base_object) { ActiveFedora::Base.create } - - let(:error_message) { 'parent_generic_work must be a hydra-works generic work' } - - it 'should NOT accept Hydra::Works::Collection as parent generic work' do - expect{ Hydra::Works::AddGenericWorkToGenericWork.call( collection1, generic_work2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::Works::GenericFile as parent generic work' do - expect{ Hydra::Works::AddGenericWorkToGenericWork.call( generic_file1, generic_work2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::PCDM::Collections as parent generic work' do - expect{ Hydra::Works::AddGenericWorkToGenericWork.call( pcdm_collection1, generic_work2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::PCDM::Objects as parent generic work' do - expect{ Hydra::Works::AddGenericWorkToGenericWork.call( pcdm_object1, generic_work2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::PCDM::Files as parent generic work' do - expect{ Hydra::Works::AddGenericWorkToGenericWork.call( pcdm_file1, generic_work2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept non-PCDM objects as parent generic work' do - expect{ Hydra::Works::AddGenericWorkToGenericWork.call( non_PCDM_object, generic_work2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept AF::Base objects as parent generic work' do - expect{ Hydra::Works::AddGenericWorkToGenericWork.call( af_base_object, generic_work2 ) }.to raise_error(ArgumentError,error_message) - end - end - end - end diff --git a/spec/hydra/works/services/generic_work/add_related_object_spec.rb b/spec/hydra/works/services/generic_work/add_related_object_spec.rb index c38b48ce..753a7892 100644 --- a/spec/hydra/works/services/generic_work/add_related_object_spec.rb +++ b/spec/hydra/works/services/generic_work/add_related_object_spec.rb @@ -2,17 +2,17 @@ describe Hydra::Works::AddRelatedObjectToGenericWork do - let(:subject) { Hydra::Works::GenericWork::Base.create } + let(:subject) { Hydra::Works::GenericWork::Base.new } describe '#call' do context 'with acceptable related objects' do - let(:object1) { Hydra::PCDM::Object.create } - let(:object2) { Hydra::PCDM::Object.create } - let(:generic_work1) { Hydra::Works::GenericWork::Base.create } - let(:generic_work2) { Hydra::Works::GenericWork::Base.create } - let(:generic_file1) { Hydra::Works::GenericFile::Base.create } - let(:generic_file2) { Hydra::Works::GenericFile::Base.create } + let(:object1) { Hydra::PCDM::Object.new } + let(:object2) { Hydra::PCDM::Object.new } + let(:generic_work1) { Hydra::Works::GenericWork::Base.new } + let(:generic_work2) { Hydra::Works::GenericWork::Base.new } + let(:generic_file1) { Hydra::Works::GenericFile::Base.new } + let(:generic_file2) { Hydra::Works::GenericFile::Base.new } it 'should add various types of related objects to generic_work' do Hydra::Works::AddRelatedObjectToGenericWork.call( subject, generic_work1 ) @@ -32,7 +32,6 @@ Hydra::Works::AddGenericWorkToGenericWork.call( subject, generic_work1 ) Hydra::Works::AddGenericWorkToGenericWork.call( subject, generic_work2 ) Hydra::Works::AddRelatedObjectToGenericWork.call( subject, object1 ) - subject.save end it 'should add a related object to generic_work with generic_works and generic_files' do @@ -57,11 +56,11 @@ end context 'with unacceptable child related objects' do - let(:collection1) { Hydra::Works::Collection.create } - let(:pcdm_collection1) { Hydra::PCDM::Collection.create } + let(:collection1) { Hydra::Works::Collection.new } + let(:pcdm_collection1) { Hydra::PCDM::Collection.new } let(:pcdm_file1) { Hydra::PCDM::File.new } let(:non_PCDM_object) { "I'm not a PCDM object" } - let(:af_base_object) { ActiveFedora::Base.create } + let(:af_base_object) { ActiveFedora::Base.new } let(:error_message) { 'child_related_object must be a pcdm object' } @@ -86,51 +85,9 @@ end end - context 'with unacceptable parent generic work' do - let(:collection1) { Hydra::Works::Collection.create } - let(:generic_file1) { Hydra::Works::GenericFile::Base.create } - let(:pcdm_collection1) { Hydra::PCDM::Collection.create } - let(:pcdm_object1) { Hydra::PCDM::Object.create } - let(:pcdm_object2) { Hydra::PCDM::Object.create } - let(:pcdm_file1) { Hydra::PCDM::File.new } - let(:non_PCDM_object) { "I'm not a PCDM object" } - let(:af_base_object) { ActiveFedora::Base.create } - - let(:error_message) { 'parent_generic_work must be a hydra-works generic work' } - - it 'should NOT accept Hydra::Works::Collection as parent generic work' do - expect{ Hydra::Works::AddRelatedObjectToGenericWork.call( collection1, pcdm_object2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::Works::GenericFile as parent generic work' do - expect{ Hydra::Works::AddRelatedObjectToGenericWork.call( generic_file1, pcdm_object2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::PCDM::Collections as parent generic work' do - expect{ Hydra::Works::AddRelatedObjectToGenericWork.call( pcdm_collection1, pcdm_object2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::PCDM::Objects as parent generic work' do - expect{ Hydra::Works::AddRelatedObjectToGenericWork.call( pcdm_object1, pcdm_object2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::PCDM::Files as parent generic work' do - expect{ Hydra::Works::AddRelatedObjectToGenericWork.call( pcdm_file1, pcdm_object2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept non-PCDM objects as parent generic work' do - expect{ Hydra::Works::AddRelatedObjectToGenericWork.call( non_PCDM_object, pcdm_object2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept AF::Base objects as parent generic work' do - expect{ Hydra::Works::AddRelatedObjectToGenericWork.call( af_base_object, pcdm_object2 ) }.to raise_error(ArgumentError,error_message) - end - end - - context 'with invalid bahaviors' do - let(:object1) { Hydra::PCDM::Object.create } - let(:object2) { Hydra::PCDM::Object.create } + let(:object1) { Hydra::PCDM::Object.new } + let(:object2) { Hydra::PCDM::Object.new } it 'should NOT allow related objects to repeat' do skip 'skipping this test because issue pcdm#92 needs to be addressed' do diff --git a/spec/hydra/works/services/generic_work/get_generic_files_spec.rb b/spec/hydra/works/services/generic_work/get_generic_files_spec.rb index 284d34c4..cbad9dde 100644 --- a/spec/hydra/works/services/generic_work/get_generic_files_spec.rb +++ b/spec/hydra/works/services/generic_work/get_generic_files_spec.rb @@ -2,19 +2,18 @@ describe Hydra::Works::GetGenericFilesFromGenericWork do - subject { Hydra::Works::GenericWork::Base.create } + subject { Hydra::Works::GenericWork::Base.new } - let(:generic_file1) { Hydra::Works::GenericFile::Base.create } - let(:generic_file2) { Hydra::Works::GenericFile::Base.create } + let(:generic_file1) { Hydra::Works::GenericFile::Base.new } + let(:generic_file2) { Hydra::Works::GenericFile::Base.new } - let(:generic_work1) { Hydra::Works::GenericWork::Base.create } - let(:generic_work2) { Hydra::Works::GenericWork::Base.create } + let(:generic_work1) { Hydra::Works::GenericWork::Base.new } + let(:generic_work2) { Hydra::Works::GenericWork::Base.new } describe '#call' do it 'should return empty array when only generic_works are aggregated' do Hydra::Works::AddGenericWorkToGenericWork.call( subject, generic_work1 ) Hydra::Works::AddGenericWorkToGenericWork.call( subject, generic_work2 ) - subject.save expect(Hydra::Works::GetGenericFilesFromGenericWork.call( subject )).to eq [] end @@ -24,7 +23,6 @@ Hydra::Works::AddGenericFileToGenericWork.call( subject, generic_file2 ) Hydra::Works::AddGenericWorkToGenericWork.call( subject, generic_work1 ) Hydra::Works::AddGenericWorkToGenericWork.call( subject, generic_work2 ) - subject.save end it 'should only return generic_files' do diff --git a/spec/hydra/works/services/generic_work/get_generic_works_spec.rb b/spec/hydra/works/services/generic_work/get_generic_works_spec.rb index aa8771f1..d05b6d8f 100644 --- a/spec/hydra/works/services/generic_work/get_generic_works_spec.rb +++ b/spec/hydra/works/services/generic_work/get_generic_works_spec.rb @@ -2,19 +2,18 @@ describe Hydra::Works::GetGenericWorksFromGenericWork do - subject { Hydra::Works::GenericWork::Base.create } + subject { Hydra::Works::GenericWork::Base.new } - let(:generic_file1) { Hydra::Works::GenericFile::Base.create } - let(:generic_file2) { Hydra::Works::GenericFile::Base.create } + let(:generic_file1) { Hydra::Works::GenericFile::Base.new } + let(:generic_file2) { Hydra::Works::GenericFile::Base.new } - let(:generic_work1) { Hydra::Works::GenericWork::Base.create } - let(:generic_work2) { Hydra::Works::GenericWork::Base.create } + let(:generic_work1) { Hydra::Works::GenericWork::Base.new } + let(:generic_work2) { Hydra::Works::GenericWork::Base.new } describe '#call' do it 'should return empty array when only generic_files are aggregated' do Hydra::Works::AddGenericFileToGenericWork.call( subject, generic_file1 ) Hydra::Works::AddGenericFileToGenericWork.call( subject, generic_file2 ) - subject.save expect(Hydra::Works::GetGenericWorksFromGenericWork.call( subject )).to eq [] end @@ -24,7 +23,6 @@ Hydra::Works::AddGenericFileToGenericWork.call( subject, generic_file2 ) Hydra::Works::AddGenericWorkToGenericWork.call( subject, generic_work1 ) Hydra::Works::AddGenericWorkToGenericWork.call( subject, generic_work2 ) - subject.save end it 'should only return generic_works' do diff --git a/spec/hydra/works/services/generic_work/get_related_objects_spec.rb b/spec/hydra/works/services/generic_work/get_related_objects_spec.rb index 85d0725b..66308ef2 100644 --- a/spec/hydra/works/services/generic_work/get_related_objects_spec.rb +++ b/spec/hydra/works/services/generic_work/get_related_objects_spec.rb @@ -2,14 +2,14 @@ describe Hydra::Works::GetRelatedObjectsFromGenericWork do - subject { Hydra::Works::GenericWork::Base.create } + subject { Hydra::Works::GenericWork::Base.new } - let(:object1) { Hydra::PCDM::Object.create } - let(:object2) { Hydra::PCDM::Object.create } + let(:object1) { Hydra::PCDM::Object.new } + let(:object2) { Hydra::PCDM::Object.new } - let(:generic_work1) { Hydra::Works::GenericWork::Base.create } - let(:generic_work2) { Hydra::Works::GenericWork::Base.create } - let(:generic_file1) { Hydra::Works::GenericFile::Base.create } + let(:generic_work1) { Hydra::Works::GenericWork::Base.new } + let(:generic_work2) { Hydra::Works::GenericWork::Base.new } + let(:generic_file1) { Hydra::Works::GenericFile::Base.new } describe '#call' do context 'with generic files and works' do @@ -17,7 +17,6 @@ Hydra::Works::AddGenericWorkToGenericWork.call( subject, generic_work1 ) Hydra::Works::AddGenericWorkToGenericWork.call( subject, generic_work1 ) Hydra::Works::AddGenericFileToGenericWork.call( subject, generic_file1 ) - subject.save end it 'should return empty array when only generic files and generic works are aggregated' do diff --git a/spec/hydra/works/services/generic_work/move_generic_file_spec.rb b/spec/hydra/works/services/generic_work/move_generic_file_spec.rb index 63e847dc..f47e5a12 100644 --- a/spec/hydra/works/services/generic_work/move_generic_file_spec.rb +++ b/spec/hydra/works/services/generic_work/move_generic_file_spec.rb @@ -1,10 +1,10 @@ require 'spec_helper' describe Hydra::Works::MoveGenericFileToGenericWork do - let(:source_work) { Hydra::Works::GenericWork::Base.create } - let(:target_work) { Hydra::Works::GenericWork::Base.create } - let(:file1) { Hydra::Works::GenericFile::Base.create } - let(:file2) { Hydra::Works::GenericFile::Base.create } + let(:source_work) { Hydra::Works::GenericWork::Base.new } + let(:target_work) { Hydra::Works::GenericWork::Base.new } + let(:file1) { Hydra::Works::GenericFile::Base.new } + let(:file2) { Hydra::Works::GenericFile::Base.new } context "move generic file" do before do Hydra::Works::AddGenericFileToGenericWork.call(source_work, file1) diff --git a/spec/hydra/works/services/generic_work/remove_generic_file_spec.rb b/spec/hydra/works/services/generic_work/remove_generic_file_spec.rb index 098efb68..e4e547f0 100644 --- a/spec/hydra/works/services/generic_work/remove_generic_file_spec.rb +++ b/spec/hydra/works/services/generic_work/remove_generic_file_spec.rb @@ -2,16 +2,16 @@ describe Hydra::Works::RemoveGenericFileFromGenericWork do - subject { Hydra::Works::GenericWork::Base.create } + subject { Hydra::Works::GenericWork::Base.new } - let(:generic_file1) { Hydra::Works::GenericFile::Base.create } - let(:generic_file2) { Hydra::Works::GenericFile::Base.create } - let(:generic_file3) { Hydra::Works::GenericFile::Base.create } - let(:generic_file4) { Hydra::Works::GenericFile::Base.create } - let(:generic_file5) { Hydra::Works::GenericFile::Base.create } + let(:generic_file1) { Hydra::Works::GenericFile::Base.new } + let(:generic_file2) { Hydra::Works::GenericFile::Base.new } + let(:generic_file3) { Hydra::Works::GenericFile::Base.new } + let(:generic_file4) { Hydra::Works::GenericFile::Base.new } + let(:generic_file5) { Hydra::Works::GenericFile::Base.new } - let(:generic_work1) { Hydra::Works::GenericWork::Base.create } - let(:generic_work2) { Hydra::Works::GenericWork::Base.create } + let(:generic_work1) { Hydra::Works::GenericWork::Base.new } + let(:generic_work2) { Hydra::Works::GenericWork::Base.new } describe '#call' do context 'when multiple collections' do @@ -48,13 +48,13 @@ end context 'with unacceptable generic files' do - let(:collection1) { Hydra::Works::Collection.create } - let(:generic_work1) { Hydra::Works::GenericWork::Base.create } - let(:pcdm_collection1) { Hydra::PCDM::Collection.create } - let(:pcdm_object1) { Hydra::PCDM::Object.create } + let(:collection1) { Hydra::Works::Collection.new } + let(:generic_work1) { Hydra::Works::GenericWork::Base.new } + let(:pcdm_collection1) { Hydra::PCDM::Collection.new } + let(:pcdm_object1) { Hydra::PCDM::Object.new } let(:pcdm_file1) { Hydra::PCDM::File.new } let(:non_PCDM_object) { "I'm not a PCDM object" } - let(:af_base_object) { ActiveFedora::Base.create } + let(:af_base_object) { ActiveFedora::Base.new } let(:error_type) { ArgumentError } let(:error_message) { 'child_generic_file must be a hydra-works generic file' } @@ -87,46 +87,4 @@ expect{ Hydra::Works::RemoveGenericFileFromGenericWork.call( subject, af_base_object ) }.to raise_error(error_type,error_message) end end - - context 'with unacceptable parent generic work' do - let(:generic_work2) { Hydra::Works::GenericWork::Base.create } - let(:collection1) { Hydra::Works::Collection.create } - let(:generic_file1) { Hydra::Works::GenericFile::Base.create } - let(:pcdm_collection1) { Hydra::PCDM::Collection.create } - let(:pcdm_object1) { Hydra::PCDM::Object.create } - let(:pcdm_file1) { Hydra::PCDM::File.new } - let(:non_PCDM_object) { "I'm not a PCDM object" } - let(:af_base_object) { ActiveFedora::Base.create } - - let(:error_type) { ArgumentError } - let(:error_message) { 'parent_generic_work must be a hydra-works generic work' } - - it 'should NOT accept Hydra::Works::Collection as parent generic work' do - expect{ Hydra::Works::RemoveGenericFileFromGenericWork.call( collection1, generic_work2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::Works::GenericFile as parent generic work' do - expect{ Hydra::Works::RemoveGenericFileFromGenericWork.call( generic_file1, generic_work2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::PCDM::Collections as parent generic work' do - expect{ Hydra::Works::RemoveGenericFileFromGenericWork.call( pcdm_collection1, generic_work2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::PCDM::Objects as parent generic work' do - expect{ Hydra::Works::RemoveGenericFileFromGenericWork.call( pcdm_object1, generic_work2 ) }.to raise_error(error_type,error_message) - end - - it 'should NOT accept Hydra::PCDM::Files as parent generic work' do - expect{ Hydra::Works::RemoveGenericFileFromGenericWork.call( pcdm_file1, generic_work2 ) }.to raise_error(error_type,error_message) - end - - it 'should NOT accept non-PCDM objects as parent generic work' do - expect{ Hydra::Works::RemoveGenericFileFromGenericWork.call( non_PCDM_object, generic_work2 ) }.to raise_error(error_type,error_message) - end - - it 'should NOT accept AF::Base objects as parent generic work' do - expect{ Hydra::Works::RemoveGenericFileFromGenericWork.call( af_base_object, generic_work2 ) }.to raise_error(error_type,error_message) - end - end end diff --git a/spec/hydra/works/services/generic_work/remove_generic_work_spec.rb b/spec/hydra/works/services/generic_work/remove_generic_work_spec.rb index 692d5ac1..19ebb60c 100644 --- a/spec/hydra/works/services/generic_work/remove_generic_work_spec.rb +++ b/spec/hydra/works/services/generic_work/remove_generic_work_spec.rb @@ -2,16 +2,16 @@ describe Hydra::Works::RemoveGenericWorkFromGenericWork do - subject { Hydra::Works::GenericWork::Base.create } + subject { Hydra::Works::GenericWork::Base.new } - let(:generic_work1) { Hydra::Works::GenericWork::Base.create } - let(:generic_work2) { Hydra::Works::GenericWork::Base.create } - let(:generic_work3) { Hydra::Works::GenericWork::Base.create } - let(:generic_work4) { Hydra::Works::GenericWork::Base.create } - let(:generic_work5) { Hydra::Works::GenericWork::Base.create } + let(:generic_work1) { Hydra::Works::GenericWork::Base.new } + let(:generic_work2) { Hydra::Works::GenericWork::Base.new } + let(:generic_work3) { Hydra::Works::GenericWork::Base.new } + let(:generic_work4) { Hydra::Works::GenericWork::Base.new } + let(:generic_work5) { Hydra::Works::GenericWork::Base.new } - let(:generic_file1) { Hydra::Works::GenericFile::Base.create } - let(:generic_file2) { Hydra::Works::GenericFile::Base.create } + let(:generic_file1) { Hydra::Works::GenericFile::Base.new } + let(:generic_file2) { Hydra::Works::GenericFile::Base.new } describe '#call' do @@ -49,13 +49,13 @@ end context 'with unacceptable generic works' do - let(:collection1) { Hydra::Works::Collection.create } - let(:generic_file1) { Hydra::Works::GenericFile::Base.create } - let(:pcdm_collection1) { Hydra::PCDM::Collection.create } - let(:pcdm_object1) { Hydra::PCDM::Object.create } + let(:collection1) { Hydra::Works::Collection.new } + let(:generic_file1) { Hydra::Works::GenericFile::Base.new } + let(:pcdm_collection1) { Hydra::PCDM::Collection.new } + let(:pcdm_object1) { Hydra::PCDM::Object.new } let(:pcdm_file1) { Hydra::PCDM::File.new } let(:non_PCDM_object) { "I'm not a PCDM object" } - let(:af_base_object) { ActiveFedora::Base.create } + let(:af_base_object) { ActiveFedora::Base.new } let(:error_type) { ArgumentError } let(:error_message) { 'child_generic_work must be a hydra-works generic work' } @@ -88,46 +88,4 @@ expect{ Hydra::Works::RemoveGenericWorkFromGenericWork.call( subject, af_base_object ) }.to raise_error(error_type,error_message) end end - - context 'with unacceptable parent generic work' do - let(:generic_work2) { Hydra::Works::GenericWork::Base.create } - let(:collection1) { Hydra::Works::Collection.create } - let(:generic_file1) { Hydra::Works::GenericFile::Base.create } - let(:pcdm_collection1) { Hydra::PCDM::Collection.create } - let(:pcdm_object1) { Hydra::PCDM::Object.create } - let(:pcdm_file1) { Hydra::PCDM::File.new } - let(:non_PCDM_object) { "I'm not a PCDM object" } - let(:af_base_object) { ActiveFedora::Base.create } - - let(:error_type) { ArgumentError } - let(:error_message) { 'parent_generic_work must be a hydra-works generic work' } - - it 'should NOT accept Hydra::Works::Collection as parent generic work' do - expect{ Hydra::Works::RemoveGenericWorkFromGenericWork.call( collection1, generic_work2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::Works::GenericFile as parent generic work' do - expect{ Hydra::Works::RemoveGenericWorkFromGenericWork.call( generic_file1, generic_work2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::PCDM::Collections as parent generic work' do - expect{ Hydra::Works::RemoveGenericWorkFromGenericWork.call( pcdm_collection1, generic_work2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::PCDM::Objects as parent generic work' do - expect{ Hydra::Works::RemoveGenericWorkFromGenericWork.call( pcdm_object1, generic_work2 ) }.to raise_error(error_type,error_message) - end - - it 'should NOT accept Hydra::PCDM::Files as parent generic work' do - expect{ Hydra::Works::RemoveGenericWorkFromGenericWork.call( pcdm_file1, generic_work2 ) }.to raise_error(error_type,error_message) - end - - it 'should NOT accept non-PCDM objects as parent generic work' do - expect{ Hydra::Works::RemoveGenericWorkFromGenericWork.call( non_PCDM_object, generic_work2 ) }.to raise_error(error_type,error_message) - end - - it 'should NOT accept AF::Base objects as parent generic work' do - expect{ Hydra::Works::RemoveGenericWorkFromGenericWork.call( af_base_object, generic_work2 ) }.to raise_error(error_type,error_message) - end - end end diff --git a/spec/hydra/works/services/generic_work/remove_related_object_spec.rb b/spec/hydra/works/services/generic_work/remove_related_object_spec.rb index 00240cff..287dfcaa 100644 --- a/spec/hydra/works/services/generic_work/remove_related_object_spec.rb +++ b/spec/hydra/works/services/generic_work/remove_related_object_spec.rb @@ -2,17 +2,17 @@ describe Hydra::Works::RemoveRelatedObjectFromGenericWork do - subject { Hydra::Works::GenericWork::Base.create } + subject { Hydra::Works::GenericWork::Base.new } - let(:related_object1) { Hydra::PCDM::Object.create } - let(:related_work2) { Hydra::Works::GenericWork::Base.create } - let(:related_file3) { Hydra::Works::GenericFile::Base.create } - let(:related_object4) { Hydra::PCDM::Object.create } - let(:related_work5) { Hydra::Works::GenericWork::Base.create } + let(:related_object1) { Hydra::PCDM::Object.new } + let(:related_work2) { Hydra::Works::GenericWork::Base.new } + let(:related_file3) { Hydra::Works::GenericFile::Base.new } + let(:related_object4) { Hydra::PCDM::Object.new } + let(:related_work5) { Hydra::Works::GenericWork::Base.new } - let(:generic_work1) { Hydra::Works::GenericWork::Base.create } - let(:generic_work2) { Hydra::Works::GenericWork::Base.create } - let(:generic_file1) { Hydra::Works::GenericFile::Base.create } + let(:generic_work1) { Hydra::Works::GenericWork::Base.new } + let(:generic_work2) { Hydra::Works::GenericWork::Base.new } + let(:generic_file1) { Hydra::Works::GenericFile::Base.new } describe '#call' do @@ -54,11 +54,11 @@ end context 'with unacceptable related object' do - let(:collection1) { Hydra::Works::Collection.create } - let(:pcdm_collection1) { Hydra::PCDM::Collection.create } + let(:collection1) { Hydra::Works::Collection.new } + let(:pcdm_collection1) { Hydra::PCDM::Collection.new } let(:pcdm_file1) { Hydra::PCDM::File.new } let(:non_PCDM_object) { "I'm not a PCDM object" } - let(:af_base_object) { ActiveFedora::Base.create } + let(:af_base_object) { ActiveFedora::Base.new } let(:error_type) { ArgumentError } let(:error_message) { 'child_related_object must be a pcdm object' } @@ -83,46 +83,4 @@ expect{ Hydra::Works::RemoveRelatedObjectFromGenericWork.call( subject, af_base_object ) }.to raise_error(error_type,error_message) end end - - context 'with unacceptable parent generic work' do - let(:related_object2) { Hydra::PCDM::Object.create } - let(:collection1) { Hydra::Works::Collection.create } - let(:generic_file1) { Hydra::Works::GenericFile::Base.create } - let(:pcdm_collection1) { Hydra::PCDM::Collection.create } - let(:pcdm_object1) { Hydra::PCDM::Object.create } - let(:pcdm_file1) { Hydra::PCDM::File.new } - let(:non_PCDM_object) { "I'm not a PCDM object" } - let(:af_base_object) { ActiveFedora::Base.create } - - let(:error_type) { ArgumentError } - let(:error_message) { 'parent_generic_work must be a hydra-works generic work' } - - it 'should NOT accept Hydra::Works::Collection as parent generic work' do - expect{ Hydra::Works::RemoveRelatedObjectFromGenericWork.call( collection1, related_object2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::Works::GenericFile as parent generic work' do - expect{ Hydra::Works::RemoveRelatedObjectFromGenericWork.call( generic_file1, related_object2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::PCDM::Collections as parent generic work' do - expect{ Hydra::Works::RemoveRelatedObjectFromGenericWork.call( pcdm_collection1, related_object2 ) }.to raise_error(ArgumentError,error_message) - end - - it 'should NOT accept Hydra::PCDM::Objects as parent generic work' do - expect{ Hydra::Works::RemoveRelatedObjectFromGenericWork.call( pcdm_object1, related_object2 ) }.to raise_error(error_type,error_message) - end - - it 'should NOT accept Hydra::PCDM::Files as parent generic work' do - expect{ Hydra::Works::RemoveRelatedObjectFromGenericWork.call( pcdm_file1, related_object2 ) }.to raise_error(error_type,error_message) - end - - it 'should NOT accept non-PCDM objects as parent generic work' do - expect{ Hydra::Works::RemoveRelatedObjectFromGenericWork.call( non_PCDM_object, related_object2 ) }.to raise_error(error_type,error_message) - end - - it 'should NOT accept AF::Base objects as parent generic work' do - expect{ Hydra::Works::RemoveRelatedObjectFromGenericWork.call( af_base_object, related_work2 ) }.to raise_error(error_type,error_message) - end - end end diff --git a/spec/hydra/works_spec.rb b/spec/hydra/works_spec.rb index 799f3973..48de4d04 100644 --- a/spec/hydra/works_spec.rb +++ b/spec/hydra/works_spec.rb @@ -2,12 +2,12 @@ describe Hydra::Works do - let(:works_coll) { Hydra::Works::Collection.create } - let(:works_gwork) { Hydra::Works::GenericWork::Base.create } - let(:works_gfile) { Hydra::Works::GenericFile::Base.create } + let(:works_coll) { Hydra::Works::Collection.new } + let(:works_gwork) { Hydra::Works::GenericWork::Base.new } + let(:works_gfile) { Hydra::Works::GenericFile::Base.new } - let(:pcdm_coll) { Hydra::PCDM::Collection.create } - let(:pcdm_obj) { Hydra::PCDM::Object.create } + let(:pcdm_coll) { Hydra::PCDM::Collection.new } + let(:pcdm_obj) { Hydra::PCDM::Object.new } let(:pcdm_file) { Hydra::PCDM::File.new } describe 'Validations' do