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

Commit

Permalink
Merge fdf4cec into 61644b8
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed May 21, 2019
2 parents 61644b8 + fdf4cec commit 1f83762
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 61 deletions.
4 changes: 3 additions & 1 deletion app/models/hydrus/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ def self.create(user)
# Create the object, with the correct model.
apo = Hydrus::AdminPolicyObject.create(user)
response = Hydrus::GenericObject.register_dor_object(user, 'collection', apo.pid)
coll = Hydrus::Collection.find(response[:pid])
workflow_client.create_workflow_by_name(response[:pid], Dor::Config.hydrus.app_workflow)

coll = Hydrus::Collection.find(response[:pid])
coll.remove_relationship :has_model, 'info:fedora/afmodel:Dor_Collection'
coll.assert_content_model
# Set the item_type, and add some Hydrus-specific info to identityMetadata.
Expand Down
3 changes: 1 addition & 2 deletions app/models/hydrus/generic_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,7 @@ def self.dor_registration_params(user_string, obj_typ, apo_pid)
admin_policy: apo_pid,
source_id: "Hydrus:#{obj_typ}-#{user_string}-#{HyTime.now_datetime_full}",
label: 'Hydrus',
tag: [Settings.hydrus.project_tag],
initiate_workflow: [Dor::Config.hydrus.app_workflow],
tag: [Settings.hydrus.project_tag]
}
end

Expand Down
10 changes: 8 additions & 2 deletions app/services/item_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ def validate!
# Create the object, with the correct model.
# @return [Hydrus::Item]
def build_item(item_type)
dor_item = Hydrus::GenericObject.register_dor_object(user, 'item', collection.apo_pid)
Hydrus::Item.find(dor_item[:pid]).tap do |item|
registration_response = Hydrus::GenericObject.register_dor_object(user, 'item', collection.apo_pid)
workflow_client.create_workflow_by_name(registration_response[:pid], Dor::Config.hydrus.app_workflow)

Hydrus::Item.find(registration_response[:pid]).tap do |item|
item.remove_relationship :has_model, 'info:fedora/afmodel:Dor_Item'
item.assert_content_model
# Set the item_type, and add some Hydrus-specific info to identityMetadata.
Expand All @@ -52,6 +54,10 @@ def build_item(item_type)
end
end

def workflow_client
@workflow_client ||= Dor::Workflow::Client.new(url: Settings.workflow.url)
end

# Add the Item to the Collection.
def assign_to_collection
item.collections << collection
Expand Down
49 changes: 30 additions & 19 deletions spec/models/hydrus/generic_object_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,27 +59,38 @@
expect(ri.url).to eq('')
end

describe 'registration' do
it 'dor_registration_params() should return the expected hash' do
# Non-APO: hash should include initiate_workflow.
args = %w(whobar item somePID)
drp = Hydrus::GenericObject.dor_registration_params(*args)
expect(drp).to be_instance_of Hash
expect(drp[:admin_policy]).to eq(args.last)
expect(drp).to include(:initiate_workflow)
# APO: hash should not includes initiate_workflow.
args = %w(whobar adminPolicy somePID)
drp = Hydrus::GenericObject.dor_registration_params(*args)
expect(drp).to be_instance_of Hash
expect(drp).to include(:initiate_workflow)
end

it 'should be able to exercise register_dor_object(), using stubbed call to Dor' do
args = %w(whobar item somePID)
drp = Hydrus::GenericObject.dor_registration_params(*args)
expect(Dor::Services::Client.objects).to receive(:register).with(params: hash_including(*drp.keys))
describe '.dor_registration_params' do
subject(:dor_registration_params) do
Hydrus::GenericObject.dor_registration_params(*args)
end

let(:args) { %w(whobar item somePID) }

it 'returns the expected hash' do
expect(dor_registration_params).to be_instance_of Hash
expect(dor_registration_params[:admin_policy]).to eq(args.last)
end
end

describe '.register_dor_object' do
subject(:register_dor_object) do
Hydrus::GenericObject.register_dor_object(nil, nil, nil)
end

let(:dor_registration_params) do
Hydrus::GenericObject.dor_registration_params(*args)
end
let(:args) { %w(whobar item somePID) }
let(:objects_client) { instance_double(Dor::Services::Client::Objects, register: nil) }

before do
allow(Dor::Services::Client).to receive(:objects).and_return(objects_client)
end

it 'calls the dor-serivices-client to register' do
register_dor_object
expect(objects_client).to have_received(:register).with(params: hash_including(*dor_registration_params.keys))
end
end

describe 'license and terms of use' do
Expand Down
79 changes: 42 additions & 37 deletions spec/services/item_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,47 +11,52 @@
end

describe '.create' do
describe('terms of acceptance for a new item', integration: true) do
let(:item) { described_class.create(collection.pid, user) }
let(:collection) { Hydrus::Collection.find('druid:oo000oo0003') }

context 'if the user has already accepted another item in this collection but it was more than 1 year ago' do
let(:user) { create :archivist1 } # this user accepted more than 1 year ago
it 'indicates that a new item in a collection requires terms acceptance' do
expect(collection.users_accepted_terms_of_deposit.keys.include?(user.sunetid)).to eq(true)
expect(item.requires_terms_acceptance(user, collection)).to eq(true)
expect(item.accepted_terms_of_deposit).to eq('false')
expect(item.terms_of_deposit_accepted?).to eq(false)
end
subject(:item) { described_class.create(collection.pid, user) }

let(:workflow_client) { instance_double(Dor::Workflow::Client, create_workflow_by_name: nil) }
let(:collection) { Hydrus::Collection.find('druid:oo000oo0003') }

before do
allow(Dor::Workflow::Client).to receive(:new).and_return(workflow_client)
end

context 'if the user has already accepted another item in this collection but it was more than 1 year ago' do
let(:user) { create :archivist1 } # this user accepted more than 1 year ago
it 'indicates that a new item in a collection requires terms acceptance' do
expect(collection.users_accepted_terms_of_deposit.keys.include?(user.sunetid)).to eq(true)
expect(item.requires_terms_acceptance(user, collection)).to eq(true)
expect(item.accepted_terms_of_deposit).to eq('false')
expect(item.terms_of_deposit_accepted?).to eq(false)
expect(workflow_client).to have_received(:create_workflow_by_name).with(String, 'hydrusAssemblyWF')
end
end

context 'if the user has already accepted another item in this collection less than 1 year ago' do
let(:user) { create :archivist3 }
before do
dt = HyTime.now - 1.month # force this user to have accepted 1 month ago.
collection.hydrusProperties.accept_terms_of_deposit(user, HyTime.datetime(dt))
collection.save!
end

context 'if the user has already accepted another item in this collection less than 1 year ago' do
let(:user) { create :archivist3 }
before do
dt = HyTime.now - 1.month # force this user to have accepted 1 month ago.
collection.hydrusProperties.accept_terms_of_deposit(user, HyTime.datetime(dt))
collection.save!
end

it 'indicates that a new item in a collection does not require terms acceptance' do
expect(collection.users_accepted_terms_of_deposit.keys.include?(user.sunetid)).to eq(true)
expect(item.requires_terms_acceptance(user, collection)).to eq(false)
expect(item.accepted_terms_of_deposit).to eq('true')
expect(item.terms_of_deposit_accepted?).to eq(true)
end
it 'indicates that a new item in a collection does not require terms acceptance' do
expect(collection.users_accepted_terms_of_deposit.keys.include?(user.sunetid)).to eq(true)
expect(item.requires_terms_acceptance(user, collection)).to eq(false)
expect(item.accepted_terms_of_deposit).to eq('true')
expect(item.terms_of_deposit_accepted?).to eq(true)
end
end

context 'when the user has not already accepted another item in this collection' do
let(:user) { create :archivist5 }
before do
allow(Hydrus::Authorizable).to receive(:can_create_items_in).and_return(true)
end

context 'when the user has not already accepted another item in this collection' do
let(:user) { create :archivist5 }
before do
allow(Hydrus::Authorizable).to receive(:can_create_items_in).and_return(true)
end

it 'indicates that a new item in a collection requires terms acceptance' do
expect(item.requires_terms_acceptance(user, collection)).to eq(true)
expect(item.accepted_terms_of_deposit).to eq('false')
expect(item.terms_of_deposit_accepted?).to eq(false)
end
it 'indicates that a new item in a collection requires terms acceptance' do
expect(item.requires_terms_acceptance(user, collection)).to eq(true)
expect(item.accepted_terms_of_deposit).to eq('false')
expect(item.terms_of_deposit_accepted?).to eq(false)
end
end
end
Expand Down

0 comments on commit 1f83762

Please sign in to comment.