ddr-models 2.6.2 → 2.7.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/.travis.yml +1 -1
  4. data/Gemfile +2 -3
  5. data/app/models/collection.rb +11 -3
  6. data/app/models/component.rb +54 -4
  7. data/app/models/item.rb +1 -2
  8. data/config/initializers/active_fedora_base.rb +8 -5
  9. data/config/initializers/rubydora_monkey_patch.rb +11 -0
  10. data/config/initializers/subscriptions.rb +16 -9
  11. data/config/locales/ddr-models.en.yml +3 -0
  12. data/ddr-models.gemspec +3 -2
  13. data/lib/ddr/actions/virus_check.rb +10 -16
  14. data/lib/ddr/auth.rb +0 -8
  15. data/lib/ddr/datastreams.rb +13 -2
  16. data/lib/ddr/datastreams/administrative_metadata_datastream.rb +9 -0
  17. data/lib/ddr/datastreams/content_datastream.rb +5 -0
  18. data/lib/ddr/datastreams/datastream_behavior.rb +60 -15
  19. data/lib/ddr/datastreams/delete_external_files.rb +29 -0
  20. data/lib/ddr/datastreams/descriptive_metadata_datastream.rb +33 -33
  21. data/lib/ddr/datastreams/external_file_datastream.rb +69 -0
  22. data/lib/ddr/datastreams/fits_datastream.rb +15 -5
  23. data/lib/ddr/datastreams/intermediate_file_datastream.rb +5 -0
  24. data/lib/ddr/datastreams/metadata_datastream.rb +15 -17
  25. data/lib/ddr/datastreams/multires_image_datastream.rb +5 -0
  26. data/lib/ddr/derivatives.rb +1 -0
  27. data/lib/ddr/derivatives/ptif_generator.rb +5 -1
  28. data/lib/ddr/derivatives/update_derivatives.rb +23 -0
  29. data/lib/ddr/events/deletion_event.rb +5 -9
  30. data/lib/ddr/events/event.rb +7 -9
  31. data/lib/ddr/events/ingestion_event.rb +5 -9
  32. data/lib/ddr/events/update_event.rb +12 -5
  33. data/lib/ddr/index.rb +0 -1
  34. data/lib/ddr/index/csv_query_result.rb +10 -2
  35. data/lib/ddr/index/fields.rb +10 -9
  36. data/lib/ddr/index/filter.rb +1 -0
  37. data/lib/ddr/managers/derivatives_manager.rb +84 -98
  38. data/lib/ddr/managers/technical_metadata_manager.rb +20 -5
  39. data/lib/ddr/models.rb +24 -24
  40. data/lib/ddr/models/base.rb +98 -74
  41. data/lib/ddr/models/cache.rb +20 -0
  42. data/lib/ddr/models/engine.rb +4 -6
  43. data/lib/ddr/models/file_management.rb +57 -152
  44. data/lib/ddr/models/fixity_checkable.rb +0 -5
  45. data/lib/ddr/models/has_admin_metadata.rb +4 -2
  46. data/lib/ddr/models/has_children.rb +35 -1
  47. data/lib/ddr/models/has_content.rb +3 -33
  48. data/lib/ddr/models/has_intermediate_file.rb +18 -0
  49. data/lib/ddr/models/has_multires_image.rb +12 -15
  50. data/lib/ddr/models/has_struct_metadata.rb +2 -38
  51. data/lib/ddr/models/indexing.rb +160 -163
  52. data/lib/ddr/models/permanent_id.rb +26 -49
  53. data/lib/ddr/models/solr_document.rb +21 -19
  54. data/lib/ddr/models/structure.rb +168 -41
  55. data/lib/ddr/models/structures/agent.rb +49 -0
  56. data/lib/ddr/models/structures/div.rb +64 -0
  57. data/lib/ddr/models/structures/f_locat.rb +54 -0
  58. data/lib/ddr/models/structures/file.rb +52 -0
  59. data/lib/ddr/models/structures/file_grp.rb +35 -0
  60. data/lib/ddr/models/structures/file_sec.rb +22 -0
  61. data/lib/ddr/models/structures/fptr.rb +31 -0
  62. data/lib/ddr/models/structures/mets_hdr.rb +37 -0
  63. data/lib/ddr/models/structures/mptr.rb +49 -0
  64. data/lib/ddr/models/structures/struct_map.rb +40 -0
  65. data/lib/ddr/models/version.rb +1 -1
  66. data/lib/ddr/notifications.rb +10 -12
  67. data/lib/ddr/utils.rb +29 -16
  68. data/lib/ddr/vocab.rb +15 -17
  69. data/lib/ddr/vocab/asset.rb +29 -19
  70. data/lib/ddr/vocab/contact.rb +5 -7
  71. data/lib/ddr/vocab/display.rb +6 -8
  72. data/lib/ddr/vocab/duke_terms.rb +8 -10
  73. data/lib/ddr/vocab/rdf_vocabulary_parser.rb +37 -39
  74. data/lib/ddr/vocab/roles.rb +17 -19
  75. data/lib/ddr/vocab/vocabulary.rb +26 -26
  76. data/spec/datastreams/external_file_datastream_spec.rb +37 -0
  77. data/spec/derivatives/png_generator_spec.rb +21 -25
  78. data/spec/derivatives/ptif_generator_spec.rb +22 -26
  79. data/spec/dummy/config/environments/test.rb +1 -1
  80. data/spec/dummy/db/schema.rb +23 -23
  81. data/spec/factories/structure_factories.rb +8 -2
  82. data/spec/fixtures/imageA.jpg +0 -0
  83. data/spec/fixtures/imageB.jpg +0 -0
  84. data/spec/index/csv_query_result_spec.rb +3 -3
  85. data/spec/index/fields_spec.rb +7 -6
  86. data/spec/managers/derivatives_manager_spec.rb +105 -112
  87. data/spec/managers/technical_metadata_manager_spec.rb +22 -18
  88. data/spec/models/active_fedora_base_spec.rb +0 -106
  89. data/spec/models/active_fedora_datastream_spec.rb +33 -2
  90. data/spec/models/attachment_spec.rb +0 -2
  91. data/spec/models/cache_spec.rb +32 -0
  92. data/spec/models/collection_spec.rb +43 -19
  93. data/spec/models/component_spec.rb +41 -51
  94. data/spec/models/descriptive_metadata_datastream_spec.rb +99 -87
  95. data/spec/models/events_spec.rb +50 -69
  96. data/spec/models/file_management_spec.rb +79 -187
  97. data/spec/models/has_children_spec.rb +54 -3
  98. data/spec/models/has_struct_metadata_spec.rb +32 -38
  99. data/spec/models/indexing_spec.rb +11 -6
  100. data/spec/models/item_spec.rb +21 -7
  101. data/spec/models/permanent_id_spec.rb +1 -5
  102. data/spec/models/solr_document_spec.rb +13 -41
  103. data/spec/models/structure_spec.rb +85 -16
  104. data/spec/models/structures/agent_spec.rb +30 -0
  105. data/spec/models/structures/div_spec.rb +26 -0
  106. data/spec/models/structures/f_locat_spec.rb +78 -0
  107. data/spec/models/structures/file_grp_spec.rb +23 -0
  108. data/spec/models/structures/file_sec_spec.rb +22 -0
  109. data/spec/models/structures/file_spec.rb +60 -0
  110. data/spec/models/structures/fptr_spec.rb +23 -0
  111. data/spec/models/structures/mets_hdr_spec.rb +26 -0
  112. data/spec/models/structures/mptr_spec.rb +25 -0
  113. data/spec/models/structures/struct_map_spec.rb +24 -0
  114. data/spec/models/target_spec.rb +0 -2
  115. data/spec/spec_helper.rb +4 -9
  116. data/spec/support/shared_examples_for_ddr_models.rb +96 -156
  117. data/spec/support/shared_examples_for_has_content.rb +56 -30
  118. data/spec/support/shared_examples_for_has_intermediate_spec.rb +28 -0
  119. data/spec/support/shared_examples_for_non_collection_models.rb +5 -0
  120. data/spec/support/structural_metadata_helper.rb +230 -59
  121. data/spec/utils_spec.rb +0 -2
  122. metadata +86 -44
  123. data/app/helpers/models_helper.rb +0 -10
  124. data/lib/ddr/auth/legacy/abstract_legacy_permissions.rb +0 -17
  125. data/lib/ddr/auth/legacy/legacy_authorization.rb +0 -44
  126. data/lib/ddr/auth/legacy/legacy_default_permissions.rb +0 -33
  127. data/lib/ddr/auth/legacy/legacy_permissions.rb +0 -33
  128. data/lib/ddr/auth/legacy/legacy_roles.rb +0 -25
  129. data/lib/ddr/index/legacy_license_fields.rb +0 -12
  130. data/lib/ddr/jobs.rb +0 -12
  131. data/lib/ddr/jobs/fits_file_characterization.rb +0 -13
  132. data/lib/ddr/jobs/fixity_check.rb +0 -13
  133. data/lib/ddr/jobs/job.rb +0 -36
  134. data/lib/ddr/jobs/queue.rb +0 -27
  135. data/lib/ddr/jobs/update_index.rb +0 -13
  136. data/lib/ddr/models/access_controllable.rb +0 -24
  137. data/lib/ddr/models/struct_div.rb +0 -63
  138. data/spec/auth/legacy_default_permissions_spec.rb +0 -37
  139. data/spec/auth/legacy_permissions_spec.rb +0 -37
  140. data/spec/helpers/models_helper_spec.rb +0 -11
  141. data/spec/jobs/fits_file_characterization_spec.rb +0 -16
  142. data/spec/jobs/fixity_check_spec.rb +0 -22
  143. data/spec/jobs/job_spec.rb +0 -40
  144. data/spec/jobs/update_index_spec.rb +0 -22
  145. data/spec/models/struct_div_spec.rb +0 -70
  146. data/spec/support/shared_examples_for_access_controllables.rb +0 -6
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ module Ddr::Models::Structures
4
+ RSpec.describe Agent, type: :model, structure: true do
5
+
6
+ let(:attrs) { { id: 'abc', role: 'OTHER', otherrole: 'INVESTIGATOR', type: 'OTHER', othertype: 'SOMETHING',
7
+ name: 'Sam Spade' } }
8
+ let(:doc) { Ddr::Models::Structure.xml_template }
9
+ let(:node) do
10
+ node = Nokogiri::XML::Node.new('agent', doc)
11
+ node['ID'] = attrs[:id]
12
+ node['ROLE'] = attrs[:role]
13
+ node['OTHERROLE'] = attrs[:otherrole]
14
+ node['TYPE'] = attrs[:type]
15
+ node['OTHERTYPE'] = attrs[:othertype]
16
+ doc.root.add_child(node)
17
+ name_node = Nokogiri::XML::Node.new('name', doc)
18
+ name_node.content = 'Sam Spade'
19
+ node.add_child(name_node)
20
+ node
21
+ end
22
+
23
+ describe ".build" do
24
+ it "should build the correct node" do
25
+ expect(described_class.build(attrs.merge(document: doc)).to_xml).to be_equivalent_to(node.to_xml)
26
+ end
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ module Ddr::Models::Structures
4
+ RSpec.describe Div, type: :model, structure: true do
5
+
6
+ let(:attrs) { { id: 'abc', label: 'ghi', order: '5', orderlabel: 'def', type: 'pqr' } }
7
+ let(:doc) { Ddr::Models::Structure.xml_template }
8
+ let(:node) do
9
+ node = Nokogiri::XML::Node.new('div', doc)
10
+ node['ID'] = attrs[:id]
11
+ node['LABEL'] = attrs[:label]
12
+ node['ORDER'] = attrs[:order]
13
+ node['ORDERLABEL'] = attrs[:orderlabel]
14
+ node['TYPE'] = attrs[:type]
15
+ doc.root.add_child(node)
16
+ node
17
+ end
18
+
19
+ describe ".build" do
20
+ it "should build the correct node" do
21
+ expect(described_class.build(attrs.merge(document: doc)).to_xml).to be_equivalent_to(node.to_xml)
22
+ end
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,78 @@
1
+ require 'spec_helper'
2
+
3
+ module Ddr::Models::Structures
4
+ RSpec.describe FLocat, type: :model, structure: true do
5
+
6
+ let(:attrs) { { id: 'abc', loctype: 'OTHER', use: 'def', href: 'ijk' } }
7
+ let(:doc) { Ddr::Models::Structure.xml_template }
8
+ let(:node) do
9
+ node = Nokogiri::XML::Node.new('FLocat', doc)
10
+ node['ID'] = attrs[:id]
11
+ node['LOCTYPE'] = attrs[:loctype]
12
+ node['USE'] = attrs[:use]
13
+ node['xlink:href'] = attrs[:href]
14
+ doc.root.add_child(node)
15
+ node
16
+ end
17
+
18
+ describe ".build" do
19
+ it "should build the correct node" do
20
+ expect(described_class.build(attrs.merge(document: doc)).to_xml).to be_equivalent_to(node.to_xml)
21
+ end
22
+ end
23
+
24
+ describe "location" do
25
+ describe "is not an ARK" do
26
+ subject { described_class.new(node) }
27
+ its(:ark?) { is_expected.to eq(false) }
28
+ its(:ark) { is_expected.to be_nil }
29
+ its(:repo_id) { is_expected.to be_nil }
30
+ end
31
+ describe "is an ARK" do
32
+ let(:node) do
33
+ node = Nokogiri::XML::Node.new('FLocat', doc)
34
+ node['LOCTYPE'] = 'ARK'
35
+ node['xlink:href'] = 'ark:/99999/fk4edf'
36
+ doc.root.add_child(node)
37
+ node
38
+ end
39
+ let(:repo_object) { Item.create }
40
+ before { repo_object.update_attributes(permanent_id: 'ark:/99999/fk4edf') }
41
+ subject { described_class.new(node) }
42
+ its(:ark?) { is_expected.to eq(true) }
43
+ its(:ark) { is_expected.to eq('ark:/99999/fk4edf') }
44
+ its(:repo_id) { is_expected.to eq(repo_object.id) }
45
+ end
46
+ end
47
+
48
+ describe "effective use" do
49
+ before do
50
+ allow(subject).to receive(:parent) { Nokogiri::XML::Node.new('file', doc) }
51
+ end
52
+ describe "use attribute present" do
53
+ subject { described_class.new(node) }
54
+ its(:effective_use) { is_expected.to eq(subject.use) }
55
+ end
56
+ describe "use attribute not present" do
57
+ before do
58
+ allow(subject).to receive(:use) { nil }
59
+ end
60
+ describe "parent node has effective use" do
61
+ subject { described_class.new(node) }
62
+ before do
63
+ allow_any_instance_of(File).to receive(:effective_use) { 'xyz' }
64
+ end
65
+ its(:effective_use) { is_expected.to eq('xyz') }
66
+ end
67
+ describe "parent node does not have an effective use" do
68
+ subject { described_class.new(node) }
69
+ before do
70
+ allow_any_instance_of(File).to receive(:effective_use) { nil }
71
+ end
72
+ its(:effective_use) { is_expected.to be_nil }
73
+ end
74
+ end
75
+ end
76
+
77
+ end
78
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ module Ddr::Models::Structures
4
+ RSpec.describe FileGrp, type: :model, structure: true do
5
+
6
+ let(:attrs) { { id: 'abc', use: 'efg' } }
7
+ let(:doc) { Ddr::Models::Structure.xml_template }
8
+ let(:node) do
9
+ node = Nokogiri::XML::Node.new('fileGrp', doc)
10
+ node['ID'] = attrs[:id]
11
+ node['USE'] = attrs[:use]
12
+ doc.root.add_child(node)
13
+ node
14
+ end
15
+
16
+ describe ".build" do
17
+ it "should build the correct node" do
18
+ expect(described_class.build(attrs.merge(document: doc)).to_xml).to be_equivalent_to(node.to_xml)
19
+ end
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ module Ddr::Models::Structures
4
+ RSpec.describe FileSec, type: :model, structure: true do
5
+
6
+ let(:attrs) { { id: 'abc' } }
7
+ let(:doc) { Ddr::Models::Structure.xml_template }
8
+ let(:node) do
9
+ node = Nokogiri::XML::Node.new('fileSec', doc)
10
+ node['ID'] = attrs[:id]
11
+ doc.root.add_child(node)
12
+ node
13
+ end
14
+
15
+ describe ".build" do
16
+ it "should build the correct node" do
17
+ expect(described_class.build(attrs.merge(document: doc)).to_xml).to be_equivalent_to(node.to_xml)
18
+ end
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+ module Ddr::Models::Structures
4
+ RSpec.describe File, type: :model, structure: true do
5
+
6
+ let(:attrs) { { id: 'abc', use: 'efg' } }
7
+ let(:doc) { Ddr::Models::Structure.xml_template }
8
+ let(:node) do
9
+ node = Nokogiri::XML::Node.new('file', doc)
10
+ node['ID'] = attrs[:id]
11
+ node['USE'] = attrs[:use]
12
+ doc.root.add_child(node)
13
+ node
14
+ end
15
+
16
+ describe ".build" do
17
+ it "should build the correct node" do
18
+ expect(described_class.build(attrs.merge(document: doc)).to_xml).to be_equivalent_to(node.to_xml)
19
+ end
20
+ end
21
+
22
+ describe ".find" do
23
+ let(:structure) { FactoryGirl.build(:simple_structure) }
24
+ it "finds the requested File" do
25
+ expect(File.find(structure, 'def')).to be_a(File)
26
+ expect(File.find(structure, 'def').id).to eq('def')
27
+ end
28
+ end
29
+
30
+ describe "effective use" do
31
+ before do
32
+ allow(subject).to receive(:parent) { Nokogiri::XML::Node.new('fileGrp', doc) }
33
+ end
34
+ describe "use attribute present" do
35
+ subject { described_class.new(node) }
36
+ its(:effective_use) { is_expected.to eq(subject.use) }
37
+ end
38
+ describe "use attribute not present" do
39
+ before do
40
+ allow(subject).to receive(:use) { nil }
41
+ end
42
+ describe "parent node has effective use" do
43
+ subject { described_class.new(node) }
44
+ before do
45
+ allow_any_instance_of(FileGrp).to receive(:effective_use) { 'xyz' }
46
+ end
47
+ its(:effective_use) { is_expected.to eq('xyz') }
48
+ end
49
+ describe "parent node does not have an effective use" do
50
+ subject { described_class.new(node) }
51
+ before do
52
+ allow_any_instance_of(FileGrp).to receive(:effective_use) { nil }
53
+ end
54
+ its(:effective_use) { is_expected.to be_nil }
55
+ end
56
+ end
57
+ end
58
+
59
+ end
60
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ module Ddr::Models::Structures
4
+ RSpec.describe Fptr, type: :model, structure: true do
5
+
6
+ let(:attrs) { { id: 'abc', fileid: 'def' } }
7
+ let(:doc) { Ddr::Models::Structure.xml_template }
8
+ let(:node) do
9
+ node = Nokogiri::XML::Node.new('fptr', doc)
10
+ node['ID'] = attrs[:id]
11
+ node['FILEID'] = attrs[:fileid]
12
+ doc.root.add_child(node)
13
+ node
14
+ end
15
+
16
+ describe ".build" do
17
+ it "should build the correct node" do
18
+ expect(described_class.build(attrs.merge(document: doc)).to_xml).to be_equivalent_to(node.to_xml)
19
+ end
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ module Ddr::Models::Structures
4
+ RSpec.describe MetsHdr, type: :model, structure: true do
5
+
6
+ let(:attrs) { { id: 'abc', createdate: '2017-01-17T16:48:36Z', lastmoddate: '2017-01-18T16:46:48Z',
7
+ recordstatus: 'foo' } }
8
+ let(:doc) { Ddr::Models::Structure.xml_template }
9
+ let(:node) do
10
+ node = Nokogiri::XML::Node.new('metsHdr', doc)
11
+ node['ID'] = attrs[:id]
12
+ node['CREATEDATE'] = attrs[:createdate]
13
+ node['LASTMODDATE'] = attrs[:lastmoddate]
14
+ node['RECORDSTATUS'] = attrs[:recordstatus]
15
+ doc.root.add_child(node)
16
+ node
17
+ end
18
+
19
+ describe ".build" do
20
+ it "should build the correct node" do
21
+ expect(described_class.build(attrs.merge(document: doc)).to_xml).to be_equivalent_to(node.to_xml)
22
+ end
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ module Ddr::Models::Structures
4
+ RSpec.describe Mptr, type: :model, structure: true do
5
+
6
+ let(:attrs) { { id: 'abc', loctype: 'OTHER', otherloctype: 'def', href: 'ijk' } }
7
+ let(:doc) { Ddr::Models::Structure.xml_template }
8
+ let(:node) do
9
+ node = Nokogiri::XML::Node.new('mptr', doc)
10
+ node['ID'] = attrs[:id]
11
+ node['LOCTYPE'] = attrs[:loctype]
12
+ node['OTHERLOCTYPE'] = attrs[:otherloctype]
13
+ node['xlink:href'] = attrs[:href]
14
+ doc.root.add_child(node)
15
+ node
16
+ end
17
+
18
+ describe ".build" do
19
+ it "should build the correct node" do
20
+ expect(described_class.build(attrs.merge(document: doc)).to_xml).to be_equivalent_to(node.to_xml)
21
+ end
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ module Ddr::Models::Structures
4
+ RSpec.describe StructMap, type: :model, structure: true do
5
+
6
+ let(:attrs) { { id: 'abc', label: 'ghi', type: 'def' } }
7
+ let(:doc) { Ddr::Models::Structure.xml_template }
8
+ let(:node) do
9
+ node = Nokogiri::XML::Node.new('structMap', doc)
10
+ node['ID'] = attrs[:id]
11
+ node['LABEL'] = attrs[:label]
12
+ node['TYPE'] = attrs[:type]
13
+ doc.root.add_child(node)
14
+ node
15
+ end
16
+
17
+ describe ".build" do
18
+ it "should build the correct node" do
19
+ expect(described_class.build(attrs.merge(document: doc)).to_xml).to be_equivalent_to(node.to_xml)
20
+ end
21
+ end
22
+
23
+ end
24
+ end
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  RSpec.describe Target, type: :model, targets: true do
4
2
 
5
3
  it_behaves_like "a DDR model"
data/spec/spec_helper.rb CHANGED
@@ -85,7 +85,7 @@ RSpec.configure do |config|
85
85
  # Print the 10 slowest examples and example groups at the
86
86
  # end of the spec run, to help surface which specs are running
87
87
  # particularly slow.
88
- config.profile_examples = 10
88
+ # config.profile_examples = 10
89
89
 
90
90
  # Run specs in random order to surface order dependencies. If you find an
91
91
  # order dependency and want to debug it, you can fix the order by providing
@@ -108,19 +108,14 @@ RSpec.configure do |config|
108
108
  config.update_derivatives = [ :multires_image, :thumbnail ]
109
109
  end
110
110
  Ddr::Models.configure do |config|
111
- config.external_file_store = Dir.mktmpdir
112
- config.multires_image_external_file_store = Dir.mktmpdir
113
- config.external_file_subpath_pattern = "--"
114
111
  config.fits_home = Dir.mktmpdir
115
112
  end
113
+ Ddr::Datastreams::ExternalFileDatastream.file_store = Dir.mktmpdir
116
114
  end
117
115
 
118
116
  config.after(:suite) do
119
- if Ddr::Models.external_file_store && Dir.exist?(Ddr::Models.external_file_store)
120
- FileUtils.remove_entry_secure(Ddr::Models.external_file_store)
121
- end
122
- if Ddr::Models.multires_image_external_file_store && Dir.exist?(Ddr::Models.multires_image_external_file_store)
123
- FileUtils.remove_entry_secure(Ddr::Models.multires_image_external_file_store)
117
+ if Ddr::Datastreams::ExternalFileDatastream.file_store
118
+ FileUtils.rm_rf Ddr::Datastreams::ExternalFileDatastream.file_store
124
119
  end
125
120
  end
126
121
 
@@ -2,10 +2,64 @@ RSpec.shared_examples "a DDR model" do
2
2
 
3
3
  it_behaves_like "a describable object"
4
4
  it_behaves_like "a governable object"
5
- it_behaves_like "an access controllable object"
6
5
  it_behaves_like "an object that has a display title"
7
6
  it_behaves_like "an object that has identifiers"
8
7
 
8
+ describe "ingested by" do
9
+ let(:user) { User.new(username: "foo@bar.com") }
10
+ describe "on create" do
11
+ describe "when :user option passed to #save" do
12
+ describe "and ingested_by is not set" do
13
+ it "sets ingested by" do
14
+ expect { subject.save(user: user) }.to change(subject, :ingested_by).from(nil).to("foo@bar.com")
15
+ end
16
+ end
17
+ describe "and ingested_by is set" do
18
+ before { subject.ingested_by = "bob@example.com" }
19
+ it "does not set ingested by" do
20
+ expect { subject.save(user: user) }.not_to change(subject, :ingested_by)
21
+ end
22
+ end
23
+ end
24
+ describe "when :user option passed to #save!" do
25
+ describe "and ingested_by is not set" do
26
+ it "sets ingested by" do
27
+ expect { subject.save!(user: user) }.to change(subject, :ingested_by).from(nil).to("foo@bar.com")
28
+ end
29
+ end
30
+ describe "and ingested_by is set" do
31
+ before { subject.ingested_by = "bob@example.com" }
32
+ it "does not set ingested by" do
33
+ expect { subject.save!(user: user) }.not_to change(subject, :ingested_by)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ describe "saving after create" do
39
+ before { subject.save! }
40
+ it "does not set ingested_by" do
41
+ expect { subject.save(user: user) }.not_to change(subject, :ingested_by)
42
+ expect { subject.save!(user: user) }.not_to change(subject, :ingested_by)
43
+ end
44
+ end
45
+ end
46
+
47
+ describe "ingestion date" do
48
+ describe "on create" do
49
+ describe "when it's set" do
50
+ before { subject.ingestion_date = "2017-01-13T19:03:15Z" }
51
+ it "preserves the date" do
52
+ expect { subject.save! }.not_to change(subject, :ingestion_date)
53
+ end
54
+ end
55
+ describe "when it's not set" do
56
+ it "sets the date" do
57
+ expect { subject.save! }.to change(subject, :ingestion_date)
58
+ end
59
+ end
60
+ end
61
+ end
62
+
9
63
  describe "permanent ID assignment" do
10
64
  describe "when auto assignment is enabled" do
11
65
  before do
@@ -36,80 +90,55 @@ RSpec.shared_examples "a DDR model" do
36
90
  end
37
91
  end
38
92
 
39
- describe "notification on save" do
40
- let(:events) { [] }
41
- before {
42
- @subscriber = ActiveSupport::Notifications.subscribe("save.#{described_class.to_s.underscore}") do |name, start, finish, id, payload|
43
- events << payload
44
- end
45
- }
46
- after {
47
- ActiveSupport::Notifications.unsubscribe(@subscriber)
48
- }
49
- it "happens when save succeeds" do
50
- subject.title = [ "My Title Changed" ]
51
- subject.save
52
- subject.title = [ "My Title Changed Again" ]
53
- subject.save
54
- expect(events.first[:changes]).to eq({"title"=>[[], ["My Title Changed"]]})
55
- expect(events.first[:created]).to be true
56
- expect(events.first[:pid]).to eq(subject.pid)
57
- expect(events.last[:changes]).to eq({"title"=>[["My Title Changed"], ["My Title Changed Again"]]})
58
- expect(events.last[:created]).to be false
59
- expect(events.last[:pid]).to eq(subject.pid)
60
- end
61
- end
62
-
63
- describe "notification on workflow state change" do
64
- let(:events) { [] }
65
- before {
66
- @subscriber = ActiveSupport::Notifications.subscribe(/workflow\.#{described_class.to_s.underscore}/) do |*args|
67
- events << ActiveSupport::Notifications::Event.new(*args)
93
+ describe "events" do
94
+ describe "ingestion" do
95
+ it "creates an ingestion event" do
96
+ expect { subject.save! }.to change { Ddr::Events::IngestionEvent.for_object(subject).count }.by(1)
68
97
  end
69
- }
70
- after {
71
- ActiveSupport::Notifications.unsubscribe(@subscriber)
72
- }
73
- it "doesn't happen on create" do
74
- subject.workflow_state = "published"
75
- subject.save(validate: false)
76
- expect(events).to be_empty
77
98
  end
78
- describe "with a previously persisted object" do
79
- before do
80
- subject.save(validate: false)
81
- end
82
- it "happens on publish!" do
83
- subject.workflow_state = "published"
84
- subject.save(validate: false)
85
- expect(events.size).to eq(1)
86
- expect(events.first.name).to eq("published.workflow.#{described_class.to_s.underscore}")
87
- end
88
- it "happens on unpublish!" do
89
- subject.workflow_state = "unpublished"
90
- subject.save(validate: false)
91
- expect(events.size).to eq(1)
92
- expect(events.first.name).to eq("unpublished.workflow.#{described_class.to_s.underscore}")
99
+ describe "update" do
100
+ before { subject.save! }
101
+ it "creates an update event" do
102
+ expect { subject.save! }.to change { Ddr::Events::UpdateEvent.for_object(subject).count }.by(1)
103
+ end
104
+ describe "with options" do
105
+ let(:user) { FactoryGirl.create(:user) }
106
+ it "creates an update event with options" do
107
+ subject.title = [ "Changed Title" ]
108
+ subject.save(user: user, summary: "This event rocks!", comment: "I was testing things", detail: "A bunch of extra stuff I want to record")
109
+ event = Ddr::Events::UpdateEvent.for_object(subject).last
110
+ expect(event.user_key).to eq(user.to_s)
111
+ expect(event.summary).to eq "This event rocks!"
112
+ expect(event.comment).to eq "I was testing things"
113
+ end
93
114
  end
94
115
  end
95
- end
96
-
97
- describe "events" do
98
- before {
99
- subject.save(validate: false)
100
- }
101
116
  describe "deaccession" do
117
+ before { subject.save! }
102
118
  it "creates a deaccession event" do
103
119
  expect { subject.deaccession }.to change { Ddr::Events::DeaccessionEvent.for_object(subject).count }.by(1)
104
120
  end
121
+ it "records attributes with the event" do
122
+ allow(subject).to receive(:permanent_id) { "foo" }
123
+ subject.deaccession
124
+ event = Ddr::Events::DeaccessionEvent.for_object(subject).first
125
+ expect(event.permanent_id).to eq "foo"
126
+ end
105
127
  end
106
128
  describe "on deletion with #destroy" do
129
+ before { subject.save! }
107
130
  it "creates a deletion event" do
108
131
  expect { subject.destroy }.to change { Ddr::Events::DeletionEvent.for_object(subject).count }.from(0).to(1)
109
132
  end
133
+ it "records attributes with the event" do
134
+ allow(subject).to receive(:permanent_id) { "foo" }
135
+ subject.destroy
136
+ event = Ddr::Events::DeletionEvent.for_object(subject).first
137
+ expect(event.permanent_id).to eq "foo"
138
+ end
110
139
  end
111
-
112
140
  describe "last virus check" do
141
+ before { subject.save! }
113
142
  let!(:fixity_check) { Ddr::Events::FixityCheckEvent.new }
114
143
  before { allow(subject).to receive(:last_fixity_check) { fixity_check } }
115
144
  its(:last_fixity_check_on) { should eq(fixity_check.event_date_time) }
@@ -117,101 +146,12 @@ RSpec.shared_examples "a DDR model" do
117
146
  end
118
147
  end
119
148
 
120
- describe "move first desc metadata identifier to local id" do
121
- let(:local_id) { 'locl001' }
122
- let(:identifiers) { [ 'id001', 'id002' ] }
123
- context "no desc metadata identifiers" do
124
- context "local id present" do
125
- before { subject.local_id = local_id }
126
- it "should not change the local id" do
127
- result = subject.move_first_identifier_to_local_id
128
- expect(result).to be false
129
- expect(subject.local_id).to eq(local_id)
130
- end
131
- end
132
- end
133
- context "one desc metadata identifier" do
134
- before { subject.identifier = Array(identifiers.first) }
135
- context "local id not present" do
136
- it "sets the local id and removes the identifier" do
137
- result = subject.move_first_identifier_to_local_id
138
- expect(result).to be true
139
- expect(subject.local_id).to eq(identifiers.first)
140
- expect(subject.identifier).to be_empty
141
- end
142
- end
143
- context "local id present" do
144
- before { subject.local_id = local_id }
145
- context "replace option is true" do
146
- it "sets the local id and removes the identifier" do
147
- result = subject.move_first_identifier_to_local_id
148
- expect(result).to be true
149
- expect(subject.local_id).to eq(identifiers.first)
150
- expect(subject.identifier).to be_empty
151
- end
152
- end
153
- context "replace option is false" do
154
- context "local id matches first identifier" do
155
- before { subject.identifier = Array(local_id) }
156
- it "removes the identifier" do
157
- result = subject.move_first_identifier_to_local_id(replace: false)
158
- expect(result).to be true
159
- expect(subject.local_id).to eq(local_id)
160
- expect(subject.identifier).to be_empty
161
- end
162
- end
163
- context "local id does not match first identifier" do
164
- it "does not change the local id and does not remove the identifier" do
165
- result = subject.move_first_identifier_to_local_id(replace: false)
166
- expect(result).to be false
167
- expect(subject.local_id).to eq(local_id)
168
- expect(subject.identifier).to eq(Array(identifiers.first))
169
- end
170
- end
171
- end
172
- end
173
- end
174
- context "more than one desc metadata identifer" do
175
- before { subject.identifier = identifiers }
176
- context "local id not present" do
177
- it "sets the local id and removes the identifier" do
178
- result = subject.move_first_identifier_to_local_id
179
- expect(result).to be true
180
- expect(subject.local_id).to eq(identifiers.first)
181
- expect(subject.identifier).to eq(Array(identifiers.last))
182
- end
183
- end
184
- context "local id present" do
185
- before { subject.local_id = local_id }
186
- context "replace option is true" do
187
- it "sets the local id and removes the identifier" do
188
- result = subject.move_first_identifier_to_local_id
189
- expect(result).to be true
190
- expect(subject.local_id).to eq(identifiers.first)
191
- expect(subject.identifier).to eq(Array(identifiers.last))
192
- end
193
- end
194
- context "replace option is false" do
195
- context "local id matches first identifier" do
196
- before { subject.identifier = [ local_id, identifiers.last ] }
197
- it "removes the identifier" do
198
- result = subject.move_first_identifier_to_local_id(replace: false)
199
- expect(result).to be true
200
- expect(subject.local_id).to eq(local_id)
201
- expect(subject.identifier).to eq(Array(identifiers.last))
202
- end
203
- end
204
- context "local id does not match first identifier" do
205
- it "does not change the local id and does not remove the identifier" do
206
- result = subject.move_first_identifier_to_local_id(replace: false)
207
- expect(result).to be false
208
- expect(subject.local_id).to eq(local_id)
209
- expect(subject.identifier).to eq(identifiers)
210
- end
211
- end
212
- end
213
- end
214
- end
149
+ describe "thumbnails" do
150
+ its(:can_have_thumbnail?) { is_expected.to be true }
151
+ it { is_expected.not_to have_thumbnail }
152
+ specify {
153
+ allow(subject.thumbnail).to receive(:has_content?) { true }
154
+ expect(subject).to have_thumbnail
155
+ }
215
156
  end
216
-
217
157
  end