Skip to content

Commit

Permalink
Merge 91a0305 into d02bb03
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Aug 29, 2019
2 parents d02bb03 + 91a0305 commit 4d3fa1f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 27 deletions.
1 change: 1 addition & 0 deletions app/controllers/versions_controller.rb
Expand Up @@ -58,6 +58,7 @@ def close_params
:description,
:significance,
:start_accession,
:user_name,
:version_num
).to_h.symbolize_keys
end
Expand Down
6 changes: 5 additions & 1 deletion app/services/version_service.rb
Expand Up @@ -60,12 +60,14 @@ def can_open?(opts = {})
# @option opts [Symbol] :significance which part of the version tag to increment
# :major, :minor, :admin (see Dor::VersionTag#increment)
# @option opts [String] :version_num version number to archive rows with. Otherwise, current version is used
# @option opts [String] :user_name add username to the events datastream
# @option opts [Boolean] :start_accesion set to true if you want accessioning to start (default), false otherwise
# @raise [Dor::Exception] if the object hasn't been opened for versioning, or if accessionWF has
# already been instantiated or the current version is missing a tag or description
def close(opts = {})
unless opts.empty?
work.versionMetadata.update_current_version opts
work.versionMetadata.update_current_version(description: opts[:description], significance: opts[:significance].to_sym) if opts[:description] && opts[:significance]

work.versionMetadata.save
end

Expand All @@ -74,6 +76,8 @@ def close(opts = {})
raise Dor::Exception, 'accessionWF already created for versioned object' if accessioning?

Dor::Config.workflow.client.close_version 'dor', work.pid, opts.fetch(:start_accession, true) # Default to creating accessionWF when calling close_version
work.events.add_event('close', opts[:user_name], "Version #{work.current_version} closed") if opts[:user_name]
work.save!
end

# Performs checks on whether a new version can be opened for an object
Expand Down
59 changes: 33 additions & 26 deletions spec/services/version_service_spec.rb
Expand Up @@ -184,32 +184,39 @@
describe '.close' do
subject(:close) { described_class.close(obj) }

it 'sets tag and description if passed in as optional paramaters' do
allow(vmd_ds).to receive(:pid).and_return('druid:ab123cd4567')
allow(Dor::Config.workflow.client).to receive(:active_lifecycle).and_return(true, false)

# Stub out calls to update and archive workflow
allow(Dor::Config.workflow.client).to receive(:update_workflow_status)

expect(Dor::Config.workflow.client).to receive(:close_version).with('dor', druid, true)

allow(obj).to receive(:create_workflow)

vmd_ds.increment_version
expect(vmd_ds).to receive(:save)
described_class.close obj, description: 'closing text', significance: :major

expect(vmd_ds.to_xml).to be_equivalent_to(<<-XML
<versionMetadata objectId="druid:ab123cd4567">
<version versionId="1" tag="1.0.0">
<description>Initial Version</description>
</version>
<version versionId="2" tag="2.0.0">
<description>closing text</description>
</version>
</versionMetadata>
XML
)
context 'when significance, description and user_name are passed in' do
before do
end

it 'sets tag, description and an event' do
allow(vmd_ds).to receive(:pid).and_return('druid:ab123cd4567')
allow(Dor::Config.workflow.client).to receive(:active_lifecycle).and_return(true, false)

# Stub out calls to update and archive workflow
allow(Dor::Config.workflow.client).to receive(:update_workflow_status)

expect(Dor::Config.workflow.client).to receive(:close_version).with('dor', druid, true)

allow(obj).to receive(:create_workflow)
vmd_ds.increment_version

expect(vmd_ds).to receive(:save)
expect(ev_ds).to receive(:add_event).with('close', 'jcoyne', 'Version 2 closed')
expect(obj).to receive(:save!)

described_class.close obj, description: 'closing text', significance: 'major', user_name: 'jcoyne'

expect(vmd_ds.to_xml).to be_equivalent_to <<~XML
<versionMetadata objectId="druid:ab123cd4567">
<version versionId="1" tag="1.0.0">
<description>Initial Version</description>
</version>
<version versionId="2" tag="2.0.0">
<description>closing text</description>
</version>
</versionMetadata>
XML
end
end

context 'when the object has not been opened for versioning' do
Expand Down

0 comments on commit 4d3fa1f

Please sign in to comment.