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
@@ -8,21 +8,23 @@ module Ddr::Managers
8
8
  let(:obj) { Component.new }
9
9
 
10
10
  describe "when fits datastream not present" do
11
- its(:valid) { is_expected.to be_empty }
12
- its(:well_formed) { is_expected.to be_empty }
11
+ its(:fits?) { is_expected.to be false }
12
+
13
+ its(:created) { is_expected.to be_empty }
14
+ its(:creating_application) { is_expected.to be_empty }
15
+ its(:creation_time) { is_expected.to be_empty }
16
+ its(:file_size) { is_expected.to be_empty }
17
+ its(:fits_datetime) { is_expected.to be_nil }
18
+ its(:fits_version) { is_expected.to be_nil }
13
19
  its(:format_label) { is_expected.to be_empty }
14
- its(:media_type) { is_expected.to be_empty }
15
20
  its(:format_version) { is_expected.to be_empty }
16
21
  its(:last_modified) { is_expected.to be_empty }
22
+ its(:md5) { is_expected.to be_nil }
23
+ its(:media_type) { is_expected.to be_empty }
17
24
  its(:modification_time) { is_expected.to be_empty }
18
- its(:created) { is_expected.to be_empty }
19
- its(:creation_time) { is_expected.to be_empty }
20
25
  its(:pronom_identifier) { is_expected.to be_empty }
21
- its(:creating_application) { is_expected.to be_empty }
22
- its(:file_size) { is_expected.to be_empty }
23
- its(:fits_version) { is_expected.to be_nil }
24
- its(:fits_datetime) { is_expected.to be_nil }
25
- its(:fits?) { is_expected.to be false }
26
+ its(:valid) { is_expected.to be_empty }
27
+ its(:well_formed) { is_expected.to be_empty }
26
28
  end
27
29
 
28
30
  describe "when content is not present" do
@@ -34,20 +36,22 @@ module Ddr::Managers
34
36
  before do
35
37
  obj.fits.content = fixture_file_upload(File.join("fits", "document.xml"))
36
38
  end
39
+
37
40
  its(:fits?) { is_expected.to be true }
38
- its(:valid) { is_expected.to eq(["false"]) }
39
- its(:well_formed) { is_expected.to eq(["true"]) }
40
- its(:format_label) { is_expected.to eq(["Portable Document Format"]) }
41
- its(:media_type) { is_expected.to eq(["application/pdf"]) }
42
- its(:format_version) { is_expected.to eq(["1.6"]) }
43
- its(:last_modified) { is_expected.to eq(["2015-06-08T21:22:35Z"]) }
41
+
44
42
  its(:created) { is_expected.to eq(["2015:06:05 15:16:23-04:00"]) }
45
- its(:pronom_identifier) { is_expected.to eq(["fmt/20"]) }
46
43
  its(:creating_application) { is_expected.to contain_exactly("Adobe Acrobat Pro 11.0.3 Paper Capture Plug-in/PREMIS Editorial Committee", "Adobe Acrobat Pro 11.0.3 Paper Capture Plug-in/Acrobat PDFMaker 11 for Word") }
47
- its(:fits_version) { is_expected.to eq("0.8.5") }
48
44
  its(:extent) { is_expected.to eq(["3786205"]) }
49
45
  its(:file_size) { is_expected.to eq([3786205]) }
46
+ its(:fits_version) { is_expected.to eq("0.8.5") }
47
+ its(:format_label) { is_expected.to eq(["Portable Document Format"]) }
48
+ its(:format_version) { is_expected.to eq(["1.6"]) }
49
+ its(:last_modified) { is_expected.to eq(["2015-06-08T21:22:35Z"]) }
50
+ its(:md5) { is_expected.to eq("432ab76d650bfdc8f8d4a98cea9634bb") }
50
51
  its(:media_type) { is_expected.to eq(["application/pdf"]) }
52
+ its(:pronom_identifier) { is_expected.to eq(["fmt/20"]) }
53
+ its(:valid) { is_expected.to eq(["false"]) }
54
+ its(:well_formed) { is_expected.to eq(["true"]) }
51
55
 
52
56
  describe "datetime fields" do
53
57
  its(:creation_time) { is_expected.to contain_exactly(DateTime.parse("2015-06-05 15:16:23-04:00").to_time.utc) }
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  RSpec.describe ActiveFedora::Base do
4
2
 
5
3
  describe ".find" do
@@ -26,108 +24,4 @@ RSpec.describe ActiveFedora::Base do
26
24
  end
27
25
  end
28
26
 
29
- describe "attachments", attachments: true do
30
- before do
31
- class AttachToable < ActiveFedora::Base
32
- include Ddr::Models::HasAttachments
33
- end
34
- end
35
- after do
36
- Object.send(:remove_const, :AttachToable)
37
- end
38
- describe "#can_have_attachments?" do
39
- it "#should return true if the object can have attachments, otherwise false" do
40
- expect(AttachToable.new.can_have_attachments?).to be_truthy
41
- expect(ActiveFedora::Base.new.can_have_attachments?).to be_falsey
42
- end
43
- end
44
- describe "#has_attachments?" do
45
- let(:attach_toable) { AttachToable.new }
46
- before { attach_toable.attachments << Attachment.new }
47
- it "should return true if the object has Attachments, otherwise false" do
48
- expect(AttachToable.new).not_to have_attachments
49
- expect(ActiveFedora::Base.new).not_to have_attachments
50
- expect(attach_toable).to have_attachments
51
- end
52
- end
53
- end
54
-
55
- describe "children", children: true do
56
- before do
57
- class Childrenable < ActiveFedora::Base
58
- has_many :children, property: :is_member_of, class_name: 'ActiveFedora::Base'
59
- end
60
- end
61
- after do
62
- Object.send(:remove_const, :Childrenable)
63
- end
64
- describe "#can_have_children?" do
65
- it "should return true if object can have children, otherwise false" do
66
- expect(Childrenable.new.can_have_children?).to be_truthy
67
- expect(ActiveFedora::Base.new.can_have_children?).to be_falsey
68
- end
69
- end
70
- describe "#has_children?" do
71
- let(:childrenable) { Childrenable.new }
72
- before { childrenable.children << ActiveFedora::Base.new }
73
- it "should return true if object has children, otherwise false" do
74
- expect(Childrenable.new).not_to have_children
75
- expect(ActiveFedora::Base.new).not_to have_children
76
- expect(childrenable).to have_children
77
- end
78
- end
79
- end
80
-
81
- describe "thumbnail" do
82
- before do
83
- class Thumbnailable < ActiveFedora::Base
84
- include Ddr::Models::HasThumbnail
85
- end
86
- end
87
- after do
88
- Object.send(:remove_const, :Thumbnailable)
89
- end
90
- describe "#can_have_thumbnail?" do
91
- it "should return true if object can have a thumbnail, else false" do
92
- expect(Thumbnailable.new.can_have_thumbnail?).to be_truthy
93
- expect(ActiveFedora::Base.new.can_have_thumbnail?).to be_falsey
94
- end
95
- end
96
- describe "#has_thumbnail?" do
97
- let(:thumbnailable) { Thumbnailable.new }
98
- before { allow(thumbnailable.datastreams[Ddr::Datastreams::THUMBNAIL]).to receive(:has_content?).and_return(true) }
99
- it "should return true if object has a thumbnail, else false" do
100
- expect(thumbnailable).to have_thumbnail
101
- expect(Thumbnailable.new).not_to have_thumbnail
102
- expect(ActiveFedora::Base.new).not_to have_thumbnail
103
- end
104
- end
105
- end
106
-
107
- describe "content" do
108
- before do
109
- class Contentable < ActiveFedora::Base
110
- include Ddr::Models::HasContent
111
- end
112
- end
113
- after do
114
- Object.send(:remove_const, :Contentable)
115
- end
116
- describe "#can_have_content?" do
117
- it "should return true if object can have content, else false" do
118
- expect(Contentable.new.can_have_content?).to be_truthy
119
- expect(ActiveFedora::Base.new.can_have_content?).to be_falsey
120
- end
121
- end
122
- describe "#has_content?" do
123
- let(:contentable) { Contentable.new }
124
- before { allow(contentable.datastreams[Ddr::Datastreams::CONTENT]).to receive(:has_content?).and_return(true) }
125
- it "should return true if object has content, else false" do
126
- expect(contentable).to have_content
127
- expect(Contentable.new).not_to have_content
128
- expect(ActiveFedora::Base.new).not_to have_content
129
- end
130
- end
131
- end
132
-
133
27
  end
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  module ActiveFedora
4
2
  RSpec.describe Datastream do
5
3
 
@@ -162,5 +160,38 @@ module ActiveFedora
162
160
 
163
161
  end # external datastreams
164
162
 
163
+ describe "notifications" do
164
+ let(:events) { [] }
165
+ before {
166
+ @subscriber = ActiveSupport::Notifications.subscribe(event_name) do |name, start, finish, id, payload|
167
+ events << payload
168
+ end
169
+ }
170
+ after {
171
+ ActiveSupport::Notifications.unsubscribe(@subscriber)
172
+ }
173
+ describe "on create" do
174
+ let(:obj) { ActiveFedora::Base.create }
175
+ let(:event_name) { "save.repo_file" }
176
+ specify {
177
+ obj.add_file_datastream("foo", dsid: "DS1", controlGroup: "M")
178
+ obj.save!
179
+ expect(events.last[:pid]).to eq obj.pid
180
+ expect(events.last[:file_id]).to eq "DS1"
181
+ expect(events.last[:profile]).to be_present
182
+ }
183
+ end
184
+ describe "on destroy" do
185
+ let(:obj) { FactoryGirl.create(:item) }
186
+ let(:event_name) { "delete.repo_file" }
187
+ specify {
188
+ obj.descMetadata.delete
189
+ expect(events.first[:pid]).to eq obj.pid
190
+ expect(events.first[:file_id]).to eq "descMetadata"
191
+ expect(events.first[:profile]).to be_present
192
+ }
193
+ end
194
+ end
195
+
165
196
  end
166
197
  end
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  RSpec.describe Attachment, type: :model, attachments: true do
4
2
 
5
3
  it_behaves_like "a DDR model"
@@ -0,0 +1,32 @@
1
+ module Ddr::Models
2
+ RSpec.describe Cache do
3
+
4
+ describe "#get" do
5
+ it "retrieves a value by key" do
6
+ expect(subject.get(:foo)).to be_nil
7
+ subject[:foo] = "bar"
8
+ expect(subject.get(:foo)).to eq "bar"
9
+ end
10
+ end
11
+
12
+ describe "#put" do
13
+ it "inserts a key/value" do
14
+ expect { subject.put(:foo, "bar") }.to change { subject[:foo] }.from(nil).to("bar")
15
+ end
16
+ end
17
+
18
+ describe "#with" do
19
+ it "returns the value of the block" do
20
+ result = subject.with(foo: "bar") { 1 }
21
+ expect(result).to eq 1
22
+ end
23
+ it "temporarily caches the arguments" do
24
+ subject.with(foo: "bar") do
25
+ expect(subject.get(:foo)).to eq "bar"
26
+ end
27
+ expect(subject.get(:foo)).to be_nil
28
+ end
29
+ end
30
+
31
+ end
32
+ end
@@ -21,27 +21,11 @@ RSpec.describe Collection, type: :model do
21
21
  end
22
22
 
23
23
  describe "title" do
24
- before do
25
- subject.title = [ "Test Collection" ]
26
- end
27
24
  it "indexes the collection title" do
28
25
  expect(subject.to_solr[Ddr::Index::Fields::COLLECTION_TITLE]).to eq("Test Collection")
29
26
  end
30
27
  end
31
28
 
32
- describe "legacy license information" do
33
- before do
34
- subject.defaultRights.license.title = ["License Title"]
35
- subject.defaultRights.license.description = ["License Description"]
36
- subject.defaultRights.license.url = ["http://library.duke.edu"]
37
- end
38
- it "indexes the terms" do
39
- expect(subject.to_solr[Ddr::Index::Fields::DEFAULT_LICENSE_TITLE]).to eq("License Title")
40
- expect(subject.to_solr[Ddr::Index::Fields::DEFAULT_LICENSE_DESCRIPTION]).to eq("License Description")
41
- expect(subject.to_solr[Ddr::Index::Fields::DEFAULT_LICENSE_URL]).to eq("http://library.duke.edu")
42
- end
43
- end
44
-
45
29
  describe "#components_from_solr" do
46
30
  subject { Collection.new(pid: 'test:1') }
47
31
  before do
@@ -66,7 +50,7 @@ RSpec.describe Collection, type: :model do
66
50
  end
67
51
 
68
52
  describe "creation" do
69
- subject { Collection.create(title: [ "Test Collection" ]) }
53
+ before { subject.save! }
70
54
  it "is governed by itself" do
71
55
  expect(subject.admin_policy).to eq(subject)
72
56
  end
@@ -75,9 +59,49 @@ RSpec.describe Collection, type: :model do
75
59
  describe "roles granted to creator" do
76
60
  let(:user) { FactoryGirl.build(:user) }
77
61
  before { subject.grant_roles_to_creator(user) }
78
- it "includes Curator roles in both resource and policy scopes" do
79
- expect(subject.roles.to_a).to eq([Ddr::Auth::Roles::Role.build(type: "Curator", agent: user.agent, scope: "resource"), Ddr::Auth::Roles::Role.build(type: "Curator", agent: user.agent, scope: "policy")])
62
+ its(:roles) { is_expected.to include(Ddr::Auth::Roles::Role.build(type: "Curator", agent: user, scope: "policy")) }
63
+ end
64
+
65
+ describe "default roles granted" do
66
+ describe "and the metadata managers group is set" do
67
+ before do
68
+ allow(Ddr::Auth).to receive(:metadata_managers_group) { "metadata_managers" }
69
+ subject.save!
70
+ end
71
+ it "includes the MetadataEditor role in policy scope for the Metadata Managers group" do
72
+ expect(subject.roles.to_a).to eq([Ddr::Auth::Roles::Role.build(type: "MetadataEditor", agent: "metadata_managers", scope: "policy")])
73
+ end
74
+ end
75
+ describe "and the metadata managers group is not set" do
76
+ before do
77
+ allow(Ddr::Auth).to receive(:metadata_managers_group) { nil }
78
+ subject.save!
79
+ end
80
+ its(:roles) { is_expected.to be_empty }
80
81
  end
81
82
  end
82
83
 
84
+ describe "attachments" do
85
+ its(:can_have_attachments?) { is_expected.to be true }
86
+ it { is_expected.not_to have_attachments }
87
+ specify {
88
+ subject.attachments << Attachment.new
89
+ expect(subject).to have_attachments
90
+ }
91
+ end
92
+
93
+ describe "content" do
94
+ its(:can_have_content?) { is_expected.to be false }
95
+ it { is_expected.to_not have_content }
96
+ end
97
+
98
+ describe "children" do
99
+ its(:can_have_children?) { is_expected.to be true }
100
+ it { is_expected.to_not have_children }
101
+ specify {
102
+ subject.children << Item.new
103
+ expect(subject).to have_children
104
+ }
105
+ end
106
+
83
107
  end
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  RSpec.describe Component, type: :model, components: true do
4
2
 
5
3
  it_behaves_like "a DDR model"
@@ -8,6 +6,7 @@ RSpec.describe Component, type: :model, components: true do
8
6
  it_behaves_like "it has an association", :belongs_to, :target, :has_external_target, "Target"
9
7
  it_behaves_like "a non-collection model"
10
8
  it_behaves_like "a potentially publishable object"
9
+ it_behaves_like "an object that can have an intermediate file"
11
10
 
12
11
  describe "indexing" do
13
12
  subject { FactoryGirl.build(:component) }
@@ -17,68 +16,59 @@ RSpec.describe Component, type: :model, components: true do
17
16
  its(:index_fields) { is_expected.to include(Ddr::Index::Fields::COLLECTION_URI => "info:fedora/test:1") }
18
17
  end
19
18
 
20
- describe "extracted text" do
21
- let(:parent) { FactoryGirl.create(:item) }
22
- describe "when the child is not already associated with the parent" do
23
- before {
24
- subject.extractedText.content = fixture_file_upload('extractedText1.txt')
25
- subject.save
26
- subject.reload
27
- }
28
- it "updates the parent index when associated" do
29
- expect(subject).to receive(:index_parent)
30
- subject.parent = parent
31
- subject.save
19
+ describe "default structure" do
20
+ describe "no content" do
21
+ it "should be nil" do
22
+ expect(subject.default_structure).to be_nil
32
23
  end
33
24
  end
34
- describe "when the child is already associated with the parent" do
35
- before {
36
- subject.parent = parent
37
- subject.save
38
- }
39
- describe "when there is no extracted text" do
40
- describe "and none is added" do
41
- it "does not trigger an index update on the parent" do
42
- expect(subject).not_to receive(:index_parent)
43
- subject.save
25
+ describe "has content" do
26
+ before { allow(subject).to receive(:has_content?) { true } }
27
+ before { allow(subject).to receive(:has_thumbnail?) { true } }
28
+ let(:struct) { subject.default_structure }
29
+ it "has the correct original file" do
30
+ expect(struct.uses[Ddr::Models::Structure::USE_ORIGINAL_FILE].first.href).to eq(Ddr::Datastreams::CONTENT)
31
+ end
32
+ it "has the correct preservation master file" do
33
+ expect(struct.uses[Ddr::Models::Structure::USE_PRESERVATION_MASTER_FILE].first.href)
34
+ .to eq(Ddr::Datastreams::CONTENT)
35
+ end
36
+ describe "intermediate file" do
37
+ describe "with intermediate file" do
38
+ before do
39
+ allow(subject).to receive(:has_intermediate_file?) { true }
40
+ end
41
+ it "has the correct structure file" do
42
+ expect(struct.uses[Ddr::Models::Structure::USE_INTERMEDIATE_FILE].first.href)
43
+ .to eq(Ddr::Datastreams::INTERMEDIATE_FILE)
44
44
  end
45
45
  end
46
- describe "and extracted text is added" do
47
- it "triggers an index update on the parent" do
48
- expect(subject).to receive(:index_parent)
49
- subject.extractedText.content = fixture_file_upload('extractedText1.txt')
50
- subject.save
46
+ describe "without intermediate image" do
47
+ it "has the correct structure file" do
48
+ expect(struct.uses[Ddr::Models::Structure::USE_INTERMEDIATE_FILE]).to be nil
51
49
  end
52
50
  end
53
51
  end
54
- describe "when extracted text exists" do
55
- before {
56
- subject.extractedText.content = fixture_file_upload('extractedText1.txt')
57
- subject.save
58
- subject.reload
59
- }
60
- describe "and is removed" do
61
- it "triggers an index update on the parent" do
62
- pending "Deleting a datastream does not mark the content as changed"
63
- expect(subject).to receive(:index_parent)
64
- subject.extractedText.delete
65
- subject.save
52
+ describe "service file" do
53
+ describe "with multires image" do
54
+ before do
55
+ allow(subject).to receive(:has_multires_image?) { true }
66
56
  end
67
- end
68
- describe "and doesn't change" do
69
- it "triggers an index update on the parent" do
70
- expect(subject).to receive(:index_parent)
71
- subject.save
57
+ it "has the correct structure file" do
58
+ expect(struct.uses[Ddr::Models::Structure::USE_SERVICE_FILE].first.href)
59
+ .to eq(Ddr::Datastreams::MULTIRES_IMAGE)
72
60
  end
73
61
  end
74
- describe "and changes" do
75
- it "triggers an index update on the parent" do
76
- expect(subject).to receive(:index_parent)
77
- subject.extractedText.content = fixture_file_upload('extractedText2.txt')
78
- subject.save
62
+ describe "without multires image" do
63
+ it "has the correct structure file" do
64
+ expect(struct.uses[Ddr::Models::Structure::USE_SERVICE_FILE].first.href).to eq(Ddr::Datastreams::CONTENT)
79
65
  end
80
66
  end
81
67
  end
68
+ it "has the correct thumbnail image" do
69
+ expect(struct.uses[Ddr::Models::Structure::USE_THUMBNAIL_IMAGE].first.href).to eq(Ddr::Datastreams::THUMBNAIL)
70
+ end
82
71
  end
72
+
83
73
  end
84
74
  end