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

Commit

Permalink
Merge 120ca2f into c0f8383
Browse files Browse the repository at this point in the history
  • Loading branch information
justinlittman committed May 24, 2019
2 parents c0f8383 + 120ca2f commit 4a31f11
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 53 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ gem 'assembly-objectfile', '~> 1.5'
# We don't require this by default, because we need it to load after hydrus models
# or we'll get a superclass mismatch for Hydrus::Item
gem 'dor-services', '~> 7.1', require: false
gem 'dor-services-client', '~> 1.1'
gem 'dor-services-client', '~> 1.9.2'
gem 'rubydora', '~> 2.1'
gem 'bagit', '~> 0.4'
gem 'blacklight', '~> 6.19'
Expand Down
6 changes: 4 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,13 @@ GEM
stanford-mods (>= 2.3.1)
stanford-mods-normalizer (~> 0.1)
systemu (~> 2.6)
dor-services-client (1.8.0)
dor-services-client (1.9.2)
activesupport (>= 4.2, < 6)
deprecation
faraday (~> 0.15)
moab-versioning (~> 4.0)
nokogiri (~> 1.8)
zeitwerk (~> 2.1)
dor-workflow-client (3.2.0)
activesupport (>= 3.2.1, < 6)
deprecation (~> 0)
Expand Down Expand Up @@ -539,6 +540,7 @@ GEM
xml-simple (1.1.5)
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.1.6)

PLATFORMS
ruby
Expand All @@ -565,7 +567,7 @@ DEPENDENCIES
devise-remote-user (~> 1.0)
dlss-capistrano
dor-services (~> 7.1)
dor-services-client (~> 1.1)
dor-services-client (~> 1.9.2)
dynamic_form
equivalent-xml
factory_bot_rails
Expand Down
6 changes: 3 additions & 3 deletions app/models/hydrus/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def resubmit
# - Other options:
# :no_super Used to prevent super() during testing.
def open_new_version(opts = {})
raise "#{cannot_do_message(:open_new_version)}\nItem is not accessioned" unless is_accessioned
raise "#{cannot_do_message(:open_new_version)}\nItem is not accessioned" unless version_openeable?
# Store the time when the object was initially published.
self.initial_publish_time = publish_time if is_initial_version

Expand All @@ -179,7 +179,7 @@ def open_new_version(opts = {})
vers_md_upd_info[:significance] = opts[:significance] || :major
vers_md_upd_info[:description] = opts[:description] || ''
# Use the dor-services-client to open a new version, passing along args needed by Hydrus
Dor::Services::Client.object(pid).open_new_version(assume_accessioned: should_treat_as_accessioned, vers_md_upd_info: vers_md_upd_info)
Dor::Services::Client.object(pid).version.open(assume_accessioned: should_treat_as_accessioned, vers_md_upd_info: vers_md_upd_info)
# Varying behavior: remediations vs ordinary user edits.
if opts[:is_remediation]
# Just log the event.
Expand Down Expand Up @@ -207,7 +207,7 @@ def close_version(opts = {})
# We want to start accessioning only if ...
sa = !!opts[:is_remediation] # ... we are running a remediation and
sa = false if should_treat_as_accessioned # ... we are not in development or test
Dor::Services::Client.object(pid).close_version(version_num: version_id, start_accession: sa)
Dor::Services::Client.object(pid).version.close(version_num: version_id, start_accession: sa)
end

# indicates if this item has an accepted terms of deposit, or if the supplied
Expand Down
22 changes: 5 additions & 17 deletions app/models/hydrus/processable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,12 @@ def should_start_assembly_wf
Dor::Config.hydrus.start_assembly_wf
end

# Returns true if the most recent version of the object has been accessioned.
def is_accessioned
# Basic tests:
# - Must be published before it can be accessioned.
# - For local development and automated testing, treat published as
# equivalent to accessioned.
# Returns true if a new version can be opened for the object.
def version_openeable?
return false unless is_published
return true if should_treat_as_accessioned

# Return false unless has been accessioned at least once.
# accessioned lifecyle is set in the last step in the accessionWF.
return false unless workflow_client.lifecycle(REPO, pid, 'accessioned')

# Return false if accessionWF has been started for most current version and there are there are any incomplete workflow steps.
return false if workflow_client.active_lifecycle(REPO, pid, 'submitted')

# Accessioned.
true
# For testing, this avoids Dor::Services::Client.
return false if should_treat_as_accessioned
Dor::Services::Client.object(pid).version.openeable?(assume_accessioned: should_treat_as_accessioned)
end

# Returns a string -- the datetime when the object achived the published
Expand Down
2 changes: 1 addition & 1 deletion app/views/hydrus_items/_actions_box_show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
</p>

<!-- Open new version. -->
<% elsif @fobj.is_accessioned && can?(:edit, @fobj) %>
<% elsif @fobj.version_openeable? && can?(:edit, @fobj) %>
<p>
<%= button_to "Open new version",
open_new_version_item_path(@fobj),
Expand Down
18 changes: 12 additions & 6 deletions spec/models/hydrus/item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1112,7 +1112,7 @@
# 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)
allow(item).to receive(:version_openeable?).and_return(false)
end

it 'raises an exception' do
Expand All @@ -1121,20 +1121,23 @@
end

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

let(:version_client) { instance_double(Dor::Services::Client::ObjectVersion, open: true) }

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

it 'calls the client and sets prior_visibility to the old visibility value' do
expect(item).to receive(:start_hydrus_wf)
item.open_new_version
expect(object_client).to have_received(:open_new_version)
expect(version_client).to have_received(:open)
expect(item.prior_visibility).to eq 'stanford'
end
end
Expand All @@ -1148,16 +1151,19 @@
end
end
context 'when item is not initial version' do
let(:object_client) { instance_double(Dor::Services::Client::Object, close_version: true) }
let(:object_client) { instance_double(Dor::Services::Client::Object) }

let(:version_client) { instance_double(Dor::Services::Client::ObjectVersion, close: true) }

before do
allow(item).to receive(:is_initial_version).and_return(false)
allow(Dor::Services::Client).to receive(:object).and_return(object_client)
allow(object_client).to receive(:version).and_return(version_client)
end

it 'calls the client and sets prior_visibility to the old visibility value' do
item.close_version
expect(object_client).to have_received(:close_version).with(version_num: '1', start_accession: false)
expect(version_client).to have_received(:close).with(version_num: '1', start_accession: false)
end
end
end
Expand Down
55 changes: 32 additions & 23 deletions spec/models/hydrus/processable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,32 +88,41 @@
end
end

describe 'is_accessioned()' do
let(:wfs) { instance_double(Dor::Workflow::Client) }
before do
allow(Dor::Config.workflow).to receive(:client).and_return(wfs)
end
describe 'version_openeable?' do
let(:object_client) { instance_double(Dor::Services::Client::Object) }
let(:version_client) { instance_double(Dor::Services::Client::ObjectVersion) }

it 'can exercise all logic branches' do
# At each stage, we set a stub, call is_accessioned(), and then reverse the stub.
# Not published: false.
allow(@go).to receive(:is_published).and_return(false)
expect(@go.is_accessioned).to eq(false)
before do
allow(@go).to receive(:is_published).and_return(true)
# Running in development or test mode: true.
allow(@go).to receive(:should_treat_as_accessioned).and_return(true)
expect(@go.is_accessioned).to eq(true)
allow(@go).to receive(:should_treat_as_accessioned).and_return(false)
# Never accessioned: false.
allow(wfs).to receive(:lifecycle).with('dor', @go.pid, 'accessioned').and_return(false)
expect(@go.is_accessioned).to eq(false)
allow(wfs).to receive(:lifecycle).with('dor', @go.pid, 'accessioned').and_return(true)
# AccessionWF active for current version: true
allow(wfs).to receive(:active_lifecycle).with('dor', @go.pid, 'submitted').and_return(true)
expect(@go.is_accessioned).to eq(false)
allow(wfs).to receive(:active_lifecycle).with('dor', @go.pid, 'submitted').and_return(false)
# Survived all tests: true.
expect(@go.is_accessioned).to eq(true)
allow(version_client).to receive(:openeable?).and_return(true)
allow(Dor::Services::Client).to receive(:object).and_return(object_client)
allow(object_client).to receive(:version).and_return(version_client)
end

context 'when item has not been published' do
before do
allow(@go).to receive(:is_published).and_return(false)
end

it 'returns false' do
expect(@go.version_openeable?).to eq(false)
end
end
context 'when published, but dor-services-app reports a new version cannot be opened' do
before do
allow(version_client).to receive(:openeable?).and_return(false)
end

it 'returns false' do
expect(@go.version_openeable?).to eq(false)
end
end

context 'when published and dor-services-app reports a new version can be opened' do
it 'returns true' do
expect(@go.version_openeable?).to eq(true)
end
end
end

Expand Down

0 comments on commit 4a31f11

Please sign in to comment.