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
@@ -0,0 +1,70 @@
1
+ require 'spec_helper'
2
+ require 'support/structural_metadata_helper'
3
+
4
+ module Ddr
5
+ module Models
6
+ RSpec.describe StructDiv, type: :model, structural_metadata: true do
7
+
8
+ let(:structmap_node) { nested_structure_document.xpath('//xmlns:structMap').first }
9
+ let(:struct_div) { described_class.new(structmap_node) }
10
+
11
+ describe "#initialize" do
12
+ it "should create the correct object" do
13
+ expect(struct_div.divs.size).to eq(2)
14
+ expect(struct_div.divs.first.label).to eq("Front")
15
+ expect(struct_div.divs.first.divs).to be_empty
16
+ expect(struct_div.divs.first.fptrs).to eq([ "test:5" ])
17
+ expect(struct_div.divs.last.label).to eq("Back")
18
+ expect(struct_div.divs.last.divs.size).to eq(2)
19
+ expect(struct_div.divs.last.fptrs).to be_empty
20
+ expect(struct_div.divs.last.divs.first.label).to eq("Top")
21
+ expect(struct_div.divs.last.divs.first.divs).to be_empty
22
+ expect(struct_div.divs.last.divs.first.fptrs).to eq([ "test:7" ])
23
+ expect(struct_div.divs.last.divs.last.label).to eq("Bottom")
24
+ expect(struct_div.divs.last.divs.last.divs).to be_empty
25
+ expect(struct_div.divs.last.divs.last.fptrs).to eq([ "test:6" ])
26
+ end
27
+ end
28
+
29
+ describe "#pids" do
30
+ context "top level" do
31
+ it "should return all pids in the structMap" do
32
+ expect(struct_div.pids).to match_array([ 'test:5', 'test:6', 'test:7' ])
33
+ end
34
+ end
35
+ end
36
+
37
+ describe "#docs" do
38
+ let(:solr_response) { [ { 'id'=>'test:5' }, { 'id'=>'test:6' }, { 'id'=>'test:7'} ] }
39
+ before do
40
+ allow(ActiveFedora::SolrService).to receive(:query) { solr_response }
41
+ end
42
+ it "should return a hash of Solr documents" do
43
+ results = struct_div.docs
44
+ expect(results.keys).to match_array([ 'test:5', 'test:6', 'test:7' ])
45
+ results.keys.each do |key|
46
+ expect(results[key]).to be_a(SolrDocument)
47
+ expect(results[key].id).to eq(key)
48
+ end
49
+ end
50
+ end
51
+
52
+ describe "#objects" do
53
+ let(:repo_objects) { [ Component.new(pid: 'test:5'), Component.new(pid: 'test:6'), Component.new(pid: 'test:7') ] }
54
+ before do
55
+ allow(ActiveFedora::Base).to receive(:find).with('test:5') { repo_objects[0] }
56
+ allow(ActiveFedora::Base).to receive(:find).with('test:6') { repo_objects[1] }
57
+ allow(ActiveFedora::Base).to receive(:find).with('test:7') { repo_objects[2] }
58
+ end
59
+ it "should return a hash of Active Fedora objects" do
60
+ results = struct_div.objects
61
+ expect(results.keys).to match_array([ 'test:5', 'test:6', 'test:7' ])
62
+ expect(results['test:5']).to eq(repo_objects[0])
63
+ expect(results['test:6']).to eq(repo_objects[1])
64
+ expect(results['test:7']).to eq(repo_objects[2])
65
+ end
66
+ end
67
+
68
+ end
69
+ end
70
+ end
@@ -1,99 +1,21 @@
1
1
  require 'spec_helper'
2
2
  require 'support/structural_metadata_helper'
3
3
 
4
- module Ddr::Models
5
- RSpec.describe Structure, type: :model, structural_metadata: true do
4
+ module Ddr
5
+ module Models
6
+ RSpec.describe Structure, type: :model, structural_metadata: true do
6
7
 
7
- describe "#files" do
8
- let(:structure) { FactoryGirl.build(:simple_structure)}
9
- it "returns a hash of structure files" do
10
- expect(structure.files.keys).to match_array([ 'abc', 'def', 'ghi' ])
11
- structure.files.values.each do |value|
12
- expect(value).to be_a(Structures::File)
13
- end
14
- end
15
- end
16
-
17
- describe "#uses" do
18
- let(:structure) { FactoryGirl.build(:simple_structure)}
19
- it "returns a hash of uses" do
20
- expect(structure.uses.keys).to match_array([ 'foo', 'bar', 'baz' ])
21
- expect(structure.uses['foo'].first.href).to eq('ark:/99999/fk4ab3')
22
- expect(structure.uses['bar'].first.href).to eq('ark:/99999/fk4cd9')
23
- expect(structure.uses['baz'].first.href).to eq('ark:/99999/fk4ef1')
24
- end
25
- end
8
+ let(:structure) { FactoryGirl.build(:multiple_struct_maps_structure) }
26
9
 
27
- describe "#creator" do
28
- describe "structure has a metsHdr" do
29
- let(:structure) { FactoryGirl.build(:simple_structure) }
30
- it "returns the creator" do
31
- expect(structure.creator).to eq(Ddr::Models::Structures::Agent::NAME_REPOSITORY_DEFAULT)
10
+ describe "#struct_maps" do
11
+ let(:struct_maps) { structure.struct_maps }
12
+ it "should include struct divs for each struct map" do
13
+ expect(struct_maps.keys).to match_array([ 'default', 'reverse' ])
14
+ expect(struct_maps['default']).to be_a(Ddr::Models::StructDiv)
15
+ expect(struct_maps['reverse']).to be_a(Ddr::Models::StructDiv)
32
16
  end
33
17
  end
34
- describe "structure does not have a metsHdr" do
35
- let(:structure) { FactoryGirl.build(:multiple_struct_maps_structure) }
36
- it "returns the creator" do
37
- expect(structure.creator).to be nil
38
- end
39
- end
40
- end
41
18
 
42
- describe "#repository_maintained?" do
43
- let(:structure) { FactoryGirl.build(:simple_structure)}
44
- before do
45
- allow(structure).to receive(:creator) { creator }
46
- end
47
- describe "maintained by the repository" do
48
- let(:creator) { Ddr::Models::Structures::Agent::NAME_REPOSITORY_DEFAULT }
49
- it "is true" do
50
- expect(structure.repository_maintained?).to be true
51
- end
52
- end
53
- describe "not maintained by the repository" do
54
- let(:creator) { 'foo' }
55
- it "is false" do
56
- expect(structure.repository_maintained?).to be false
57
- end
58
- end
59
19
  end
60
-
61
- describe "#dereferenced_structure" do
62
- describe "fptr case" do
63
- let(:structure) { FactoryGirl.build(:nested_structure) }
64
- let(:expected) { nested_structure_dereferenced_hash }
65
- before do
66
- flocat_x = instance_double("Structures::FLocat", effective_use: 'foo')
67
- flocat_y = instance_double("Structures::FLocat", effective_use: 'bar')
68
- flocat_z = instance_double("Structures::FLocat", effective_use: 'baz')
69
- file_a = instance_double("Structures::File", repo_ids: [ 'test:7' ], flocats: [ flocat_x ])
70
- file_b = instance_double("Structures::File", repo_ids: [ 'test:8' ], flocats: [ flocat_y ])
71
- file_c = instance_double("Structures::File", repo_ids: [ 'test:9' ], flocats: [ flocat_z ])
72
- allow(Structures::File).to receive(:find).with(an_instance_of(Ddr::Models::Structure), 'abc') { file_a }
73
- allow(Structures::File).to receive(:find).with(an_instance_of(Ddr::Models::Structure), 'def') { file_b }
74
- allow(Structures::File).to receive(:find).with(an_instance_of(Ddr::Models::Structure), 'ghi') { file_c }
75
- end
76
- it "returns the dereferenced structure" do
77
- expect(structure.dereferenced_structure).to eq(expected)
78
- end
79
- end
80
- describe "mptr case" do
81
- let(:structure) { FactoryGirl.build(:nested_structure_mptr) }
82
- let(:expected) { nested_structure_mptr_dereferenced_hash }
83
- before do
84
- solr_doc_a = instance_double("SolrDocument", id: 'test:7')
85
- solr_doc_b = instance_double("SolrDocument", id: 'test:8')
86
- solr_doc_c = instance_double("SolrDocument", id: 'test:9')
87
- allow_any_instance_of(Ddr::Models::Structures::Mptr).to receive(:ark?) { true }
88
- allow(::SolrDocument).to receive(:find_by_permanent_id).with('ark:/99999/fk4ab3') { solr_doc_a }
89
- allow(::SolrDocument).to receive(:find_by_permanent_id).with('ark:/99999/fk4cd9') { solr_doc_b }
90
- allow(::SolrDocument).to receive(:find_by_permanent_id).with('ark:/99999/fk4ef1') { solr_doc_c }
91
- end
92
- it "returns the dereferenced structure" do
93
- expect(structure.dereferenced_structure).to eq(expected)
94
- end
95
- end
96
- end
97
-
98
20
  end
99
- end
21
+ end
@@ -1,11 +1,9 @@
1
+ require 'spec_helper'
2
+
1
3
  RSpec.describe Target, type: :model, targets: true do
2
4
 
3
5
  it_behaves_like "a DDR model"
4
6
  it_behaves_like "an object that can have content"
5
- it_behaves_like "it has an association", :has_many, :components, :has_external_target, "Component"
6
- it_behaves_like "it has an association", :belongs_to, :collection, :is_external_target_for, "Collection"
7
7
  it_behaves_like "a non-collection model"
8
- it_behaves_like "an unpublishable object"
9
- it_behaves_like "an object that cannot be streamable"
10
8
 
11
9
  end
@@ -1,91 +1,64 @@
1
1
  module Ddr::Models
2
2
  RSpec.describe YearFacet do
3
3
 
4
- subject { described_class.call(obj) }
4
+ subject { described_class.new(obj) }
5
5
  let(:obj) { Item.new }
6
- before { obj.date = [ date ] }
6
+ before { obj.dc_date = [ date ] }
7
7
 
8
8
  describe "splitting on semicolons" do
9
9
  let(:date) { "1935; 1936; 1937; 1938" }
10
- it { is_expected.to eq([1935, 1936, 1937, 1938]) }
10
+ its(:values) { is_expected.to eq([1935, 1936, 1937, 1938]) }
11
11
  end
12
12
 
13
13
  describe "year range" do
14
- %w( 1935-1940 1935/1940 1935?/1940? 1935~/1940~ ).each do |value|
14
+ %w( 1935-1940 1935/1940 ).each do |value|
15
15
  describe value do
16
16
  let(:date) { value }
17
- it { is_expected.to eq((1935..1940).to_a) }
17
+ its(:values) { is_expected.to eq((1935..1940).to_a) }
18
18
  end
19
19
  end
20
20
  end
21
21
 
22
- describe "decade" do
23
- %w( 192u 192x 192X 192? 192- 192-? 1920s 1920s? ).each do |value|
24
- describe value do
25
- let(:date) { value }
26
- it { is_expected.to eq((1920..1929).to_a) }
27
- end
28
- end
29
- end
30
-
31
- describe "century" do
32
- %w( 19xx 19uu ).each do |value|
33
- describe value do
34
- let(:date) { value }
35
- it { is_expected.to eq((1900..1999).to_a) }
36
- end
37
- end
38
- end
39
-
40
- describe "uncertain interval" do
41
- let(:date) { "199u/200u" }
42
- it { is_expected.to eq((1990..2009).to_a) }
43
- end
44
-
45
- describe "set" do
46
- let(:date) { "[1999,2000,2003]" }
47
- it { is_expected.to eq([1999, 2000, 2003]) }
48
- end
49
-
50
- describe "year" do
51
- %w( 2010 2010? 2010~ ).each do |value|
22
+ describe "in decade" do
23
+ %w( 192x 192X 192? 192- 192-? ).each do |value|
52
24
  describe value do
53
25
  let(:date) { value }
54
- it { is_expected.to eq([2010]) }
26
+ its(:values) { is_expected.to eq((1920..1929).to_a) }
55
27
  end
56
28
  end
57
29
  end
58
30
 
59
- describe "month" do
60
- %w( 2010-01 2010/01 2010-12? 2010-11/2010-12 ).each do |value|
61
- describe value do
62
- let(:date) { value }
63
- it { is_expected.to eq([2010]) }
64
- end
65
- end
31
+ describe "in century -- YYxx (19xx)" do
32
+ let(:date) { "19xx" }
33
+ its(:values) { is_expected.to eq((1900..1999).to_a) }
66
34
  end
67
35
 
68
- describe "day" do
69
- %w( 2010-12-10 2010-12-10? 2010-12-10/2010-12-20 ).each do |value|
36
+ describe "decade" do
37
+ %w( 1920s 1920s? ).each do |value|
70
38
  describe value do
71
39
  let(:date) { value }
72
- it { is_expected.to eq([2010]) }
40
+ its(:values) { is_expected.to eq((1920..1929).to_a) }
73
41
  end
74
42
  end
75
43
  end
76
44
 
77
- describe "season" do
78
- %w( 2010-21 2010-22 2010-23 2010-24 ).each do |value|
45
+ describe "year + month" do
46
+ %w( 2010-01 2010/01 ).each do |value|
79
47
  describe value do
80
48
  let(:date) { value }
81
- it { is_expected.to eq([2010]) }
49
+ its(:values) { is_expected.to eq([2010]) }
82
50
  end
83
51
  end
84
52
  end
85
53
 
86
54
  describe "between" do
87
55
  let(:date) { "Between 1965 and 1968" }
88
- it { is_expected.to eq((1965..1968).to_a) }
56
+ its(:values) { is_expected.to eq((1965..1968).to_a) }
57
+ end
58
+
59
+ describe "year" do
60
+ let(:date) { "1965" }
61
+ its(:values) { is_expected.to eq([1965]) }
89
62
  end
90
63
 
91
64
  end
@@ -1,7 +1,5 @@
1
1
  ENV['RAILS_ENV'] ||= "test"
2
2
 
3
- ENV['DDR_AUX_API_URL'] ||= "http://localhost:3000/api"
4
-
5
3
  require File.expand_path("../dummy/config/environment.rb", __FILE__)
6
4
 
7
5
  require "ddr-models"
@@ -25,6 +23,10 @@ Dir[File.join(File.dirname(__FILE__), "support", "*.rb")].each { |f| require f }
25
23
 
26
24
  DatabaseCleaner.strategy = :truncation
27
25
 
26
+ # Silence deprecation warnings
27
+ warn "Default deprecation behavior set to :silence!"
28
+ Deprecation.default_deprecation_behavior = :silence
29
+
28
30
  RSpec.configure do |config|
29
31
 
30
32
  config.include ActionDispatch::TestProcess
@@ -85,7 +87,7 @@ RSpec.configure do |config|
85
87
  # Print the 10 slowest examples and example groups at the
86
88
  # end of the spec run, to help surface which specs are running
87
89
  # particularly slow.
88
- # config.profile_examples = 10
90
+ config.profile_examples = 10
89
91
 
90
92
  # Run specs in random order to surface order dependencies. If you find an
91
93
  # order dependency and want to debug it, you can fix the order by providing
@@ -108,26 +110,20 @@ RSpec.configure do |config|
108
110
  config.update_derivatives = [ :multires_image, :thumbnail ]
109
111
  end
110
112
  Ddr::Models.configure do |config|
113
+ config.external_file_store = Dir.mktmpdir
114
+ config.multires_image_external_file_store = Dir.mktmpdir
115
+ config.external_file_subpath_pattern = "--"
111
116
  config.fits_home = Dir.mktmpdir
112
117
  end
113
- Ddr::Datastreams::ExternalFileDatastream.file_store = Dir.mktmpdir
114
118
  end
115
119
 
116
120
  config.after(:suite) do
117
- if Ddr::Datastreams::ExternalFileDatastream.file_store
118
- FileUtils.rm_rf Ddr::Datastreams::ExternalFileDatastream.file_store
121
+ if Ddr::Models.external_file_store && Dir.exist?(Ddr::Models.external_file_store)
122
+ FileUtils.remove_entry_secure(Ddr::Models.external_file_store)
123
+ end
124
+ if Ddr::Models.multires_image_external_file_store && Dir.exist?(Ddr::Models.multires_image_external_file_store)
125
+ FileUtils.remove_entry_secure(Ddr::Models.multires_image_external_file_store)
119
126
  end
120
- end
121
-
122
- config.before(:each) do
123
- allow(Ddr::Models::AdminSet).to receive(:find_by_code).with("foo") {
124
- Ddr::Models::AdminSet.new(code: 'foo', title: 'Foo Admin Set')
125
- }
126
- allow(Ddr::Models::Language).to receive(:find_by_code).with("cym") {
127
- Ddr::Models::Language.new(code: 'cym', label: 'Welsh')
128
- }
129
- allow(Ddr::Models::Language).to receive(:find_by_code).with("Not a Code")
130
- .and_raise(ActiveResource::ResourceNotFound, "404")
131
127
  end
132
128
 
133
129
  config.after(:each) do
@@ -6,8 +6,8 @@ module Ezid
6
6
 
7
7
  self.defaults = {}
8
8
 
9
- def load_metadata; self; end
10
- def reset_metadata; self; end
9
+ def reload; self; end
10
+ def reset; self; end
11
11
 
12
12
  private
13
13
 
@@ -23,39 +23,6 @@ module Ddr::Auth
23
23
  end
24
24
  end
25
25
 
26
- describe "#metadata_manager?" do
27
- describe "when a user is present" do
28
- before { allow(subject).to receive(:user) { double(agent: "bob@example.com") } }
29
- describe "and there is no metadata managers group" do
30
- before {
31
- allow(Ddr::Auth).to receive(:metadata_managers_group) { nil }
32
- }
33
- its(:metadata_manager?) { should be false }
34
- end
35
- describe "and there is a metadata managers group" do
36
- before {
37
- allow(Ddr::Auth).to receive(:metadata_managers_group) { "metadata_managers" }
38
- }
39
- describe "and the auth context is a member of the group" do
40
- before {
41
- allow(subject).to receive(:groups) { [ Group.new("metadata_managers") ] }
42
- }
43
- its(:metadata_manager?) { should be true }
44
- end
45
- describe "and the auth context is not a member of the group" do
46
- before {
47
- allow(subject).to receive(:groups) { [ Group.new("foo"), Group.new("bar") ] }
48
- }
49
- its(:metadata_manager?) { should be false }
50
- end
51
- end
52
- end
53
- describe "when no user is present" do
54
- before { allow(subject).to receive(:user) { nil } }
55
- its(:metadata_manager?) { should be false }
56
- end
57
- end
58
-
59
26
  describe "#duke_agent?" do
60
27
  describe "when the auth context is anonymous" do
61
28
  before { allow(subject).to receive(:user) { nil } }
@@ -5,165 +5,117 @@ RSpec.shared_examples "a DDR model" do
5
5
  it_behaves_like "an object that has a display title"
6
6
  it_behaves_like "an object that has identifiers"
7
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
8
+ describe "events" do
9
+ describe "on deletion with #destroy" do
10
+ before { subject.save(validate: false) }
11
+ it "should create a deletion event" do
12
+ expect { subject.destroy }.to change { Ddr::Events::DeletionEvent.for_object(subject).count }.from(0).to(1)
36
13
  end
37
14
  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
15
+
16
+ describe "last virus check" do
17
+ let!(:fixity_check) { Ddr::Events::FixityCheckEvent.new }
18
+ before { allow(subject).to receive(:last_fixity_check) { fixity_check } }
19
+ its(:last_fixity_check_on) { should eq(fixity_check.event_date_time) }
20
+ its(:last_fixity_check_outcome) { should eq(fixity_check.outcome) }
44
21
  end
45
22
  end
46
23
 
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)
24
+ describe "move first desc metadata identifier to local id" do
25
+ let(:local_id) { 'locl001' }
26
+ let(:identifiers) { [ 'id001', 'id002' ] }
27
+ context "no desc metadata identifiers" do
28
+ context "local id present" do
29
+ before { subject.local_id = local_id }
30
+ it "should not change the local id" do
31
+ result = subject.move_first_identifier_to_local_id
32
+ expect(result).to be false
33
+ expect(subject.local_id).to eq(local_id)
58
34
  end
59
35
  end
60
36
  end
61
- end
62
-
63
- describe "permanent ID assignment" do
64
- describe "when auto assignment is enabled" do
65
- before do
66
- allow(Ddr::Models).to receive(:auto_assign_permanent_id) { true }
67
- end
68
- describe "and a permanent ID is pre-assigned" do
69
- before do
70
- subject.permanent_id = "foo"
71
- end
72
- it "does not assign a permanent ID" do
73
- expect { subject.save(validate: false) }.not_to change(subject, :permanent_id)
37
+ context "one desc metadata identifier" do
38
+ before { subject.descMetadata.identifier = Array(identifiers.first) }
39
+ context "local id not present" do
40
+ it "should set the local id and remove the identifier" do
41
+ result = subject.move_first_identifier_to_local_id
42
+ expect(result).to be true
43
+ expect(subject.local_id).to eq(identifiers.first)
44
+ expect(subject.descMetadata.identifier).to be_empty
74
45
  end
75
46
  end
76
- describe "and no permanent ID has been pre-assigned" do
77
- before do
78
- expect(Ddr::Models::PermanentId).to receive(:assign!).with(subject) { nil }
79
- subject.save(validate: false)
47
+ context "local id present" do
48
+ before { subject.local_id = local_id }
49
+ context "replace option is true" do
50
+ it "should set the local id and remove the identifier" do
51
+ result = subject.move_first_identifier_to_local_id
52
+ expect(result).to be true
53
+ expect(subject.local_id).to eq(identifiers.first)
54
+ expect(subject.descMetadata.identifier).to be_empty
55
+ end
80
56
  end
81
- end
82
- end
83
- describe "when auto assignment is disabled" do
84
- before do
85
- allow(Ddr::Models).to receive(:auto_assign_permanent_id) { false }
86
- end
87
- it "does not assign a permanent ID" do
88
- expect { subject.save(validate: false) }.not_to change(subject, :permanent_id)
89
- end
90
- end
91
- end
92
-
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)
97
- end
98
- end
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"
57
+ context "replace option is false" do
58
+ context "local id matches first identifier" do
59
+ before { subject.descMetadata.identifier = Array(local_id) }
60
+ it "should remove the identifier" do
61
+ result = subject.move_first_identifier_to_local_id(replace: false)
62
+ expect(result).to be true
63
+ expect(subject.local_id).to eq(local_id)
64
+ expect(subject.descMetadata.identifier).to be_empty
65
+ end
66
+ end
67
+ context "local id does not match first identifier" do
68
+ it "should not change the local id and not remove the identifier" do
69
+ result = subject.move_first_identifier_to_local_id(replace: false)
70
+ expect(result).to be false
71
+ expect(subject.local_id).to eq(local_id)
72
+ expect(subject.descMetadata.identifier).to eq(Array(identifiers.first))
73
+ end
74
+ end
113
75
  end
114
76
  end
115
77
  end
116
- describe "deaccession" do
117
- before { subject.save! }
118
- it "creates a deaccession event" do
119
- expect { subject.deaccession }.to change { Ddr::Events::DeaccessionEvent.for_object(subject).count }.by(1)
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
127
- end
128
- describe "on deletion with #destroy" do
129
- before { subject.save! }
130
- it "creates a deletion event" do
131
- expect { subject.destroy }.to change { Ddr::Events::DeletionEvent.for_object(subject).count }.from(0).to(1)
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"
78
+ context "more than one desc metadata identifer" do
79
+ before { subject.descMetadata.identifier = identifiers }
80
+ context "local id not present" do
81
+ it "should set the local id and remove the identifier" do
82
+ result = subject.move_first_identifier_to_local_id
83
+ expect(result).to be true
84
+ expect(subject.local_id).to eq(identifiers.first)
85
+ expect(subject.descMetadata.identifier).to eq(Array(identifiers.last))
86
+ end
138
87
  end
139
- end
140
- describe "last virus check" do
141
- before { subject.save! }
142
- let!(:fixity_check) { Ddr::Events::FixityCheckEvent.new }
143
- before { allow(subject).to receive(:last_fixity_check) { fixity_check } }
144
- its(:last_fixity_check_on) { should eq(fixity_check.event_date_time) }
145
- its(:last_fixity_check_outcome) { should eq(fixity_check.outcome) }
146
- end
147
- end
148
-
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
- }
156
- end
157
-
158
- describe "#rights_statement" do
159
- let(:rights_statement) { Ddr::Models::RightsStatement.new(url: "http://example.com") }
160
- before do
161
- allow(Ddr::Models::RightsStatement).to receive(:get).with(:find, url: "http://example.com") do
162
- { url: "http://example.com" }
88
+ context "local id present" do
89
+ before { subject.local_id = local_id }
90
+ context "replace option is true" do
91
+ it "should set the local id and remove the identifier" do
92
+ result = subject.move_first_identifier_to_local_id
93
+ expect(result).to be true
94
+ expect(subject.local_id).to eq(identifiers.first)
95
+ expect(subject.descMetadata.identifier).to eq(Array(identifiers.last))
96
+ end
97
+ end
98
+ context "replace option is false" do
99
+ context "local id matches first identifier" do
100
+ before { subject.descMetadata.identifier = [ local_id, identifiers.last ] }
101
+ it "should remove the identifier" do
102
+ result = subject.move_first_identifier_to_local_id(replace: false)
103
+ expect(result).to be true
104
+ expect(subject.local_id).to eq(local_id)
105
+ expect(subject.descMetadata.identifier).to eq(Array(identifiers.last))
106
+ end
107
+ end
108
+ context "local id does not match first identifier" do
109
+ it "should not change the local id and not remove the identifier" do
110
+ result = subject.move_first_identifier_to_local_id(replace: false)
111
+ expect(result).to be false
112
+ expect(subject.local_id).to eq(local_id)
113
+ expect(subject.descMetadata.identifier).to eq(identifiers)
114
+ end
115
+ end
116
+ end
163
117
  end
164
- subject.rights = ["http://example.com"]
165
118
  end
166
- its(:rights_statement) { is_expected.to eq rights_statement }
167
119
  end
168
120
 
169
121
  end