diff --git a/.rubocop.yml b/.rubocop.yml index 26241ce4..0415fb41 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,4 +1,6 @@ inherit_from: .rubocop_todo.yml +require: rubocop-rspec + AllCops: TargetRubyVersion: 2.3 diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index a542e9c9..ac7db6ac 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,16 +1,11 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2018-12-21 13:23:36 -0600 using RuboCop version 0.60.0. +# on 2019-01-30 10:49:20 -0600 using RuboCop version 0.60.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 3 -Lint/AmbiguousBlockAssociation: - Exclude: - - 'spec/models/concerns/processable_spec.rb' - # Offense count: 3 Lint/AmbiguousOperator: Exclude: @@ -70,24 +65,24 @@ Lint/Void: # Offense count: 83 Metrics/AbcSize: - Max: 122 + Max: 119 -# Offense count: 198 +# Offense count: 203 # Configuration parameters: CountComments, ExcludedMethods. # ExcludedMethods: refine Metrics/BlockLength: - Max: 395 + Max: 394 # Offense count: 14 # Configuration parameters: CountComments. Metrics/ClassLength: Max: 253 -# Offense count: 17 +# Offense count: 18 Metrics/CyclomaticComplexity: Max: 25 -# Offense count: 79 +# Offense count: 80 # Configuration parameters: CountComments, ExcludedMethods. Metrics/MethodLength: Max: 58 @@ -102,7 +97,7 @@ Metrics/ModuleLength: Metrics/ParameterLists: Max: 7 -# Offense count: 17 +# Offense count: 18 Metrics/PerceivedComplexity: Max: 25 @@ -113,7 +108,7 @@ Naming/AccessorMethodName: - 'lib/dor/models/concerns/describable.rb' - 'lib/dor/models/concerns/governable.rb' -# Offense count: 14 +# Offense count: 15 # Configuration parameters: EnforcedStyle. # SupportedStyles: lowercase, uppercase Naming/HeredocDelimiterCase: @@ -161,12 +156,6 @@ Naming/PredicateName: - 'lib/dor/models/concerns/contentable.rb' - 'lib/dor/models/concerns/identifiable.rb' -# Offense count: 1 -# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. -Naming/UncommunicativeBlockParamName: - Exclude: - - 'lib/dor/services/public_xml_service.rb' - # Offense count: 11 # Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. # AllowedNames: io, id, to, by, on, in, at, ip, db @@ -179,7 +168,7 @@ Naming/UncommunicativeMethodParamName: - 'lib/dor/models/concerns/describable.rb' - 'lib/dor/models/concerns/rightsable.rb' -# Offense count: 15 +# Offense count: 14 # Configuration parameters: EnforcedStyle. # SupportedStyles: snake_case, camelCase Naming/VariableName: @@ -187,7 +176,6 @@ Naming/VariableName: - 'lib/dor/datastreams/content_metadata_ds.rb' - 'lib/dor/datastreams/version_metadata_ds.rb' - 'lib/dor/services/public_desc_metadata_service.rb' - - 'lib/dor/services/public_xml_service.rb' - 'spec/datastreams/content_metadata_ds_spec.rb' - 'spec/datastreams/workflow_ds_spec.rb' - 'spec/indexers/processable_indexer_spec.rb' @@ -200,6 +188,172 @@ Naming/VariableNumber: - 'spec/services/cleanup_reset_service_spec.rb' - 'spec/services/cleanup_service_filesystem_spec.rb' +# Offense count: 31 +RSpec/AnyInstance: + Exclude: + - 'spec/indexers/indexer_spec.rb' + - 'spec/indexers/processable_indexer_spec.rb' + - 'spec/models/concerns/describable_spec.rb' + - 'spec/models/concerns/embargoable_spec.rb' + - 'spec/models/concerns/publishable_spec.rb' + - 'spec/models/concerns/versionable_spec.rb' + - 'spec/models/workflow_object_spec.rb' + - 'spec/services/datastream_builder_spec.rb' + - 'spec/services/public_xml_service_spec.rb' + - 'spec/services/publish_metadata_service_spec.rb' + - 'spec/services/registration_service_spec.rb' + +# Offense count: 23 +RSpec/Be: + Exclude: + - 'spec/datastreams/embargo_metadata_spec.rb' + - 'spec/services/file_metadata_merge_service_spec.rb' + - 'spec/services/public_xml_service_spec.rb' + +# Offense count: 11 +RSpec/BeforeAfterAll: + Exclude: + - 'spec/spec_helper.rb' + - 'spec/rails_helper.rb' + - 'spec/support/**/*.rb' + - 'spec/models/concerns/assembleable_spec.rb' + - 'spec/services/cleanup_reset_service_spec.rb' + - 'spec/services/cleanup_service_spec.rb' + - 'spec/services/digital_stacks_service_spec.rb' + - 'spec/services/metadata_service_spec.rb' + - 'spec/services/suri_service_spec.rb' + - 'spec/services/technical_metadata_service_spec.rb' + +# Offense count: 50 +# Configuration parameters: Prefixes. +# Prefixes: when, with, without +RSpec/ContextWording: + Enabled: false + +# Offense count: 6 +RSpec/DescribeClass: + Exclude: + - 'spec/datastreams/simple_dublin_core_ds_spec.rb' + - 'spec/models/concerns/releaseable_no_vcr_spec.rb' + - 'spec/models/concerns/releaseable_spec.rb' + - 'spec/services/cleanup_service_filesystem_spec.rb' + - 'spec/services/digital_stacks_service_spec.rb' + +# Offense count: 216 +# Configuration parameters: Max. +RSpec/ExampleLength: + Enabled: false + +# Offense count: 47 +RSpec/ExpectInHook: + Exclude: + - 'spec/datastreams/content_metadata_ds_spec.rb' + - 'spec/datastreams/workflow_ds_spec.rb' + - 'spec/models/concerns/assembleable_spec.rb' + - 'spec/models/concerns/contentable_spec.rb' + - 'spec/models/concerns/publishable_spec.rb' + - 'spec/models/concerns/releaseable_spec.rb' + - 'spec/services/indexing_service_spec.rb' + - 'spec/services/metadata_service_spec.rb' + - 'spec/services/public_desc_metadata_service_spec.rb' + - 'spec/services/public_xml_service_spec.rb' + - 'spec/services/publish_metadata_service_spec.rb' + - 'spec/services/registration_service_spec.rb' + - 'spec/services/sdr_ingest_service_spec.rb' + - 'spec/services/shelving_service_spec.rb' + - 'spec/services/status_service_spec.rb' + +# Offense count: 69 +# Configuration parameters: CustomTransform, IgnoreMethods. +RSpec/FilePath: + Enabled: false + +# Offense count: 939 +# Configuration parameters: AssignmentOnly. +RSpec/InstanceVariable: + Enabled: false + +# Offense count: 1 +RSpec/MessageChain: + Exclude: + - 'spec/services/suri_service_spec.rb' + +# Offense count: 276 +# Configuration parameters: EnforcedStyle. +# SupportedStyles: have_received, receive +RSpec/MessageSpies: + Enabled: false + +# Offense count: 2 +RSpec/MultipleDescribes: + Exclude: + - 'spec/models/concerns/releaseable_spec.rb' + - 'spec/services/digital_stacks_service_spec.rb' + +# Offense count: 345 +# Configuration parameters: AggregateFailuresByDefault. +RSpec/MultipleExpectations: + Max: 14 + +# Offense count: 55 +# Configuration parameters: IgnoreSharedExamples. +RSpec/NamedSubject: + Exclude: + - 'spec/datastreams/default_object_rights_ds_spec.rb' + - 'spec/models/admin_policy_object_spec.rb' + - 'spec/models/collection_spec.rb' + - 'spec/models/concerns/publishable_spec.rb' + - 'spec/services/shelving_service_spec.rb' + - 'spec/services/thumbnail_service_spec.rb' + +# Offense count: 35 +RSpec/NestedGroups: + Max: 5 + +# Offense count: 22 +RSpec/RepeatedDescription: + Exclude: + - 'spec/models/concerns/governable_spec.rb' + - 'spec/services/abiltiy_spec.rb' + - 'spec/services/release_tag_service_spec.rb' + +# Offense count: 18 +RSpec/ScatteredLet: + Exclude: + - 'spec/indexers/describable_indexer_spec.rb' + - 'spec/indexers/editable_indexer_spec.rb' + - 'spec/indexers/identifiable_indexer_spec.rb' + - 'spec/indexers/indexer_spec.rb' + - 'spec/indexers/processable_indexer_spec.rb' + - 'spec/indexers/releaseable_indexer_spec.rb' + - 'spec/models/item_spec.rb' + - 'spec/models/workflow_document_spec.rb' + - 'spec/services/public_desc_metadata_service_spec.rb' + - 'spec/services/public_xml_service_spec.rb' + - 'spec/services/shelving_service_spec.rb' + +# Offense count: 26 +RSpec/ScatteredSetup: + Exclude: + - 'spec/datastreams/content_metadata_ds_spec.rb' + - 'spec/datastreams/rights_metadata_spec.rb' + - 'spec/datastreams/workflow_ds_spec.rb' + - 'spec/models/concerns/contentable_spec.rb' + - 'spec/models/concerns/describable_spec.rb' + - 'spec/models/concerns/editable_spec.rb' + - 'spec/models/concerns/governable_spec.rb' + - 'spec/models/workflow_object_spec.rb' + - 'spec/services/public_desc_metadata_service_spec.rb' + - 'spec/services/publish_metadata_service_spec.rb' + - 'spec/services/reset_workspace_service_spec.rb' + - 'spec/services/search_service_spec.rb' + - 'spec/services/suri_service_spec.rb' + +# Offense count: 58 +# Configuration parameters: IgnoreNameless, IgnoreSymbolicNames. +RSpec/VerifiedDoubles: + Enabled: false + # Offense count: 3 Security/Open: Exclude: @@ -258,7 +412,7 @@ Style/DateTime: - 'lib/dor/indexers/processable_indexer.rb' - 'lib/dor/services/status_service.rb' -# Offense count: 78 +# Offense count: 79 Style/Documentation: Enabled: false diff --git a/dor-services.gemspec b/dor-services.gemspec index 221360cf..9b89d1aa 100644 --- a/dor-services.gemspec +++ b/dor-services.gemspec @@ -55,6 +55,7 @@ Gem::Specification.new do |s| s.add_development_dependency 'rdoc' s.add_development_dependency 'rspec', '~> 3.1' s.add_development_dependency 'rubocop', '~> 0.60.0' + s.add_development_dependency 'rubocop-rspec' s.add_development_dependency 'simplecov' s.add_development_dependency 'vcr' s.add_development_dependency 'webmock' diff --git a/spec/datastreams/administrative_metadata_ds_spec.rb b/spec/datastreams/administrative_metadata_ds_spec.rb index 0454ff3f..6253abba 100644 --- a/spec/datastreams/administrative_metadata_ds_spec.rb +++ b/spec/datastreams/administrative_metadata_ds_spec.rb @@ -5,7 +5,7 @@ describe Dor::AdministrativeMetadataDS do context 'defaults terms' do it '#default_workflow_lane gets and sets the attribute defaults/initiateWorkflow/@lane' do - ds = Dor::AdministrativeMetadataDS.new + ds = described_class.new ds.default_workflow_lane = 'slow' expect(ds.to_xml).to be_equivalent_to(<<-XML @@ -20,7 +20,7 @@ end it '#default_shelving_path gets and sets the attribute defaults/shelving/@path ' do - ds = Dor::AdministrativeMetadataDS.new + ds = described_class.new ds.default_shelving_path = '/hoover' expect(ds.to_xml).to be_equivalent_to(<<-XML diff --git a/spec/datastreams/content_metadata_ds_spec.rb b/spec/datastreams/content_metadata_ds_spec.rb index 09ce014c..f69c0e36 100644 --- a/spec/datastreams/content_metadata_ds_spec.rb +++ b/spec/datastreams/content_metadata_ds_spec.rb @@ -3,10 +3,11 @@ require 'spec_helper' describe Dor::ContentMetadataDS do - before(:each) { stub_config } - after(:each) { unstub_config } + before { stub_config } - before(:each) do + after { unstub_config } + + before do @item = instantiate_fixture('druid:ab123cd4567', Dor::Item) @item.contentMetadata.content = ' @@ -42,7 +43,7 @@ end describe 'add_resource' do - it 'should add a resource with default type="file"' do + it 'adds a resource with default type="file"' do ret = @cm.add_resource(@files, 'resource', 1) expect(ret).to be_a(Nokogiri::XML::Node) nodes = @cm.ng_xml.search('//resource[@id=\'resource\']') @@ -57,12 +58,12 @@ %i[shelve publish preserve].each { |x| expect(resource.attr(x.to_s)).to eq(@file[x]) } end - it 'should raise error if same ID resource is added twice' do + it 'raises error if same ID resource is added twice' do @cm.add_resource(@files, 'resource', 1) expect{ @cm.add_resource(@files, 'resource', 1) }.to raise_error StandardError end - it 'should add multiple resources' do + it 'adds multiple resources' do more_files = [ @file.merge(name: 'new_file.tiff', size: '23456', preserve: 'yes'), @file.merge(name: 'new_file_thumb.gif', size: '678901', publish: 'yes') @@ -87,7 +88,7 @@ end end - it 'should add a resource with a type="image"' do + it 'adds a resource with a type="image"' do @cm.add_resource(@files, 'resource', 1, 'image') nodes = @cm.ng_xml.search('//resource[@id=\'resource\']') expect(nodes.length).to eq(1) @@ -97,7 +98,7 @@ expect(node['sequence']).to eq('1') end - it 'should add a resource with a checksum' do + it 'adds a resource with a checksum' do @files[0][:md5 ] = '123456' @files[0][:sha1] = '56789' @cm.add_resource(@files, 'resource', 1) @@ -108,7 +109,7 @@ end end - it 'should add a file with a role="transcription"' do + it 'adds a file with a role="transcription"' do files = [ @file.merge(name: 'transcription.txt', role: 'transcription', size: '23456', preserve: 'yes') ] @@ -122,11 +123,11 @@ end describe 'remove_resource' do - it 'should remove the only resource' do + it 'removes the only resource' do @cm.remove_resource('0001') expect(@cm.ng_xml.search('//resource').length).to eq(0) end - it 'should remove one resource and renumber remaining resources' do + it 'removes one resource and renumber remaining resources' do @cm.add_resource(@files, 'resource', 1) @cm.remove_resource('resource') resources = @cm.ng_xml.search('//resource') @@ -134,14 +135,16 @@ expect(resources.first['sequence']).to eq('1') end end + describe 'remove_file' do - it 'should remove the file' do + it 'removes the file' do @cm.remove_file('gw177fc7976_00_0001.tif') expect(@cm.ng_xml.search('//file').length).to eq(2) end end + describe 'add_file' do - it 'should add a file to the resource' do + it 'adds a file to the resource' do @cm.add_file(@file.merge(role: 'some-role'), '0001') xml = @cm.ng_xml hits = xml.search('//resource[@id=\'0001\']/file') @@ -158,7 +161,7 @@ end describe 'update_file' do - it 'should modify an existing file record' do + it 'modifies an existing file record' do @cm.update_file(@file.merge(role: 'some-role'), 'gw177fc7976_05_0001.jp2') file = @cm.ng_xml.search('//file[@id=\'new_file.jp2\']') expect(file.length).to eq(1) @@ -169,51 +172,56 @@ expect(file['size']).to eq('12345') expect(file['role']).to eq('some-role') end - it 'should error out if there isnt an existing record to modify' do + it 'errors out if there isnt an existing record to modify' do expect { @cm.update_file(@file, 'gw177fc7976_05_0001_different.jp2') }.to raise_error(StandardError) end end + describe 'rename_file' do - it 'should update the file id' do + it 'updates the file id' do @cm.rename_file('gw177fc7976_05_0001.jp2', 'test.jp2') file = @cm.ng_xml.search('//file[@id=\'test.jp2\']') expect(file.length).to eq(1) end end + describe 'move_resource' do - it 'should renumber the resources correctly' do + it 'renumbers the resources correctly' do @cm.add_resource(@files, 'resource', 1) @cm.move_resource('0001', '2') skip 'No expectation defined!' end end + describe 'update resource label' do - it 'should update an existing label' do + it 'updates an existing label' do @cm.update_resource_label '0001', 'an old label' @cm.update_resource_label '0001', 'label!' labels = @cm.ng_xml.search('//resource[@id=\'0001\']/label') expect(labels.length).to eq(1) expect(labels.first.content).to eq('label!') end - it 'should add a new label' do + it 'adds a new label' do @cm.update_resource_label '0001', 'qbert!' labels = @cm.ng_xml.search('//resource[@id=\'0001\']/label') expect(labels.length).to eq(1) expect(labels.first.content).to eq('qbert!') end end + describe 'update_resource_type' do - it 'should update an existing type' do + it 'updates an existing type' do @cm.update_resource_type '0001', 'book' skip 'No expectation defined!' end end describe 'to_solr' do - before :each do + before do @doc = @cm.to_solr end - it 'should generate required fields' do + + it 'generates required fields' do expected = { 'content_type_ssim' => 'map', 'content_file_mimetypes_ssim' => ['image/jp2', 'image/gif', 'image/tiff'], @@ -230,20 +238,23 @@ expect(@doc).to include expected end end + describe 'set_content_type' do - it 'should change the content type and the resource types' do + it 'changes the content type and the resource types' do @cm.set_content_type 'map', 'image', 'book', 'page' expect(@cm.ng_xml.search('//contentMetadata[@type=\'book\']').length).to eq(1) expect(@cm.ng_xml.search('//contentMetadata/resource[@type=\'page\']').length).to eq(1) end end + describe 'get stacks value' do - it 'should read the stacks value' do + it 'reads the stacks value' do expect(@cm.stacks).to eq(['/specialstack']) end end + describe 'add_virtual_resource' do - it 'should add a virtual resource to the target child item' do + it 'adds a virtual resource to the target child item' do child_druid = 'bb273jy3359' child_resource = Nokogiri::XML(' @@ -285,7 +296,7 @@ expect(relationship.first['objectId']).to eq('bb273jy3359') end - it 'should add a virtual resource to the target child item even if it has 2 published files' do + it 'adds a virtual resource to the target child item even if it has 2 published files' do child_druid = 'bb273jy3359' child_resource = Nokogiri::XML(' diff --git a/spec/datastreams/default_object_rights_ds_spec.rb b/spec/datastreams/default_object_rights_ds_spec.rb index 109de9f2..5c19c727 100644 --- a/spec/datastreams/default_object_rights_ds_spec.rb +++ b/spec/datastreams/default_object_rights_ds_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe Dor::DefaultObjectRightsDS do - before(:each) do + before do subject.content = <<~XML @@ -135,7 +135,7 @@ ' - default_object_rights = Dor::DefaultObjectRightsDS.new + default_object_rights = described_class.new pretty_xml = default_object_rights.prettify(Nokogiri::XML(subject.content)) expect(pretty_xml).to eq(expected_result) end diff --git a/spec/datastreams/desc_metadata_spec.rb b/spec/datastreams/desc_metadata_spec.rb index debb3052..bcdb9071 100644 --- a/spec/datastreams/desc_metadata_spec.rb +++ b/spec/datastreams/desc_metadata_spec.rb @@ -4,8 +4,8 @@ describe Dor::DescMetadataDS do context 'Marshalling to/from a Fedora Datastream' do - before(:each) do - @dsdoc = Dor::DescMetadataDS.from_xml <<-EOF + before do + @dsdoc = described_class.from_xml <<-EOF @@ -36,7 +36,7 @@ Topic2: The Interesting Part! EOF - @partial = Dor::DescMetadataDS.from_xml <<-EOF + @partial = described_class.from_xml <<-EOF @@ -63,7 +63,7 @@ Topic2: The Interesting Part! EOF - @empty = Dor::DescMetadataDS.from_xml <<-EOF + @empty = described_class.from_xml <<-EOF ['1890-1910', '20th century', 'another']) expect(doc).to match a_hash_including('subject_topic_ssim' => ['Topic1: Boring Part', 'Topic2: The Interesting Part!']) @@ -98,19 +98,19 @@ @partial.abstract = 'Abstract contents.' expect(@partial.to_xml).to be_equivalent_to(@dsdoc.to_xml) end - it 'should not throw an error when retrieving title_info if titleInfo is missing from the xml' do + it 'does not throw an error when retrieving title_info if titleInfo is missing from the xml' do expect(@empty.title_info.main_title).to eq([]) end end context 'Behavior of a freshly initialized Datastream' do - it 'should not throw an error when retrieving title_info if the datastream object has yet to have XML content set' do - desc_md_datastream = Dor::DescMetadataDS.new + it 'does not throw an error when retrieving title_info if the datastream object has yet to have XML content set' do + desc_md_datastream = described_class.new expect(desc_md_datastream.title_info.main_title).to eq(['']) end - it 'should use the expected MODS version' do - desc_md_datastream = Dor::DescMetadataDS.new + it 'uses the expected MODS version' do + desc_md_datastream = described_class.new base_xpath = desc_md_datastream.ng_xml.at_xpath('/xmlns:mods', 'mods') expect(base_xpath.name).to eq 'mods' expect(base_xpath['version']).to eq '3.6' diff --git a/spec/datastreams/embargo_metadata_spec.rb b/spec/datastreams/embargo_metadata_spec.rb index be345d8f..6ed58d75 100644 --- a/spec/datastreams/embargo_metadata_spec.rb +++ b/spec/datastreams/embargo_metadata_spec.rb @@ -4,8 +4,8 @@ require 'nokogiri' describe Dor::EmbargoMetadataDS do - before :each do - @ds = Dor::EmbargoMetadataDS.new nil, 'embargoMetadata' + before do + @ds = described_class.new nil, 'embargoMetadata' end context 'Marshalling to and from a Fedora Datastream' do @@ -33,7 +33,7 @@ end it 'creates itself from xml' do - ds = Dor::EmbargoMetadataDS.from_xml(dsxml) + ds = described_class.from_xml(dsxml) expect(ds.term_values(:status)).to eq(['embargoed']) expect(ds.term_values(:release_date)).to eq(['2011-10-12T15:47:52-07:00']) expect(ds.term_values(:twenty_pct_status)).to eq(['released']) @@ -54,8 +54,8 @@ expect(@ds.to_xml).to be_equivalent_to(emb_xml) end - it 'should solrize correctly' do - ds = Dor::EmbargoMetadataDS.from_xml(dsxml) + it 'solrizes correctly' do + ds = described_class.from_xml(dsxml) release_date_field = Solrizer.solr_name('embargo_release', :dateable) twenty_pct_field = Solrizer.solr_name('twenty_pct_visibility_release', :dateable) expect(ds.to_solr).to match a_hash_including(release_date_field, twenty_pct_field) @@ -68,6 +68,7 @@ before do @ds.status = 'released' end + it '= sets status' do expect(@ds.term_values(:status)).to eq(['released']) end @@ -84,6 +85,7 @@ @t = Time.now.utc - 10 @ds.release_date = @t end + it '= sets releaseDate from a Time object' do # does NOT do beginning_of_day truncation, leave that for indexing rd = Time.parse(@ds.term_values(:release_date).first) diff --git a/spec/datastreams/events_ds_spec.rb b/spec/datastreams/events_ds_spec.rb index f512a71e..87f83eb2 100644 --- a/spec/datastreams/events_ds_spec.rb +++ b/spec/datastreams/events_ds_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe Dor::EventsDS do - before(:each) do + before do @dsxml = <<-EOF Request created by Joe Wible @@ -16,18 +16,18 @@ context 'Marshalling to and from a Fedora Datastream' do it 'creates itself from xml' do - ds = Dor::EventsDS.from_xml(@dsxml) + ds = described_class.from_xml(@dsxml) expect(ds.find_by_terms(:event).size).to eq(4) end it 'creates a simple default with #new' do - ds = Dor::EventsDS.new nil, 'events' + ds = described_class.new nil, 'events' expect(ds.to_xml).to be_equivalent_to('') end end describe '#add_event' do it 'appends a new event element to the set of events' do - ds = Dor::EventsDS.new nil, 'events' + ds = described_class.new nil, 'events' ds.add_event 'embargo', 'application:etd-robot', 'Embargo released' events = ds.find_by_terms(:event) @@ -39,13 +39,13 @@ end it 'keeps events in sorted order' do - ds = Dor::EventsDS.from_xml(@dsxml) + ds = described_class.from_xml(@dsxml) ds.add_event 'embargo', 'application:etd-robot', 'Embargo go bye-bye' expect(ds.find_by_terms(:event).last.content).to eq('Embargo go bye-bye') end it 'markes the datastream changed' do - ds = Dor::EventsDS.from_xml(@dsxml) + ds = described_class.from_xml(@dsxml) ds.add_event 'embargo', 'application:etd-robot', 'Embargo go bye-bye' expect(ds).to be_changed end @@ -53,7 +53,7 @@ describe '#find_events_by_type' do it 'returns a block with who, timestamp, and message' do - ds = Dor::EventsDS.from_xml(@dsxml) + ds = described_class.from_xml(@dsxml) ds.add_event 'publish', 'application:common-accessioning-robot', 'Released to the world' ds.find_events_by_type('publish') do |who, timestamp, message| @@ -70,7 +70,7 @@ describe '#each_event' do it 'returns a block with type, who, timestamp, and message for all events' do - ds = Dor::EventsDS.from_xml(@dsxml) + ds = described_class.from_xml(@dsxml) all_types = [] all_whos = [] count = 0 diff --git a/spec/datastreams/geo_metadata_spec.rb b/spec/datastreams/geo_metadata_spec.rb index adb222fd..5ea3641e 100644 --- a/spec/datastreams/geo_metadata_spec.rb +++ b/spec/datastreams/geo_metadata_spec.rb @@ -4,12 +4,12 @@ require 'nokogiri' describe Dor::GeoMetadataDS do - before :each do + before do stub_config @doc = {} @test_keys = %w(co2_pipe oil_gas_fields) @test_keys.each do |k| - @doc[k] = Dor::GeoMetadataDS.from_xml(read_fixture("geoMetadata_#{k}.xml")) + @doc[k] = described_class.from_xml(read_fixture("geoMetadata_#{k}.xml")) end @template = Nokogiri::XML(read_fixture('geoMetadata_template.xml')) end @@ -17,7 +17,7 @@ context 'Exports' do it '#to_bbox' do @test_keys.each do |k| - expect(@doc[k]).to be_a(Dor::GeoMetadataDS) + expect(@doc[k]).to be_a(described_class) expect(@doc[k].to_bbox.to_s).to eq({ 'co2_pipe' => Struct.new(:w, :e, :n, :s).new(-109.758319, -88.990844, 48.999336, 29.423028).to_s, 'oil_gas_fields' => Struct.new(:w, :e, :n, :s).new(-151.479444, -78.085007, 69.4325, 26.071745).to_s @@ -26,7 +26,7 @@ end it '#xml_template' do - expect(Dor::GeoMetadataDS.xml_template.to_xml).to be_equivalent_to(@template) + expect(described_class.xml_template.to_xml).to be_equivalent_to(@template) end it '#metadata' do diff --git a/spec/datastreams/identity_metadata_spec.rb b/spec/datastreams/identity_metadata_spec.rb index 36ae544d..9ddab684 100644 --- a/spec/datastreams/identity_metadata_spec.rb +++ b/spec/datastreams/identity_metadata_spec.rb @@ -4,7 +4,7 @@ describe Dor::IdentityMetadataDS do context 'Marshalling to and from a Fedora Datastream' do - before(:each) do + before do @dsxml = <<-EOF DOR @@ -19,7 +19,7 @@ EOF - @dsdoc = Dor::IdentityMetadataDS.from_xml(@dsxml) + @dsdoc = described_class.from_xml(@dsxml) end it 'creates itself from xml' do @@ -81,6 +81,7 @@ EOF end + it 'on nil' do @dsdoc.sourceId = nil expect(@dsdoc.sourceId).to be_nil @@ -106,7 +107,7 @@ end it 'creates a simple default with #new' do - new_doc = Dor::IdentityMetadataDS.new nil, 'identityMetadata' + new_doc = described_class.new nil, 'identityMetadata' expect(new_doc.to_xml).to be_equivalent_to '' end @@ -119,7 +120,7 @@ Created By : Spec Tests EOF - new_doc = Dor::IdentityMetadataDS.new nil, 'identityMetadata' + new_doc = described_class.new nil, 'identityMetadata' new_doc.add_value('objectId', 'druid:ab123cd4567') new_doc.add_value('otherId', '12345678-abcd-1234-ef01-23456789abcd', 'name' => 'uuid') new_doc.add_value('otherId', 'ab123cd4567', 'name' => 'mdtoolkit') diff --git a/spec/datastreams/rights_metadata_spec.rb b/spec/datastreams/rights_metadata_spec.rb index 7a8a87ee..a848d3df 100644 --- a/spec/datastreams/rights_metadata_spec.rb +++ b/spec/datastreams/rights_metadata_spec.rb @@ -3,21 +3,22 @@ require 'spec_helper' RSpec.describe Dor::RightsMetadataDS do - before(:each) { stub_config } - after(:each) { unstub_config } + before { stub_config } - before(:each) do + after { unstub_config } + + before do @item = instantiate_fixture('druid:bb046xn0881', Dor::Item) allow(Dor).to receive(:find).with(@item.pid).and_return(@item) allow(Dor::Config.workflow.client).to receive(:get_milestones).and_return([]) end it '#new' do - expect { Dor::RightsMetadataDS.new }.not_to raise_error + expect { described_class.new }.not_to raise_error end - it 'should have a rightsMetadata datastream accessible' do - expect(@item.datastreams['rightsMetadata']).to be_a(Dor::RightsMetadataDS) + it 'has a rightsMetadata datastream accessible' do + expect(@item.datastreams['rightsMetadata']).to be_a(described_class) expect(@item.rightsMetadata).to eq(@item.datastreams['rightsMetadata']) end @@ -244,49 +245,49 @@ it 'has the expected rights xml when read rights are set to world' do rights_ng_xml = Nokogiri::XML(original_rights_xml) - Dor::RightsMetadataDS.upd_rights_xml_for_rights_type(rights_ng_xml, 'world') + described_class.upd_rights_xml_for_rights_type(rights_ng_xml, 'world') expect(rights_ng_xml).to be_equivalent_to world_rights_xml end it 'has the expected rights xml when read rights are set to world with the no-download rule' do rights_ng_xml = Nokogiri::XML(original_rights_xml) - Dor::RightsMetadataDS.upd_rights_xml_for_rights_type(rights_ng_xml, 'world-nd') + described_class.upd_rights_xml_for_rights_type(rights_ng_xml, 'world-nd') expect(rights_ng_xml).to be_equivalent_to world_no_download_rights_xml end it 'has the expected rights xml when read rights are set to group stanford' do rights_ng_xml = Nokogiri::XML(original_rights_xml) - Dor::RightsMetadataDS.upd_rights_xml_for_rights_type(rights_ng_xml, 'stanford') + described_class.upd_rights_xml_for_rights_type(rights_ng_xml, 'stanford') expect(rights_ng_xml).to be_equivalent_to stanford_rights_xml end it 'has the expected rights xml when read rights are set to group stanford with the no-download rule' do rights_ng_xml = Nokogiri::XML(original_rights_xml) - Dor::RightsMetadataDS.upd_rights_xml_for_rights_type(rights_ng_xml, 'stanford-nd') + described_class.upd_rights_xml_for_rights_type(rights_ng_xml, 'stanford-nd') expect(rights_ng_xml).to be_equivalent_to stanford_no_download_rights_xml end it 'has the expected rights xml when read rights are set to location spec' do rights_ng_xml = Nokogiri::XML(original_rights_xml) - Dor::RightsMetadataDS.upd_rights_xml_for_rights_type(rights_ng_xml, 'loc:spec') + described_class.upd_rights_xml_for_rights_type(rights_ng_xml, 'loc:spec') expect(rights_ng_xml).to be_equivalent_to loc_spec_rights_xml end it 'has the expected rights xml when read rights are set to dark' do rights_ng_xml = Nokogiri::XML(original_rights_xml) - Dor::RightsMetadataDS.upd_rights_xml_for_rights_type(rights_ng_xml, 'dark') + described_class.upd_rights_xml_for_rights_type(rights_ng_xml, 'dark') expect(rights_ng_xml).to be_equivalent_to dark_rights_xml end it 'has the expected rights xml when read rights are set to citation only' do rights_ng_xml = Nokogiri::XML(original_rights_xml) - Dor::RightsMetadataDS.upd_rights_xml_for_rights_type(rights_ng_xml, 'none') + described_class.upd_rights_xml_for_rights_type(rights_ng_xml, 'none') expect(rights_ng_xml).to be_equivalent_to citation_only_rights_xml end it 'will set an unrecognized location, because it is not where rights type code is validated' do rights_ng_xml = Nokogiri::XML(original_rights_xml) - Dor::RightsMetadataDS.upd_rights_xml_for_rights_type(rights_ng_xml, 'loc:unsupported') + described_class.upd_rights_xml_for_rights_type(rights_ng_xml, 'loc:unsupported') expect(rights_ng_xml).to be_equivalent_to loc_unsupported_rights_xml end end @@ -297,7 +298,7 @@ end it 'will set the xml properly and indicate that datastream content has changed' do - expect(Dor::RightsMetadataDS).to receive(:upd_rights_xml_for_rights_type).with(@item.rightsMetadata.ng_xml, 'world') + expect(described_class).to receive(:upd_rights_xml_for_rights_type).with(@item.rightsMetadata.ng_xml, 'world') expect(@item.rightsMetadata).to receive(:ng_xml_will_change!).and_call_original @item.rightsMetadata.set_read_rights 'world' @@ -306,9 +307,10 @@ end describe 'rightsMetadata' do - before :each do + before do @rm = @item.rightsMetadata end + it 'has accessors from defined terminology' do expect(@rm.copyright).to eq ['Courtesy of the Revs Institute for Automotive Research. All rights reserved unless otherwise indicated.'] expect(@rm.use_statement).to eq ['Users must contact the The Revs Institute for Automotive Research for re-use and reproduction information.'] @@ -332,11 +334,11 @@ end describe 'to_solr' do - before :each do + before do allow(OpenURI).to receive(:open_uri).with('https://purl-test.stanford.edu/bb046xn0881.xml').and_return('') end - it 'should have correct primary' do + it 'has correct primary' do doc = @item.to_solr expect(doc).to match a_hash_including( @@ -359,8 +361,8 @@ ) # don't include empties end - it 'should filter access_restricted from what gets aggregated into rights_descriptions_ssim' do - rights_md_ds = Dor::RightsMetadataDS.new + it 'filters access_restricted from what gets aggregated into rights_descriptions_ssim' do + rights_md_ds = described_class.new mock_dra_obj = double(Dor::RightsAuth) expect(mock_dra_obj).to receive(:index_elements).with(no_args).at_least(:once).and_return( primary: 'access_restricted', @@ -381,8 +383,8 @@ ) end - it 'should filter world_qualified from what gets aggregated into rights_descriptions_ssim' do - rights_md_ds = Dor::RightsMetadataDS.new + it 'filters world_qualified from what gets aggregated into rights_descriptions_ssim' do + rights_md_ds = described_class.new mock_dra_obj = double(Dor::RightsAuth) expect(mock_dra_obj).to receive(:index_elements).with(no_args).at_least(:once).and_return( primary: 'world_qualified', @@ -402,8 +404,8 @@ ) end - it 'should include the simple fields that are present' do - rights_md_ds = Dor::RightsMetadataDS.new + it 'includes the simple fields that are present' do + rights_md_ds = described_class.new mock_dra_obj = double(Dor::RightsAuth) expect(mock_dra_obj).to receive(:index_elements).with(no_args).at_least(:once).and_return( primary: 'access_restricted', diff --git a/spec/datastreams/role_metadata_ds_spec.rb b/spec/datastreams/role_metadata_ds_spec.rb index ee94ddfe..153acee6 100644 --- a/spec/datastreams/role_metadata_ds_spec.rb +++ b/spec/datastreams/role_metadata_ds_spec.rb @@ -14,7 +14,7 @@ XML - ds = Dor::RoleMetadataDS.from_xml xml + ds = described_class.from_xml xml doc = ds.to_solr expect(doc['apo_register_permissions_ssim']).to include('workgroup:dlss:dor-admin') @@ -31,11 +31,11 @@ XML - ds = Dor::RoleMetadataDS.from_xml xml + ds = described_class.from_xml xml doc = ds.to_solr - expect(doc).to_not have_key('apo_register_permissions_ssim') - expect(doc).to_not have_key('apo_register_permissions_tesim') + expect(doc).not_to have_key('apo_register_permissions_ssim') + expect(doc).not_to have_key('apo_register_permissions_tesim') end end end diff --git a/spec/datastreams/simple_dublin_core_ds_spec.rb b/spec/datastreams/simple_dublin_core_ds_spec.rb index c0b90539..81202ad3 100644 --- a/spec/datastreams/simple_dublin_core_ds_spec.rb +++ b/spec/datastreams/simple_dublin_core_ds_spec.rb @@ -4,7 +4,7 @@ describe 'Dor::SimpleDublinCoreDs' do describe '#to_solr' do - it 'should do OM mapping' do + it 'does OM mapping' do @xml = ' title creator @@ -22,7 +22,7 @@ end context 'sort fields' do - it 'should only produce single valued fields' do + it 'onlies produce single valued fields' do @xml = ' title title2 @@ -38,7 +38,7 @@ expect(dublin.to_solr[Solrizer.solr_name('dc_creator', :stored_sortable)]).to eq 'creator' end - it 'should create sort fields for each type of identifier' do + it 'creates sort fields for each type of identifier' do @xml = ' druid:identifier druid:identifier2 diff --git a/spec/datastreams/version_metadata_spec.rb b/spec/datastreams/version_metadata_spec.rb index c58d5c6d..9292fee7 100644 --- a/spec/datastreams/version_metadata_spec.rb +++ b/spec/datastreams/version_metadata_spec.rb @@ -30,7 +30,7 @@ end let(:ds) do - d = Dor::VersionMetadataDS.new double(pid: 'druid:ab123cd4567', new?: false, repository: double), 'versionMetadata' + d = described_class.new double(pid: 'druid:ab123cd4567', new?: false, repository: double), 'versionMetadata' allow(d).to receive(:new?).and_return(false) allow(d).to receive(:inline?).and_return true allow(d).to receive(:datastream_content).and_return(first_xml) @@ -39,12 +39,12 @@ describe 'Marshalling to and from a Fedora Datastream' do it 'creates itself from xml' do - ds = Dor::VersionMetadataDS.from_xml(dsxml) + ds = described_class.from_xml(dsxml) expect(ds.find_by_terms(:version).size).to eq(3) end it 'creates a simple default with #new' do - ds = Dor::VersionMetadataDS.new nil, 'versionMetadata' + ds = described_class.new nil, 'versionMetadata' allow(ds).to receive(:pid).and_return('druid:ab123cd4567') expect(ds.to_xml).to be_equivalent_to(first_xml) end @@ -141,58 +141,58 @@ describe '#current_version_id' do it 'finds the largest versionId within the versionMetadataDS' do - ds = Dor::VersionMetadataDS.from_xml(dsxml) + ds = described_class.from_xml(dsxml) expect(ds.current_version_id).to eq('3') end end describe 'current_tag' do it 'returns the tag of the lastest version' do - ds = Dor::VersionMetadataDS.from_xml(dsxml) + ds = described_class.from_xml(dsxml) expect(ds.current_tag).to eq('2.1.0') end - it 'should work if there is no tag' do + it 'works if there is no tag' do no_tag = ' Some text ' - ds = Dor::VersionMetadataDS.from_xml(no_tag) + ds = described_class.from_xml(no_tag) expect(ds.current_tag).to eq('') end end describe 'current_description' do it 'returns the description of the latest version' do - ds = Dor::VersionMetadataDS.from_xml(dsxml) + ds = described_class.from_xml(dsxml) expect(ds.current_description).to eq('Fixed title typo') end - it 'should work ok if there isnt a description' do + it 'works ok if there isnt a description' do no_desc = ' ' - ds = Dor::VersionMetadataDS.from_xml(no_desc) + ds = described_class.from_xml(no_desc) expect(ds.current_description).to eq('') end end describe 'tag_for_version' do - it 'should fetch the tag for a version' do - ds = Dor::VersionMetadataDS.from_xml(dsxml) + it 'fetches the tag for a version' do + ds = described_class.from_xml(dsxml) expect(ds.tag_for_version('2')).to eq('2.0.0') end end describe 'description_for_version' do - it 'should fetch the description for a version' do - ds = Dor::VersionMetadataDS.from_xml(dsxml) + it 'fetches the description for a version' do + ds = described_class.from_xml(dsxml) expect(ds.description_for_version('3')).to eq('Fixed title typo') end - it 'should return empty string if the description doesnt exist' do + it 'returns empty string if the description doesnt exist' do no_desc = ' ' - ds = Dor::VersionMetadataDS.from_xml(no_desc) + ds = described_class.from_xml(no_desc) expect(ds.description_for_version('3')).to eq('') end end @@ -221,7 +221,7 @@ end it 'removes any version tags greater than the last known version, then creates a new version tag' do - ds = Dor::VersionMetadataDS.from_xml(five_versions_xml) + ds = described_class.from_xml(five_versions_xml) allow(ds).to receive(:pid).and_return('druid:ab123cd4567') ds.sync_then_increment_version(2, description: 'Down to third version', significance: :major) @@ -243,7 +243,7 @@ end it 'increments the version if the requested version is equal to the current version' do - ds = Dor::VersionMetadataDS.from_xml(five_versions_xml) + ds = described_class.from_xml(five_versions_xml) allow(ds).to receive(:pid).and_return('druid:ab123cd4567') ds.sync_then_increment_version(5, description: 'Up to 6', significance: :major) @@ -274,7 +274,7 @@ end it 'performs synch and increment without any options' do - ds = Dor::VersionMetadataDS.from_xml(five_versions_xml) + ds = described_class.from_xml(five_versions_xml) allow(ds).to receive(:pid).and_return('druid:ab123cd4567') ds.sync_then_increment_version(3) @@ -283,7 +283,7 @@ end it 'raises an Exception if requested version is greater than current version' do - ds = Dor::VersionMetadataDS.from_xml(five_versions_xml) + ds = described_class.from_xml(five_versions_xml) allow(ds).to receive(:pid).and_return('druid:ab123cd4567') expect{ ds.sync_then_increment_version(6) }.to raise_error(Dor::Exception, 'Cannot sync to a version greater than current: 5, requested 6') diff --git a/spec/datastreams/version_tag_spec.rb b/spec/datastreams/version_tag_spec.rb index c7032cfa..334bb4fe 100644 --- a/spec/datastreams/version_tag_spec.rb +++ b/spec/datastreams/version_tag_spec.rb @@ -5,7 +5,7 @@ describe Dor::VersionTag do describe '.parse' do it 'parses a String into a VersionTag object' do - t = Dor::VersionTag.parse('1.1.0') + t = described_class.parse('1.1.0') expect(t.major).to eq(1) expect(t.minor).to eq(1) expect(t.admin).to eq(0) @@ -13,7 +13,7 @@ end describe '#increment' do - let(:tag) { Dor::VersionTag.parse('1.2.3') } + let(:tag) { described_class.parse('1.2.3') } it 'adds 1 to major and zeros out minor and admin when :major is passed in' do tag.increment(:major) @@ -36,14 +36,14 @@ describe 'ordering' do it 'handles <, >, == comparisons' do - v1 = Dor::VersionTag.new(1, 1, 0) - v2 = Dor::VersionTag.new(1, 1, 2) + v1 = described_class.new(1, 1, 0) + v2 = described_class.new(1, 1, 2) expect(v1).to be < v2 - v3 = Dor::VersionTag.new(0, 1, 1) + v3 = described_class.new(0, 1, 1) expect(v1).to be > v3 - v4 = Dor::VersionTag.new(1, 1, 0) + v4 = described_class.new(1, 1, 0) expect(v1).to eq(v4) end end diff --git a/spec/datastreams/workflow_definition_ds_spec.rb b/spec/datastreams/workflow_definition_ds_spec.rb index 22019c77..2e55ca9e 100644 --- a/spec/datastreams/workflow_definition_ds_spec.rb +++ b/spec/datastreams/workflow_definition_ds_spec.rb @@ -21,7 +21,7 @@ EOF end - let(:ds) { Dor::WorkflowDefinitionDs.from_xml(dsxml) } + let(:ds) { described_class.from_xml(dsxml) } context 'Marshalling to and from a Fedora Datastream' do it 'creates itself from xml' do diff --git a/spec/datastreams/workflow_ds_spec.rb b/spec/datastreams/workflow_ds_spec.rb index 0491fce9..3d2eec6b 100644 --- a/spec/datastreams/workflow_ds_spec.rb +++ b/spec/datastreams/workflow_ds_spec.rb @@ -3,10 +3,11 @@ require 'spec_helper' RSpec.describe Dor::WorkflowDs do - before(:each) { stub_config } - after(:each) { unstub_config } + before { stub_config } - before(:each) do + after { unstub_config } + + before do @item = instantiate_fixture('druid:ab123cd4567', Dor::Item) end @@ -15,7 +16,7 @@ expect(Deprecation).to receive(:warn).twice end - it 'should build a Document object if there is xml' do + it 'builds a Document object if there is xml' do xml = ' Dor::AdminPolicyObject, 'agreement' => Dor::Agreement, 'collection' => Dor::Collection, diff --git a/spec/indexers/describable_indexer_spec.rb b/spec/indexers/describable_indexer_spec.rb index 994a0ca1..905cb64d 100644 --- a/spec/indexers/describable_indexer_spec.rb +++ b/spec/indexers/describable_indexer_spec.rb @@ -14,6 +14,7 @@ end end before { stub_config } + after { unstub_config } let(:obj) { instantiate_fixture('druid:ab123cd4567', model) } diff --git a/spec/indexers/editable_indexer_spec.rb b/spec/indexers/editable_indexer_spec.rb index c3955449..3a0a065e 100644 --- a/spec/indexers/editable_indexer_spec.rb +++ b/spec/indexers/editable_indexer_spec.rb @@ -7,6 +7,7 @@ Dor::AdminPolicyObject end before { stub_config } + after { unstub_config } # @apo = instantiate_fixture('druid_zt570tx3016', Dor::AdminPolicyObject) diff --git a/spec/indexers/identifiable_indexer_spec.rb b/spec/indexers/identifiable_indexer_spec.rb index b2bc8bc4..26e2bb07 100644 --- a/spec/indexers/identifiable_indexer_spec.rb +++ b/spec/indexers/identifiable_indexer_spec.rb @@ -66,6 +66,7 @@ def self.name ) end + before do allow(obj.datastreams['RELS-EXT']).to receive(:content).and_return(mock_rels_ext_xml) end @@ -87,6 +88,7 @@ def self.name context 'when related collection and APOs are found' do let(:mock_obj) { instance_double(Dor::Item, full_title: 'Test object', tags: '') } + before do allow(Dor).to receive(:find).with(mock_rel_druid).and_return(mock_obj) end diff --git a/spec/indexers/indexer_spec.rb b/spec/indexers/indexer_spec.rb index 2989c086..85ed259f 100644 --- a/spec/indexers/indexer_spec.rb +++ b/spec/indexers/indexer_spec.rb @@ -7,7 +7,9 @@ Dor::Abstract end before { stub_config } + after { unstub_config } + let(:obj) { instantiate_fixture('druid:ab123cd4567', model) } let(:indexer) do described_class.new( @@ -23,6 +25,7 @@ allow_any_instance_of(Dor::StatusService).to receive(:milestones).and_return({}) obj.datastreams['descMetadata'].content = read_fixture('bs646cd8717_mods.xml') end + let(:doc) { indexer.new(resource: obj).to_solr } it 'searchworks date-fu: temporal periods and pub_dates' do diff --git a/spec/indexers/processable_indexer_spec.rb b/spec/indexers/processable_indexer_spec.rb index 9f5bd2c4..82277380 100644 --- a/spec/indexers/processable_indexer_spec.rb +++ b/spec/indexers/processable_indexer_spec.rb @@ -10,7 +10,9 @@ end before { stub_config } + after { unstub_config } + let(:obj) { instantiate_fixture('druid:ab123cd4567', model) } let(:indexer) { described_class.new(resource: obj) } @@ -29,7 +31,7 @@ let(:indexer) do Dor::CompositeIndexer.new( Dor::DataIndexer, - Dor::ProcessableIndexer + described_class ).new(resource: obj) end diff --git a/spec/indexers/releaseable_indexer_spec.rb b/spec/indexers/releaseable_indexer_spec.rb index e9b3d478..245b7f55 100644 --- a/spec/indexers/releaseable_indexer_spec.rb +++ b/spec/indexers/releaseable_indexer_spec.rb @@ -9,11 +9,13 @@ end end before { stub_config } + after { unstub_config } + let(:obj) { instantiate_fixture('druid:ab123cd4567', model) } describe 'to_solr' do - let(:doc) { Dor::ReleasableIndexer.new(resource: obj).to_solr } + let(:doc) { described_class.new(resource: obj).to_solr } it 'indexes release tags' do released_for_info = { diff --git a/spec/indexers/workflow_indexer_spec.rb b/spec/indexers/workflow_indexer_spec.rb index 06d6fee4..b3ec4ebc 100644 --- a/spec/indexers/workflow_indexer_spec.rb +++ b/spec/indexers/workflow_indexer_spec.rb @@ -84,6 +84,7 @@ describe 'workflow_status_ssim' do subject { solr_doc['workflow_status_ssim'] } + it { is_expected.to eq ['accessionWF|completed|0|dor', 'assemblyWF|active|1|dor', 'disseminationWF|active|1|dor', 'hydrusAssemblyWF|active|1|dor', 'versioningWF|active|1|dor'] } end end diff --git a/spec/models/admin_policy_object_spec.rb b/spec/models/admin_policy_object_spec.rb index 8253a1f6..c79cd9e0 100644 --- a/spec/models/admin_policy_object_spec.rb +++ b/spec/models/admin_policy_object_spec.rb @@ -5,16 +5,18 @@ RSpec.describe Dor::AdminPolicyObject do describe 'datastreams' do subject { described_class.ds_specs.keys } + it do - is_expected.to match_array ['RELS-EXT', 'DC', 'identityMetadata', - 'events', 'rightsMetadata', 'descMetadata', 'versionMetadata', - 'workflows', 'administrativeMetadata', 'roleMetadata', - 'defaultObjectRights', 'provenanceMetadata'] + expect(subject).to match_array ['RELS-EXT', 'DC', 'identityMetadata', + 'events', 'rightsMetadata', 'descMetadata', 'versionMetadata', + 'workflows', 'administrativeMetadata', 'roleMetadata', + 'defaultObjectRights', 'provenanceMetadata'] end end describe '#to_solr' do subject(:doc) { apo.to_solr } + let(:apo) { described_class.new(pid: 'foo:123') } before { allow(Dor::Config.workflow.client).to receive(:get_milestones).and_return([]) } diff --git a/spec/models/collection_spec.rb b/spec/models/collection_spec.rb index f6e595c5..bfa21941 100644 --- a/spec/models/collection_spec.rb +++ b/spec/models/collection_spec.rb @@ -5,15 +5,17 @@ RSpec.describe Dor::Collection do describe '.datastreams' do subject { described_class.ds_specs.keys } + it do - is_expected.to match_array ['RELS-EXT', 'DC', 'identityMetadata', - 'events', 'rightsMetadata', 'descMetadata', 'versionMetadata', - 'workflows', 'provenanceMetadata'] + expect(subject).to match_array ['RELS-EXT', 'DC', 'identityMetadata', + 'events', 'rightsMetadata', 'descMetadata', 'versionMetadata', + 'workflows', 'provenanceMetadata'] end end describe '#to_solr' do subject(:doc) { collection.to_solr } + let(:collection) { described_class.new(pid: 'foo:123') } before { allow(Dor::Config.workflow.client).to receive(:get_milestones).and_return([]) } diff --git a/spec/models/concerns/assembleable_spec.rb b/spec/models/concerns/assembleable_spec.rb index 861d6d4b..0625e5d8 100644 --- a/spec/models/concerns/assembleable_spec.rb +++ b/spec/models/concerns/assembleable_spec.rb @@ -26,12 +26,12 @@ class AssembleableItem < ActiveFedora::Base FileUtils.rm_rf(@temp_workspace) end - before(:each) do + before do allow(ActiveFedora).to receive(:fedora).and_return(double('frepo').as_null_object) end describe '#initialize_workspace' do - before(:each) do + before do @ai = AssembleableItem.new allow(@ai).to receive(:pid).and_return('aa123bb7890') @druid_path = File.join(@temp_workspace, 'aa', '123', 'bb', '7890', 'aa123bb7890') diff --git a/spec/models/concerns/contentable_spec.rb b/spec/models/concerns/contentable_spec.rb index 475a1407..d064d6ee 100644 --- a/spec/models/concerns/contentable_spec.rb +++ b/spec/models/concerns/contentable_spec.rb @@ -21,7 +21,7 @@ def internal_uri end describe Dor::Contentable do - before(:each) do + before do stub_config Dor.configure do content do @@ -31,9 +31,10 @@ def internal_uri end end end - after(:each) { unstub_config } - before(:each) do + after { unstub_config } + + before do @item = instantiate_fixture('druid:ab123cd4567', Dor::Item) @item.contentMetadata.content = ' @@ -65,11 +66,13 @@ def internal_uri allow(Net::SFTP).to receive(:start).and_return(@sftp) # mock sftp obj @file = File.new(File.expand_path(file_path)) end + describe 'add_file' do before do expect(Deprecation).to receive(:warn) end - it 'should generate the md5, find the size, attempt to sftp, and call the metadata update' do + + it 'generates the md5, find the size, attempt to sftp, and call the metadata update' do @item.add_file(@file, '0001', 'ab123cd4567_descMetadata.xml') xml = @item.contentMetadata.ng_xml file_node = xml.search('//file[@id=\'ab123cd4567_descMetadata.xml\']') @@ -85,11 +88,11 @@ def internal_uri end end end - it 'should raise an exception if the resource doesnt exist' do + it 'raises an exception if the resource doesnt exist' do expect{ @item.add_file(@file, 'abc0001', 'ab123cd4567_descMetadata.xml') }.to raise_error(RuntimeError) end - it 'should work ok if the object was set up using the old directory structure' do + it 'works ok if the object was set up using the old directory structure' do allow(@sftp).to receive(:stat!) do |arg| raise(Net::SFTP::StatusException.new(@resp, 'sup')) if arg =~ /desc/ || arg =~ /ab123/ end @@ -115,7 +118,7 @@ def internal_uri expect(Deprecation).to receive(:warn) end - it 'should update the md5, sha1, and size for the file, and attempt to ftp it to the workspace' do + it 'updates the md5, sha1, and size for the file, and attempt to ftp it to the workspace' do @item.replace_file(@file, 'ab123cd4567_00_0001.tif') xml = @item.contentMetadata.ng_xml file_node = xml.search('//file[@id=\'ab123cd4567_00_0001.tif\']') @@ -131,7 +134,7 @@ def internal_uri end end - it 'should raise an exception if there isnt a matching file record in the metadata' do + it 'raises an exception if there isnt a matching file record in the metadata' do expect{ @item.replace_file(@file, 'abcdab123cd4567_00_0001.tif') }.to raise_error(StandardError) end end @@ -140,7 +143,8 @@ def internal_uri let(:filename) { 'old_file' } let(:item_version) { 2 } let(:preserved_file_content) { 'expected content' } - it 'should get the file content' do + + it 'gets the file content' do expect(Sdr::Client).to receive(:get_preserved_file_content).with(@item.id, filename, item_version).and_return(preserved_file_content) expect(Deprecation).to receive(:warn) returned_content = @item.get_preserved_file(filename, item_version) @@ -149,7 +153,7 @@ def internal_uri end describe 'get_file' do - it 'should fetch the file' do + it 'fetches the file' do data_file = File.new(File.join(fixture_dir, 'ab123cd4567_descMetadata.xml')) expect(@sftp).to receive(:download!).and_return(data_file.read) expect(Deprecation).to receive(:warn) @@ -163,7 +167,7 @@ def internal_uri expect(Deprecation).to receive(:warn) end - it 'should attempt to rename the file in the workspace and update the metadata' do + it 'attempts to rename the file in the workspace and update the metadata' do expect(@sftp).to receive(:rename!) @item.rename_file('ab123cd4567_05_0001.jp2', 'test.jp2') end @@ -174,7 +178,7 @@ def internal_uri expect(Deprecation).to receive(:warn) end - it 'should use sftp to remove the file and update the metadata' do + it 'uses sftp to remove the file and update the metadata' do expect(@sftp).to receive(:remove!) @item.remove_file('ab123cd4567_05_0001.jp2') end @@ -188,13 +192,13 @@ def internal_uri expect(DruidTools::Druid).to receive(:new).and_return(@mock_druid_obj) end - it 'should return true if the file is in the workspace for the object' do + it 'returns true if the file is in the workspace for the object' do expect(@mock_druid_obj).to receive(:find_content).with(@mock_filename).and_return('this is not nil') - expect(@item.is_file_in_workspace?(@mock_filename)).to be_truthy + expect(@item).to be_is_file_in_workspace(@mock_filename) end - it 'should return false if the file is not in the workspace for the object' do + it 'returns false if the file is not in the workspace for the object' do expect(@mock_druid_obj).to receive(:find_content).with(@mock_filename).and_return(nil) - expect(@item.is_file_in_workspace?(@mock_filename)).to be_falsey + expect(@item).not_to be_is_file_in_workspace(@mock_filename) end end @@ -221,7 +225,7 @@ def internal_uri node end - before(:each) do + before do allow(Dor::SearchService).to receive(:sdr_graveyard_apo_druid) allow(ActiveFedora::Base).to receive(:find) { graveyard_apo } end @@ -229,7 +233,7 @@ def internal_uri it 'removes existing isMemberOf and isGovernedBy relationships' do expect(obj.relationships(:is_member_of_collection)).to be_empty expect(obj.relationships(:is_member_of)).to be_empty - expect(obj.relationships(:is_governed_by)).to_not include('info:fedora/old:apo') + expect(obj.relationships(:is_governed_by)).not_to include('info:fedora/old:apo') end it 'adds an isGovernedBy relationship to the SDR graveyard APO' do @@ -257,7 +261,7 @@ def internal_uri node end - before(:each) do + before do allow(ActiveFedora::Base).to receive(:find) { child_obj } end diff --git a/spec/models/concerns/describable_spec.rb b/spec/models/concerns/describable_spec.rb index 4d2f2b28..09b4e133 100644 --- a/spec/models/concerns/describable_spec.rb +++ b/spec/models/concerns/describable_spec.rb @@ -15,6 +15,7 @@ class SimpleItem < ActiveFedora::Base RSpec.describe Dor::Describable do before { stub_config } + after { unstub_config } before do @@ -24,7 +25,7 @@ class SimpleItem < ActiveFedora::Base @obj.datastreams['descMetadata'].content = read_fixture('ex1_mods.xml') end - it 'should have a descMetadata datastream' do + it 'has a descMetadata datastream' do expect(@item.datastreams['descMetadata']).to be_a(Dor::DescMetadataDS) end @@ -66,10 +67,11 @@ class SimpleItem < ActiveFedora::Base end describe 'get_collection_title' do - before(:each) do + before do @item = instantiate_fixture('druid:ab123cd4567', Dor::Item) end - it 'should get a titleInfo/title' do + + it 'gets a titleInfo/title' do @item.descMetadata.content = <<-XML @@ -78,10 +80,10 @@ class SimpleItem < ActiveFedora::Base XML - expect(Dor::Describable.get_collection_title(@item)).to eq 'Foxml Test Object' + expect(described_class.get_collection_title(@item)).to eq 'Foxml Test Object' end - it 'should include a subtitle if there is one' do + it 'includes a subtitle if there is one' do @item.descMetadata.content = <<-XML @@ -91,12 +93,12 @@ class SimpleItem < ActiveFedora::Base XML - expect(Dor::Describable.get_collection_title(@item)).to eq 'Foxml Test Object : Hello world' + expect(described_class.get_collection_title(@item)).to eq 'Foxml Test Object : Hello world' end end describe 'set_desc_metadata_using_label' do - it 'should create basic mods using the object label' do + it 'creates basic mods using the object label' do allow(@obj.datastreams['descMetadata']).to receive(:content).and_return '' @obj.set_desc_metadata_using_label expect(@obj.datastreams['descMetadata'].ng_xml).to be_equivalent_to <<-XML @@ -108,12 +110,12 @@ class SimpleItem < ActiveFedora::Base XML end - it 'should throw an exception if there is content in the descriptive metadata stream' do + it 'throws an exception if there is content in the descriptive metadata stream' do # @obj.stub(:descMetadata).and_return(ActiveFedora::OmDatastream.new) allow(@obj.descMetadata).to receive(:new?).and_return(false) expect{ @obj.set_desc_metadata_using_label }.to raise_error(StandardError) end - it 'should run if there is content in the descriptive metadata stream and force is true' do + it 'runs if there is content in the descriptive metadata stream and force is true' do allow(@obj.descMetadata).to receive(:new?).and_return(false) @obj.set_desc_metadata_using_label(true) expect(@obj.datastreams['descMetadata'].ng_xml).to be_equivalent_to <<-XML @@ -128,7 +130,7 @@ class SimpleItem < ActiveFedora::Base end describe 'stanford_mods accessor to DS' do - it 'should fetch Stanford::Mods object' do + it 'fetches Stanford::Mods object' do expect(@obj.methods).to include(:stanford_mods) sm = nil expect{ sm = @obj.stanford_mods }.not_to raise_error @@ -136,7 +138,7 @@ class SimpleItem < ActiveFedora::Base expect(sm.format_main).to eq(['Book']) expect(sm.pub_year_sort_str).to eq('1911') end - it 'should allow override argument(s)' do + it 'allows override argument(s)' do sm = nil nk = Nokogiri::XML('ape') expect{ sm = @obj.stanford_mods(nk, false) }.not_to raise_error diff --git a/spec/models/concerns/editable_spec.rb b/spec/models/concerns/editable_spec.rb index adab9f55..489205f3 100644 --- a/spec/models/concerns/editable_spec.rb +++ b/spec/models/concerns/editable_spec.rb @@ -3,15 +3,17 @@ require 'spec_helper' describe Dor::Editable do - before(:each) { stub_config } - after(:each) { unstub_config } - before :each do + before { stub_config } + + after { unstub_config } + + before do @apo = instantiate_fixture('druid_zt570tx3016', Dor::AdminPolicyObject) @empty_item = instantiate_fixture('pw570tx3016', Dor::AdminPolicyObject) end describe 'add_roleplayer' do - it 'should add a role' do + it 'adds a role' do @apo.add_roleplayer('dor-apo-manager', 'dlss:some-staff') exp_result = { 'dor-apo-manager' => [ @@ -22,7 +24,7 @@ expect(@apo.roles).to eq exp_result end - it 'should create a new role' do + it 'creates a new role' do @apo.add_roleplayer('dor-apo-viewer', 'dlss:some-staff') exp_result = { 'dor-apo-manager' => [ @@ -34,43 +36,46 @@ expect(@apo.roles).to eq exp_result end - it 'should work on an empty datastream' do + it 'works on an empty datastream' do @empty_item.add_roleplayer('dor-apo-manager', 'dlss:some-staff') expect(@empty_item.roles).to eq('dor-apo-manager' => ['workgroup:dlss:some-staff']) end end describe 'default_collections' do - it 'should fetch the default collections' do + it 'fetches the default collections' do expect(@apo.default_collections).to eq(['druid:fz306fj8334']) end - it 'should not fail on an item with an empty datastream' do + it 'does not fail on an item with an empty datastream' do expect(@empty_item.default_collections).to eq([]) end end + describe 'add_default_collection' do - it 'should set the collection values' do + it 'sets the collection values' do @apo.add_default_collection 'druid:fz306fj8335' expect(@apo.default_collections).to eq ['druid:fz306fj8334', 'druid:fz306fj8335'] end - it 'should work for empty datastreams' do + it 'works for empty datastreams' do @empty_item.add_default_collection 'druid:fz306fj8335' expect(@empty_item.default_collections).to eq ['druid:fz306fj8335'] end end + describe 'remove_default_collection' do - it 'should remove the collection' do + it 'removes the collection' do @apo.remove_default_collection 'druid:fz306fj8334' expect(@apo.default_collections).to eq([]) end - it 'should work on an empty datastream' do + it 'works on an empty datastream' do @empty_item.add_default_collection 'druid:fz306fj8335' @empty_item.remove_default_collection 'druid:fz306fj8335' expect(@empty_item.default_collections).to eq([]) end end + describe 'roles' do - it 'should create a roles hash' do + it 'creates a roles hash' do exp_result = { 'dor-apo-manager' => [ 'workgroup:dlss:developers', 'workgroup:dlss:pmag-staff', 'workgroup:dlss:smpl-staff', @@ -79,109 +84,116 @@ } expect(@apo.roles).to eq exp_result end - it 'should not fail on an item with an empty datastream' do + it 'does not fail on an item with an empty datastream' do expect(@empty_item.roles).to eq({}) end end + describe 'use_statement' do - it 'should find the use statement' do + it 'finds the use statement' do expect(@apo.use_statement).to eq('Rights are owned by Stanford University Libraries. All Rights Reserved. This work is protected by copyright law. No part of the materials may be derived, copied, photocopied, reproduced, translated or reduced to any electronic medium or machine readable form, in whole or in part, without specific permission from the copyright holder. To access this content or to request reproduction permission, please send a written request to speccollref@stanford.edu.') end - it 'should not fail on an item with an empty datastream' do + it 'does not fail on an item with an empty datastream' do expect(@empty_item.use_statement).to eq('') end end describe 'use_statement=' do - it 'should assign use statement' do + it 'assigns use statement' do @apo.use_statement = 'hi' expect(@apo.use_statement).to eq('hi') end - it 'should assign null use statements' do + it 'assigns null use statements' do [' ', nil].each do |v| @apo.use_statement = v expect(@apo.use_statement).to be_nil expect(@apo.defaultObjectRights.ng_xml.at_xpath('/rightsMetadata/use/human[@type="useAndReproduction"]')).to be_nil end end - it 'should fail if trying to set use statement after it is null' do + it 'fails if trying to set use statement after it is null' do @apo.use_statement = nil expect { @apo.use_statement = 'force fail' }.not_to raise_error end end describe 'copyright_statement' do - it 'should find the copyright statement' do + it 'finds the copyright statement' do expect(@apo.copyright_statement).to eq('Additional copyright info') end - it 'should not fail on an item with an empty datastream' do + it 'does not fail on an item with an empty datastream' do expect(@empty_item.copyright_statement).to eq('') end end + describe 'copyright_statement =' do - it 'should assign copyright' do + it 'assigns copyright' do @apo.copyright_statement = 'hi' expect(@apo.copyright_statement).to eq('hi') doc = Nokogiri::XML(@apo.defaultObjectRights.content) expect(doc.at_xpath('/rightsMetadata/copyright/human[@type="copyright"]').text).to eq('hi') end - it 'should assign null copyright' do + it 'assigns null copyright' do @apo.copyright_statement = nil expect(@apo.copyright_statement).to be_nil doc = Nokogiri::XML(@apo.defaultObjectRights.content) expect(doc.at_xpath('/rightsMetadata/copyright')).to be_nil expect(doc.at_xpath('/rightsMetadata/copyright/human[@type="copyright"]')).to be_nil end - it 'should assign blank copyright' do + it 'assigns blank copyright' do @apo.copyright_statement = ' ' expect(@apo.copyright_statement).to be_nil end - it 'should error if assigning copyright after removing one' do + it 'errors if assigning copyright after removing one' do @apo.copyright_statement = nil @apo.copyright_statement = nil # call twice to ensure repeatability expect { @apo.copyright_statement = 'will fail' }.not_to raise_error end end + describe 'metadata_source' do - it 'should get the metadata source' do + it 'gets the metadata source' do expect(@apo.metadata_source).to eq('MDToolkit') end - it 'should get nil for an empty datastream' do + it 'gets nil for an empty datastream' do expect(@empty_item.metadata_source).to eq(nil) end end + describe 'metadata_source=' do - it 'should set the metadata source' do + it 'sets the metadata source' do @apo.metadata_source = 'Symphony' expect(@apo.metadata_source).to eq('Symphony') expect(@apo.administrativeMetadata).to be_changed end - it 'should set the metadata source for an empty datastream' do + it 'sets the metadata source for an empty datastream' do @empty_item.desc_metadata_format = 'TEI' @empty_item.metadata_source = 'Symphony' expect(@empty_item.metadata_source).to eq('Symphony') end end + describe 'creative_commons_license' do - it 'should find the creative commons license' do + it 'finds the creative commons license' do expect(@apo.creative_commons_license).to eq('by-nc-sa') end - it 'should not fail on an item with an empty datastream' do + it 'does not fail on an item with an empty datastream' do expect(@empty_item.creative_commons_license).to eq('') end end + describe 'creative_commons_human' do - it 'should find the human readable cc license' do + it 'finds the human readable cc license' do expect(@apo.creative_commons_license_human).to eq('CC Attribution-NonCommercial-ShareAlike 3.0') end end + describe 'creative_commons_license=' do # these are less relevant now that we're moving to use_license= and away from setting individual use license components so directly - it 'should work on an empty ds' do + it 'works on an empty ds' do @empty_item.creative_commons_license = 'by-nc' expect(@empty_item.creative_commons_license).to eq('by-nc') end - it 'should not create multiple use nodes' do + it 'does not create multiple use nodes' do @empty_item.creative_commons_license = 'pdm' @empty_item.creative_commons_license_human = 'greetings' @empty_item.use_statement = 'this is my use statement' @@ -191,12 +203,13 @@ expect(@empty_item.defaultObjectRights.ng_xml.search('//use').length).to eq(1) end end + describe 'creative_commons_license_human=' do - it 'should set the human readable cc license' do + it 'sets the human readable cc license' do @apo.creative_commons_license_human = 'greetings' expect(@apo.creative_commons_license_human).to eq('greetings') end - it 'should work on an empty ds' do + it 'works on an empty ds' do @empty_item.creative_commons_license_human = 'greetings' expect(@empty_item.creative_commons_license_human).to eq('greetings') end @@ -205,7 +218,7 @@ describe 'use_license=' do it 'sets the machine and human readable CC licenses given the right license code' do use_license_machine = 'by-nc-nd' - expect(ActiveSupport::Deprecation.instance).to receive(:warn).at_least(1).times + expect(ActiveSupport::Deprecation.instance).to receive(:warn).at_least(:once) use_license = Dor::Editable::CREATIVE_COMMONS_USE_LICENSES.property(use_license_machine) @empty_item.use_license = use_license_machine expect(@empty_item.use_license).to eq use_license_machine @@ -219,7 +232,7 @@ it 'sets the machine and human readable ODC licenses given the right license code' do use_license_machine = 'odc-by' - expect(ActiveSupport::Deprecation.instance).to receive(:warn).at_least(1).times + expect(ActiveSupport::Deprecation.instance).to receive(:warn).at_least(:once) use_license = Dor::Editable::OPEN_DATA_COMMONS_USE_LICENSES.property(use_license_machine) @empty_item.use_license = use_license_machine expect(@empty_item.use_license).to eq use_license_machine @@ -258,6 +271,7 @@ expect(@empty_item.default_rights).to eq('world') end end + describe '#default_rights=' do it 'sets default rights' do @apo.default_rights = 'stanford' @@ -268,14 +282,15 @@ expect(@empty_item.default_rights).to eq('stanford') end end + describe 'desc metadata format' do - it 'should find the desc metadata format' do + it 'finds the desc metadata format' do expect(@apo.desc_metadata_format).to eq('MODS') end - it 'should not fail on an item with an empty datastream' do + it 'does not fail on an item with an empty datastream' do expect(@empty_item.desc_metadata_format).to eq(nil) end - it 'should set dark correctly' do + it 'sets dark correctly' do @apo.default_rights = 'dark' expect(@apo.default_rights).to eq('dark') end @@ -283,55 +298,60 @@ @apo.default_rights = 'Dark' expect(@apo.default_rights).to eq('dark') end - it 'should set read rights to none for dark' do + it 'sets read rights to none for dark' do @apo.default_rights = 'Dark' xml = @apo.datastreams['defaultObjectRights'].ng_xml expect(xml.search('//rightsMetadata/access[@type=\'read\']/machine/none').length).to eq(1) end end + describe 'desc_metadata_format=' do - it 'should set the desc metadata format' do + it 'sets the desc metadata format' do @apo.desc_metadata_format = 'TEI' expect(@apo.desc_metadata_format).to eq('TEI') end - it 'should set the desc metadata format for an empty datastream' do + it 'sets the desc metadata format for an empty datastream' do @empty_item.desc_metadata_format = 'TEI' expect(@empty_item.desc_metadata_format).to eq('TEI') end end + describe 'mods_title' do - it 'should get the title' do + it 'gets the title' do expect(@apo.mods_title).to eq('Ampex') end - it 'should not fail on an item with an empty datastream' do + it 'does not fail on an item with an empty datastream' do expect(@empty_item.mods_title).to eq('') end end + describe 'mods_title=' do - it 'should set the title' do + it 'sets the title' do @apo.mods_title = 'hello world' expect(@apo.mods_title).to eq('hello world') end - it 'should work on an empty datastream' do + it 'works on an empty datastream' do @empty_item.mods_title = 'hello world' expect(@empty_item.mods_title).to eq('hello world') end end + describe 'default workflows' do - it 'should find the default workflows' do + it 'finds the default workflows' do expect(@apo.default_workflows).to eq(['digitizationWF']) end - it 'should be able to set default workflows' do + it 'is able to set default workflows' do @apo.default_workflow = 'accessionWF' expect(@apo.default_workflows).to eq(['accessionWF']) end - it 'should NOT be able to set a null default workflows' do + it 'is not able to set a null default workflows' do expect { @apo.default_workflow = '' }.to raise_error(ArgumentError) expect(@apo.default_workflows).to eq(['digitizationWF']) # the original default workflow end end + describe 'copyright_statement=' do - it 'should assign' do + it 'assigns' do @apo.copyright_statement = 'hi' expect(@apo.copyright_statement).to eq('hi') end @@ -340,6 +360,7 @@ expect(@empty_item.copyright_statement).to eq('hi') end end + describe 'purge_roles' do it 'works' do @apo.purge_roles @@ -348,17 +369,17 @@ end describe 'agreement=' do - it 'should assign' do + it 'assigns' do skip 'dispatches "belongs_to" association for agreement_object down into internals of ActiveFedora' end end describe 'default_workflow=' do - it 'should set the default workflow' do + it 'sets the default workflow' do @apo.default_workflow = 'thisWF' expect(@apo.default_workflows).to include('thisWF') end - it 'should work on an empty ds' do + it 'works on an empty ds' do @empty_item.default_workflow = 'thisWF' expect(@empty_item.default_workflows).to include('thisWF') adm_md_ds = @empty_item.datastreams['administrativeMetadata'] diff --git a/spec/models/concerns/embargoable_spec.rb b/spec/models/concerns/embargoable_spec.rb index db077916..bb58996f 100644 --- a/spec/models/concerns/embargoable_spec.rb +++ b/spec/models/concerns/embargoable_spec.rb @@ -51,11 +51,12 @@ class EmbargoedItem < ActiveFedora::Base EOXML end - before :each do + before do stub_config allow(ActiveFedora).to receive(:fedora).and_return(double('frepo').as_null_object) end - after :each do + + after do unstub_config end @@ -80,7 +81,7 @@ class EmbargoedItem < ActiveFedora::Base it 'sets the embargo status to released and indicates it is not embargoed' do expect(embargo_ds.status).to eq('released') - expect(embargo_item.embargoed?).to be_falsey + expect(embargo_item).not_to be_embargoed end context 'rightsMetadata modifications' do @@ -168,7 +169,7 @@ class EmbargoedItem < ActiveFedora::Base end it 'indicates the item is embargoed' do - expect(embargo_item.embargoed?).to be_truthy + expect(embargo_item).to be_embargoed end it 'updates embargo date' do diff --git a/spec/models/concerns/geoable_spec.rb b/spec/models/concerns/geoable_spec.rb index 6c0ec53c..ffbc9881 100644 --- a/spec/models/concerns/geoable_spec.rb +++ b/spec/models/concerns/geoable_spec.rb @@ -8,14 +8,14 @@ class GeoableItem < ActiveFedora::Base end describe Dor::Geoable do - after(:each) { unstub_config } + after { unstub_config } - before :each do + before do stub_config @item = GeoableItem.new end - it 'should have a geoMetadata datastream' do + it 'has a geoMetadata datastream' do expect(@item.datastreams['geoMetadata']).to be_a(Dor::GeoMetadataDS) end diff --git a/spec/models/concerns/governable_spec.rb b/spec/models/concerns/governable_spec.rb index 0ce021f2..2c5cbd14 100644 --- a/spec/models/concerns/governable_spec.rb +++ b/spec/models/concerns/governable_spec.rb @@ -10,6 +10,7 @@ class GovernableItem < ActiveFedora::Base RSpec.describe Dor::Governable do before { stub_config } + after { unstub_config } let(:mock_collection) do @@ -27,10 +28,10 @@ class GovernableItem < ActiveFedora::Base end describe 'set_read_rights error handling' do - it 'should raise an exception if the rights option doesnt match the accepted values' do + it 'raises an exception if the rights option doesnt match the accepted values' do expect{ @item.set_read_rights('"druid:oo201oo0001"', 'Something') }.to raise_error(ArgumentError) end - it 'should raise an exception if the rights option doesnt match the accepted values' do + it 'raises an exception if the rights option doesnt match the accepted values' do expect{ @item.set_read_rights('mambo') }.to raise_error(ArgumentError) end end @@ -39,18 +40,19 @@ class GovernableItem < ActiveFedora::Base before do @current_item = instantiate_fixture('druid:bb046xn0881', Dor::Item) end - it 'should not do anything if there is no contentMetadata' do + + it 'does not do anything if there is no contentMetadata' do @current_item = instantiate_fixture('druid:bb004bn8654', Dor::Item) expect(@current_item).not_to receive(:ng_xml_will_change!) @current_item.unshelve_and_unpublish end - it 'should notify that the XML will change' do - expect(@current_item.contentMetadata).to receive(:ng_xml_will_change!).exactly(1).times + it 'notifies that the XML will change' do + expect(@current_item.contentMetadata).to receive(:ng_xml_will_change!).once @current_item.unshelve_and_unpublish end - it 'should set publish and shelve to no for all files' do + it 'sets publish and shelve to no for all files' do @current_item.unshelve_and_unpublish new_metadata = @current_item.datastreams['contentMetadata'] expect(new_metadata.ng_xml.xpath('/contentMetadata/resource//file[@publish="yes"]').length).to eq(0) @@ -59,7 +61,7 @@ class GovernableItem < ActiveFedora::Base end describe 'set_read_rights' do - it 'should set rights to dark, unshelving and unpublishing content metadata' do + it 'sets rights to dark, unshelving and unpublishing content metadata' do @current_item = instantiate_fixture('druid:bb046xn0881', Dor::Item) allow(Dor).to receive(:find).with(@current_item.pid).and_return(@current_item) @@ -67,7 +69,7 @@ class GovernableItem < ActiveFedora::Base @current_item.set_read_rights('dark') end - it 'should set rights to dark (double none), removing the discovery rights' do + it 'sets rights to dark (double none), removing the discovery rights' do @item.set_read_rights('dark') expect(@item.rightsMetadata.ng_xml).to be_equivalent_to <<-XML @@ -88,7 +90,7 @@ class GovernableItem < ActiveFedora::Base XML end - it 'should set rights to and not change publish or shelve attributes' do + it 'sets rights to and not change publish or shelve attributes' do @item.set_read_rights('world') expect(@item).not_to receive(:unshelve_and_unpublish) expect(@item.rightsMetadata.ng_xml).to be_equivalent_to <<-XML @@ -110,7 +112,7 @@ class GovernableItem < ActiveFedora::Base XML end - it 'should set rights to stanford and not change publish or shelve attributes' do + it 'sets rights to stanford and not change publish or shelve attributes' do @item.set_read_rights('stanford') expect(@item).not_to receive(:unshelve_and_unpublish) expect(@item.rightsMetadata.ng_xml).to be_equivalent_to <<-XML @@ -134,7 +136,7 @@ class GovernableItem < ActiveFedora::Base XML end - it 'should set rights to ' do + it 'sets rights to ' do # this should work because the find call inside set_read_rights is stubbed to return @obj, so the modifications happen to that, not a fresh instance @item.set_read_rights('none') expect(@item.datastreams['rightsMetadata'].ng_xml).to be_equivalent_to <<-XML @@ -159,12 +161,12 @@ class GovernableItem < ActiveFedora::Base end describe 'add_collection' do - it 'should add a collection' do + it 'adds a collection' do @item.add_collection('druid:oo201oo0002') expect(@item.collection_ids).to include('druid:oo201oo0002') end - it 'should add a collection' do + it 'adds a collection' do @item.add_collection('druid:oo201oo0002') rels_ext_ds = @item.datastreams['RELS-EXT'] xml = Nokogiri::XML(rels_ext_ds.to_rels_ext.to_s) @@ -183,13 +185,13 @@ class GovernableItem < ActiveFedora::Base end describe 'remove_collection' do - it 'should delete a collection' do + it 'deletes a collection' do @item.add_collection('druid:oo201oo0002') expect(@item.collection_ids).to include('druid:oo201oo0002') @item.remove_collection('druid:oo201oo0002') end - it 'should delete a collection' do + it 'deletes a collection' do @item.add_collection('druid:oo201oo0002') rels_ext_ds = @item.datastreams['RELS-EXT'] @item.remove_collection('druid:oo201oo0002') @@ -205,7 +207,7 @@ class GovernableItem < ActiveFedora::Base XML end - it 'should change the read permissions value from stanford to ' do + it 'changes the read permissions value from stanford to ' do expect(@item.datastreams['rightsMetadata'].ng_xml).to be_equivalent_to <<-XML @@ -321,7 +323,7 @@ class GovernableItem < ActiveFedora::Base end describe 'reapplyAdminPolicyObjectDefaults' do - it 'should update rightsMetadata from the APO defaultObjectRights' do + it 'updates rightsMetadata from the APO defaultObjectRights' do expect(@item.rightsMetadata.ng_xml.search('//rightsMetadata/access[@type=\'read\']/machine/group').length).to eq(1) @apo = instantiate_fixture('druid_zt570tx3016', Dor::AdminPolicyObject) expect(@item).to receive(:admin_policy_object).and_return(@apo) diff --git a/spec/models/concerns/identifiable_spec.rb b/spec/models/concerns/identifiable_spec.rb index 83fee52c..7f5162a5 100644 --- a/spec/models/concerns/identifiable_spec.rb +++ b/spec/models/concerns/identifiable_spec.rb @@ -8,6 +8,7 @@ class IdentifiableItem < ActiveFedora::Base RSpec.describe Dor::Identifiable do before { stub_config } + after { unstub_config } let(:item) do @@ -19,7 +20,7 @@ class IdentifiableItem < ActiveFedora::Base item end - it 'should have an identityMetadata datastream' do + it 'has an identityMetadata datastream' do expect(item.datastreams['identityMetadata']).to be_a(Dor::IdentityMetadataDS) end @@ -34,17 +35,17 @@ class IdentifiableItem < ActiveFedora::Base expect{ item.source_id = ':EmptyFirstPart' }.to raise_error ArgumentError expect{ item.source_id = 'WhitespaceSecondPart: ' }.to raise_error ArgumentError end - it 'should set the source_id' do + it 'sets the source_id' do item.source_id = 'fake:sourceid' expect(item.identityMetadata.sourceId).to eq('fake:sourceid') end - it 'should replace the source_id if one exists' do + it 'replaces the source_id if one exists' do item.source_id = 'fake:sourceid' expect(item.identityMetadata.sourceId).to eq('fake:sourceid') item.source_id = 'new:sourceid2' expect(item.identityMetadata.sourceId).to eq('new:sourceid2') end - it 'should do normalization via identityMetadata.sourceID=' do + it 'does normalization via identityMetadata.sourceID=' do item.source_id = ' SourceX : Value Y ' expect(item.source_id).to eq('SourceX:Value Y') end @@ -54,7 +55,7 @@ class IdentifiableItem < ActiveFedora::Base item.source_id = 'one::two::three' expect(item.source_id).to eq('one::two::three') end - it 'should delete the sourceId node on nil or empty-string' do + it 'deletes the sourceId node on nil or empty-string' do item.source_id = nil expect(item.source_id).to be_nil item.source_id = 'fake:sourceid' @@ -65,11 +66,11 @@ class IdentifiableItem < ActiveFedora::Base end describe 'add_other_Id' do - it 'should add an other_id record' do + it 'adds an other_id record' do item.add_other_Id('mdtoolkit', 'someid123') expect(item.identityMetadata.otherId('mdtoolkit').first).to eq('someid123') end - it 'should raise an exception if a record of that type already exists' do + it 'raises an exception if a record of that type already exists' do item.add_other_Id('mdtoolkit', 'someid123') expect(item.identityMetadata.otherId('mdtoolkit').first).to eq('someid123') expect{ item.add_other_Id('mdtoolkit', 'someid123') }.to raise_error(RuntimeError) @@ -77,7 +78,7 @@ class IdentifiableItem < ActiveFedora::Base end describe 'update_other_Id' do - it 'should update an existing id and return true to indicate that it found something to update' do + it 'updates an existing id and return true to indicate that it found something to update' do item.add_other_Id('mdtoolkit', 'someid123') expect(item.identityMetadata.otherId('mdtoolkit').first).to eq('someid123') # return value should be true when it finds something to update @@ -85,20 +86,20 @@ class IdentifiableItem < ActiveFedora::Base expect(item.identityMetadata).to be_changed expect(item.identityMetadata.otherId('mdtoolkit').first).to eq('someotherid234') end - it 'should return false if there was no existing record to update' do + it 'returns false if there was no existing record to update' do expect(item.update_other_Id('mdtoolkit', 'someotherid234')).to be_falsey end end describe 'remove_other_Id' do - it 'should remove an existing otherid when the tag and value match' do + it 'removes an existing otherid when the tag and value match' do item.add_other_Id('mdtoolkit', 'someid123') expect(item.identityMetadata).to be_changed expect(item.identityMetadata.otherId('mdtoolkit').first).to eq('someid123') expect(item.remove_other_Id('mdtoolkit', 'someid123')).to be_truthy expect(item.identityMetadata.otherId('mdtoolkit').length).to eq(0) end - it 'should return false if there was nothing to delete' do + it 'returns false if there was nothing to delete' do expect(item.remove_other_Id('mdtoolkit', 'someid123')).to be_falsey expect(item.identityMetadata).not_to be_changed end @@ -108,33 +109,33 @@ class IdentifiableItem < ActiveFedora::Base let(:current_catkey) { '129483625' } let(:new_catkey) { '999' } - it 'should get the current catkey with the convenience method' do + it 'gets the current catkey with the convenience method' do expect(item.catkey).to eq(current_catkey) end - it 'should get the previous catkeys with the convenience method' do + it 'gets the previous catkeys with the convenience method' do expect(item.previous_catkeys).to eq([]) end - it 'should update the catkey when one exists, and store the previous value (when there is no current history yet)' do + it 'updates the catkey when one exists, and store the previous value (when there is no current history yet)' do expect(item.identityMetadata.otherId('catkey').length).to eq(1) expect(item.catkey).to eq(current_catkey) - expect(item.previous_catkeys.empty?).to be_truthy + expect(item.previous_catkeys).to be_empty item.catkey = new_catkey expect(item.identityMetadata.otherId('catkey').length).to eq(1) expect(item.catkey).to eq(new_catkey) expect(item.previous_catkeys.length).to eq(1) expect(item.previous_catkeys).to eq([current_catkey]) end - it 'should add the catkey when it does not exist and never did' do + it 'adds the catkey when it does not exist and never did' do item.remove_other_Id('catkey') expect(item.identityMetadata.otherId('catkey').length).to eq(0) expect(item.catkey).to be_nil - expect(item.previous_catkeys.empty?).to be_truthy + expect(item.previous_catkeys).to be_empty item.catkey = new_catkey expect(item.identityMetadata.otherId('catkey').length).to eq(1) expect(item.catkey).to eq(new_catkey) - expect(item.previous_catkeys.empty?).to be_truthy + expect(item.previous_catkeys).to be_empty end - it 'should add the catkey when it does not currently exist and there is a previous history (not touching that)' do + it 'adds the catkey when it does not currently exist and there is a previous history (not touching that)' do item.remove_other_Id('catkey') expect(item.identityMetadata.otherId('catkey').length).to eq(0) expect(item.catkey).to be_nil @@ -147,17 +148,17 @@ class IdentifiableItem < ActiveFedora::Base expect(item.previous_catkeys.length).to eq(2) # still two entries, nothing changed in the history expect(item.previous_catkeys).to eq(%w[123 456]) end - it 'should remove the catkey from the XML when it is set to blank, but store the previously set value in the history' do + it 'removes the catkey from the XML when it is set to blank, but store the previously set value in the history' do expect(item.identityMetadata.otherId('catkey').length).to eq(1) expect(item.catkey).to eq(current_catkey) - expect(item.previous_catkeys.empty?).to be_truthy + expect(item.previous_catkeys).to be_empty item.catkey = '' expect(item.identityMetadata.otherId('catkey').length).to eq(0) expect(item.catkey).to be_nil expect(item.previous_catkeys.length).to eq(1) expect(item.previous_catkeys).to eq([current_catkey]) end - it 'should update the catkey when one exists, and add the previous catkey id to the list' do + it 'updates the catkey when one exists, and add the previous catkey id to the list' do previous_catkey = '111' item.add_other_Id('previous_catkey', previous_catkey) expect(item.identityMetadata.otherId('catkey').length).to eq(1) @@ -170,14 +171,14 @@ class IdentifiableItem < ActiveFedora::Base expect(item.previous_catkeys.length).to eq(2) expect(item.previous_catkeys).to eq([previous_catkey, current_catkey]) end - it 'should not do anything if there is a previous catkey and you set the catkey to the same value' do + it 'does not do anything if there is a previous catkey and you set the catkey to the same value' do expect(item.identityMetadata.otherId('catkey').length).to eq(1) expect(item.catkey).to eq(current_catkey) - expect(item.previous_catkeys.empty?).to be_truthy # no previous catkeys + expect(item.previous_catkeys).to be_empty # no previous catkeys item.catkey = current_catkey expect(item.identityMetadata.otherId('catkey').length).to eq(1) expect(item.catkey).to eq(current_catkey) - expect(item.previous_catkeys.empty?).to be_truthy # still empty, we haven't updated the previous catkey since it was the same + expect(item.previous_catkeys).to be_empty # still empty, we haven't updated the previous catkey since it was the same end end @@ -201,43 +202,43 @@ class IdentifiableItem < ActiveFedora::Base end describe 'remove_druid_prefix' do - it 'should remove the druid prefix if it is present' do + it 'removes the druid prefix if it is present' do expect(item.remove_druid_prefix).to eq('ab123cd4567') end - it 'should remove the druid prefix for an arbitrary druid passed in' do + it 'removes the druid prefix for an arbitrary druid passed in' do expect(item.remove_druid_prefix('druid:oo000oo0001')).to eq('oo000oo0001') end - it 'should leave the string unchanged if the druid prefix is already stripped' do + it 'leaves the string unchanged if the druid prefix is already stripped' do expect(item.remove_druid_prefix('oo000oo0001')).to eq('oo000oo0001') end - it 'should just return the input string if there are no matches' do + it 'justs return the input string if there are no matches' do expect(item.remove_druid_prefix('bogus')).to eq('bogus') end end describe 'regex' do - it 'should identify pids by regex' do + it 'identifies pids by regex' do expect('ab123cd4567'.match(item.pid_regex).size).to eq(1) end - it 'should pull out a pid by regex' do + it 'pulls out a pid by regex' do expect('druid:ab123cd4567/other crappola'.match(item.pid_regex)[0]).to eq('ab123cd4567') end - it 'should not identify non-pids' do + it 'does not identify non-pids' do expect('bogus'.match(item.pid_regex)).to be_nil end - it 'should not identify pid by druid regex' do + it 'does not identify pid by druid regex' do expect('ab123cd4567'.match(item.druid_regex)).to be_nil end - it 'should identify full druid by regex' do + it 'identifies full druid by regex' do expect('druid:ab123cd4567'.match(item.druid_regex).size).to eq(1) end - it 'should pull out a full druid by regex' do + it 'pulls out a full druid by regex' do expect('druid:ab123cd4567/other crappola'.match(item.druid_regex)[0]).to eq('druid:ab123cd4567') end - it 'should not identify non-druids' do + it 'does not identify non-druids' do expect('bogus'.match(item.druid_regex)).to be_nil end end diff --git a/spec/models/concerns/preservable_spec.rb b/spec/models/concerns/preservable_spec.rb index 9159dc8e..99642adf 100644 --- a/spec/models/concerns/preservable_spec.rb +++ b/spec/models/concerns/preservable_spec.rb @@ -14,8 +14,9 @@ class PreservableItem < ActiveFedora::Base let(:event_text) { 'DOR Common Accessioning' } - before(:each) { stub_config } - after(:each) { unstub_config } + before { stub_config } + + after { unstub_config } describe 'provenanceMetadata' do it 'builds the provenanceMetadata datastream' do diff --git a/spec/models/concerns/processable_spec.rb b/spec/models/concerns/processable_spec.rb index 5dec632f..e5aa9a2d 100644 --- a/spec/models/concerns/processable_spec.rb +++ b/spec/models/concerns/processable_spec.rb @@ -24,6 +24,7 @@ class ProcessableWithApoItem < ActiveFedora::Base after { unstub_config } let(:item) { instantiate_fixture('druid:ab123cd4567', ProcessableItem) } + before do stub_config item.contentMetadata.content = '' @@ -34,16 +35,16 @@ class ProcessableWithApoItem < ActiveFedora::Base expect(item.workflows).to eq(item.datastreams['workflows']) end - it 'should load its content directly from the workflow service' do - expect(Dor::Config.workflow.client).to receive(:get_workflow_xml).with('dor', 'druid:ab123cd4567', nil).once { '' } + it 'loads its content directly from the workflow service' do + expect(Dor::Config.workflow.client).to receive(:get_workflow_xml).with('dor', 'druid:ab123cd4567', nil).once.and_return('') expect(item.workflows.content).to eq('') end - it 'should be able to invalidate the cache of its content' do - expect(Dor::Config.workflow.client).to receive(:get_workflow_xml).with('dor', 'druid:ab123cd4567', nil).once { '' } + it 'is able to invalidate the cache of its content' do + expect(Dor::Config.workflow.client).to receive(:get_workflow_xml).with('dor', 'druid:ab123cd4567', nil).once.and_return('') expect(item.workflows.content).to eq('') expect(item.workflows.content).to eq('') # should be cached copy - expect(Dor::Config.workflow.client).to receive(:get_workflow_xml).with('dor', 'druid:ab123cd4567', nil).once { 'with some data' } + expect(Dor::Config.workflow.client).to receive(:get_workflow_xml).with('dor', 'druid:ab123cd4567', nil).once.and_return('with some data') # pass refresh flag and should be refreshed copy expect(item.workflows.content(true)).to eq('with some data') expect(item.workflows.content).to eq('with some data') diff --git a/spec/models/concerns/publishable_spec.rb b/spec/models/concerns/publishable_spec.rb index 598aaa25..17f0421b 100644 --- a/spec/models/concerns/publishable_spec.rb +++ b/spec/models/concerns/publishable_spec.rb @@ -42,10 +42,12 @@ class PublishableItem < ActiveFedora::Base end describe '#thumb' do + subject { item.thumb } + before do expect(Deprecation).to receive(:warn) end - subject { item.thumb } + let(:service) { instance_double(Dor::ThumbnailService, thumb: 'Test Result') } it 'calls the thumbnail service' do @@ -56,17 +58,18 @@ class PublishableItem < ActiveFedora::Base describe '#thumb_url' do before do - expect(Deprecation).to receive(:warn).at_least(1).times + expect(Deprecation).to receive(:warn).at_least(:once) end - it 'should return nil if there is no contentMetadata datastream' do + + it 'returns nil if there is no contentMetadata datastream' do collection = instantiate_fixture('druid:ab123cd4567', Dor::Collection) expect(collection.thumb_url).to be_nil end - it 'should return nil if there is no contentMetadata' do + it 'returns nil if there is no contentMetadata' do expect(item.thumb_url).to be_nil end - it 'should find the first image as the thumb when no specific thumbs are specified' do + it 'finds the first image as the thumb when no specific thumbs are specified' do item.contentMetadata.content = <<-XML @@ -78,7 +81,7 @@ class PublishableItem < ActiveFedora::Base expect(item.thumb_url).to eq('https://stacks.stanford.edu/image/iiif/ab123cd4567%2Fab123cd4567_05_0001/full/!400,400/0/default.jpg') end - it 'should find a page resource marked as thumb with the thumb attribute when there is a resource thumb specified but not the thumb attribute' do + it 'finds a page resource marked as thumb with the thumb attribute when there is a resource thumb specified but not the thumb attribute' do item.contentMetadata.content = <<-XML @@ -97,7 +100,7 @@ class PublishableItem < ActiveFedora::Base expect(item.encoded_thumb).to eq('ab123cd4567%2Fab123cd4567_05_0002.jp2') expect(item.thumb_url).to eq('https://stacks.stanford.edu/image/iiif/ab123cd4567%2Fab123cd4567_05_0002/full/!400,400/0/default.jpg') end - it 'should find an externalFile image resource when there are no other images' do + it 'finds an externalFile image resource when there are no other images' do item.contentMetadata.content = <<-XML @@ -112,7 +115,7 @@ class PublishableItem < ActiveFedora::Base expect(item.encoded_thumb).to eq('cg767mn6478%2F2542A.jp2') expect(item.thumb_url).to eq('https://stacks.stanford.edu/image/iiif/cg767mn6478%2F2542A/full/!400,400/0/default.jpg') end - it 'should find an externalFile page resource when there are no other images, even if objectId attribute is missing druid prefix' do + it 'finds an externalFile page resource when there are no other images, even if objectId attribute is missing druid prefix' do item.contentMetadata.content = <<-XML @@ -127,7 +130,7 @@ class PublishableItem < ActiveFedora::Base expect(item.encoded_thumb).to eq('cg767mn6478%2F2542A.jp2') expect(item.thumb_url).to eq('https://stacks.stanford.edu/image/iiif/cg767mn6478%2F2542A/full/!400,400/0/default.jpg') end - it 'should find an explicit externalFile thumb resource before another image resource, and encode the space' do + it 'finds an explicit externalFile thumb resource before another image resource, and encode the space' do item.contentMetadata.content = <<-XML @@ -142,7 +145,7 @@ class PublishableItem < ActiveFedora::Base expect(item.encoded_thumb).to eq('cg767mn6478%2F2542A%20withspace.jp2') expect(item.thumb_url).to eq('https://stacks.stanford.edu/image/iiif/cg767mn6478%2F2542A%20withspace/full/!400,400/0/default.jpg') end - it 'should return nil if no thumb is identified' do + it 'returns nil if no thumb is identified' do item.contentMetadata.content = <<-XML @@ -154,7 +157,7 @@ class PublishableItem < ActiveFedora::Base expect(item.encoded_thumb).to be_nil expect(item.thumb_url).to be_nil end - it 'should return nil if there is no contentMetadata datastream at all' do + it 'returns nil if there is no contentMetadata datastream at all' do item.datastreams['contentMetadata'] = nil expect(item.encoded_thumb).to be_nil expect(item.thumb_url).to be_nil diff --git a/spec/models/concerns/releaseable_no_vcr_spec.rb b/spec/models/concerns/releaseable_no_vcr_spec.rb index b9401905..89793a02 100644 --- a/spec/models/concerns/releaseable_no_vcr_spec.rb +++ b/spec/models/concerns/releaseable_no_vcr_spec.rb @@ -97,6 +97,7 @@ END_OF_HTML ) end + after do unstub_config end diff --git a/spec/models/concerns/releaseable_spec.rb b/spec/models/concerns/releaseable_spec.rb index ecfde29b..64d7e925 100644 --- a/spec/models/concerns/releaseable_spec.rb +++ b/spec/models/concerns/releaseable_spec.rb @@ -22,14 +22,14 @@ class ReleaseableItem < ActiveFedora::Base # TODO: rework all VCR recs into conventional fixtures or re-record them for AF6. # If these tests fail, check not just the logic, but also the specific tags describe 'handling tags on objects and determining release status' do - it 'should use only the most recent self tag to determine if an item is released, with no release tags on the collection' do + it 'uses only the most recent self tag to determine if an item is released, with no release tags on the collection' do VCR.use_cassette('should_use_only_the_most_recent_self_tag_to_determine_if_an_item_is_released_with_no_release_tags_on_the_collection') do item = instantiate_fixture('druid:vs298kg2555', Dor::Item) expect(item.released_for['Kurita']['release']).to be_truthy end end - it 'should deal with a bad collection record that references itself and not end up in an infinite loop by skipping the tag check for itself' do + it 'deals with a bad collection record that references itself and not end up in an infinite loop by skipping the tag check for itself' do collection_druid = 'druid:wz243gf4151' collection = instantiate_fixture(collection_druid, Dor::Item) allow(collection).to receive(:collections).and_return([collection]) # force it to return itself as a member @@ -45,7 +45,7 @@ class ReleaseableItem < ActiveFedora::Base end # This test takes an object with a self tag that is older and opposite the tag on this object's collection and ensures the self tag still is the one that is used to decide release status - it 'should use the self tag over the collection tag to determine if an item is released, even if the collection tag is newer' do + it 'uses the self tag over the collection tag to determine if an item is released, even if the collection tag is newer' do skip 'VCR cassette recorded on only one (old) version of ActiveFedora. Stub methods or record on both AF5 and AF6' VCR.use_cassette('releaseable_self_over_collection') do item = Dor::Item.find('druid:bb537hc4022') @@ -54,7 +54,7 @@ class ReleaseableItem < ActiveFedora::Base end # This test looks at an item whose only tags are on the collection and ensures the most recent one wins - it 'should use only most the recent collection tag if no self tags are present' do + it 'uses only most the recent collection tag if no self tags are present' do skip 'VCR cassette recorded on only one (old) version of ActiveFedora. Stub methods or record on both AF5 and AF6' VCR.use_cassette('releaseable_most_recent_collection_tag_wins') do item = Dor::Item.find('druid:bc566xq6031') @@ -74,7 +74,7 @@ class ReleaseableItem < ActiveFedora::Base # Here we have an object governed by both the Marcus Chambers, druid:wz243gf4151, Collection and the Revs Collection, druid:nt028fd5773 # When determining if an item is released, it should look at both collections and pick the most recent timestamp - it 'should look all collections and sets that an item is a member of' do + it 'looks all collections and sets that an item is a member of' do skip 'VCR cassette recorded on only one (old) version of ActiveFedora. Stub methods or record on both AF5 and AF6' VCR.use_cassette('releaseable_multiple_collections') do item = Dor::Item.find('druid:dc235vd9662') @@ -87,7 +87,7 @@ class ReleaseableItem < ActiveFedora::Base end # If an items release is controlled with the tag= attr, meaning that only items with that administrative tag are released, that should be respected - it 'should respect the tag= attr and apply it when releasing' do + it 'respects the tag= attr and apply it when releasing' do skip 'VCR cassette recorded on only one (old) version of ActiveFedora. Stub methods or record on both AF5 and AF6' VCR.use_cassette('releaseable_respect_admin_tagging') do chambers_collection = Dor::Item.find('druid:wz243gf4151') @@ -102,7 +102,7 @@ class ReleaseableItem < ActiveFedora::Base end end - it 'should return release xml for an item as string of elements wrapped in a ReleaseDigestRoot' do + it 'returns release xml for an item as string of elements wrapped in a ReleaseDigestRoot' do skip 'VCR cassette recorded on only one (old) version of ActiveFedora. Stub methods or record on both AF5 and AF6' VCR.use_cassette('releaseable_release_xml') do item = Dor::Item.find('druid:dc235vd9662') @@ -114,7 +114,7 @@ class ReleaseableItem < ActiveFedora::Base expect(release_node.name).to eq('release') # Well, duh expect(release_node.attributes.keys).to eq(['to']) expect(release_node.attributes['to'].value).to be_a(String) - expect(true_or_false.include?(release_node.children.text)).to be_truthy + expect(true_or_false).to include(release_node.children.text) end end end @@ -134,6 +134,7 @@ class ReleaseableItem < ActiveFedora::Base describe '#release_tags' do subject(:release_tags) { item.release_tags } + let(:service) { instance_double(Dor::ReleaseTagService, release_tags: ['foo']) } before do @@ -148,6 +149,7 @@ class ReleaseableItem < ActiveFedora::Base describe '#get_newest_release_tag' do subject(:get_newest_release_tag) { item.get_newest_release_tag('Revs' => %w[foo bar], 'FRDA' => %w[quax qwerk]) } + let(:service) { instance_double(Dor::ReleaseTagService, newest_release_tag: { 'Revs' => 'foo', 'FRDA' => 'qwerk' }) } before do @@ -164,13 +166,14 @@ class ReleaseableItem < ActiveFedora::Base before do expect(Deprecation).to receive(:warn) end - it 'should release an item with one release tag supplied' do + + it 'releases an item with one release tag supplied' do allow(item).to receive(:save).and_return(true) # stud out the true in that it we lack a connection to solr expect(item).to receive(:create_workflow).with('releaseWF') # Make sure releaseWF is called expect(item).to receive(:add_release_node).once expect(item.add_release_nodes_and_start_releaseWF(release: true, what: 'self', who: 'carrickr', to: 'FRDA')).to eq(nil) # Should run and return void end - it 'should release an item with multiple release tags supplied' do + it 'releases an item with multiple release tags supplied' do allow(item).to receive(:save).and_return(true) # stud out the true in that it we lack a connection to solr expect(item).to receive(:create_workflow).with('releaseWF') # Make sure releaseWF is called expect(item).to receive(:add_release_node).twice @@ -185,7 +188,7 @@ class ReleaseableItem < ActiveFedora::Base @args = { when: '2015-01-05T23:23:45Z', who: 'carrickr', to: 'Revs', what: 'collection', tag: 'Project:Fitch:Batch2' } end - it 'should raise an error when :who, :to, :what are missing or are not strings' do + it 'raises an error when :who, :to, :what are missing or are not strings' do expect{ item.valid_release_attributes(true, @args.merge(who: nil)) }.to raise_error(ArgumentError) expect{ item.valid_release_attributes(false, @args.merge(to: nil)) }.to raise_error(ArgumentError) expect{ item.valid_release_attributes(true, @args.merge(what: nil)) }.to raise_error(ArgumentError) @@ -193,43 +196,43 @@ class ReleaseableItem < ActiveFedora::Base expect{ item.valid_release_attributes(true, @args.merge(to: true)) }.to raise_error(ArgumentError) expect{ item.valid_release_attributes(false, @args.merge(what: %w(i am an array))) }.to raise_error(ArgumentError) end - it 'should not raise an error when :what is self or collection' do + it 'does not raise an error when :what is self or collection' do expect(item.valid_release_attributes(false, @args)).to be true expect(item.valid_release_attributes(true, @args.merge(what: 'self'))).to be true end it 'raises an argument error when :what is a string, but is not self or collection' do expect{ item.valid_release_attributes(true, @args.merge(what: 'foo')) }.to raise_error(ArgumentError) end - it 'should add a tag when all attributes are properly provided, and drop the invalid attribute' do + it 'adds a tag when all attributes are properly provided, and drop the invalid attribute' do VCR.use_cassette('simple_release_tag_add_success_test') do tag_xml = item.add_release_node(true, @args.merge(what: 'self')) expect(tag_xml).to be_a_kind_of(Nokogiri::XML::Element) expect(tag_xml.to_xml).to eq('true') end end - it 'should fail to add a release node when there is an attribute error' do + it 'fails to add a release node when there is an attribute error' do VCR.use_cassette('simple_release_tag_add_success_test') do expect{ item.add_release_node(true, who: nil, to: 'Revs', what: 'self') }.to raise_error(ArgumentError) # who is not a string expect{ item.add_release_node(true, who: nil, to: 'Revs', what: 'unknown_value') }.to raise_error(ArgumentError) # who is not a string expect{ item.add_release_node(1, @args) }.to raise_error(ArgumentError) # invalid release value end end - it 'should drop all invalid attributes passed in' do + it 'drops all invalid attributes passed in' do VCR.use_cassette('simple_release_tag_add_success_test') do new_tag = 'true' - expect(item.identityMetadata.to_xml).to_not include new_tag + expect(item.identityMetadata.to_xml).not_to include new_tag item.add_release_node(true, :when => '2016-01-05T23:23:45Z', :who => 'petucket', :to => 'Revs', :what => 'self', :blop => 'something', :tag => 'Revs', 'something_else' => 'whatup') expect(item.identityMetadata.to_xml).to include new_tag end end - it 'should return true when valid_release_attributes is called with valid attributes and no tag attribute' do + it 'returns true when valid_release_attributes is called with valid attributes and no tag attribute' do @args.delete :tag expect(item.valid_release_attributes(true, @args)).to be true end - it 'should return true when valid_release_attributes is called with valid attributes and tag attribute' do + it 'returns true when valid_release_attributes is called with valid attributes and tag attribute' do expect(item.valid_release_attributes(true, @args)).to be true end - it 'should raise an error when valid_release_attributes is called with a tag content that is not a boolean' do + it 'raises an error when valid_release_attributes is called with a tag content that is not a boolean' do expect{ item.valid_release_attributes(1, @args) }.to raise_error(ArgumentError) end end diff --git a/spec/models/concerns/versionable_spec.rb b/spec/models/concerns/versionable_spec.rb index 869ea07d..d1c2a28f 100644 --- a/spec/models/concerns/versionable_spec.rb +++ b/spec/models/concerns/versionable_spec.rb @@ -19,7 +19,7 @@ class VersionableItem < ActiveFedora::Base let(:vmd_ds) { obj.datastreams['versionMetadata'] } let(:ev_ds) { obj.datastreams['events'] } - before(:each) do + before do allow(obj.inner_object).to receive(:repository).and_return(double('frepo').as_null_object) end @@ -42,20 +42,20 @@ class VersionableItem < ActiveFedora::Base describe 'allows_modification?' do it "allows modification if the object hasn't been submitted" do allow(Dor::Config.workflow.client).to receive(:get_lifecycle).and_return(false) - expect(obj.allows_modification?).to be_truthy + expect(obj).to be_allows_modification end it 'allows modification if there is an open version' do allow(Dor::Config.workflow.client).to receive(:get_lifecycle).and_return(true) allow_any_instance_of(Dor::VersionService).to receive(:open?).and_return(true) - expect(obj.allows_modification?).to be_truthy + expect(obj).to be_allows_modification end it 'allows modification if the item has sdr-ingest-transfer set to hold' do allow(Dor::Config.workflow.client).to receive(:get_lifecycle).and_return(true) allow_any_instance_of(Dor::VersionService).to receive(:open?).and_return(false) allow(Dor::Config.workflow.client).to receive(:get_workflow_status).and_return('hold') - expect(obj.allows_modification?).to be_truthy + expect(obj).to be_allows_modification end end end diff --git a/spec/models/item_spec.rb b/spec/models/item_spec.rb index dec5454d..45709be7 100644 --- a/spec/models/item_spec.rb +++ b/spec/models/item_spec.rb @@ -5,6 +5,7 @@ RSpec.describe Dor::Item do describe '#to_solr' do subject(:doc) { item.to_solr } + let(:item) { described_class.new(pid: 'foo:123') } before { allow(Dor::Config.workflow.client).to receive(:get_milestones).and_return([]) } @@ -20,7 +21,8 @@ allow(obj).to receive(:update_index) obj.save! end - let(:reloaded) { Dor::Item.find(obj.pid) } + + let(:reloaded) { described_class.find(obj.pid) } let(:workflows) { reloaded.workflows } it 'is set automatically' do diff --git a/spec/models/workflow_document_spec.rb b/spec/models/workflow_document_spec.rb index 952fc59d..1cd58014 100644 --- a/spec/models/workflow_document_spec.rb +++ b/spec/models/workflow_document_spec.rb @@ -21,8 +21,10 @@ let(:step4) { 'some-other-step' } describe '#processes' do - let(:document) { described_class.new(xml) } subject(:processes) { document.processes } + + let(:document) { described_class.new(xml) } + before do allow(document).to receive(:definition).and_return(@wf_definition) end @@ -87,6 +89,7 @@ eos end + it 'generates a process list based on the reified workflow which has sequence, not the processes list from the workflow service' do expect(processes.length).to eq(4) proc = processes.first @@ -110,9 +113,9 @@ eos - d = Dor::Workflow::Document.new(xml) + d = described_class.new(xml) allow(d).to receive(:definition).and_return(@wf_definition) - expect(d.expedited?).to be_falsey + expect(d).not_to be_expedited end it 'says true if there are incomplete prioritized items' do @@ -126,9 +129,9 @@ eos - d = Dor::Workflow::Document.new(xml) + d = described_class.new(xml) allow(d).to receive(:definition).and_return(@wf_definition) - expect(d.expedited?).to be_truthy + expect(d).to be_expedited end end @@ -142,8 +145,8 @@ eos - d = Dor::Workflow::Document.new(xml) - expect(d.active?).to be_truthy + d = described_class.new(xml) + expect(d).to be_active end it 'returns false if there are only archived rows' do @@ -155,17 +158,20 @@ eos - d = Dor::Workflow::Document.new(xml) - expect(d.active?).to be_falsey + d = described_class.new(xml) + expect(d).not_to be_active end end describe '#to_solr' do - let(:document) { described_class.new(xml) } subject(:solr_doc) { document.to_solr } + + let(:document) { described_class.new(xml) } + before do allow(document).to receive(:definition).and_return(@wf_definition) end + let(:xml) do <<-eos @@ -213,6 +219,7 @@ eos end + it 'indexes the right workflow status (completed)' do expect(solr_doc).to match a_hash_including('workflow_status_ssim' => ['accessionWF|completed|0|dor']) end @@ -234,6 +241,7 @@ eos end + it 'indexes the right workflow status (completed)' do expect(solr_doc).to match a_hash_including('workflow_status_ssim' => ['accessionWF|completed|0|dor']) end diff --git a/spec/models/workflow_object_spec.rb b/spec/models/workflow_object_spec.rb index 3417e4b9..8de3af78 100644 --- a/spec/models/workflow_object_spec.rb +++ b/spec/models/workflow_object_spec.rb @@ -6,22 +6,23 @@ describe '.initial_workflow' do it 'caches the intial workflow xml for subsequent requests' do wobj = double('workflow_object').as_null_object - expect(Dor::WorkflowObject).to receive(:find_by_name).once.and_return(wobj) + expect(described_class).to receive(:find_by_name).once.and_return(wobj) # First call, object not in cache - Dor::WorkflowObject.initial_workflow('accessionWF') + described_class.initial_workflow('accessionWF') # Second call, object in cache - expect(Dor::WorkflowObject.initial_workflow('accessionWF')).to eq(wobj) + expect(described_class.initial_workflow('accessionWF')).to eq(wobj) end end # TODO: Move to the DataIndexer spec describe '#to_solr' do - before(:each) { stub_config } - after(:each) { unstub_config } + before { stub_config } + + after { unstub_config } before do - @item = instantiate_fixture('druid:ab123cd4567', Dor::WorkflowObject) + @item = instantiate_fixture('druid:ab123cd4567', described_class) @item.workflowDefinition.content = '' end diff --git a/spec/services/abiltiy_spec.rb b/spec/services/abiltiy_spec.rb index 70a3c1e8..4a1b5559 100644 --- a/spec/services/abiltiy_spec.rb +++ b/spec/services/abiltiy_spec.rb @@ -6,86 +6,86 @@ subject(:ability) { described_class } describe 'can_manage_item?' do - it 'should match a group that has rights' do - expect(ability.can_manage_item?(['dor-administrator'])).to be_truthy + it 'matches a group that has rights' do + expect(ability).to be_can_manage_item(['dor-administrator']) end - it 'should match a group that has rights' do - expect(ability.can_manage_item?(['sdr-administrator'])).to be_truthy + it 'matches a group that has rights' do + expect(ability).to be_can_manage_item(['sdr-administrator']) end it 'shouldnt match a group that doesnt have rights' do - expect(ability.can_manage_item?(['dor-apo-metadata'])).to be_falsey + expect(ability).not_to be_can_manage_item(['dor-apo-metadata']) end end describe 'can_manage_desc_metadata?' do - it 'should match a group that has rights' do - expect(ability.can_manage_desc_metadata?(['dor-apo-metadata'])).to be_truthy + it 'matches a group that has rights' do + expect(ability).to be_can_manage_desc_metadata(['dor-apo-metadata']) end it 'shouldnt match a group that doesnt have rights' do - expect(ability.can_manage_desc_metadata?(['dor-viewer'])).to be_falsey + expect(ability).not_to be_can_manage_desc_metadata(['dor-viewer']) end it 'shouldnt match a group that doesnt have rights' do - expect(ability.can_manage_desc_metadata?(['sdr-viewer'])).to be_falsey + expect(ability).not_to be_can_manage_desc_metadata(['sdr-viewer']) end end describe 'can_manage_content?' do - it 'should match a group that has rights' do - expect(ability.can_manage_content?(['dor-administrator'])).to be_truthy + it 'matches a group that has rights' do + expect(ability).to be_can_manage_content(['dor-administrator']) end - it 'should match a group that has rights' do - expect(ability.can_manage_content?(['sdr-administrator'])).to be_truthy + it 'matches a group that has rights' do + expect(ability).to be_can_manage_content(['sdr-administrator']) end it 'shouldnt match a group that doesnt have rights' do - expect(ability.can_manage_content?(['dor-apo-metadata'])).to be_falsey + expect(ability).not_to be_can_manage_content(['dor-apo-metadata']) end end describe 'can_manage_rights?' do - it 'should match a group that has rights' do - expect(ability.can_manage_rights?(['dor-administrator'])).to be_truthy + it 'matches a group that has rights' do + expect(ability).to be_can_manage_rights(['dor-administrator']) end - it 'should match a group that has rights' do - expect(ability.can_manage_rights?(['sdr-administrator'])).to be_truthy + it 'matches a group that has rights' do + expect(ability).to be_can_manage_rights(['sdr-administrator']) end it 'shouldnt match a group that doesnt have rights' do - expect(ability.can_manage_rights?(['dor-apo-metadata'])).to be_falsey + expect(ability).not_to be_can_manage_rights(['dor-apo-metadata']) end end describe 'can_manage_embargo?' do - it 'should match a group that has rights' do - expect(ability.can_manage_embargo?(['dor-administrator'])).to be_truthy + it 'matches a group that has rights' do + expect(ability).to be_can_manage_embargo(['dor-administrator']) end - it 'should match a group that has rights' do - expect(ability.can_manage_embargo?(['sdr-administrator'])).to be_truthy + it 'matches a group that has rights' do + expect(ability).to be_can_manage_embargo(['sdr-administrator']) end it 'shouldnt match a group that doesnt have rights' do - expect(ability.can_manage_embargo?(['dor-apo-metadata'])).to be_falsey + expect(ability).not_to be_can_manage_embargo(['dor-apo-metadata']) end end describe 'can_view_content?' do - it 'should match a group that has rights' do - expect(ability.can_view_content?(['dor-viewer'])).to be_truthy + it 'matches a group that has rights' do + expect(ability).to be_can_view_content(['dor-viewer']) end - it 'should match a group that has rights' do - expect(ability.can_view_content?(['sdr-viewer'])).to be_truthy + it 'matches a group that has rights' do + expect(ability).to be_can_view_content(['sdr-viewer']) end it 'shouldnt match a group that doesnt have rights' do - expect(ability.can_view_content?(['dor-people'])).to be_falsey + expect(ability).not_to be_can_view_content(['dor-people']) end end describe 'can_view_metadata?' do - it 'should match a group that has rights' do - expect(ability.can_view_metadata?(['dor-viewer'])).to be_truthy + it 'matches a group that has rights' do + expect(ability).to be_can_view_metadata(['dor-viewer']) end - it 'should match a group that has rights' do - expect(ability.can_view_metadata?(['sdr-viewer'])).to be_truthy + it 'matches a group that has rights' do + expect(ability).to be_can_view_metadata(['sdr-viewer']) end it 'shouldnt match a group that doesnt have rights' do - expect(ability.can_view_metadata?(['dor-people'])).to be_falsey + expect(ability).not_to be_can_view_metadata(['dor-people']) end end end diff --git a/spec/services/cleanup_reset_service_spec.rb b/spec/services/cleanup_reset_service_spec.rb index 51b554e3..58358ccc 100644 --- a/spec/services/cleanup_reset_service_spec.rb +++ b/spec/services/cleanup_reset_service_spec.rb @@ -26,7 +26,7 @@ end context 'cleanup_by_reset_druid' do - before :each do + before do @druid_id = 'cc111cm1111' @druid = "druid:#{@druid_id}" @base_bag_dir = "#{@export_pathname}/#{@druid_id}_v1" @@ -38,44 +38,44 @@ @base_assembly_druid_dir = @base_assembly_druid_path.to_s end - it 'should remove the reset druid tree from dor workspace and assembly, and reset bag from export' do + it 'removes the reset druid tree from dor workspace and assembly, and reset bag from export' do create_bag_dir(@druid_id + '_v1') create_bag_tar(@druid_id + '_v1') create_druid_dir(@druid_id, 1, @workspace_root_pathname.to_s) create_druid_dir(@druid_id, nil, @assembly_root_pathname.to_s) - expect(File.exist?(@base_bag_dir)).to be_truthy - expect(File.exist?(@base_tar_dir)).to be_truthy - expect(File.exist?(@base_workspace_druid_dir + '_v1')).to be_truthy - expect(File.exist?(@base_assembly_druid_dir)).to be_truthy + expect(File).to exist(@base_bag_dir) + expect(File).to exist(@base_tar_dir) + expect(File).to exist(@base_workspace_druid_dir + '_v1') + expect(File).to exist(@base_assembly_druid_dir) Dor::CleanupResetService.cleanup_by_reset_druid(@druid) - expect(File.exist?(@base_bag_dir)).to be_falsey - expect(File.exist?(@base_tar_dir)).to be_falsey - expect(File.exist?(@base_workspace_druid_dir + '_v1')).to be_falsey - expect(File.exist?(@base_assembly_druid_dir)).to be_falsey + expect(File).not_to exist(@base_bag_dir) + expect(File).not_to exist(@base_tar_dir) + expect(File).not_to exist(@base_workspace_druid_dir + '_v1') + expect(File).not_to exist(@base_assembly_druid_dir) end - it 'should remove the reset druid tree from dor workspace and reset bag from export only, there is no assembly ws' do + it 'removes the reset druid tree from dor workspace and reset bag from export only, there is no assembly ws' do create_bag_dir(@druid_id + '_v1') create_bag_tar(@druid_id + '_v1') create_druid_dir(@druid_id, 1, @workspace_root_pathname.to_s) - expect(File.exist?(@base_bag_dir)).to be_truthy - expect(File.exist?(@base_tar_dir)).to be_truthy - expect(File.exist?(@base_workspace_druid_dir + '_v1')).to be_truthy - expect(File.exist?(@base_assembly_druid_dir)).to be_falsey + expect(File).to exist(@base_bag_dir) + expect(File).to exist(@base_tar_dir) + expect(File).to exist(@base_workspace_druid_dir + '_v1') + expect(File).not_to exist(@base_assembly_druid_dir) Dor::CleanupResetService.cleanup_by_reset_druid(@druid) - expect(File.exist?(@base_bag_dir)).to be_falsey - expect(File.exist?(@base_tar_dir)).to be_falsey - expect(File.exist?(@base_workspace_druid_dir + '_v1')).to be_falsey - expect(File.exist?(@base_assembly_druid_dir)).to be_falsey + expect(File).not_to exist(@base_bag_dir) + expect(File).not_to exist(@base_tar_dir) + expect(File).not_to exist(@base_workspace_druid_dir + '_v1') + expect(File).not_to exist(@base_assembly_druid_dir) end - it 'should remove the reset druid tree from dor workspace and assembly however they are symlink' do + it 'removes the reset druid tree from dor workspace and assembly however they are symlink' do create_druid_dir(@druid_id, nil, @assembly_root_pathname.to_s) FileUtils.mkdir_p @base_workspace_druid_path.parent FileUtils.ln_s(@base_assembly_druid_dir, @base_workspace_druid_dir + '_v1', force: true) - expect(File.exist?(@base_workspace_druid_dir + '_v1')).to be_truthy - expect(File.exist?(@base_assembly_druid_dir)).to be_truthy + expect(File).to exist(@base_workspace_druid_dir + '_v1') + expect(File).to exist(@base_assembly_druid_dir) Dor::CleanupResetService.cleanup_by_reset_druid(@druid) - expect(File.exist?(@base_workspace_druid_dir + '_v1')).to be_falsey - expect(File.exist?(@base_assembly_druid_dir)).to be_falsey + expect(File).not_to exist(@base_workspace_druid_dir + '_v1') + expect(File).not_to exist(@base_assembly_druid_dir) end end @@ -86,19 +86,19 @@ ## cc111ck1111 - 1 version with immediate ancestor ### cc111ck1112 support the previous version context 'cleanup_reset_workspace_content' do - it 'should remove the reset directory in workspace' do + it 'removes the reset directory in workspace' do druid_id = 'cc111ci1111' druid = "druid:#{druid_id}" create_druid_dir(druid_id, 1, @workspace_root_pathname.to_s) base_druid_dir = DruidTools::Druid.new(druid, @workspace_root_pathname.to_s).pathname.to_s last_version = 1 - expect(File.exist?(base_druid_dir + '_v1')).to be_truthy + expect(File).to exist(base_druid_dir + '_v1') Dor::CleanupResetService.cleanup_reset_workspace_content(druid, last_version, @workspace_root_pathname.to_s) - expect(File.exist?(base_druid_dir + '_v1')).to be_falsey + expect(File).not_to exist(base_druid_dir + '_v1') end - it 'should remove the reset directory and keep the open version' do + it 'removes the reset directory and keep the open version' do druid_id = 'cc111cj1111' druid = "druid:#{druid_id}" create_druid_dir(druid_id, 2, @workspace_root_pathname.to_s) @@ -107,25 +107,25 @@ base_druid_dir = DruidTools::Druid.new(druid, @workspace_root_pathname.to_s).pathname.to_s last_version = 2 - expect(File.exist?(base_druid_dir + '_v2')).to be_truthy - expect(File.exist?(base_druid_dir + '_v3')).to be_truthy + expect(File).to exist(base_druid_dir + '_v2') + expect(File).to exist(base_druid_dir + '_v3') Dor::CleanupResetService.cleanup_reset_workspace_content(druid, last_version, @workspace_root_pathname.to_s) - expect(File.exist?(base_druid_dir + '_v2')).to be_falsey - expect(File.exist?(base_druid_dir + '_v3')).to be_truthy + expect(File).not_to exist(base_druid_dir + '_v2') + expect(File).to exist(base_druid_dir + '_v3') end - it 'should remove 1 version with root ancestor' do + it 'removes 1 version with root ancestor' do druid_id = 'cz111cz1111' druid = "druid:#{druid_id}" create_druid_dir(druid_id, 1, @workspace_root_pathname.to_s) base_druid_dir = DruidTools::Druid.new(druid, @workspace_root_pathname.to_s).pathname.to_s last_version = 1 - expect(File.exist?(base_druid_dir + '_v1')).to be_truthy + expect(File).to exist(base_druid_dir + '_v1') Dor::CleanupResetService.cleanup_reset_workspace_content(druid, last_version, @workspace_root_pathname.to_s) - expect(File.exist?(@workspace_root_pathname.join('cz'))).to be_falsey + expect(File).not_to exist(@workspace_root_pathname.join('cz')) end - it 'should remove 1 version with immediate ancestor' do + it 'removes 1 version with immediate ancestor' do druid_id1 = 'cc111ck1111' druid_1 = "druid:#{druid_id1}" create_druid_dir(druid_id1, 1, @workspace_root_pathname.to_s) @@ -137,13 +137,13 @@ base_druid_dir_2 = DruidTools::Druid.new(druid_2, @workspace_root_pathname.to_s).pathname.to_s last_version = 1 - expect(File.exist?(base_druid_dir_1 + '_v1')).to be_truthy - expect(File.exist?(base_druid_dir_2)).to be_truthy + expect(File).to exist(base_druid_dir_1 + '_v1') + expect(File).to exist(base_druid_dir_2) Dor::CleanupResetService.cleanup_reset_workspace_content(druid_1, last_version, @workspace_root_pathname.to_s) - expect(File.exist?(base_druid_dir_1 + '_v1')).to be_falsey - expect(File.exist?(base_druid_dir_2)).to be_truthy - expect(File.exist?(@workspace_root_pathname.join('cc').join('111').join('ck').join('1111'))).to be_falsey - expect(File.exist?(@workspace_root_pathname.join('cc').join('111').join('ck'))).to be_truthy + expect(File).not_to exist(base_druid_dir_1 + '_v1') + expect(File).to exist(base_druid_dir_2) + expect(File).not_to exist(@workspace_root_pathname.join('cc').join('111').join('ck').join('1111')) + expect(File).to exist(@workspace_root_pathname.join('cc').join('111').join('ck')) end end @@ -153,7 +153,7 @@ ## cc111ch1111 - 1 version (v1) and 1 opened version (v2) context 'get_reset_dirctories_list' do - before(:each) do + before do @druid_1v = 'cc111cf1111' @druid_2v = 'cc111cg1111' @druid_1_1v = 'cc111ch1111' @@ -164,7 +164,7 @@ create_druid_dir(@druid_1_1v, 2, @workspace_root_pathname.to_s) end - it 'should get one reset directory from workspace' do + it 'gets one reset directory from workspace' do druid = "druid:#{@druid_1v}" base_druid_tree = DruidTools::Druid.new(druid, @workspace_root_pathname.to_s) last_version = 1 @@ -174,7 +174,7 @@ expect(dir_list[0]).to eq expect_dir_path end - it 'should get two reset directories from workspace' do + it 'gets two reset directories from workspace' do druid = "druid:#{@druid_2v}" base_druid_tree = DruidTools::Druid.new(druid, @workspace_root_pathname.to_s) last_version = 3 @@ -186,7 +186,7 @@ expect(dir_list[1]).to eq expect_dir_path_2 end - it 'should get one reset directory from workspace and avoid the open version' do + it 'gets one reset directory from workspace and avoid the open version' do druid = "druid:#{@druid_1_1v}" base_druid_tree = DruidTools::Druid.new(druid, @workspace_root_pathname.to_s) last_version = 1 @@ -202,25 +202,25 @@ ## cc111ce1111 - 2 dir opened and versioned and 2 tar opened and reset ## context 'cleanup_reset_export' do - before(:each) do + before do @druid_1v = 'cc111cd1111' create_bag_dir(@druid_1v + '_v1') create_bag_tar(@druid_1v + '_v1') end - it 'should remove both bag tar and directory' do + it 'removes both bag tar and directory' do druid = "druid:#{@druid_1v}" base_bag_dir = "#{@export_pathname}/#{@druid_1v}_v1" - expect(File.exist?(base_bag_dir)).to be_truthy - expect(File.exist?(base_bag_dir + '.tar')).to be_truthy + expect(File).to exist(base_bag_dir) + expect(File).to exist(base_bag_dir + '.tar') Dor::CleanupResetService.cleanup_reset_export(druid, 1) - expect(File.exist?(base_bag_dir)).to be_falsey - expect(File.exist?(base_bag_dir + '.tar')).to be_falsey + expect(File).not_to exist(base_bag_dir) + expect(File).not_to exist(base_bag_dir + '.tar') end end context 'get_reset_bag_dir_list' do - before(:each) do + before do @druid_1v = 'cc111ca1111' @druid_2v = 'cc111cb1111' @druid_1_1v = 'cc111cc1111' @@ -231,7 +231,7 @@ create_bag_dir(@druid_1_1v) end - it 'should read the bag directory with 1 version' do + it 'reads the bag directory with 1 version' do base_bag_dir = "#{@export_pathname}/#{@druid_1v}" dir_list = Dor::CleanupResetService.get_reset_bag_dir_list(1, base_bag_dir) expect_dir_file = "#{base_bag_dir}_v1" @@ -239,7 +239,7 @@ expect(dir_list[0]).to eq expect_dir_file end - it 'should return a list of bag directories with 2 versions' do + it 'returns a list of bag directories with 2 versions' do base_bag_dir = "#{@export_pathname}/#{@druid_2v}" dir_list = Dor::CleanupResetService.get_reset_bag_dir_list(3, base_bag_dir) expect_dir_file_1 = "#{base_bag_dir}_v2" @@ -249,7 +249,7 @@ expect(dir_list[1]).to eq expect_dir_file_2 end - it 'should return a list of tars with 1 version and 1 opened version' do + it 'returns a list of tars with 1 version and 1 opened version' do base_bag_dir = "#{@export_pathname}/#{@druid_1_1v}" dir_list = Dor::CleanupResetService.get_reset_bag_dir_list(1, base_bag_dir) expect_dir_file = "#{base_bag_dir}_v1" @@ -259,7 +259,7 @@ end context 'get_reset_bag_tar_list' do - before(:each) do + before do @druid_1v = 'cc111ca1111' @druid_2v = 'cc111cb1111' @druid_1_1v = 'cc111cc1111' @@ -270,7 +270,7 @@ create_bag_tar(@druid_1_1v) end - it 'should return a list of tars with 1 version' do + it 'returns a list of tars with 1 version' do base_bag_dir = "#{@export_pathname}/#{@druid_1v}" tar_list = Dor::CleanupResetService.get_reset_bag_tar_list(1, base_bag_dir) expect_tar_file = "#{base_bag_dir}_v1.tar" @@ -278,7 +278,7 @@ expect(tar_list[0]).to eq expect_tar_file end - it 'should return a list of tars with 2 versions' do + it 'returns a list of tars with 2 versions' do base_bag_dir = "#{@export_pathname}/#{@druid_2v}" tar_list = Dor::CleanupResetService.get_reset_bag_tar_list(3, base_bag_dir) expect_tar_file_1 = "#{base_bag_dir}_v2.tar" @@ -288,7 +288,7 @@ expect(tar_list[1]).to eq expect_tar_file_2 end - it 'should return a list of tars with 1 version and 1 opened version' do + it 'returns a list of tars with 1 version and 1 opened version' do base_bag_dir = "#{@export_pathname}/#{@druid_1_1v}" tar_list = Dor::CleanupResetService.get_reset_bag_tar_list(1, base_bag_dir) expect_tar_file = "#{base_bag_dir}_v1.tar" @@ -298,18 +298,18 @@ end context 'cleanup_assembly_content' do - it 'should cleanup the assembly workspace' do + it 'cleanups the assembly workspace' do druid_id = 'ab123cd4567' create_druid_dir(druid_id, nil, @assembly_root_pathname.to_s) - expect(File.exist?(@assembly_root_pathname.join('ab').join('123').join('cd').join('4567'))).to be_truthy + expect(File).to exist(@assembly_root_pathname.join('ab').join('123').join('cd').join('4567')) Dor::CleanupResetService.cleanup_assembly_content(druid_id, @assembly_root_pathname.to_s) - expect(File.exist?(@assembly_root_pathname.join('ab').join('123').join('cd').join('4567'))).to be_falsey + expect(File).not_to exist(@assembly_root_pathname.join('ab').join('123').join('cd').join('4567')) end - it 'should not do anything if the assembly workspace is empty' do + it 'does not do anything if the assembly workspace is empty' do druid_id = 'ef123gh4567' - expect(File.exist?(@assembly_root_pathname.join('ab').join('123').join('cd').join('4567'))).to be_falsey - expect{ Dor::CleanupResetService.cleanup_assembly_content(druid_id, @assembly_root_pathname.to_s) }.to_not raise_error - expect(File.exist?(@assembly_root_pathname.join('ab').join('123').join('cd').join('4567'))).to be_falsey + expect(File).not_to exist(@assembly_root_pathname.join('ab').join('123').join('cd').join('4567')) + expect{ Dor::CleanupResetService.cleanup_assembly_content(druid_id, @assembly_root_pathname.to_s) }.not_to raise_error + expect(File).not_to exist(@assembly_root_pathname.join('ab').join('123').join('cd').join('4567')) end end diff --git a/spec/services/cleanup_service_filesystem_spec.rb b/spec/services/cleanup_service_filesystem_spec.rb index 163f2a3f..cd5d38d7 100644 --- a/spec/services/cleanup_service_filesystem_spec.rb +++ b/spec/services/cleanup_service_filesystem_spec.rb @@ -12,7 +12,7 @@ let(:druid_1) { 'druid:cd456ef7890' } let(:druid_2) { 'druid:cd456gh1234' } - before(:each) do + before do Dor::Config.push! do |config| config.cleanup.local_workspace_root workspace_dir config.cleanup.local_export_home export_dir @@ -27,7 +27,7 @@ FileUtils.mkdir stacks_dir end - after(:each) do + after do FileUtils.rm_rf fixture_dir Dor::Config.pop! end @@ -42,7 +42,7 @@ def create_tempfile(path) let(:item1) { double('item1') } let(:item2) { double('item1') } - before(:each) do + before do allow(item1).to receive(:druid) { druid_1 } allow(item2).to receive(:druid) { druid_2 } end @@ -113,7 +113,7 @@ def create_tempfile(path) expect(File).to exist(stacks_dr.path) Dor::CleanupService.cleanup_stacks druid_1 - expect(File).to_not exist(stacks_dr.path) + expect(File).not_to exist(stacks_dr.path) end end end diff --git a/spec/services/cleanup_service_spec.rb b/spec/services/cleanup_service_spec.rb index 986bbf77..43b0a0ce 100644 --- a/spec/services/cleanup_service_spec.rb +++ b/spec/services/cleanup_service_spec.rb @@ -33,7 +33,7 @@ @tarfile_pathname = @export_pathname.join(@bag_pathname + '.tar') end - before(:each) do + before do @workitem_pathname.join('content').mkpath @workitem_pathname.join('temp').mkpath @bag_pathname.mkpath @@ -55,45 +55,45 @@ end it 'can find the fixtures workspace and export folders' do - expect(File.directory?(Dor::Config.cleanup.local_workspace_root)).to be_truthy - expect(File.directory?(Dor::Config.cleanup.local_export_home)).to be_truthy + expect(File).to be_directory(Dor::Config.cleanup.local_workspace_root) + expect(File).to be_directory(Dor::Config.cleanup.local_export_home) end specify 'Dor::CleanupService.cleanup' do - expect(Dor::CleanupService).to receive(:cleanup_export).once.with(@druid) + expect(described_class).to receive(:cleanup_export).once.with(@druid) mock_item = double('item') expect(mock_item).to receive(:druid).and_return(@druid) - Dor::CleanupService.cleanup(mock_item) + described_class.cleanup(mock_item) end specify 'Dor::CleanupService.cleanup_export' do - expect(Dor::CleanupService).to receive(:remove_branch).once.with(@fixtures.join('export/aa123bb4567').to_s) - expect(Dor::CleanupService).to receive(:remove_branch).once.with(@fixtures.join('export/aa123bb4567.tar').to_s) - Dor::CleanupService.cleanup_export(@druid) + expect(described_class).to receive(:remove_branch).once.with(@fixtures.join('export/aa123bb4567').to_s) + expect(described_class).to receive(:remove_branch).once.with(@fixtures.join('export/aa123bb4567.tar').to_s) + described_class.cleanup_export(@druid) end specify 'Dor::CleanupService.remove_branch non-existing branch' do @bag_pathname.rmtree if @bag_pathname.exist? expect(@bag_pathname).not_to receive(:rmtree) - Dor::CleanupService.remove_branch(@bag_pathname) + described_class.remove_branch(@bag_pathname) end specify 'Dor::CleanupService.remove_branch existing branch' do @bag_pathname.mkpath - expect(@bag_pathname.exist?).to be_truthy + expect(@bag_pathname).to exist expect(@bag_pathname).to receive(:rmtree) - Dor::CleanupService.remove_branch(@bag_pathname) + described_class.remove_branch(@bag_pathname) end it 'can do a complete cleanup' do - expect(@workitem_pathname.join('content').exist?).to be_truthy - expect(@bag_pathname.exist?).to be_truthy - expect(@tarfile_pathname.exist?).to be_truthy + expect(@workitem_pathname.join('content')).to exist + expect(@bag_pathname).to exist + expect(@tarfile_pathname).to exist mock_item = double('item') expect(mock_item).to receive(:druid).and_return(@druid) - Dor::CleanupService.cleanup(mock_item) - expect(@workitem_pathname.parent.parent.parent.parent.exist?).to be_falsey - expect(@bag_pathname.exist?).to be_falsey - expect(@tarfile_pathname.exist?).to be_falsey + described_class.cleanup(mock_item) + expect(@workitem_pathname.parent.parent.parent.parent).not_to exist + expect(@bag_pathname).not_to exist + expect(@tarfile_pathname).not_to exist end end diff --git a/spec/services/create_workflow_service_spec.rb b/spec/services/create_workflow_service_spec.rb index fc3321c6..101d2dc5 100644 --- a/spec/services/create_workflow_service_spec.rb +++ b/spec/services/create_workflow_service_spec.rb @@ -5,9 +5,11 @@ RSpec.describe Dor::CreateWorkflowService do describe '.create_workflow' do subject(:create_workflow) { described_class.create_workflow(item, name: 'accessionWF') } + before do allow(item).to receive(:admin_policy_object).and_return(apo) end + let(:apo) { instantiate_fixture('druid:fg890hi1234', Dor::AdminPolicyObject) } let(:item) { instantiate_fixture('druid:ab123cd4567', Dor::Item) } @@ -20,9 +22,10 @@ end describe '#default_workflow_lane' do - let(:item) { instantiate_fixture('druid:ab123cd4567', Dor::Item) } subject { described_class.new(item).send(:default_workflow_lane) } + let(:item) { instantiate_fixture('druid:ab123cd4567', Dor::Item) } + context 'when the object has an APO' do before do allow(item).to receive(:admin_policy_object).and_return(apo) @@ -42,6 +45,7 @@ context 'without administrativeMetadata' do let(:apo) { instantiate_fixture('druid:fg890hi1234', Dor::AdminPolicyObject) } + before do allow(apo.datastreams).to receive(:[]).with('administrativeMetadata').and_return(nil) end @@ -64,6 +68,7 @@ i.admin_policy_object = instantiate_fixture('druid:zt570tx3016', Dor::AdminPolicyObject) end end + it { is_expected.to eq 'default' } end end diff --git a/spec/services/datastream_builder_spec.rb b/spec/services/datastream_builder_spec.rb index b81792d5..c9135f1a 100644 --- a/spec/services/datastream_builder_spec.rb +++ b/spec/services/datastream_builder_spec.rb @@ -10,14 +10,17 @@ class ProcessableItem < ActiveFedora::Base include Dor::Describable end - let(:required) { false } - let(:dsid) { 'descMetadata' } subject(:builder) do described_class.new(object: item, datastream: item.datastreams[dsid], force: true, required: required) end + let(:required) { false } + let(:dsid) { 'descMetadata' } + describe '#build' do # Paths to two files with the same content. + subject(:build) { builder.build } + let(:f1) { 'workspace/ab/123/cd/4567/ab123cd4567/metadata/descMetadata.xml' } let(:f2) { 'workspace/ab/123/cd/4567/desc_metadata.xml' } @@ -25,8 +28,6 @@ class ProcessableItem < ActiveFedora::Base let(:dm_fixture_xml) { read_fixture(f2) } # Path to fixture. let(:dm_builder_xml) { dm_fixture_xml.sub(/FROM_FILE/, 'FROM_BUILDER') } - subject(:build) { builder.build } - describe 'when the item is a collection (and the datastream is nil)' do let(:item) { Dor::Collection.new(pid: 'druid:bd185gs2256') } let(:dsid) { 'contentMetadata' } @@ -38,12 +39,14 @@ class ProcessableItem < ActiveFedora::Base context 'when operating on an Item' do before { item.contentMetadata.content = '' } + let(:item) { instantiate_fixture('druid:ab123cd4567', ProcessableItem) } context 'when the datastream exists as a file' do let(:time) { Time.now.utc } + before do - allow_any_instance_of(Dor::DatastreamBuilder).to receive(:find_metadata_file).and_return(dm_filename) + allow_any_instance_of(described_class).to receive(:find_metadata_file).and_return(dm_filename) allow(File).to receive(:read).and_return(dm_fixture_xml) end @@ -75,7 +78,7 @@ class ProcessableItem < ActiveFedora::Base context 'when the datastream does not exist as a file' do before do - allow_any_instance_of(Dor::DatastreamBuilder).to receive(:find_metadata_file).and_return(nil) + allow_any_instance_of(described_class).to receive(:find_metadata_file).and_return(nil) allow(item).to receive(:fetch_descMetadata_datastream).and_return(dm_builder_xml) end diff --git a/spec/services/digital_stacks_service_spec.rb b/spec/services/digital_stacks_service_spec.rb index 4222c562..e0c2698e 100644 --- a/spec/services/digital_stacks_service_spec.rb +++ b/spec/services/digital_stacks_service_spec.rb @@ -4,7 +4,7 @@ require 'moab/stanford' describe Dor::DigitalStacksService do - before(:each) do + before do @content_diff_reports = Pathname('spec').join('fixtures', 'content_diff_reports') inventory_diff_xml = @content_diff_reports.join('gj643zf5650-v3-v4.xml') @@ -28,9 +28,9 @@ delete_list = get_delete_list(content_diff) expect(delete_list.map { |file| file[0, 2] }).to eq([[:deleted, 'page-3.jpg']]) delete_list.each do |_change_type, filename, signature| - expect(Dor::DigitalStacksService).to receive(:delete_file).with(s.join(filename), signature) + expect(described_class).to receive(:delete_file).with(s.join(filename), signature) end - Dor::DigitalStacksService.remove_from_stacks(s, content_diff) + described_class.remove_from_stacks(s, content_diff) content_diff = @jq937jp0017_content_diff delete_list = get_delete_list(content_diff) @@ -40,9 +40,9 @@ [:modified, 'page-1.jpg'] ]) delete_list.each do |_change_type, filename, signature| - expect(Dor::DigitalStacksService).to receive(:delete_file).with(s.join(filename), signature) + expect(described_class).to receive(:delete_file).with(s.join(filename), signature) end - Dor::DigitalStacksService.remove_from_stacks(s, content_diff) + described_class.remove_from_stacks(s, content_diff) content_diff = @ng782rw8378_content_diff delete_list = get_delete_list(content_diff) @@ -52,9 +52,9 @@ [:deleted, 'SUB2_b2000_1.nii.gz'] ]) delete_list.each do |_change_type, filename, signature| - expect(Dor::DigitalStacksService).to receive(:delete_file).with(s.join(filename), signature) + expect(described_class).to receive(:delete_file).with(s.join(filename), signature) end - Dor::DigitalStacksService.remove_from_stacks(s, content_diff) + described_class.remove_from_stacks(s, content_diff) end end @@ -82,15 +82,15 @@ def get_delete_list(content_diff) ]) rename_list.each do |_change_type, oldname, newname, signature| tempname = signature.checksums.values.last - expect(Dor::DigitalStacksService).to receive(:rename_file).with(s.join(oldname), s.join(tempname), signature) - expect(Dor::DigitalStacksService).to receive(:rename_file).with(s.join(tempname), s.join(newname), signature) + expect(described_class).to receive(:rename_file).with(s.join(oldname), s.join(tempname), signature) + expect(described_class).to receive(:rename_file).with(s.join(tempname), s.join(newname), signature) end - Dor::DigitalStacksService.rename_in_stacks(s, content_diff) + described_class.rename_in_stacks(s, content_diff) content_diff = @jq937jp0017_content_diff rename_list = get_rename_list(content_diff) expect(rename_list.map { |file| file[0, 3] }).to eq([]) - expect{ Dor::DigitalStacksService.rename_in_stacks(s, content_diff) }.not_to raise_error + expect{ described_class.rename_in_stacks(s, content_diff) }.not_to raise_error content_diff = @ng782rw8378_content_diff rename_list = get_rename_list(content_diff) @@ -100,10 +100,10 @@ def get_delete_list(content_diff) ]) rename_list.each do |_change_type, oldname, newname, signature| tempname = signature.checksums.values.last - expect(Dor::DigitalStacksService).to receive(:rename_file).with(s.join(oldname), s.join(tempname), signature) - expect(Dor::DigitalStacksService).to receive(:rename_file).with(s.join(tempname), s.join(newname), signature) + expect(described_class).to receive(:rename_file).with(s.join(oldname), s.join(tempname), signature) + expect(described_class).to receive(:rename_file).with(s.join(tempname), s.join(newname), signature) end - Dor::DigitalStacksService.rename_in_stacks(s, content_diff) + described_class.rename_in_stacks(s, content_diff) end end @@ -126,17 +126,17 @@ def get_rename_list(content_diff) shelve_list = get_shelve_list(content_diff) expect(shelve_list.map { |file| file[0, 2] }).to eq([[:added, 'page-4.jpg']]) shelve_list.each do |_change_type, filename, signature| - expect(Dor::DigitalStacksService).to receive(:copy_file).with(w.join(filename), s.join(filename), signature) + expect(described_class).to receive(:copy_file).with(w.join(filename), s.join(filename), signature) end - Dor::DigitalStacksService.shelve_to_stacks(w, s, content_diff) + described_class.shelve_to_stacks(w, s, content_diff) content_diff = @jq937jp0017_content_diff shelve_list = get_shelve_list(content_diff) expect(shelve_list.map { |file| file[0, 2] }).to eq([[:modified, 'page-1.jpg']]) shelve_list.each do |_change_type, filename, signature| - expect(Dor::DigitalStacksService).to receive(:copy_file).with(w.join(filename), s.join(filename), signature) + expect(described_class).to receive(:copy_file).with(w.join(filename), s.join(filename), signature) end - Dor::DigitalStacksService.shelve_to_stacks(w, s, content_diff) + described_class.shelve_to_stacks(w, s, content_diff) content_diff = @ng782rw8378_content_diff shelve_list = get_shelve_list(content_diff) @@ -146,9 +146,9 @@ def get_rename_list(content_diff) [:copyadded, 'SUB2_b2000_1.bvals'] ]) shelve_list.each do |_change_type, filename, signature| - expect(Dor::DigitalStacksService).to receive(:copy_file).with(w.join(filename), s.join(filename), signature) + expect(described_class).to receive(:copy_file).with(w.join(filename), s.join(filename), signature) end - Dor::DigitalStacksService.shelve_to_stacks(w, s, content_diff) + described_class.shelve_to_stacks(w, s, content_diff) end end @@ -176,49 +176,49 @@ def get_shelve_list(content_diff) end describe '.delete_file' do - it 'should delete a file, but only if it exists and matches the expected signature' do + it 'deletes a file, but only if it exists and matches the expected signature' do # if file does not exist file_pathname = @tmpdir.join('delete-me.txt') moab_signature = Moab::FileSignature.new - expect(file_pathname.exist?).to be_falsey + expect(file_pathname).not_to exist expect(Dor::DigitalStacksService.delete_file(file_pathname, moab_signature)).to be_falsey # if file exists, but has unexpected signature FileUtils.touch(file_pathname.to_s) - expect(file_pathname.exist?).to be_truthy + expect(file_pathname).to exist expect(Dor::DigitalStacksService.delete_file(file_pathname, moab_signature)).to be_falsey - expect(file_pathname.exist?).to be_truthy + expect(file_pathname).to exist # if file exists, and has expected signature moab_signature = Moab::FileSignature.new.signature_from_file(file_pathname) expect(Dor::DigitalStacksService.delete_file(file_pathname, moab_signature)).to be_truthy - expect(file_pathname.exist?).to be_falsey + expect(file_pathname).not_to exist end end describe '.rename_file' do - it 'should rename a file, but only if it exists and has the expected signature' do + it 'renames a file, but only if it exists and has the expected signature' do # if file does not exist old_pathname = @tmpdir.join('rename-me.txt') new_pathname = @tmpdir.join('new-name.txt') moab_signature = Moab::FileSignature.new - expect(old_pathname.exist?).to be_falsey - expect(new_pathname.exist?).to be_falsey + expect(old_pathname).not_to exist + expect(new_pathname).not_to exist expect(Dor::DigitalStacksService.rename_file(old_pathname, new_pathname, moab_signature)).to be_falsey # if file exists, but has unexpected signature FileUtils.touch(old_pathname.to_s) - expect(old_pathname.exist?).to be_truthy + expect(old_pathname).to exist expect(Dor::DigitalStacksService.rename_file(old_pathname, new_pathname, moab_signature)).to be_falsey - expect(old_pathname.exist?).to be_truthy - expect(new_pathname.exist?).to be_falsey + expect(old_pathname).to exist + expect(new_pathname).not_to exist # if file exists, and has expected signature moab_signature = Moab::FileSignature.new.signature_from_file(old_pathname) expect(Dor::DigitalStacksService.rename_file(old_pathname, new_pathname, moab_signature)).to be_truthy - expect(old_pathname.exist?).to be_falsey - expect(new_pathname.exist?).to be_truthy + expect(old_pathname).not_to exist + expect(new_pathname).to exist end end describe '.copy_file' do - it 'should copy a file to stacks, but only if it does not yet exist with the expected signature' do + it 'copies a file to stacks, but only if it does not yet exist with the expected signature' do # if file does not exist in stacks workspace_pathname = @tmpdir.join('copy-me.txt') stacks_pathname = @tmpdir.join('stacks-name.txt') @@ -226,19 +226,19 @@ def get_shelve_list(content_diff) FileUtils.chmod 0o640, workspace_pathname.to_s expect(File::Stat.new(workspace_pathname.to_s).mode.to_s(8)).to eq('100640') moab_signature = Moab::FileSignature.new.signature_from_file(workspace_pathname) - expect(workspace_pathname.exist?).to be_truthy - expect(stacks_pathname.exist?).to be_falsey + expect(workspace_pathname).to exist + expect(stacks_pathname).not_to exist expect(Dor::DigitalStacksService.copy_file(workspace_pathname, stacks_pathname, moab_signature)).to be_truthy # if file exists, and has expected signature - expect(workspace_pathname.exist?).to be_truthy - expect(stacks_pathname.exist?).to be_truthy + expect(workspace_pathname).to exist + expect(stacks_pathname).to exist expect(File::Stat.new(stacks_pathname.to_s).mode.to_s(8)).to eq('100644') moab_signature = Moab::FileSignature.new.signature_from_file(stacks_pathname) expect(Dor::DigitalStacksService.copy_file(workspace_pathname, stacks_pathname, moab_signature)).to be_falsey # if file exists, but has unexpected signature moab_signature = Moab::FileSignature.new - expect(workspace_pathname.exist?).to be_truthy - expect(stacks_pathname.exist?).to be_truthy + expect(workspace_pathname).to exist + expect(stacks_pathname).to exist expect(Dor::DigitalStacksService.copy_file(workspace_pathname, stacks_pathname, moab_signature)).to be_truthy end end @@ -262,7 +262,7 @@ def get_shelve_list(content_diff) File.open(File.join(item_root, 'somefile'), 'w') { |f| f.write 'junk' } Dor::DigitalStacksService.prune_stacks_dir 'druid:aa123bb4567' item_pathname = Pathname item_root - expect(File).to_not exist(item_pathname) - expect(File).to_not exist(item_pathname.parent) + expect(File).not_to exist(item_pathname) + expect(File).not_to exist(item_pathname.parent) end end diff --git a/spec/services/dublin_core_service_spec.rb b/spec/services/dublin_core_service_spec.rb index 97c436a7..ea6e0d2e 100644 --- a/spec/services/dublin_core_service_spec.rb +++ b/spec/services/dublin_core_service_spec.rb @@ -3,10 +3,10 @@ require 'spec_helper' RSpec.describe Dor::DublinCoreService do - let(:item) { instantiate_fixture('druid:ab123cd4567', Dor::Item) } - subject(:service) { described_class.new(item) } + let(:item) { instantiate_fixture('druid:ab123cd4567', Dor::Item) } + describe '#ng_xml' do subject(:xml) { service.ng_xml } diff --git a/spec/services/indexing_service_spec.rb b/spec/services/indexing_service_spec.rb index f640314c..17a7f45f 100644 --- a/spec/services/indexing_service_spec.rb +++ b/spec/services/indexing_service_spec.rb @@ -3,21 +3,22 @@ require 'spec_helper' describe Dor::IndexingService do - before(:each) { stub_config } - after(:each) { unstub_config } + before { stub_config } + + after { unstub_config } describe '#generate_index_logger' do - before :each do + before do @mock_log_msg = 'something noteworthy' end - after :each do + after do File.delete Dor::Config.indexing_svc.log if File.exist? Dor::Config.indexing_svc.log end - it 'should call entry_id_block for each logging event, and include the result in the logging statement' do + it 'calls entry_id_block for each logging event, and include the result in the logging statement' do mock_req_id_ctr = 0 - test_index_logger = Dor::IndexingService.generate_index_logger do + test_index_logger = described_class.generate_index_logger do # this entry_id_block returns next value from a counter each time its called mock_req_id_ctr += 1 # ruby has no [post-]increment operator end @@ -41,15 +42,15 @@ expect(mock_req_id_ctr).to eq(mock_log_messages.length) end - it 'should log the default entry_id if entry_id_block is nil' do - test_index_logger = Dor::IndexingService.generate_index_logger + it 'logs the default entry_id if entry_id_block is nil' do + test_index_logger = described_class.generate_index_logger test_index_logger.info @mock_log_msg last_log_line = open(Dor::Config.indexing_svc.log).read.split("\n")[-1] expect(last_log_line).to match(/\[---\] \[.*\] #{@mock_log_msg}$/) end - it 'should log the default entry_id if entry_id_block throws a StandardError' do - test_index_logger = Dor::IndexingService.generate_index_logger do + it 'logs the default entry_id if entry_id_block throws a StandardError' do + test_index_logger = described_class.generate_index_logger do raise ZeroDivisionError, 'whoops' end test_index_logger.info @mock_log_msg @@ -58,159 +59,160 @@ expect(last_log_line).to match(/\[---\] \[.*\] #{@mock_log_msg}$/) end - it "should not trap the exception if it's not StandardError" do + it "does not trap the exception if it's not StandardError" do stack_overflow_ex = SystemStackError.new 'really? here?' - test_index_logger = Dor::IndexingService.generate_index_logger { raise stack_overflow_ex } + test_index_logger = described_class.generate_index_logger { raise stack_overflow_ex } expect { test_index_logger.info @mock_log_msg }.to raise_error(stack_overflow_ex) end end describe '#default_index_logger' do - it 'should call generate_index_logger, and memoize the result' do + it 'calls generate_index_logger, and memoize the result' do mock_default_logger = double(Logger) - expect(Dor::IndexingService).to receive(:generate_index_logger).once.and_return(mock_default_logger) - expect(Dor::IndexingService.default_index_logger).to eq(mock_default_logger) - expect(Dor::IndexingService.default_index_logger).to eq(mock_default_logger) + expect(described_class).to receive(:generate_index_logger).once.and_return(mock_default_logger) + expect(described_class.default_index_logger).to eq(mock_default_logger) + expect(described_class.default_index_logger).to eq(mock_default_logger) end end describe '#reindex_pid_list' do - before :each do + before do @mock_solr_conn = double(ActiveFedora.solr.conn) end - it 'should reindex the pids and not commit by default' do + it 'reindexes the pids and not commit by default' do pids = [1..10].map(&:to_s) - pids.each { |pid| expect(Dor::IndexingService).to receive(:reindex_pid).with(pid, raise_errors: false) } - expect(@mock_solr_conn).to_not receive(:commit) - Dor::IndexingService.reindex_pid_list pids + pids.each { |pid| expect(described_class).to receive(:reindex_pid).with(pid, raise_errors: false) } + expect(@mock_solr_conn).not_to receive(:commit) + described_class.reindex_pid_list pids end - it 'should reindex the pids and commit if should_commit is true' do + it 'reindexes the pids and commit if should_commit is true' do pids = [1..10].map(&:to_s) - pids.each { |pid| expect(Dor::IndexingService).to receive(:reindex_pid).with(pid, raise_errors: false) } + pids.each { |pid| expect(described_class).to receive(:reindex_pid).with(pid, raise_errors: false) } expect(ActiveFedora.solr).to receive(:conn).and_return(@mock_solr_conn) expect(@mock_solr_conn).to receive(:commit) - Dor::IndexingService.reindex_pid_list pids, true + described_class.reindex_pid_list pids, true end - it 'should proceed despite individual indexing failures' do + it 'proceeds despite individual indexing failures' do pids = (1..10).map(&:to_s) - pids.each { |pid| expect(Dor::IndexingService).to receive(:reindex_pid).with(pid, raise_errors: false) } + pids.each { |pid| expect(described_class).to receive(:reindex_pid).with(pid, raise_errors: false) } expect(ActiveFedora.solr).to receive(:conn).and_return(@mock_solr_conn) expect(@mock_solr_conn).to receive(:commit) - Dor::IndexingService.reindex_pid_list pids, true + described_class.reindex_pid_list pids, true end end describe '#reindex_object' do - before :each do + before do @mock_pid = 'unique_id' @mock_obj = double(Dor::Item) @mock_solr_doc = { id: @mock_pid, text_field_tesim: 'a field to be searched' } end - it 'should reindex the object via Dor::SearchService' do + it 'reindexes the object via Dor::SearchService' do expect(@mock_obj).to receive(:to_solr).and_return(@mock_solr_doc) expect(Dor::SearchService.solr).to receive(:add).with(hash_including(id: @mock_pid), {}) - ret_val = Dor::IndexingService.reindex_object @mock_obj + ret_val = described_class.reindex_object @mock_obj expect(ret_val).to eq(@mock_solr_doc) end it 'passes add_attributes options to solr' do expect(@mock_obj).to receive(:to_solr).and_return(@mock_solr_doc) expect(Dor::SearchService.solr).to receive(:add).with(hash_including(id: @mock_pid), add_attributes: { commitWithin: 10 }) - ret_val = Dor::IndexingService.reindex_object @mock_obj, add_attributes: { commitWithin: 10 } + ret_val = described_class.reindex_object @mock_obj, add_attributes: { commitWithin: 10 } expect(ret_val).to eq(@mock_solr_doc) end end describe '#reindex_pid' do - before :each do + before do @mock_pid = 'unique_id' @mock_default_logger = double(Logger) @mock_obj = double(Dor::Item) @mock_solr_doc = { id: @mock_pid, text_field_tesim: 'a field to be searched' } - expect(Dor::IndexingService).to receive(:default_index_logger).at_least(:once).and_return(@mock_default_logger) + expect(described_class).to receive(:default_index_logger).at_least(:once).and_return(@mock_default_logger) end it 'handles old, primitive arguments' do expect(Dor).to receive(:load_instance).with(@mock_pid).and_raise(ActiveFedora::ObjectNotFoundError) expect(@mock_default_logger).to receive(:warn).with("failed to update index for #{@mock_pid}, object not found in Fedora") - expect(Dor::IndexingService).to receive(:warn) - expect { Dor::IndexingService.reindex_pid(@mock_pid, nil, false) }.to_not raise_error + expect(described_class).to receive(:warn) + expect { described_class.reindex_pid(@mock_pid, nil, false) }.not_to raise_error end - it 'should reindex the object via Dor::IndexingService.reindex_pid and log success' do + it 'reindexes the object via Dor::IndexingService.reindex_pid and log success' do expect(Dor).to receive(:load_instance).with(@mock_pid).and_return(@mock_obj) - expect(Dor::IndexingService).to receive(:reindex_object).with(@mock_obj, {}).and_return(@mock_solr_doc) + expect(described_class).to receive(:reindex_object).with(@mock_obj, {}).and_return(@mock_solr_doc) expect(@mock_default_logger).to receive(:info).with(/successfully updated index for #{@mock_pid}.*metrics.*load_instance.*to_solr/) - ret_val = Dor::IndexingService.reindex_pid @mock_pid + ret_val = described_class.reindex_pid @mock_pid expect(ret_val).to eq(@mock_solr_doc) end - it 'should log the right thing if an object is not found, then re-raise the exception by default' do + it 'logs the right thing if an object is not found, then re-raise the exception by default' do expect(Dor).to receive(:load_instance).with(@mock_pid).and_raise(ActiveFedora::ObjectNotFoundError) expect(@mock_default_logger).to receive(:warn).with("failed to update index for #{@mock_pid}, object not found in Fedora") - expect { Dor::IndexingService.reindex_pid(@mock_pid) }.to raise_error(ActiveFedora::ObjectNotFoundError) + expect { described_class.reindex_pid(@mock_pid) }.to raise_error(ActiveFedora::ObjectNotFoundError) end - it 'should log the right thing if an object is not found, but swallow the exception when should_raise_errors is false' do + it 'logs the right thing if an object is not found, but swallow the exception when should_raise_errors is false' do expect(Dor).to receive(:load_instance).with(@mock_pid).and_raise(ActiveFedora::ObjectNotFoundError) expect(@mock_default_logger).to receive(:warn).with("failed to update index for #{@mock_pid}, object not found in Fedora") - expect { Dor::IndexingService.reindex_pid(@mock_pid, raise_errors: false) }.to_not raise_error + expect { described_class.reindex_pid(@mock_pid, raise_errors: false) }.not_to raise_error end - it "should log the right thing if there's an unexpected error, then re-raise the exception by default" do + it "logs the right thing if there's an unexpected error, then re-raise the exception by default" do unexpected_err = ZeroDivisionError.new "how'd that happen?" expect(Dor).to receive(:load_instance).with(@mock_pid).and_raise(unexpected_err) expect(@mock_default_logger).to receive(:warn).with(start_with("failed to update index for #{@mock_pid}, unexpected StandardError, see main app log: [")) - expect { Dor::IndexingService.reindex_pid(@mock_pid) }.to raise_error(unexpected_err) + expect { described_class.reindex_pid(@mock_pid) }.to raise_error(unexpected_err) end - it "should log the right thing if there's an unexpected Exception that's not StandardError, then re-raise the exception, even when should_raise_errors is false" do + it "logs the right thing if there's an unexpected Exception that's not StandardError, then re-raise the exception, even when should_raise_errors is false" do stack_overflow_ex = SystemStackError.new "didn't see that one coming... maybe you shouldn't have self-referential collections?" expect(Dor).to receive(:load_instance).with(@mock_pid).and_raise(stack_overflow_ex) # TODO: fix this expectation and the code it's testing, as per https://github.com/sul-dlss/dor-services/issues/156 # expect(@mock_default_logger).to receive(:error).with(start_with("failed to update index for #{@mock_pid}, unexpected Exception, see main app log: [")) - expect { Dor::IndexingService.reindex_pid(@mock_pid, raise_errors: false) }.to raise_error(stack_overflow_ex) + expect { described_class.reindex_pid(@mock_pid, raise_errors: false) }.to raise_error(stack_overflow_ex) end end + describe '#reindex_pid_remotely' do - before :each do + before do @mock_pid = 'druid:aa111bb2222' @mock_default_logger = double(Logger) - expect(Dor::IndexingService).to receive(:default_index_logger).at_least(:once).and_return(@mock_default_logger) + expect(described_class).to receive(:default_index_logger).at_least(:once).and_return(@mock_default_logger) end it 'calls a remote service to reindex' do expect(RestClient).to receive(:post).and_return(double) expect(@mock_default_logger).to receive(:info).with(/successfully updated index for druid:/) - Dor::IndexingService.reindex_pid_remotely(@mock_pid) + described_class.reindex_pid_remotely(@mock_pid) end it 'calls a remote service to reindex even without a druid: prefix' do expect(RestClient).to receive(:post).and_return(double) expect(@mock_default_logger).to receive(:info).with(/successfully updated index for druid:/) - Dor::IndexingService.reindex_pid_remotely('aa111bb2222') + described_class.reindex_pid_remotely('aa111bb2222') end it 'raises a ReindexRemotelyError exception in cases of predictable failures' do expect(RestClient).to receive(:post).exactly(3).and_raise(RestClient::Exception.new(double)) expect(@mock_default_logger).to receive(:error).with(/failed to reindex/) - expect { Dor::IndexingService.reindex_pid_remotely(@mock_pid) }.to raise_error(Dor::IndexingService::ReindexError) + expect { described_class.reindex_pid_remotely(@mock_pid) }.to raise_error(Dor::IndexingService::ReindexError) end it 'raises a ReindexRemotelyError exception in cases of remote host is down' do expect(RestClient).to receive(:post).exactly(3).and_raise(Errno::ECONNREFUSED) expect(@mock_default_logger).to receive(:error).with(/failed to reindex/) - expect { Dor::IndexingService.reindex_pid_remotely(@mock_pid) }.to raise_error(Dor::IndexingService::ReindexError) + expect { described_class.reindex_pid_remotely(@mock_pid) }.to raise_error(Dor::IndexingService::ReindexError) end it 'raises other exceptions in cases of unpredictable failures' do expect(RestClient).to receive(:post).and_raise(RuntimeError.new) expect(@mock_default_logger).to receive(:error).with(/failed to reindex/) - expect { Dor::IndexingService.reindex_pid_remotely(@mock_pid) }.to raise_error(RuntimeError) + expect { described_class.reindex_pid_remotely(@mock_pid) }.to raise_error(RuntimeError) end end end diff --git a/spec/services/merge_service_spec.rb b/spec/services/merge_service_spec.rb index 621e58a7..7ee16f8e 100644 --- a/spec/services/merge_service_spec.rb +++ b/spec/services/merge_service_spec.rb @@ -36,20 +36,20 @@ def create_tempfile(path, filename) end end - before(:each) do + before do Dor::Config.push! do |config| config.stacks.local_workspace_root workspace config.sdr.local_workspace_root workspace end end - after(:each) do + after do unstub_config FileUtils.remove_entry workspace end describe '#copy_workspace_content' do - before(:each) do + before do primary.contentMetadata.content = <<-XML @@ -96,12 +96,12 @@ def create_tempfile(path, filename) create_tempfile sec_druid_tree.path, 'image_a.jp2' expect(Deprecation).to receive(:warn) - ms = Dor::MergeService.new primary_pid, [secondary_pid], 'some tag' + ms = described_class.new primary_pid, [secondary_pid], 'some tag' ms.copy_workspace_content druid_primary = DruidTools::Druid.new primary_pid, Dor::Config.stacks.local_workspace_root - expect(druid_primary.find_content('image_a.jp2')).to_not be_nil - expect(druid_primary.find_content('image_a_2.jp2')).to_not be_nil + expect(druid_primary.find_content('image_a.jp2')).not_to be_nil + expect(druid_primary.find_content('image_a_2.jp2')).not_to be_nil expect(druid_primary.find_content('image_a_2.jp2')).to match(/image_a_2.jp2/) end end diff --git a/spec/services/metadata_service_spec.rb b/spec/services/metadata_service_spec.rb index 03734e40..67b35704 100644 --- a/spec/services/metadata_service_spec.rb +++ b/spec/services/metadata_service_spec.rb @@ -7,7 +7,7 @@ @specdir = File.join(File.dirname(__FILE__), '..') end - it 'should register a new metadata handler' do + it 'registers a new metadata handler' do handler = Class.new do def fetch(_prefix, identifier) identifier @@ -21,23 +21,23 @@ def prefixes ['test'] end end - expect(Dor::MetadataService.register(handler)).to be_a(handler) - expect(Dor::MetadataService.known_prefixes).to include(:test) - expect(Dor::MetadataService.fetch('test:12345')).to eq('12345') - expect(Dor::MetadataService.label_for('test:12345')).to eq('title: 12345') + expect(described_class.register(handler)).to be_a(handler) + expect(described_class.known_prefixes).to include(:test) + expect(described_class.fetch('test:12345')).to eq('12345') + expect(described_class.label_for('test:12345')).to eq('title: 12345') end - it 'should raise an exception if an invalid handler is registered' do + it 'raises an exception if an invalid handler is registered' do handler = Class.new - expect { Dor::MetadataService.register(handler) }.to raise_exception(TypeError) + expect { described_class.register(handler) }.to raise_exception(TypeError) end - it 'should raise an exception if an unknown metadata type is requested' do - expect { Dor::MetadataService.fetch('foo:bar') }.to raise_exception(Dor::MetadataError) + it 'raises an exception if an unknown metadata type is requested' do + expect { described_class.fetch('foo:bar') }.to raise_exception(Dor::MetadataError) end describe 'Symphony handler' do - before :each do + before do @mods = File.read(File.join(@specdir, 'fixtures', 'mods_record.xml')) @mock_resource = double('catalog-resource', get: @mods) allow(@mock_resource).to receive(:[]).and_return(@mock_resource) @@ -46,19 +46,19 @@ def prefixes Dor::Config.metadata.catalog.pass).and_return(@mock_resource) end - it 'should fetch a record based on barcode' do + it 'fetches a record based on barcode' do expect(@mock_resource).to receive(:[]).with('?barcode=12345') - expect(Dor::MetadataService.fetch('barcode:12345')).to be_equivalent_to(@mods) + expect(described_class.fetch('barcode:12345')).to be_equivalent_to(@mods) end - it 'should fetch a record based on catkey' do + it 'fetches a record based on catkey' do expect(@mock_resource).to receive(:[]).with('?catkey=12345') - expect(Dor::MetadataService.fetch('catkey:12345')).to be_equivalent_to(@mods) + expect(described_class.fetch('catkey:12345')).to be_equivalent_to(@mods) end - it 'should return the MODS title as the label' do + it 'returns the MODS title as the label' do expect(@mock_resource).to receive(:[]).with('?barcode=12345') - expect(Dor::MetadataService.label_for('barcode:12345')).to eq('The isomorphism and thermal properties of the feldspars') + expect(described_class.label_for('barcode:12345')).to eq('The isomorphism and thermal properties of the feldspars') end end end diff --git a/spec/services/ontology_spec.rb b/spec/services/ontology_spec.rb index 126ce658..f70c0dbd 100644 --- a/spec/services/ontology_spec.rb +++ b/spec/services/ontology_spec.rb @@ -10,21 +10,25 @@ describe '#key' do subject { term.key } + it { is_expected.to eq 'foo' } end describe '#label' do subject { term.label } + it { is_expected.to eq 'Foo is a placeholder' } end describe '#uri' do subject { term.uri } + it { is_expected.to eq 'http://example.com/foo' } end describe '#deprecation_warning' do subject { term.deprecation_warning } + it { is_expected.to be_nil } end end diff --git a/spec/services/public_desc_metadata_service_spec.rb b/spec/services/public_desc_metadata_service_spec.rb index 4ab3dcfc..154f5d43 100644 --- a/spec/services/public_desc_metadata_service_spec.rb +++ b/spec/services/public_desc_metadata_service_spec.rb @@ -3,10 +3,12 @@ require 'spec_helper' RSpec.describe Dor::PublicDescMetadataService do + subject(:service) { described_class.new(obj) } + before { stub_config } + after { unstub_config } - subject(:service) { described_class.new(obj) } let(:obj) { instantiate_fixture('druid:ab123cd4567', Dor::Item) } describe '#ng_xml' do @@ -363,6 +365,7 @@ node.parent.remove end end + it 'adds a relatedItem node for the collection' do collections = public_mods.search('//mods:relatedItem/mods:typeOfResource[@collection=\'yes\']') collection_title = public_mods.search('//mods:relatedItem/mods:titleInfo/mods:title') diff --git a/spec/services/public_xml_service_spec.rb b/spec/services/public_xml_service_spec.rb index 4ce0a5e5..ca19153d 100644 --- a/spec/services/public_xml_service_spec.rb +++ b/spec/services/public_xml_service_spec.rb @@ -3,10 +3,10 @@ require 'spec_helper' RSpec.describe Dor::PublicXmlService do - let(:item) { instantiate_fixture('druid:ab123cd4567', Dor::Item) } - subject(:service) { described_class.new(item) } + let(:item) { instantiate_fixture('druid:ab123cd4567', Dor::Item) } + describe '#to_xml' do subject(:xml) { service.to_xml } @@ -68,6 +68,7 @@ allow(OpenURI).to receive(:open_uri).with('https://purl-test.stanford.edu/ab123cd4567.xml').and_return('') WebMock.disable_net_connect! end + let(:ng_xml) { Nokogiri::XML(xml) } context 'when there are no release tags' do @@ -83,6 +84,7 @@ context 'produces xml with' do let(:now) { Time.now.utc } + before do allow(Time).to receive(:now).and_return(now) end @@ -117,6 +119,7 @@ XML end + it 'include contentMetadata' do expect(ng_xml.at_xpath('/publicObject/contentMetadata')).to be end @@ -223,6 +226,7 @@ EOXML end + before do item.contentMetadata.content = <<-EOXML @@ -252,6 +256,7 @@ EOXML end + it 'raises an error' do # generate publicObject XML and verify that the content metadata portion is invalid expect { xml }.to raise_error(Dor::DataError) diff --git a/spec/services/publish_metadata_service_spec.rb b/spec/services/publish_metadata_service_spec.rb index 883a3393..051940cb 100644 --- a/spec/services/publish_metadata_service_spec.rb +++ b/spec/services/publish_metadata_service_spec.rb @@ -16,6 +16,7 @@ class PublishableItem < ActiveFedora::Base RSpec.describe Dor::PublishMetadataService do before { stub_config } + after { unstub_config } let(:item) do @@ -75,7 +76,7 @@ class PublishableItem < ActiveFedora::Base stub_request(:delete, 'example.com/purl/purls/ab123cd4567') end - after(:each) do + after do FileUtils.remove_entry purl_root Dor::Config.pop! end @@ -94,11 +95,11 @@ class PublishableItem < ActiveFedora::Base # create druid tree and dummy content in purl root druid1 = DruidTools::Druid.new item.pid, purl_root druid1.mkdir - expect(druid1.deletes_record_exists?).to be_falsey # deletes record not there yet + expect(druid1).not_to be_deletes_record_exists # deletes record not there yet File.open(File.join(druid1.path, 'tmpfile'), 'w') { |f| f.write 'junk' } service.publish - expect(File).to_not exist(druid1.path) # it should now be gone - expect(druid1.deletes_record_exists?).to be_truthy # deletes record created + expect(File).not_to exist(druid1.path) # it should now be gone + expect(druid1).to be_deletes_record_exists # deletes record created end end @@ -125,13 +126,13 @@ class PublishableItem < ActiveFedora::Base context 'with an item' do before do - expect_any_instance_of(Dor::PublishMetadataService).to receive(:transfer_to_document_store).with(/ @@ -304,7 +316,7 @@ it 'truncates label if >= 255 chars' do # expect(Dor.logger).to receive(:warn).at_least(:once) @params[:label] = 'a' * 256 - obj = Dor::RegistrationService.register_object(@params) + obj = described_class.register_object(@params) expect(obj.label).to eq('a' * 254) end @@ -312,13 +324,13 @@ expect(Dor::CreateWorkflowService).to receive(:create_workflow).with(Dor::Item, name: 'digitizationWF', create_ds: false, priority: 50) @params[:workflow_priority] = 50 @params[:initiate_workflow] = 'digitizationWF' - Dor::RegistrationService.register_object(@params) + described_class.register_object(@params) end end # context common cases end context '#create_from_request' do - before :each do + before do allow(Dor::SuriService).to receive(:mint_id).and_return(@pid) allow(Dor::SearchService).to receive(:query_by_id).and_return([]) allow(ActiveFedora::Base).to receive(:connection_for_pid).and_return(@mock_repo) @@ -335,25 +347,25 @@ end it 'source_id may have one or more colons' do - expect { Dor::RegistrationService.create_from_request(@params) }.not_to raise_error + expect { described_class.create_from_request(@params) }.not_to raise_error @params[:source_id] = 'sul:SOMETHING-http://www.example.org' - expect { Dor::RegistrationService.create_from_request(@params) }.not_to raise_error + expect { described_class.create_from_request(@params) }.not_to raise_error end it 'source_id must have at least one colon' do # Execution gets into IdentityMetadataDS code for specific error @params[:source_id] = 'no-colon' exp_regex = /Source ID must follow the format 'namespace:value'/ - expect { Dor::RegistrationService.create_from_request(@params) }.to raise_error(ArgumentError, exp_regex) + expect { described_class.create_from_request(@params) }.to raise_error(ArgumentError, exp_regex) end it 'other_id may have any number of colons' do @params[:other_id] = 'no-colon' - expect { Dor::RegistrationService.create_from_request(@params) }.not_to raise_error + expect { described_class.create_from_request(@params) }.not_to raise_error @params[:other_id] = 'catkey:000' - expect { Dor::RegistrationService.create_from_request(@params) }.not_to raise_error + expect { described_class.create_from_request(@params) }.not_to raise_error @params[:other_id] = 'catkey:oop:sie' - expect { Dor::RegistrationService.create_from_request(@params) }.not_to raise_error + expect { described_class.create_from_request(@params) }.not_to raise_error end end # create_from_request end diff --git a/spec/services/release_tag_service_spec.rb b/spec/services/release_tag_service_spec.rb index 9021bf8f..aa159cf7 100644 --- a/spec/services/release_tag_service_spec.rb +++ b/spec/services/release_tag_service_spec.rb @@ -4,6 +4,7 @@ RSpec.describe Dor::ReleaseTagService, :vcr do before { stub_config } + after { Dor::Config.pop! } let(:item) { instantiate_fixture('druid:bb004bn8654', Dor::Item) } @@ -23,11 +24,13 @@ describe '#newest_release_tag_in_an_array' do subject { releases.send(:newest_release_tag_in_an_array, dummy_tags) } + it { is_expected.to eq dummy_tags[1] } end describe '#newest_release_tag' do subject { releases.newest_release_tag(dummy_hash) } + let(:dummy_hash) { { 'Revs' => dummy_tags, 'FRDA' => dummy_tags } } it { is_expected.to eq('Revs' => dummy_tags[1], 'FRDA' => dummy_tags[1]) } @@ -96,6 +99,7 @@ # If these tests fail, check not just the logic, but also the specific tags describe 'handling tags on objects and determining release status' do let(:item) { instantiate_fixture('druid:vs298kg2555', Dor::Item) } + it 'uses only the most recent self tag to determine if an item is released, with no release tags on the collection' do VCR.use_cassette('should_use_only_the_most_recent_self_tag_to_determine_if_an_item_is_released_with_no_release_tags_on_the_collection') do expect(releases.released_for(skip_live_purl: false)['Kurita']['release']).to be_truthy @@ -147,6 +151,7 @@ describe '#form_purl_url' do subject { releases.send(:form_purl_url) } + it { is_expected.to eq "https://#{Dor::Config.stacks.document_cache_host}/bb004bn8654.xml" } end diff --git a/spec/services/reset_workspace_service_spec.rb b/spec/services/reset_workspace_service_spec.rb index ba1a37a6..59e5860e 100644 --- a/spec/services/reset_workspace_service_spec.rb +++ b/spec/services/reset_workspace_service_spec.rb @@ -3,9 +3,9 @@ require 'spec_helper' describe Dor::ResetWorkspaceService do - before(:each) { stub_config } + before { stub_config } - before(:each) do + before do @workspace_root = Dor::Config.stacks.local_workspace_root @worspace_pathname = Pathname(@workspace_root) @export_root = Dor::Config.sdr.local_export_home @@ -13,7 +13,7 @@ end describe 'reset_workspace_druid_tree' do - before(:each) do + before do @druid = 'druid:am111am1111' @druid_tree_path = "#{@workspace_root}/am/111/am/1111/am111am1111" @@ -24,40 +24,40 @@ FileUtils.mv(@druid_tree_path + '_v2', @druid_tree_path) if File.exist?(@druid_tree_path + '_v2') end - it 'should rename the directory tree with the directory not empty' do - Dor::ResetWorkspaceService.reset_workspace_druid_tree(@druid, '2', @workspace_root) - expect(File.exist?("#{@druid_tree_path}_v2")).to be_truthy - expect(File.exist?(@druid_tree_path)).to be_falsey + after do + # To reset the environment to its original format + FileUtils.mv(@druid_tree_path + '_v2', @druid_tree_path) if File.exist?(@druid_tree_path + '_v2') + FileUtils.mv("#{@archived_druid_tree_path}_v3", @archived_druid_tree_path) if File.exist?(@archived_druid_tree_path + '_v3') end - it 'should do nothing with truncated druid' do - truncated_druid = 'druid:tr111tr1111' - Dor::ResetWorkspaceService.reset_workspace_druid_tree(truncated_druid, '2', @workspace_root) - truncated_druid_tree_path = "#{@workspace_root}/tr/111/tr/1111/" - expect(File.exist?("#{truncated_druid_tree_path}_v2")).to be_falsey - expect(File.exist?(truncated_druid_tree_path)).to be_truthy + it 'renames the directory tree with the directory not empty' do + described_class.reset_workspace_druid_tree(@druid, '2', @workspace_root) + expect(File).to exist("#{@druid_tree_path}_v2") + expect(File).not_to exist(@druid_tree_path) end - it 'should throw an error if the directory is already archived' do - expect{ Dor::ResetWorkspaceService.reset_workspace_druid_tree(@archived_druid, '2', @workspace_root) }.to raise_error(RuntimeError) + it 'does nothing with truncated druid' do + truncated_druid = 'druid:tr111tr1111' + described_class.reset_workspace_druid_tree(truncated_druid, '2', @workspace_root) + truncated_druid_tree_path = "#{@workspace_root}/tr/111/tr/1111/" + expect(File).not_to exist("#{truncated_druid_tree_path}_v2") + expect(File).to exist(truncated_druid_tree_path) end - it "should archived the current directory even if there is an older archived that hasn't been cleaned up" do - Dor::ResetWorkspaceService.reset_workspace_druid_tree(@archived_druid, '3', @workspace_root) - expect(File.exist?("#{@archived_druid_tree_path}_v2")).to be_truthy - expect(File.exist?("#{@archived_druid_tree_path}_v3")).to be_truthy - expect(File.exist?(@archived_druid_tree_path.to_s)).to be_falsey + it 'throws an error if the directory is already archived' do + expect{ described_class.reset_workspace_druid_tree(@archived_druid, '2', @workspace_root) }.to raise_error(RuntimeError) end - after(:each) do - # To reset the environment to its original format - FileUtils.mv(@druid_tree_path + '_v2', @druid_tree_path) if File.exist?(@druid_tree_path + '_v2') - FileUtils.mv("#{@archived_druid_tree_path}_v3", @archived_druid_tree_path) if File.exist?(@archived_druid_tree_path + '_v3') + it "archiveds the current directory even if there is an older archived that hasn't been cleaned up" do + described_class.reset_workspace_druid_tree(@archived_druid, '3', @workspace_root) + expect(File).to exist("#{@archived_druid_tree_path}_v2") + expect(File).to exist("#{@archived_druid_tree_path}_v3") + expect(File).not_to exist(@archived_druid_tree_path.to_s) end end describe 'reset_export_bag' do - before(:each) do + before do id = 'zb871zd0767' @druid = "druid:#{id}" @bag_path = "#{@export_root}/#{id}" @@ -67,27 +67,27 @@ # FileUtils.mv("#{@bag_path}_v2.tar", @bag_path+".tar") if File.exists?(@bag_path+"_v2.tar") end - it 'should rename the export bags directory and tar files' do - Dor::ResetWorkspaceService.reset_export_bag(@druid, '2', @export_root) - expect(File.exist?("#{@bag_path}_v2")).to be_truthy - expect(File.exist?("#{@bag_path}_v2.tar")).to be_truthy - expect(File.exist?(@bag_path.to_s)).to be_falsey - expect(File.exist?("#{@bag_path}.tar")).to be_falsey + after do + FileUtils.mv("#{@bag_path}_v2", @bag_path) if File.exist?(@bag_path + '_v2') + FileUtils.mv("#{@bag_path}_v2.tar", @bag_path + '.tar') if File.exist?(@bag_path + '_v2.tar') + end + + it 'renames the export bags directory and tar files' do + described_class.reset_export_bag(@druid, '2', @export_root) + expect(File).to exist("#{@bag_path}_v2") + expect(File).to exist("#{@bag_path}_v2.tar") + expect(File).not_to exist(@bag_path.to_s) + expect(File).not_to exist("#{@bag_path}.tar") end - it 'should throw an error if the renamed bag is already existent' do + it 'throws an error if the renamed bag is already existent' do existent_id = 'az871zd0000' existent_druid = "druid:#{existent_id}" create_bag_dir(existent_id) bag_path = "#{@export_root}/#{existent_id}" # puts bag_path FileUtils.mv(bag_path, "#{bag_path}_v2") unless File.exist?(bag_path + '_v2') - expect{ Dor::ResetWorkspaceService.reset_export_bag(existent_druid, '2', @export_root) }.to raise_error(RuntimeError) - end - - after(:each) do - FileUtils.mv("#{@bag_path}_v2", @bag_path) if File.exist?(@bag_path + '_v2') - FileUtils.mv("#{@bag_path}_v2.tar", @bag_path + '.tar') if File.exist?(@bag_path + '_v2.tar') + expect{ described_class.reset_export_bag(existent_druid, '2', @export_root) }.to raise_error(RuntimeError) end end diff --git a/spec/services/sdr_ingest_service_spec.rb b/spec/services/sdr_ingest_service_spec.rb index 28e06197..81b04a5d 100644 --- a/spec/services/sdr_ingest_service_spec.rb +++ b/spec/services/sdr_ingest_service_spec.rb @@ -30,8 +30,8 @@ end it 'can find the fixtures workspace and export folders' do - expect(File.directory?(Dor::Config.sdr.local_workspace_root)).to be_truthy - expect(File.directory?(Dor::Config.sdr.local_export_home)).to be_truthy + expect(File).to be_directory(Dor::Config.sdr.local_workspace_root) + expect(File).to be_directory(Dor::Config.sdr.local_export_home) end describe 'get_datastream_content' do @@ -40,23 +40,25 @@ @mock_item = double('item') @mock_datastream = double('datastream') end + it 'retrieves content of a required datastream' do metadata_string = '' expect(@mock_datastream).to receive(:new?).and_return(false) expect(@mock_datastream).to receive(:content).and_return(metadata_string) expect(@mock_item).to receive(:datastreams).exactly(3).times.and_return(@ds_name => @mock_datastream) - expect(Dor::SdrIngestService.get_datastream_content(@mock_item, @ds_name, 'required')).to eq metadata_string + expect(described_class.get_datastream_content(@mock_item, @ds_name, 'required')).to eq metadata_string end context 'when datastream is empty or missing' do - before :each do + before do expect(@mock_datastream).not_to receive(:content) expect(@mock_item).to receive(:datastreams).and_return(@ds_name => @mock_datastream) end + it 'returns nil if datastream was optional' do - expect(Dor::SdrIngestService.get_datastream_content(@mock_item, 'dummy', 'optional')).to be_nil + expect(described_class.get_datastream_content(@mock_item, 'dummy', 'optional')).to be_nil end it 'raises exception if datastream was required' do - expect{ Dor::SdrIngestService.get_datastream_content(@mock_item, 'dummy', 'required') }.to raise_exception(RuntimeError) + expect{ described_class.get_datastream_content(@mock_item, 'dummy', 'required') }.to raise_exception(RuntimeError) end end end @@ -69,12 +71,13 @@ allow(@dor_item).to receive(:pid).and_return(druid) signature_catalog = Moab::SignatureCatalog.read_xml_file(@fixtures.join('sdr_repo/dd116zh0343/v0001/manifests')) @metadata_dir = @fixtures.join('workspace/dd/116/zh/0343/dd116zh0343/metadata') - expect(Dor::SdrIngestService).to receive(:get_signature_catalog).with(druid).and_return(signature_catalog) - expect(Dor::SdrIngestService).to receive(:extract_datastreams).with(@dor_item, an_instance_of(DruidTools::Druid)).and_return(@metadata_dir) + expect(described_class).to receive(:get_signature_catalog).with(druid).and_return(signature_catalog) + expect(described_class).to receive(:extract_datastreams).with(@dor_item, an_instance_of(DruidTools::Druid)).and_return(@metadata_dir) @files = [] end + specify 'with content changes' do - Dor::SdrIngestService.transfer(@dor_item) + described_class.transfer(@dor_item) @fixtures.join('export/dd116zh0343').find { |f| @files << f.relative_path_from(@fixtures).to_s } expect(@files.sort).to eq([ 'export/dd116zh0343', @@ -105,8 +108,8 @@ end specify 'with no change in content' do v1_content_metadata = @fixtures.join('sdr_repo/dd116zh0343/v0001/data/metadata/contentMetadata.xml') - expect(Dor::SdrIngestService).to receive(:get_content_metadata).with(@metadata_dir).and_return(v1_content_metadata.read) - Dor::SdrIngestService.transfer(@dor_item) + expect(described_class).to receive(:get_content_metadata).with(@metadata_dir).and_return(v1_content_metadata.read) + described_class.transfer(@dor_item) @fixtures.join('export/dd116zh0343').find { |f| @files << f.relative_path_from(@fixtures).to_s } expect(@files.sort).to eq([ 'export/dd116zh0343', @@ -142,15 +145,15 @@ expect(metadata_file).to receive(:open).at_least(5).times # Dor::SdrIngestService.stub(:get_datastream_content).and_return('') metadata_string = '' - expect(Dor::SdrIngestService).to receive(:get_datastream_content).with(dor_item, 'contentMetadata', 'required').once.and_return(metadata_string) - expect(Dor::SdrIngestService).to receive(:get_datastream_content).with(dor_item, 'descMetadata', 'required').once.and_return(metadata_string) - expect(Dor::SdrIngestService).to receive(:get_datastream_content).with(dor_item, 'identityMetadata', 'required').once.and_return(metadata_string) - expect(Dor::SdrIngestService).to receive(:get_datastream_content).with(dor_item, 'provenanceMetadata', 'required').once.and_return(metadata_string) - expect(Dor::SdrIngestService).to receive(:get_datastream_content).with(dor_item, 'relationshipMetadata', 'required').once.and_return(metadata_string) - expect(Dor::SdrIngestService).to receive(:get_datastream_content).with(dor_item, 'technicalMetadata', 'required').once.and_return(metadata_string) - expect(Dor::SdrIngestService).to receive(:get_datastream_content).with(dor_item, 'sourceMetadata', 'optional').once.and_return(metadata_string) - expect(Dor::SdrIngestService).to receive(:get_datastream_content).with(dor_item, 'rightsMetadata', 'optional').once.and_return(metadata_string) - Dor::SdrIngestService.extract_datastreams(dor_item, workspace) + expect(described_class).to receive(:get_datastream_content).with(dor_item, 'contentMetadata', 'required').once.and_return(metadata_string) + expect(described_class).to receive(:get_datastream_content).with(dor_item, 'descMetadata', 'required').once.and_return(metadata_string) + expect(described_class).to receive(:get_datastream_content).with(dor_item, 'identityMetadata', 'required').once.and_return(metadata_string) + expect(described_class).to receive(:get_datastream_content).with(dor_item, 'provenanceMetadata', 'required').once.and_return(metadata_string) + expect(described_class).to receive(:get_datastream_content).with(dor_item, 'relationshipMetadata', 'required').once.and_return(metadata_string) + expect(described_class).to receive(:get_datastream_content).with(dor_item, 'technicalMetadata', 'required').once.and_return(metadata_string) + expect(described_class).to receive(:get_datastream_content).with(dor_item, 'sourceMetadata', 'optional').once.and_return(metadata_string) + expect(described_class).to receive(:get_datastream_content).with(dor_item, 'rightsMetadata', 'optional').once.and_return(metadata_string) + described_class.extract_datastreams(dor_item, workspace) end specify 'get_version_inventory' do @@ -160,9 +163,9 @@ version_inventory = Moab::FileInventory.new version_inventory.groups << Moab::FileGroup.new(group_id: 'content') metadata_group = Moab::FileGroup.new(group_id: 'metadata') - expect(Dor::SdrIngestService).to receive(:get_content_inventory).with(metadata_dir, druid, version_id).and_return(version_inventory) - expect(Dor::SdrIngestService).to receive(:get_metadata_file_group).with(metadata_dir).and_return(metadata_group) - result = Dor::SdrIngestService.get_version_inventory(metadata_dir, druid, version_id) + expect(described_class).to receive(:get_content_inventory).with(metadata_dir, druid, version_id).and_return(version_inventory) + expect(described_class).to receive(:get_metadata_file_group).with(metadata_dir).and_return(metadata_group) + result = described_class.get_version_inventory(metadata_dir, druid, version_id) expect(result).to be_instance_of Moab::FileInventory expect(result.groups.size).to eq 2 end @@ -172,7 +175,7 @@ druid = 'druid:ab123cd4567' version_id = 2 - version_inventory = Dor::SdrIngestService.get_content_inventory(metadata_dir, druid, version_id) + version_inventory = described_class.get_content_inventory(metadata_dir, druid, version_id) expect(version_inventory).to be_instance_of Moab::FileInventory expect(version_inventory.version_id).to eq 2 content_group = version_inventory.groups[0] @@ -183,18 +186,18 @@ # if no content metadata metadata_dir = @fixtures.join('workspace/ab/123/cd/4567/ab123cd4567') - version_inventory = Dor::SdrIngestService.get_content_inventory(metadata_dir, druid, version_id) + version_inventory = described_class.get_content_inventory(metadata_dir, druid, version_id) expect(version_inventory.groups.size).to eq 0 end specify 'get_content_metadata' do metadata_dir = @fixtures.join('workspace/ab/123/cd/4567/ab123cd4567/metadata') - content_metadata = Dor::SdrIngestService.get_content_metadata(metadata_dir) + content_metadata = described_class.get_content_metadata(metadata_dir) expect(content_metadata).to match(/ @@ -72,25 +74,25 @@ stub_request(:get, "#{solr_url}&start=28").to_return(body: solr_resp) end - it 'should return a single batch of docs without a block' do - resp = Dor::SearchService.query(solr_field + ':"barcode:9191919191"', fl: 'id', rows: 14) + it 'returns a single batch of docs without a block' do + resp = described_class.query(solr_field + ':"barcode:9191919191"', fl: 'id', rows: 14) expect(resp['response']['docs'].length).to eq(14) end - it 'should yield multiple batches of docs with a block' do + it 'yields multiple batches of docs with a block' do batch = [14, 11] - Dor::SearchService.query(solr_field + ':"barcode:9191919191"', fl: 'id', rows: 14) do |resp| + described_class.query(solr_field + ':"barcode:9191919191"', fl: 'id', rows: 14) do |resp| expect(resp['response']['docs'].length).to eq(batch.shift) end end end context '.query_by_id' do - before :each do + before do @pid = 'druid:ab123cd4567' end - it 'should look up an object based on any of its IDs' do + it 'looks up an object based on any of its IDs' do id = 'barcode:9191919191' solr_field = Solrizer.solr_name('identifier', :symbol) solr_url = "http://solr.edu/solrizer/select?fl=id&q=%7B%21term+f%3D#{solr_field}%7Dbarcode%3A9191919191&defType=lucene&rows=1000&wt=ruby" @@ -113,15 +115,15 @@ 'response'=>{'numFound'=>5,'start'=>5,'docs'=>[]}} EOF stub_request(:get, "#{solr_url}&start=1000").to_return(body: solr_resp) - result = Dor::SearchService.query_by_id(id) + result = described_class.query_by_id(id) expect(result.size).to eq(5) expect(result).to include(@pid) end end context '.solr' do - it 'should use an RSolr connection' do - solr = Dor::SearchService.solr + it 'uses an RSolr connection' do + solr = described_class.solr expect(solr).to be_a(RSolr::Client) end end diff --git a/spec/services/shelving_service_spec.rb b/spec/services/shelving_service_spec.rb index de31f10c..5ff15deb 100644 --- a/spec/services/shelving_service_spec.rb +++ b/spec/services/shelving_service_spec.rb @@ -20,6 +20,7 @@ FileUtils.remove_entry workspace_root Dor::Config.pop! end + let(:work) { shelvable_item.new(pid: druid) } let(:service) { described_class.new work } @@ -48,9 +49,10 @@ end describe '#shelve_diff' do - let(:druid) { 'druid:jq937jp0017' } subject(:result) { service.send(:shelve_diff) } + let(:druid) { 'druid:jq937jp0017' } + context 'when contentMetadata exists' do it 'retrieves the differences between the current contentMetadata and the previously ingested version' do # read in a FileInventoryDifference manifest from the fixtures area @@ -102,6 +104,8 @@ end describe '#workspace_content_dir' do + subject { service.send(:workspace_content_dir, content_diff, workspace_druid) } + let(:druid) { 'druid:jq937jp0017' } let(:workspace_druid) { DruidTools::Druid.new(druid, Dor::Config.stacks.local_workspace_root) } @@ -114,7 +118,6 @@ let(:inventory_diff) { Moab::FileInventoryDifference.parse(inventory_diff_xml.read) } let(:content_diff) { inventory_diff.group_difference('content') } - subject { service.send(:workspace_content_dir, content_diff, workspace_druid) } context 'when the manifest files are not in the workspace' do it 'raises an error' do expect { subject }.to raise_error(RuntimeError, /content dir not found/) @@ -147,8 +150,10 @@ end describe '#stacks_location' do - let(:druid) { 'druid:xy123xy1234' } subject(:location) { service.send(:stacks_location) } + + let(:druid) { 'druid:xy123xy1234' } + it 'returns the default stack' do work.contentMetadata.content = '' expect(location).to eq stacks_root diff --git a/spec/services/status_service_spec.rb b/spec/services/status_service_spec.rb index b309f95f..fb311688 100644 --- a/spec/services/status_service_spec.rb +++ b/spec/services/status_service_spec.rb @@ -7,7 +7,9 @@ describe '#status' do subject(:status) { described_class.status(item) } + let(:versionMD) { double(Dor::VersionMetadataDS) } + before do expect(item).to receive(:versionMetadata).and_return(versionMD) expect(Dor::Config.workflow.client).to receive(:query_lifecycle).and_return(xml) @@ -27,7 +29,7 @@ ') end - it 'should generate a status string' do + it 'generates a status string' do expect(versionMD).to receive(:current_version_id).and_return('4') expect(status).to eq('v4 In accessioning (described, published)') end @@ -41,7 +43,8 @@ published ') end - it 'should generate a status string' do + + it 'generates a status string' do expect(versionMD).to receive(:current_version_id).and_return('3') expect(status).to eq('v3 In accessioning (described, published)') end @@ -68,17 +71,17 @@ ') end - it 'should handle a v2 accessioned object' do + it 'handles a v2 accessioned object' do expect(versionMD).to receive(:current_version_id).and_return('2') expect(status).to eq('v2 Accessioned') end - it 'should give a status of unknown if there are no lifecycles for the current version, indicating malfunction in workflow' do + it 'gives a status of unknown if there are no lifecycles for the current version, indicating malfunction in workflow' do expect(versionMD).to receive(:current_version_id).and_return('3') expect(status).to eq('v3 Unknown Status') end - it 'should include a formatted date/time if one is requested' do + it 'includes a formatted date/time if one is requested' do expect(versionMD).to receive(:current_version_id).and_return('2') expect(described_class.status(item, true)).to eq('v2 Accessioned 2013-10-01 07:11PM') end diff --git a/spec/services/suri_service_spec.rb b/spec/services/suri_service_spec.rb index 3e1ad222..c08ab7bb 100644 --- a/spec/services/suri_service_spec.rb +++ b/spec/services/suri_service_spec.rb @@ -4,7 +4,7 @@ describe Dor::SuriService do describe 'an enabled SuriService' do - before(:each) do + before do Dor::Config.push! do suri do mint_ids true @@ -16,32 +16,32 @@ end end - before(:each) do + before do @my_client = double('restclient').as_null_object allow(RestClient::Resource).to receive(:new).and_return(@my_client) end - after(:each) do + after do Dor::Config.pop! end - it 'should mint a druid using RestClient::Resource' do + it 'mints a druid using RestClient::Resource' do expect(@my_client).to receive(:post).with('').and_return('foo') expect(@my_client).to receive(:[]).with('identifiers?quantity=1').and_return(@my_client) - expect(Dor::SuriService.mint_id).to eq("#{Dor::Config.suri.id_namespace}:foo") + expect(described_class.mint_id).to eq("#{Dor::Config.suri.id_namespace}:foo") end - it 'should mint several druids if a quantity is passed in' do + it 'mints several druids if a quantity is passed in' do expect(@my_client).to receive(:post).with('').and_return("foo\nbar\nbaz") expect(@my_client).to receive(:[]).with('identifiers?quantity=3').and_return(@my_client) - expect(Dor::SuriService.mint_id(3)).to eq(["#{Dor::Config.suri.id_namespace}:foo", "#{Dor::Config.suri.id_namespace}:bar", "#{Dor::Config.suri.id_namespace}:baz"]) + expect(described_class.mint_id(3)).to eq(["#{Dor::Config.suri.id_namespace}:foo", "#{Dor::Config.suri.id_namespace}:bar", "#{Dor::Config.suri.id_namespace}:baz"]) end - it 'should throw log an error and rethrow the exception if Connect fails.' do + it 'throws log an error and rethrow the exception if Connect fails.' do e = 'thrown exception' ex = Exception.new(e) expect(@my_client).to receive(:post).with('').and_raise(ex) - expect{ Dor::SuriService.mint_id }.to raise_error(Exception, 'thrown exception') + expect{ described_class.mint_id }.to raise_error(Exception, 'thrown exception') end end @@ -50,7 +50,7 @@ Dor::Config.push! { suri.mint_ids false } end - before :each do + before do @mock_repo = instance_double(Rubydora::Repository) @mock_client = instance_double(Rubydora::RestApiClient) allow(@mock_repo).to receive(:api).and_return(@mock_client) @@ -66,7 +66,7 @@ Dor::Config.pop! end - it "should mint a single ID using Fedora's getNextPid API-M service" do + it "mints a single ID using Fedora's getNextPid API-M service" do xml_response = <<-EOXML @@ -74,11 +74,11 @@ EOXML expect(@mock_client).to receive(:next_pid).with(numPIDs: 1).and_return(xml_response) - expect(Dor::SuriService.mint_id).to eq('pid:123') + expect(described_class.mint_id).to eq('pid:123') Dor::Config.suri.pop end - it "should mint several IDs using Fedora's getNextPid API-M service" do + it "mints several IDs using Fedora's getNextPid API-M service" do xml_response = <<-EOXML @@ -88,7 +88,7 @@ EOXML expect(@mock_client).to receive(:next_pid).with(numPIDs: 3).and_return(xml_response) - expect(Dor::SuriService.mint_id(3)).to eq(['pid:123', 'pid:456', 'pid:789']) + expect(described_class.mint_id(3)).to eq(['pid:123', 'pid:456', 'pid:789']) Dor::Config.suri.pop end end diff --git a/spec/services/tag_service_spec.rb b/spec/services/tag_service_spec.rb index 54b16ee3..2e3a3375 100644 --- a/spec/services/tag_service_spec.rb +++ b/spec/services/tag_service_spec.rb @@ -20,13 +20,13 @@ it 'adds a new tag' do add - expect(item.identityMetadata.tags.include?('sometag : someval')).to be_truthy + expect(item.identityMetadata.tags).to include('sometag : someval') expect(item.identityMetadata).to be_changed end it 'raises an exception if there is an existing tag like it' do described_class.add(item, 'sometag:someval') - expect(item.identityMetadata.tags.include?('sometag : someval')).to be_truthy + expect(item.identityMetadata.tags).to include('sometag : someval') expect { add }.to raise_error(RuntimeError) end end @@ -36,10 +36,10 @@ it 'updates a tag' do described_class.add(item, 'sometag:someval') - expect(item.identityMetadata.tags.include?('sometag : someval')).to be_truthy + expect(item.identityMetadata.tags).to include('sometag : someval') expect(update).to be_truthy - expect(item.identityMetadata.tags.include?('sometag : someval')).to be_falsey - expect(item.identityMetadata.tags.include?('new : tag')).to be_truthy + expect(item.identityMetadata.tags).not_to include('sometag : someval') + expect(item.identityMetadata.tags).to include('new : tag') expect(item.identityMetadata).to be_changed end @@ -54,16 +54,18 @@ it 'deletes a tag' do described_class.add(item, 'sometag:someval') - expect(item.identityMetadata.tags.include?('sometag : someval')).to be_truthy + expect(item.identityMetadata.tags).to include('sometag : someval') expect(remove).to be_truthy - expect(item.identityMetadata.tags.include?('sometag : someval')).to be_falsey + expect(item.identityMetadata.tags).not_to include('sometag : someval') expect(item.identityMetadata).to be_changed end end describe '#validate_and_normalize_tag' do - let(:service) { described_class.new(item) } subject(:invoke) { service.send(:validate_and_normalize_tag, tag_str, existing_tags) } + + let(:service) { described_class.new(item) } + let(:existing_tags) { [] } context 'when the tag has too few elements' do diff --git a/spec/services/technical_metadata_service_spec.rb b/spec/services/technical_metadata_service_spec.rb index 5e7cec13..5569eab1 100644 --- a/spec/services/technical_metadata_service_spec.rb +++ b/spec/services/technical_metadata_service_spec.rb @@ -6,6 +6,7 @@ RSpec.describe Dor::TechnicalMetadataService do let(:object_ids) { %w(dd116zh0343 du000ps9999 jq937jp0017) } let(:druid_tool) { {} } + before do fixtures = Pathname(File.dirname(__FILE__)).join('../fixtures') wsfixtures = fixtures.join('workspace').to_s @@ -31,14 +32,14 @@ @inventory_differences[id] = Moab::FileGroupDifference.new @inventory_differences[id].compare_file_groups(repo_content_inventory, work_content_inventory) @deltas[id] = @inventory_differences[id].file_deltas - @new_files[id] = Dor::TechnicalMetadataService.get_new_files(@deltas[id]) + @new_files[id] = described_class.get_new_files(@deltas[id]) @repo_techmd[id] = fixtures.join('sdr_repo', id, 'v0001', 'data', 'metadata', 'technicalMetadata.xml').read - @new_file_techmd[id] = Dor::TechnicalMetadataService.get_new_technical_metadata(druid, @new_files[id]) + @new_file_techmd[id] = described_class.get_new_technical_metadata(druid, @new_files[id]) @expected_techmd[id] = Pathname(druid_tool[id].metadata_dir).join('technicalMetadata.xml').read end end - after(:each) do + after do Dor::Config.pop! end @@ -54,10 +55,10 @@ object_ids.each do |id| dor_item = double(Dor::Item) allow(dor_item).to receive(:pid).and_return("druid:#{id}") - expect(Dor::TechnicalMetadataService).to receive(:get_content_group_diff).with(dor_item).and_return(@inventory_differences[id]) - expect(Dor::TechnicalMetadataService).to receive(:get_file_deltas).with(@inventory_differences[id]).and_return(@deltas[id]) - expect(Dor::TechnicalMetadataService).to receive(:get_old_technical_metadata).with(dor_item).and_return(@repo_techmd[id]) - expect(Dor::TechnicalMetadataService).to receive(:get_new_technical_metadata).with(dor_item.pid, an_instance_of(Array)).and_return(@new_file_techmd[id]) + expect(described_class).to receive(:get_content_group_diff).with(dor_item).and_return(@inventory_differences[id]) + expect(described_class).to receive(:get_file_deltas).with(@inventory_differences[id]).and_return(@deltas[id]) + expect(described_class).to receive(:get_old_technical_metadata).with(dor_item).and_return(@repo_techmd[id]) + expect(described_class).to receive(:get_new_technical_metadata).with(dor_item.pid, an_instance_of(Array)).and_return(@new_file_techmd[id]) mock_datastream = double('datastream') ds_hash = { 'technicalMetadata' => mock_datastream } allow(dor_item).to receive(:datastreams).and_return(ds_hash) @@ -66,12 +67,13 @@ expect(mock_datastream).to receive(:content=).with(/') - sdr_techmd = Dor::TechnicalMetadataService.get_sdr_technical_metadata(druid) + allow(described_class).to receive(:get_sdr_metadata).with(druid, 'technicalMetadata').and_return('') + sdr_techmd = described_class.get_sdr_technical_metadata(druid) expect(sdr_techmd).to eq('') - allow(Dor::TechnicalMetadataService).to receive(:get_sdr_metadata).with(druid, 'technicalMetadata').and_return('') + allow(described_class).to receive(:get_sdr_metadata).with(druid, 'technicalMetadata').and_return('') jhove_service = double(JhoveService) allow(JhoveService).to receive(:new).and_return(jhove_service) allow(jhove_service).to receive(:upgrade_technical_metadata).and_return('upgraded techmd') - sdr_techmd = Dor::TechnicalMetadataService.get_sdr_technical_metadata(druid) + sdr_techmd = described_class.get_sdr_technical_metadata(druid) expect(sdr_techmd).to eq('upgraded techmd') end @@ -148,24 +150,24 @@ allow(dor_item).to receive(:datastreams).and_return(datastreams) allow(tech_ds).to receive(:new?).and_return(true) - dor_techmd = Dor::TechnicalMetadataService.get_dor_technical_metadata(dor_item) + dor_techmd = described_class.get_dor_technical_metadata(dor_item) expect(dor_techmd).to be_nil allow(tech_ds).to receive(:new?).and_return(false) - dor_techmd = Dor::TechnicalMetadataService.get_dor_technical_metadata(dor_item) + dor_techmd = described_class.get_dor_technical_metadata(dor_item) expect(dor_techmd).to eq('') allow(tech_ds).to receive(:content).and_return('') jhove_service = double(JhoveService) allow(JhoveService).to receive(:new).and_return(jhove_service) allow(jhove_service).to receive(:upgrade_technical_metadata).and_return('upgraded techmd') - dor_techmd = Dor::TechnicalMetadataService.get_dor_technical_metadata(dor_item) + dor_techmd = described_class.get_dor_technical_metadata(dor_item) expect(dor_techmd).to eq('upgraded techmd') end specify 'Dor::TechnicalMetadataService.get_new_technical_metadata' do object_ids.each do |id| - new_techmd = Dor::TechnicalMetadataService.get_new_technical_metadata("druid:#{id}", @new_files[id]) + new_techmd = described_class.get_new_technical_metadata("druid:#{id}", @new_files[id]) file_nodes = Nokogiri::XML(new_techmd).xpath('//file') case id when 'dd116zh0343' @@ -182,7 +184,7 @@ object_ids.each do |id| temp_dir = druid_tool[id].temp_dir new_files = @new_files[id] - filename = Dor::TechnicalMetadataService.write_fileset(temp_dir, new_files) + filename = described_class.write_fileset(temp_dir, new_files) if new_files.size > 0 expect(Pathname(filename).read).to eq(new_files.join("\n") + "\n") else @@ -195,9 +197,9 @@ object_ids.each do |id| old_techmd = @repo_techmd[id] new_techmd = @new_file_techmd[id] - new_nodes = Dor::TechnicalMetadataService.get_file_nodes(new_techmd) + new_nodes = described_class.get_file_nodes(new_techmd) deltas = @deltas[id] - merged_nodes = Dor::TechnicalMetadataService.merge_file_nodes(old_techmd, new_techmd, deltas) + merged_nodes = described_class.merge_file_nodes(old_techmd, new_techmd, deltas) case id when 'dd116zh0343' expect(new_nodes.keys.sort). to eq([ @@ -234,7 +236,7 @@ specify 'Dor::TechnicalMetadataService.get_file_nodes' do techmd = @repo_techmd['jq937jp0017'] - nodes = Dor::TechnicalMetadataService.get_file_nodes(techmd) + nodes = described_class.get_file_nodes(techmd) expect(nodes.size).to eq(6) expect(nodes.keys.sort).to eq(['intro-1.jpg', 'intro-2.jpg', 'page-1.jpg', 'page-2.jpg', 'page-3.jpg', 'title.jpg']) expect(nodes['page-1.jpg']).to be_equivalent_to(<<-EOF @@ -297,10 +299,10 @@ old_techmd = @repo_techmd[id] new_techmd = @new_file_techmd[id] deltas = @deltas[id] - merged_nodes = Dor::TechnicalMetadataService.merge_file_nodes(old_techmd, new_techmd, deltas) + merged_nodes = described_class.merge_file_nodes(old_techmd, new_techmd, deltas) # the final and expected_techmd need to be scrubbed of dates in a couple spots for the comparison to match since these will vary from test run to test run - final_techmd = Dor::TechnicalMetadataService.build_technical_metadata("druid:#{id}", merged_nodes).gsub(/datetime=["'].*?["']/, '').gsub(/.*?<\/jhove:lastModified>/, '') + final_techmd = described_class.build_technical_metadata("druid:#{id}", merged_nodes).gsub(/datetime=["'].*?["']/, '').gsub(/.*?<\/jhove:lastModified>/, '') expected_techmd = @expected_techmd[id].gsub(/datetime=["'].*?["']/, '').gsub(/.*?<\/jhove:lastModified>/, '') expect(final_techmd).to be_equivalent_to expected_techmd end diff --git a/spec/services/thumbnail_service_spec.rb b/spec/services/thumbnail_service_spec.rb index 25a20e41..06378c5f 100644 --- a/spec/services/thumbnail_service_spec.rb +++ b/spec/services/thumbnail_service_spec.rb @@ -14,6 +14,7 @@ context 'for a collection' do let(:object) { instantiate_fixture('druid:ab123cd4567', Dor::Collection) } + it 'returns nil if there is no contentMetadata datastream' do expect(subject).to be_nil end @@ -21,12 +22,13 @@ context 'for an item' do let(:object) { instantiate_fixture('druid:ab123cd4567', Dor::Item) } - it 'should return nil if there is no contentMetadata' do + + it 'returns nil if there is no contentMetadata' do object.contentMetadata.content = '' expect(subject).to be_nil end - it 'should find the first image as the thumb when no specific thumbs are specified' do + it 'finds the first image as the thumb when no specific thumbs are specified' do object.contentMetadata.content = <<-XML @@ -37,7 +39,7 @@ XML expect(subject).to eq('ab123cd4567/ab123cd4567_05_0001.jp2') end - it 'should find a thumb resource marked as thumb with the thumb attribute first, even if it is listed second' do + it 'finds a thumb resource marked as thumb with the thumb attribute first, even if it is listed second' do object.contentMetadata.content = <<-XML @@ -51,7 +53,7 @@ XML expect(subject).to eq('ab123cd4567/ab123cd4567_thumb.jp2') end - it 'should find a thumb resource marked as thumb without the thumb attribute first, even if it is listed second when there are no other thumbs specified' do + it 'finds a thumb resource marked as thumb without the thumb attribute first, even if it is listed second when there are no other thumbs specified' do object.contentMetadata.content = <<-XML @@ -65,7 +67,7 @@ XML expect(subject).to eq('ab123cd4567/ab123cd4567_thumb.jp2') end - it 'should find a thumb resource marked as thumb with the thumb attribute first, even if it is listed second and there is another image marked as thumb first' do + it 'finds a thumb resource marked as thumb with the thumb attribute first, even if it is listed second and there is another image marked as thumb first' do object.contentMetadata.content = <<-XML @@ -79,7 +81,7 @@ XML expect(subject).to eq('ab123cd4567/ab123cd4567_thumb.jp2') end - it 'should find an image resource marked as thumb with the thumb attribute when there is no resource thumb specified' do + it 'finds an image resource marked as thumb with the thumb attribute when there is no resource thumb specified' do object.contentMetadata.content = <<-XML @@ -93,7 +95,7 @@ XML expect(subject).to eq('ab123cd4567/ab123cd4567_05_0002.jp2') end - it 'should find an image resource marked as thumb with the thumb attribute when there is a resource thumb specified but not the thumb attribute' do + it 'finds an image resource marked as thumb with the thumb attribute when there is a resource thumb specified but not the thumb attribute' do object.contentMetadata.content = <<-XML @@ -107,7 +109,7 @@ XML expect(subject).to eq('ab123cd4567/ab123cd4567_05_0002.jp2') end - it 'should find a page resource marked as thumb with the thumb attribute when there is a resource thumb specified but not the thumb attribute' do + it 'finds a page resource marked as thumb with the thumb attribute when there is a resource thumb specified but not the thumb attribute' do object.contentMetadata.content = <<-XML @@ -125,7 +127,7 @@ XML expect(subject).to eq('ab123cd4567/ab123cd4567_05_0002.jp2') end - it 'should find an externalFile image resource when there are no other images' do + it 'finds an externalFile image resource when there are no other images' do object.contentMetadata.content = <<-XML @@ -139,7 +141,7 @@ XML expect(subject).to eq('cg767mn6478/2542A.jp2') end - it 'should find an externalFile page resource when there are no other images, even if objectId attribute is missing druid prefix' do + it 'finds an externalFile page resource when there are no other images, even if objectId attribute is missing druid prefix' do object.contentMetadata.content = <<-XML @@ -153,7 +155,7 @@ XML expect(subject).to eq('cg767mn6478/2542A.jp2') end - it 'should find an explicit externalFile thumb resource before another image resource, and encode the space' do + it 'finds an explicit externalFile thumb resource before another image resource, and encode the space' do object.contentMetadata.content = <<-XML @@ -167,7 +169,7 @@ XML expect(subject).to eq('cg767mn6478/2542A withspace.jp2') end - it 'should return nil if no thumb is identified' do + it 'returns nil if no thumb is identified' do object.contentMetadata.content = <<-XML @@ -178,7 +180,7 @@ XML expect(subject).to be_nil end - it 'should return nil if there is no contentMetadata datastream at all' do + it 'returns nil if there is no contentMetadata datastream at all' do object.datastreams['contentMetadata'] = nil expect(subject).to be_nil end diff --git a/spec/services/version_service_spec.rb b/spec/services/version_service_spec.rb index d2c09a0e..f6e8cb24 100644 --- a/spec/services/version_service_spec.rb +++ b/spec/services/version_service_spec.rb @@ -17,7 +17,7 @@ class VersionableItem < ActiveFedora::Base let(:vmd_ds) { obj.datastreams['versionMetadata'] } let(:ev_ds) { obj.datastreams['events'] } - before(:each) do + before do allow(obj).to receive(:pid).and_return(druid) allow(obj.inner_object).to receive(:repository).and_return(double('frepo').as_null_object) diff --git a/spec/utils/sdr_client_spec.rb b/spec/utils/sdr_client_spec.rb index 0b332785..f6c103d1 100644 --- a/spec/utils/sdr_client_spec.rb +++ b/spec/utils/sdr_client_spec.rb @@ -6,23 +6,23 @@ describe Sdr::Client do describe '.get_current_version' do it 'returns the current of the object from SDR' do - stub_request(:get, Sdr::Client.client['objects/druid:ab123cd4567/current_version'].url) + stub_request(:get, described_class.client['objects/druid:ab123cd4567/current_version'].url) .to_return(body: '2') - expect(Sdr::Client.current_version('druid:ab123cd4567')).to eq 2 + expect(described_class.current_version('druid:ab123cd4567')).to eq 2 end context 'raises an exception if the xml' do it 'has the wrong root element' do - stub_request(:get, Sdr::Client.client['objects/druid:ab123cd4567/current_version'].url) + stub_request(:get, described_class.client['objects/druid:ab123cd4567/current_version'].url) .to_return(body: '2') - expect{ Sdr::Client.current_version('druid:ab123cd4567') } + expect{ described_class.current_version('druid:ab123cd4567') } .to raise_error(Exception, 'Unable to parse XML from SDR current_version API call: 2') end it 'does not contain an Integer as its text' do - stub_request(:get, Sdr::Client.client['objects/druid:ab123cd4567/current_version'].url) + stub_request(:get, described_class.client['objects/druid:ab123cd4567/current_version'].url) .to_return(body: 'two') - expect{ Sdr::Client.current_version('druid:ab123cd4567') } + expect{ described_class.current_version('druid:ab123cd4567') } .to raise_error(Exception, 'Unable to parse XML from SDR current_version API call: two') end end @@ -30,19 +30,20 @@ describe '.get_sdr_metadata' do it 'fetches the datastream from SDR' do - stub_request(:get, Sdr::Client.client['objects/druid:ab123cd4567/metadata/technicalMetadata.xml'].url).to_return(body: '') - response = Sdr::Client.get_sdr_metadata('druid:ab123cd4567', 'technicalMetadata') + stub_request(:get, described_class.client['objects/druid:ab123cd4567/metadata/technicalMetadata.xml'].url).to_return(body: '') + response = described_class.get_sdr_metadata('druid:ab123cd4567', 'technicalMetadata') expect(response).to eq('') end end describe '.get_signature_catalog' do let(:druid) { 'druid:zz000zz0000' } + it 'fetches the signature catalog from SDR' do - resource = Sdr::Client.client["objects/#{druid}/manifest/signatureCatalog.xml"] + resource = described_class.client["objects/#{druid}/manifest/signatureCatalog.xml"] stub_request(:get, resource.url).to_return(body: '') - catalog = Sdr::Client.get_signature_catalog(druid) + catalog = described_class.get_signature_catalog(druid) expect(catalog.to_xml).to match(/') - inventory_difference = Sdr::Client.get_content_diff(druid, '') + inventory_difference = described_class.get_content_diff(druid, '') expect(inventory_difference.to_xml).to match(/