Skip to content
This repository has been archived by the owner on Jan 8, 2022. It is now read-only.

Commit

Permalink
Merge e7e407c into 3323af1
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Jan 28, 2019
2 parents 3323af1 + e7e407c commit 744dadd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/models/hydrus/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def open_new_version(opts = {})
# Store a copy of the current license and visibility.
# We use those values when enforcing subsequent-version validations.
self.prior_license = license
self.prior_visibility = visibility
self.prior_visibility = visibility.first
# Log the event.
events.add_event('hydrus', @current_user, 'New version opened')
end
Expand Down
30 changes: 26 additions & 4 deletions spec/models/hydrus/item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1078,12 +1078,34 @@
end
end

describe 'open_new_version()' do
describe '#open_new_version' do
# More significant testing is done at the integration level.
context 'when the item has not been accessioned' do
before do
allow(item).to receive(:is_accessioned).and_return(false)
end

it 'should raise exception if item is initial version' do
allow(item).to receive(:is_accessioned).and_return(false)
expect { item.open_new_version }.to raise_exception(@cannot_do_regex)
it 'raises an exception' do
expect { item.open_new_version }.to raise_exception(@cannot_do_regex)
end
end

context 'when it has been accessioned' do
let(:object_client) { instance_double(Dor::Services::Client::Object, open_new_version: true) }

before do
item.submitted_for_publish_time = HyTime.now_datetime
item.visibility = 'stanford'
allow(item).to receive(:is_accessioned).and_return(true)
allow(Dor::Services::Client).to receive(:object).and_return(object_client)
allow(item).to receive(:uncomplete_workflow_steps)
end

it 'calls the client and sets prior_visibility to the old visibility value' do
item.open_new_version
expect(object_client).to have_received(:open_new_version)
expect(item.prior_visibility).to eq 'stanford'
end
end
end

Expand Down

0 comments on commit 744dadd

Please sign in to comment.