This repository has been archived by the owner on May 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
processable_spec.rb
83 lines (68 loc) · 2.86 KB
/
processable_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# frozen_string_literal: true
require 'spec_helper'
class ProcessableItem < ActiveFedora::Base
include Dor::Itemizable
include Dor::Processable
include Dor::Versionable
include Dor::Describable
end
class ProcessableOnlyItem < ActiveFedora::Base
include Dor::Itemizable
include Dor::Processable
end
class ProcessableWithApoItem < ActiveFedora::Base
include Dor::Governable
include Dor::Processable
include Dor::Itemizable
end
RSpec.describe Dor::Processable do
after { unstub_config }
let(:item) { instantiate_fixture('druid:ab123cd4567', ProcessableItem) }
before do
stub_config
item.contentMetadata.content = '<contentMetadata/>'
end
it 'has a workflows datastream and workflows shortcut method' do
expect(item.datastreams['workflows']).to be_a(Dor::WorkflowDs)
expect(item.workflows).to eq(item.datastreams['workflows'])
end
it 'loads its content directly from the workflow service' do
expect(Dor::Config.workflow.client).to receive(:all_workflows_xml).with('druid:ab123cd4567').and_return('<workflows/>')
expect(item.workflows.content).to eq('<workflows/>')
end
it 'is able to invalidate the cache of its content' do
expect(Dor::Config.workflow.client).to receive(:all_workflows_xml).with('druid:ab123cd4567').and_return('<workflows/>')
expect(item.workflows.content).to eq('<workflows/>')
expect(item.workflows.content).to eq('<workflows/>') # should be cached copy
expect(Dor::Config.workflow.client).to receive(:all_workflows_xml).with('druid:ab123cd4567').and_return('<workflows>with some data</workflows>')
# pass refresh flag and should be refreshed copy
expect(item.workflows.content(true)).to eq('<workflows>with some data</workflows>')
expect(item.workflows.content).to eq('<workflows>with some data</workflows>')
end
describe '#build_datastream' do
let(:builder) { instance_double(Dor::DatastreamBuilder, build: true) }
it 'Calls the datastream builder' do
expect(Deprecation).to receive(:warn)
expect(Dor::DatastreamBuilder).to receive(:new)
.with(datastream: Dor::DescMetadataDS, force: true, object: item, required: false)
.and_return(builder)
item.build_datastream('descMetadata', true)
expect(builder).to have_received(:build)
end
end
describe '#status' do
it 'delegates to the StatusService' do
expect(Deprecation).to receive(:warn)
expect(Dor::StatusService).to receive(:status).with(item, true)
item.status(true)
end
end
describe '#create_workflow' do
let(:item) { instantiate_fixture('druid:ab123cd4567', ProcessableWithApoItem) }
it 'delegates to CreateWorkflowService' do
expect(Deprecation).to receive(:warn)
expect(Dor::CreateWorkflowService).to receive(:create_workflow).with(item, name: 'accessionWF', create_ds: true, priority: 0)
item.create_workflow('accessionWF')
end
end
end