ddr-models 2.11.0 → 3.0.0.alpha.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (268) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/.travis.yml +7 -6
  4. data/Gemfile +2 -3
  5. data/Rakefile +5 -5
  6. data/app/controllers/users/sessions_controller.rb +5 -0
  7. data/app/helpers/models_helper.rb +7 -0
  8. data/app/models/attachment.rb +3 -5
  9. data/app/models/collection.rb +12 -79
  10. data/app/models/component.rb +8 -67
  11. data/app/models/item.rb +8 -73
  12. data/app/models/target.rb +6 -5
  13. data/config/initializers/active_fedora_base.rb +11 -30
  14. data/config/initializers/{active_fedora_datastream.rb → active_fedora_file.rb} +1 -1
  15. data/config/initializers/devise.rb +2 -3
  16. data/config/initializers/subscriptions.rb +2 -19
  17. data/ddr-models.gemspec +10 -14
  18. data/lib/ddr/actions/fixity_check.rb +1 -1
  19. data/lib/ddr/actions/virus_check.rb +17 -10
  20. data/lib/ddr/auth.rb +6 -38
  21. data/lib/ddr/auth/ability.rb +1 -5
  22. data/lib/ddr/auth/ability_definitions/collection_ability_definitions.rb +0 -16
  23. data/lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb +10 -4
  24. data/lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb +16 -9
  25. data/lib/ddr/auth/ability_factory.rb +25 -2
  26. data/lib/ddr/auth/abstract_ability.rb +1 -2
  27. data/lib/ddr/auth/auth_context.rb +0 -18
  28. data/lib/ddr/auth/auth_context_factory.rb +2 -0
  29. data/lib/ddr/auth/group.rb +0 -6
  30. data/lib/ddr/auth/grouper_gateway.rb +0 -24
  31. data/lib/ddr/auth/permissions.rb +1 -12
  32. data/lib/ddr/auth/role_based_access_controls_enforcement.rb +5 -5
  33. data/lib/ddr/auth/roles.rb +1 -11
  34. data/lib/ddr/auth/roles/role_set.rb +0 -7
  35. data/lib/ddr/auth/roles/roles_datastream.rb +9 -0
  36. data/lib/ddr/contacts.rb +25 -0
  37. data/lib/ddr/datastreams.rb +10 -28
  38. data/lib/ddr/datastreams/datastream_behavior.rb +30 -100
  39. data/lib/ddr/datastreams/descriptive_metadata_datastream.rb +28 -31
  40. data/lib/ddr/datastreams/fits_datastream.rb +9 -22
  41. data/lib/ddr/datastreams/metadata_datastream.rb +17 -31
  42. data/lib/ddr/derivatives.rb +13 -16
  43. data/lib/ddr/derivatives/derivative.rb +68 -0
  44. data/lib/ddr/derivatives/{generator.rb → generators/generator.rb} +11 -7
  45. data/lib/ddr/derivatives/generators/png_generator.rb +23 -0
  46. data/lib/ddr/derivatives/generators/ptif_generator.rb +56 -0
  47. data/lib/ddr/derivatives/multires_image.rb +59 -0
  48. data/lib/ddr/derivatives/thumbnail.rb +36 -0
  49. data/lib/ddr/events.rb +0 -1
  50. data/lib/ddr/events/deletion_event.rb +9 -5
  51. data/lib/ddr/events/event.rb +8 -13
  52. data/lib/ddr/events/fixity_check_event.rb +0 -6
  53. data/lib/ddr/events/ingestion_event.rb +9 -5
  54. data/lib/ddr/events/update_event.rb +4 -17
  55. data/lib/ddr/index.rb +4 -4
  56. data/lib/ddr/index/abstract_query_result.rb +4 -3
  57. data/lib/ddr/index/connection.rb +9 -28
  58. data/lib/ddr/index/csv_query_result.rb +32 -47
  59. data/lib/ddr/index/field.rb +1 -11
  60. data/lib/ddr/index/fields.rb +16 -99
  61. data/lib/ddr/index/filter.rb +30 -103
  62. data/lib/ddr/index/filters.rb +19 -0
  63. data/lib/ddr/index/query.rb +11 -58
  64. data/lib/ddr/index/query_builder.rb +36 -147
  65. data/lib/ddr/index/query_clause.rb +19 -79
  66. data/lib/ddr/index/query_result.rb +4 -36
  67. data/lib/ddr/index/query_value.rb +18 -0
  68. data/lib/ddr/index/response.rb +2 -19
  69. data/lib/ddr/jobs.rb +12 -0
  70. data/lib/ddr/jobs/fits_file_characterization.rb +51 -0
  71. data/lib/ddr/jobs/permanent_id.rb +23 -0
  72. data/lib/ddr/managers.rb +1 -0
  73. data/lib/ddr/managers/derivatives_manager.rb +53 -93
  74. data/lib/ddr/managers/permanent_id_manager.rb +91 -0
  75. data/lib/ddr/managers/technical_metadata_manager.rb +10 -24
  76. data/lib/ddr/managers/workflow_manager.rb +10 -29
  77. data/lib/ddr/models.rb +50 -101
  78. data/lib/ddr/models/access_controllable.rb +12 -0
  79. data/lib/ddr/models/admin_set.rb +5 -16
  80. data/lib/ddr/models/base.rb +45 -165
  81. data/lib/ddr/models/describable.rb +19 -21
  82. data/lib/ddr/models/engine.rb +11 -39
  83. data/lib/ddr/models/error.rb +0 -3
  84. data/lib/ddr/models/file_management.rb +36 -72
  85. data/lib/ddr/models/finding_aid.rb +2 -35
  86. data/lib/ddr/models/fixity_checkable.rb +4 -0
  87. data/lib/ddr/models/governable.rb +3 -1
  88. data/lib/ddr/models/has_admin_metadata.rb +82 -56
  89. data/lib/ddr/models/has_attachments.rb +3 -1
  90. data/lib/ddr/models/has_children.rb +3 -7
  91. data/lib/ddr/models/has_content.rb +35 -32
  92. data/lib/ddr/models/has_multires_image.rb +7 -12
  93. data/lib/ddr/models/has_struct_metadata.rb +44 -6
  94. data/lib/ddr/models/has_thumbnail.rb +1 -4
  95. data/lib/ddr/models/indexing.rb +97 -186
  96. data/lib/ddr/models/licenses/admin_policy_license.rb +11 -0
  97. data/lib/ddr/models/licenses/effective_license.rb +9 -0
  98. data/lib/ddr/models/licenses/inherited_license.rb +9 -0
  99. data/lib/ddr/models/licenses/license.rb +21 -0
  100. data/lib/ddr/models/licenses/parent_license.rb +11 -0
  101. data/lib/ddr/models/metadata/descriptive_metadata.rb +50 -0
  102. data/lib/ddr/models/metadata/metadata.rb +37 -0
  103. data/lib/ddr/models/metadata/metadata_mapper.rb +32 -0
  104. data/lib/ddr/models/metadata/metadata_mappers.rb +18 -0
  105. data/lib/ddr/models/metadata/metadata_term.rb +24 -0
  106. data/lib/ddr/models/metadata/metadata_vocabularies.rb +18 -0
  107. data/lib/ddr/models/metadata/metadata_vocabulary.rb +34 -0
  108. data/lib/ddr/models/solr_document.rb +24 -156
  109. data/lib/ddr/models/struct_div.rb +63 -0
  110. data/lib/ddr/models/structure.rb +39 -175
  111. data/lib/ddr/models/version.rb +1 -1
  112. data/lib/ddr/models/year_facet.rb +118 -60
  113. data/lib/ddr/notifications.rb +12 -10
  114. data/lib/ddr/utils.rb +15 -28
  115. data/lib/ddr/vocab.rb +17 -15
  116. data/lib/ddr/vocab/asset.rb +17 -42
  117. data/lib/ddr/vocab/contact.rb +7 -5
  118. data/lib/ddr/vocab/display.rb +8 -6
  119. data/lib/ddr/vocab/duke_terms.rb +10 -8
  120. data/lib/ddr/vocab/rdf_vocabulary_parser.rb +39 -37
  121. data/lib/ddr/vocab/roles.rb +19 -17
  122. data/lib/ddr/vocab/sources/duketerms.rdf +8 -22
  123. data/lib/ddr/vocab/vocabulary.rb +26 -26
  124. data/spec/auth/ability_factory_spec.rb +1 -18
  125. data/spec/auth/ability_spec.rb +15 -119
  126. data/spec/auth/effective_permissions_spec.rb +1 -1
  127. data/spec/auth/effective_roles_spec.rb +1 -1
  128. data/spec/auth/ldap_gateway_spec.rb +9 -0
  129. data/spec/contacts/contacts_spec.rb +26 -0
  130. data/spec/controllers/including_role_based_access_controls_enforcement_spec.rb +5 -5
  131. data/spec/derivatives/multires_image_spec.rb +48 -0
  132. data/spec/derivatives/png_generator_spec.rb +8 -13
  133. data/spec/derivatives/ptif_generator_spec.rb +11 -9
  134. data/spec/derivatives/thumbnail_spec.rb +48 -0
  135. data/spec/dummy/config/environments/test.rb +1 -1
  136. data/spec/dummy/db/schema.rb +23 -25
  137. data/spec/factories/attachment_factories.rb +2 -2
  138. data/spec/factories/collection_factories.rb +2 -3
  139. data/spec/factories/component_factories.rb +2 -2
  140. data/spec/factories/item_factories.rb +2 -2
  141. data/spec/factories/structure_factories.rb +2 -8
  142. data/spec/factories/test_model_factories.rb +12 -4
  143. data/spec/fixtures/fits/document.xml +44 -42
  144. data/spec/fixtures/fits/image.xml +41 -42
  145. data/spec/helpers/models_helper_spec.rb +11 -0
  146. data/spec/index/filter_spec.rb +30 -208
  147. data/spec/index/filters_spec.rb +17 -0
  148. data/spec/index/query_spec.rb +10 -82
  149. data/spec/jobs/fits_file_characterization_spec.rb +52 -0
  150. data/spec/managers/derivatives_manager_spec.rb +105 -107
  151. data/spec/managers/technical_metadata_manager_spec.rb +27 -34
  152. data/spec/models/active_fedora_base_spec.rb +105 -5
  153. data/spec/models/active_fedora_datastream_spec.rb +39 -106
  154. data/spec/models/admin_set_spec.rb +10 -43
  155. data/spec/models/attachment_spec.rb +2 -3
  156. data/spec/models/collection_spec.rb +11 -225
  157. data/spec/models/component_spec.rb +4 -106
  158. data/spec/models/descriptive_metadata_spec.rb +38 -0
  159. data/spec/models/effective_license_spec.rb +64 -0
  160. data/spec/models/events_spec.rb +59 -52
  161. data/spec/models/file_management_spec.rb +13 -113
  162. data/spec/models/finding_aid_spec.rb +8 -31
  163. data/spec/models/has_admin_metadata_spec.rb +122 -131
  164. data/spec/models/has_children_spec.rb +3 -3
  165. data/spec/models/has_struct_metadata_spec.rb +37 -50
  166. data/spec/models/indexing_spec.rb +23 -160
  167. data/spec/models/item_spec.rb +2 -133
  168. data/spec/models/license_spec.rb +24 -0
  169. data/spec/models/solr_document_spec.rb +47 -236
  170. data/spec/models/struct_div_spec.rb +70 -0
  171. data/spec/models/structure_spec.rb +11 -89
  172. data/spec/models/target_spec.rb +2 -4
  173. data/spec/models/year_facet_spec.rb +23 -50
  174. data/spec/spec_helper.rb +13 -17
  175. data/spec/support/ezid_mock_identifier.rb +2 -2
  176. data/spec/support/shared_examples_for_auth_contexts.rb +0 -33
  177. data/spec/support/shared_examples_for_ddr_models.rb +94 -142
  178. data/spec/support/shared_examples_for_describables.rb +36 -31
  179. data/spec/support/shared_examples_for_governables.rb +2 -3
  180. data/spec/support/shared_examples_for_has_content.rb +46 -101
  181. data/spec/support/shared_examples_for_indexing.rb +6 -6
  182. data/spec/support/shared_examples_for_non_collection_models.rb +1 -32
  183. data/spec/support/structural_metadata_helper.rb +59 -230
  184. data/spec/utils_spec.rb +2 -0
  185. metadata +96 -229
  186. data/.ruby-version +0 -1
  187. data/config/initializers/rsolr_monkey_patches.rb +0 -7
  188. data/config/initializers/rubydora_monkey_patch.rb +0 -11
  189. data/config/locales/ddr-models.en.yml +0 -81
  190. data/db/migrate/20161021201011_add_permanent_id_to_events.rb +0 -8
  191. data/lib/ddr/auth/ability_definitions/admin_set_ability_definitions.rb +0 -9
  192. data/lib/ddr/auth/ability_definitions/lock_ability_definitions.rb +0 -13
  193. data/lib/ddr/auth/ability_definitions/publication_ability_definitions.rb +0 -16
  194. data/lib/ddr/datastreams/administrative_metadata_datastream.rb +0 -75
  195. data/lib/ddr/datastreams/caption_datastream.rb +0 -5
  196. data/lib/ddr/datastreams/content_datastream.rb +0 -17
  197. data/lib/ddr/datastreams/delete_external_files.rb +0 -29
  198. data/lib/ddr/datastreams/external_file_datastream.rb +0 -80
  199. data/lib/ddr/datastreams/intermediate_file_datastream.rb +0 -5
  200. data/lib/ddr/datastreams/multires_image_datastream.rb +0 -5
  201. data/lib/ddr/datastreams/streamable_media_datastream.rb +0 -5
  202. data/lib/ddr/derivatives/png_generator.rb +0 -17
  203. data/lib/ddr/derivatives/ptif_generator.rb +0 -55
  204. data/lib/ddr/derivatives/update_derivatives.rb +0 -25
  205. data/lib/ddr/events/deaccession_event.rb +0 -8
  206. data/lib/ddr/index/field_attribute.rb +0 -22
  207. data/lib/ddr/index/query_params.rb +0 -40
  208. data/lib/ddr/index/sort_order.rb +0 -28
  209. data/lib/ddr/models/cache.rb +0 -20
  210. data/lib/ddr/models/captionable.rb +0 -37
  211. data/lib/ddr/models/contact.rb +0 -23
  212. data/lib/ddr/models/file_characterization.rb +0 -37
  213. data/lib/ddr/models/has_intermediate_file.rb +0 -41
  214. data/lib/ddr/models/language.rb +0 -31
  215. data/lib/ddr/models/media_type.rb +0 -22
  216. data/lib/ddr/models/permanent_id.rb +0 -240
  217. data/lib/ddr/models/rights_statement.rb +0 -25
  218. data/lib/ddr/models/streamable.rb +0 -37
  219. data/lib/ddr/models/structures/agent.rb +0 -49
  220. data/lib/ddr/models/structures/component_type_term.rb +0 -29
  221. data/lib/ddr/models/structures/div.rb +0 -64
  222. data/lib/ddr/models/structures/f_locat.rb +0 -54
  223. data/lib/ddr/models/structures/file.rb +0 -52
  224. data/lib/ddr/models/structures/file_grp.rb +0 -35
  225. data/lib/ddr/models/structures/file_sec.rb +0 -22
  226. data/lib/ddr/models/structures/fptr.rb +0 -31
  227. data/lib/ddr/models/structures/mets_hdr.rb +0 -37
  228. data/lib/ddr/models/structures/mptr.rb +0 -49
  229. data/lib/ddr/models/structures/struct_map.rb +0 -40
  230. data/lib/ddr/models/with_content_file.rb +0 -37
  231. data/spec/datastreams/external_file_datastream_spec.rb +0 -48
  232. data/spec/dummy/config/structure_component_type.yml +0 -18
  233. data/spec/fixtures/abcd1234.vtt +0 -38
  234. data/spec/fixtures/arrow1rightred_e0.gif +0 -0
  235. data/spec/fixtures/extractedText1.txt +0 -1
  236. data/spec/fixtures/extractedText2.txt +0 -1
  237. data/spec/fixtures/extractedText3.txt +0 -3
  238. data/spec/fixtures/imageA.jpg +0 -0
  239. data/spec/fixtures/imageB.jpg +0 -0
  240. data/spec/index/csv_query_result_spec.rb +0 -44
  241. data/spec/index/fields_spec.rb +0 -380
  242. data/spec/index/query_builder_spec.rb +0 -140
  243. data/spec/index/query_clause_spec.rb +0 -68
  244. data/spec/models/cache_spec.rb +0 -32
  245. data/spec/models/contact_spec.rb +0 -56
  246. data/spec/models/descriptive_metadata_datastream_spec.rb +0 -139
  247. data/spec/models/file_characterization_spec.rb +0 -39
  248. data/spec/models/language_spec.rb +0 -59
  249. data/spec/models/media_type_spec.rb +0 -46
  250. data/spec/models/permanent_id_spec.rb +0 -432
  251. data/spec/models/rights_statement_spec.rb +0 -55
  252. data/spec/models/structures/agent_spec.rb +0 -30
  253. data/spec/models/structures/component_type_term_spec.rb +0 -14
  254. data/spec/models/structures/div_spec.rb +0 -26
  255. data/spec/models/structures/f_locat_spec.rb +0 -78
  256. data/spec/models/structures/file_grp_spec.rb +0 -23
  257. data/spec/models/structures/file_sec_spec.rb +0 -22
  258. data/spec/models/structures/file_spec.rb +0 -60
  259. data/spec/models/structures/fptr_spec.rb +0 -23
  260. data/spec/models/structures/mets_hdr_spec.rb +0 -26
  261. data/spec/models/structures/mptr_spec.rb +0 -25
  262. data/spec/models/structures/struct_map_spec.rb +0 -24
  263. data/spec/models/with_content_file_spec.rb +0 -37
  264. data/spec/support/shared_examples_for_associations.rb +0 -8
  265. data/spec/support/shared_examples_for_captionable.rb +0 -23
  266. data/spec/support/shared_examples_for_has_intermediate_file.rb +0 -28
  267. data/spec/support/shared_examples_for_publication.rb +0 -43
  268. data/spec/support/shared_examples_for_streamable_media.rb +0 -23
@@ -1,59 +0,0 @@
1
- module Ddr::Models
2
- RSpec.describe Language, ddr_aux: true do
3
-
4
- describe ".call" do
5
- let(:obj) { Item.new }
6
-
7
- describe "when the object has a language" do
8
- before { obj.language = ["cym"] }
9
- let(:language) {
10
- described_class.new("id"=>1, "code"=>"cym", "title"=>"Welsh", "created_at"=>"2015-09-15T16:15:58.514Z", "updated_at"=>"2015-09-15T16:15:58.514Z")
11
- }
12
- describe "and the language code is found" do
13
- before {
14
- allow(described_class).to receive(:find_by_code).with("cym") { language }
15
- }
16
- it "returns a Language instance" do
17
- expect(described_class.call(obj)).to eq([language])
18
- end
19
- end
20
- describe "and the language is not found" do
21
- before {
22
- allow(described_class).to receive(:find_by_code).with("cym")
23
- .and_raise(ActiveResource::ResourceNotFound, "404")
24
- }
25
- it "raises an exception" do
26
- expect { described_class.call(obj) }.to raise_error(Ddr::Models::NotFoundError)
27
- end
28
- end
29
- end
30
-
31
- describe "when the object does not have language" do
32
- it "returns empty array" do
33
- expect(described_class).not_to receive(:find_by_code)
34
- expect(described_class.call(obj)).to eq([])
35
- end
36
- end
37
- end
38
-
39
-
40
- describe ".codes" do
41
- let(:entries) { [ described_class.new(id: 1, code: 'cym', label: 'Welsh'),
42
- described_class.new(id: 2, code: 'fre', label: 'French') ] }
43
- let(:response_collection) { ActiveResource::Collection.new }
44
- before do
45
- response_collection.elements = entries
46
- allow(described_class).to receive(:all) { response_collection }
47
- end
48
- it "returns the defined codes" do
49
- expect(described_class.codes).to match_array([ entries[0].code, entries[1].code ])
50
- end
51
- end
52
-
53
- describe "instance methods" do
54
- subject { described_class.new("id"=>1, "code"=>"cym", "label"=>"Welsh") }
55
- its(:to_s) { is_expected.to eq("Welsh") }
56
- end
57
-
58
- end
59
- end
@@ -1,46 +0,0 @@
1
- module Ddr::Models
2
- RSpec.describe MediaType do
3
-
4
- subject { described_class.call(file) }
5
-
6
- describe "when a preferred media type is available" do
7
- describe "with a file path" do
8
- let(:file) { 'foo.mp4' }
9
- it { is_expected.to eq 'video/mp4' }
10
- end
11
- describe "with an object that responds to :path" do
12
- let(:file) { double(path: 'foo.mp4') }
13
- it { is_expected.to eq 'video/mp4' }
14
- end
15
- end
16
- describe "when a preferred media type is not available" do
17
- describe "and the file responds to :content_type" do
18
- let(:file) { double(path: 'foo.jpg', content_type: 'foo/bar') }
19
- it { is_expected.to eq 'foo/bar' }
20
- end
21
- describe "and the file does not respond to :content_type" do
22
- describe "and MIME types are present" do
23
- describe "with an object that responds to :path" do
24
- let(:file) { double(path: 'foo.jpg') }
25
- it { is_expected.to eq 'image/jpeg' }
26
- end
27
- describe "with a file path" do
28
- let(:file) { 'foo.jpg' }
29
- it { is_expected.to eq 'image/jpeg' }
30
- end
31
- end
32
- describe "and MIME types are not present" do
33
- describe "with an object that responds to :path" do
34
- let(:file) { double(path: 'foo.bar') }
35
- it { is_expected.to eq 'application/octet-stream' }
36
- end
37
- describe "with a file path" do
38
- let(:file) { 'foo.bar' }
39
- it { is_expected.to eq 'application/octet-stream' }
40
- end
41
- end
42
- end
43
- end
44
-
45
- end
46
- end
@@ -1,432 +0,0 @@
1
- module Ddr::Models
2
- RSpec.describe PermanentId do
3
-
4
- describe "auto assigment" do
5
- let(:obj) { FactoryGirl.create(:item) }
6
- describe "when enabled" do
7
- let!(:id) { described_class.identifier_class.new("foo") }
8
- before do
9
- allow(id).to receive(:save) { nil }
10
- allow(described_class.identifier_class).to receive(:mint) { id }
11
- allow(described_class.identifier_class).to receive(:find).with("foo") { id }
12
- allow(Ddr::Models).to receive(:auto_assign_permanent_id) { true }
13
- end
14
- it "assigns a permanent id to the object" do
15
- obj.reload
16
- expect(obj.permanent_id).to eq("foo")
17
- expect(obj.permanent_url).to eq("https://idn.duke.edu/foo")
18
- end
19
- end
20
- describe "when disabled" do
21
- before do
22
- allow(Ddr::Models).to receive(:auto_assign_permanent_id) { false }
23
- end
24
- it "does not assign a permanent id to the object" do
25
- expect(obj.reload.permanent_id).to be_nil
26
- end
27
- end
28
- end
29
-
30
- describe "assignment" do
31
- let(:obj) { FactoryGirl.create(:item) }
32
- let!(:id) { described_class.identifier_class.new("foo") }
33
- before do
34
- allow(id).to receive(:save) { nil }
35
- allow(described_class.identifier_class).to receive(:mint) { id }
36
- allow(described_class.identifier_class).to receive(:find).with("foo") { id }
37
- end
38
- it "creates an update event" do
39
- expect { described_class.assign!(obj) }.to change(Ddr::Events::UpdateEvent, :count).by(1)
40
- end
41
- end
42
-
43
- describe "auto updating" do
44
- let(:obj) { Item.create(pid: "test:1") }
45
- let!(:id) { described_class.identifier_class.new("foo") }
46
- before do
47
- allow(described_class.identifier_class).to receive(:find).with("foo") { id }
48
- end
49
- describe "when enabled" do
50
- before do
51
- allow(Ddr::Models).to receive(:auto_update_permanent_id) { true }
52
- end
53
- describe "when the object workflow state changes" do
54
- describe "and the object has a permanent id" do
55
- before do
56
- allow(id).to receive(:save) { nil }
57
- obj.permanent_id = "foo"
58
- end
59
- after do
60
- obj.permanent_id = nil
61
- obj.save!
62
- end
63
- it "updates the permanent id" do
64
- expect { obj.publish! }.to change(id, :status).to("public")
65
- end
66
- end
67
- describe "and the object does not have a permanent id" do
68
- it "does not update the permanent id" do
69
- expect { obj.publish! }.not_to change(id, :status)
70
- end
71
- end
72
- end
73
- describe "when the object workflow state does not change" do
74
- it "does not update the permanent id" do
75
- expect { obj.save! }.not_to change(id, :status)
76
- end
77
- end
78
- end
79
- describe "when disabled" do
80
- before do
81
- allow(Ddr::Models).to receive(:auto_update_permanent_id) { false }
82
- end
83
- describe "when the object workflow state changes" do
84
- describe "and the object has a permanent id" do
85
- before do
86
- allow(id).to receive(:save) { nil }
87
- obj.permanent_id = "foo"
88
- end
89
- after do
90
- obj.permanent_id = nil
91
- obj.save!
92
- end
93
- it "does not update the permanent id" do
94
- expect { obj.publish! }.not_to change(id, :status)
95
- end
96
- end
97
- describe "and the object does not have a permanent id" do
98
- it "does not update the permanent id" do
99
- expect { obj.publish! }.not_to change(id, :status)
100
- end
101
- end
102
- end
103
- end
104
- end
105
-
106
- describe "auto deleting / marking unavailable" do
107
- describe "when enabled" do
108
- before do
109
- allow(Ddr::Models).to receive(:auto_update_permanent_id) { true }
110
- end
111
- describe "when an object has a permanent id" do
112
- let(:obj) { Item.create(pid: "test:1", permanent_id: "foo") }
113
- let!(:id) { described_class.identifier_class.new("foo") }
114
- before do
115
- allow(id).to receive(:save) { nil }
116
- allow(described_class.identifier_class).to receive(:find).with("foo") { id }
117
- end
118
- describe "and it's deacessioned" do
119
- specify {
120
- expect(described_class).to receive(:deaccession!).with("test:1", "foo", nil) { nil }
121
- obj.deaccession
122
- }
123
- end
124
- describe "and it's deleted" do
125
- specify {
126
- expect(described_class).not_to receive(:delete!)
127
- expect(described_class).not_to receive(:deaccession!)
128
- obj.send(:delete)
129
- }
130
- end
131
- describe "and it's destroyed" do
132
- specify {
133
- expect(described_class).to receive(:delete!).with("test:1", "foo", nil) { nil }
134
- obj.destroy
135
- }
136
- end
137
- end
138
- describe "when an object does not have a permanent id" do
139
- let(:obj) { FactoryGirl.create(:item) }
140
- describe "and it's deacessioned" do
141
- specify {
142
- expect(described_class).not_to receive(:deaccession!)
143
- obj.deaccession
144
- }
145
- end
146
- describe "and it's deleted" do
147
- specify {
148
- expect(described_class).not_to receive(:deaccession!)
149
- expect(described_class).not_to receive(:delete!)
150
- obj.send(:delete)
151
- }
152
- end
153
- describe "and it's destroyed" do
154
- specify {
155
- expect(described_class).not_to receive(:delete!)
156
- obj.destroy
157
- }
158
- end
159
- end
160
- end
161
- describe "when disabled" do
162
- before do
163
- allow(Ddr::Models).to receive(:auto_update_permanent_id) { false }
164
- end
165
- describe "when an object has a permanent id" do
166
- let(:obj) { Item.create(pid: "test:1", permanent_id: "foo") }
167
- let!(:id) { described_class.identifier_class.new("foo") }
168
- before do
169
- allow(id).to receive(:save) { nil }
170
- allow(described_class.identifier_class).to receive(:find).with("foo") { id }
171
- end
172
- describe "and it's deacessioned" do
173
- specify {
174
- expect(described_class).not_to receive(:deaccession!)
175
- obj.deaccession
176
- }
177
- end
178
- describe "and it's destroyed" do
179
- specify {
180
- expect(described_class).not_to receive(:delete!)
181
- obj.destroy
182
- }
183
- end
184
- end
185
- end
186
- end
187
-
188
- describe "constructor" do
189
- describe "when the object is new" do
190
- let(:obj) { FactoryGirl.build(:item) }
191
- it "raises an error" do
192
- expect { described_class.new(obj) }.to raise_error(PermanentId::RepoObjectNotPersisted)
193
- end
194
- end
195
- describe "when passed a repo object id" do
196
- let(:obj) { FactoryGirl.create(:item) }
197
- subject { described_class.new(obj.id) }
198
- its(:repo_id) { is_expected.to eq(obj.id) }
199
- end
200
- end
201
-
202
- describe "instance methods" do
203
- let(:obj) { FactoryGirl.create(:item) }
204
- subject { described_class.new(obj) }
205
-
206
- describe "#assign!" do
207
- describe "when the object already has a permanent identifier" do
208
- before { obj.permanent_id = "foo" }
209
- it "raises an error" do
210
- expect { subject.assign! }.to raise_error(PermanentId::AlreadyAssigned)
211
- expect { subject.assign!("bar") }.to raise_error(PermanentId::AlreadyAssigned)
212
- end
213
- end
214
- describe "when the object does not have a permanent identifier" do
215
- let(:obj) { FactoryGirl.create(:item) }
216
- let!(:id) { described_class.identifier_class.new("foo") }
217
- before do
218
- allow(described_class.identifier_class).to receive(:find).with("foo") { id }
219
- allow(id).to receive(:save) { nil }
220
- allow(obj).to receive(:save) { true }
221
- end
222
- describe "when passed an ARK" do
223
- before do
224
- subject.assign!("foo")
225
- end
226
- it "assigns the ARK" do
227
- expect(obj.permanent_id).to eq("foo")
228
- end
229
- it "sets the target on the identifier" do
230
- expect(id.target).to eq("https://repository.duke.edu/id/foo")
231
- end
232
- it "sets the status on the identifier" do
233
- expect(id.status).to eq("reserved")
234
- end
235
- it "sets the repository id on the identifier" do
236
- expect(id["fcrepo3.pid"]).to eq(obj.id)
237
- end
238
- end
239
- describe "when not passed an ARK" do
240
- before do
241
- subject.assign!("foo")
242
- allow(described_class.identifier_class).to receive(:mint) { id }
243
- end
244
- it "mints and assigns an ARK" do
245
- expect(obj.permanent_id).to eq("foo")
246
- end
247
- it "sets the target on the identifier" do
248
- expect(id.target).to eq("https://repository.duke.edu/id/foo")
249
- end
250
- it "sets the status on the identifier" do
251
- expect(id.status).to eq("reserved")
252
- end
253
- it "sets the repository id on the identifier" do
254
- expect(id["fcrepo3.pid"]).to eq(obj.id)
255
- end
256
- end
257
- end
258
- end
259
-
260
- describe "#update!" do
261
- describe "when the object has not been assigned a permanent id" do
262
- it "raises an error" do
263
- expect { subject.update! }.to raise_error(PermanentId::IdentifierNotAssigned)
264
- end
265
- end
266
- describe "when the object has been assigned a permanent id" do
267
- let!(:id) { described_class.identifier_class.new("foo") }
268
- before do
269
- allow(described_class.identifier_class).to receive(:find).with("foo") { id }
270
- obj.permanent_id = "foo"
271
- end
272
- it "sets the status on the permanent id" do
273
- expect(subject).to receive(:set_status!) { nil }
274
- subject.update!
275
- end
276
- end
277
- end
278
-
279
- describe "#deaccession!" do
280
- let!(:id) { described_class.identifier_class.new("foo") }
281
- subject { described_class.new("test:1", "foo") }
282
- before do
283
- allow(described_class.identifier_class).to receive(:find).with("foo") { id }
284
- allow(id).to receive(:save) { nil }
285
- end
286
- specify {
287
- expect(id).to receive(:delete)
288
- subject.deaccession!
289
- }
290
- describe " when the identifier is not reserved" do
291
- before { id.public! }
292
- specify {
293
- expect { subject.deaccession! }.to change(id, :status).to("unavailable | deaccessioned")
294
- }
295
- end
296
- describe "when the identifier is associated with another repo id" do
297
- before { subject.identifier_repo_id = "test:2" }
298
- specify {
299
- expect { subject.deaccession! }.to raise_error(PermanentId::Error)
300
- }
301
- end
302
- end
303
-
304
- describe "#delete!" do
305
- let!(:id) { described_class.identifier_class.new("foo") }
306
- subject { described_class.new("test:1", "foo") }
307
- before do
308
- allow(described_class.identifier_class).to receive(:find).with("foo") { id }
309
- end
310
- specify {
311
- expect(id).to receive(:delete)
312
- subject.delete!
313
- }
314
- describe " when the identifier is not reserved" do
315
- before do
316
- allow(id).to receive(:save) { nil }
317
- id.public!
318
- end
319
- specify {
320
- expect { subject.delete! }.to change(id, :status).to("unavailable | deleted")
321
- }
322
- end
323
- describe "when the identifier is associated with another repo id" do
324
- before { subject.identifier_repo_id = "test:2" }
325
- specify {
326
- expect { subject.delete! }.to raise_error(PermanentId::Error)
327
- }
328
- end
329
- end
330
-
331
- describe "identifier metadata" do
332
- let(:obj) { Item.create(pid: "test:1") }
333
- let!(:id) { described_class.identifier_class.new("foo") }
334
- subject { described_class.new(obj) }
335
- before do
336
- allow(subject).to receive(:identifier) { id }
337
- end
338
- describe "#identifier_repo_id" do
339
- before do
340
- id["fcrepo3.pid"] = "test:1"
341
- end
342
- its(:identifier_repo_id) { is_expected.to eq("test:1") }
343
- end
344
- describe "#identifier_repo_id=" do
345
- specify {
346
- subject.identifier_repo_id = "test:1"
347
- expect(id["fcrepo3.pid"]).to eq("test:1")
348
- }
349
- describe "when a value was previously assigned" do
350
- before { subject.identifier_repo_id = "test:1" }
351
- specify {
352
- expect { subject.identifier_repo_id = "test:2" }.to raise_error(PermanentId::Error)
353
- }
354
- end
355
- end
356
- describe "#set_identifier_repo_id" do
357
- specify {
358
- subject.set_identifier_repo_id
359
- expect(subject.identifier_repo_id).to eq("test:1")
360
- }
361
- end
362
- describe "#set_target" do
363
- specify {
364
- subject.set_target
365
- expect(subject.target).to eq("https://repository.duke.edu/id/foo")
366
- }
367
- end
368
- describe "#set_status" do
369
- describe "when object is published" do
370
- before { obj.workflow_state = "published" }
371
- describe "and identifier is public" do
372
- before { subject.public! }
373
- it "does not change" do
374
- expect { subject.set_status }.not_to change(subject, :status)
375
- end
376
- end
377
- describe "and identifier is reserved" do
378
- it "changes to public" do
379
- expect { subject.set_status }.to change(subject, :status).to("public")
380
- end
381
- end
382
- describe "and identifier is unavailable" do
383
- before { subject.unavailable! }
384
- it "changes to public" do
385
- expect { subject.set_status }.to change(subject, :status).to("public")
386
- end
387
- end
388
- end
389
- describe "when object is unpublished" do
390
- before { obj.workflow_state = "unpublished" }
391
- describe "and identifier is public" do
392
- before { subject.public! }
393
- it "changes to unavailable" do
394
- expect { subject.set_status }.to change(subject, :status).to("unavailable | not published")
395
- end
396
- end
397
- describe "and identifier is reserved" do
398
- it "does not change" do
399
- expect { subject.set_status }.not_to change(subject, :status)
400
- end
401
- end
402
- describe "and identifier is unavailable" do
403
- before { subject.unavailable! }
404
- it "does not change" do
405
- expect { subject.set_status }.not_to change(subject, :status)
406
- end
407
- end
408
- end
409
- describe "when object has no workflow state" do
410
- describe "and identifier is public" do
411
- before { subject.public! }
412
- it "does not change" do
413
- expect { subject.set_status }.not_to change(subject, :status)
414
- end
415
- end
416
- describe "and identifier is reserved" do
417
- it "does not change" do
418
- expect { subject.set_status }.not_to change(subject, :status)
419
- end
420
- end
421
- describe "and identifier is unavailable" do
422
- before { subject.unavailable! }
423
- it "does not change" do
424
- expect { subject.set_status }.not_to change(subject, :status)
425
- end
426
- end
427
- end
428
- end
429
- end
430
- end
431
- end
432
- end