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.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/.travis.yml +7 -6
- data/Gemfile +2 -3
- data/Rakefile +5 -5
- data/app/controllers/users/sessions_controller.rb +5 -0
- data/app/helpers/models_helper.rb +7 -0
- data/app/models/attachment.rb +3 -5
- data/app/models/collection.rb +12 -79
- data/app/models/component.rb +8 -67
- data/app/models/item.rb +8 -73
- data/app/models/target.rb +6 -5
- data/config/initializers/active_fedora_base.rb +11 -30
- data/config/initializers/{active_fedora_datastream.rb → active_fedora_file.rb} +1 -1
- data/config/initializers/devise.rb +2 -3
- data/config/initializers/subscriptions.rb +2 -19
- data/ddr-models.gemspec +10 -14
- data/lib/ddr/actions/fixity_check.rb +1 -1
- data/lib/ddr/actions/virus_check.rb +17 -10
- data/lib/ddr/auth.rb +6 -38
- data/lib/ddr/auth/ability.rb +1 -5
- data/lib/ddr/auth/ability_definitions/collection_ability_definitions.rb +0 -16
- data/lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb +10 -4
- data/lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb +16 -9
- data/lib/ddr/auth/ability_factory.rb +25 -2
- data/lib/ddr/auth/abstract_ability.rb +1 -2
- data/lib/ddr/auth/auth_context.rb +0 -18
- data/lib/ddr/auth/auth_context_factory.rb +2 -0
- data/lib/ddr/auth/group.rb +0 -6
- data/lib/ddr/auth/grouper_gateway.rb +0 -24
- data/lib/ddr/auth/permissions.rb +1 -12
- data/lib/ddr/auth/role_based_access_controls_enforcement.rb +5 -5
- data/lib/ddr/auth/roles.rb +1 -11
- data/lib/ddr/auth/roles/role_set.rb +0 -7
- data/lib/ddr/auth/roles/roles_datastream.rb +9 -0
- data/lib/ddr/contacts.rb +25 -0
- data/lib/ddr/datastreams.rb +10 -28
- data/lib/ddr/datastreams/datastream_behavior.rb +30 -100
- data/lib/ddr/datastreams/descriptive_metadata_datastream.rb +28 -31
- data/lib/ddr/datastreams/fits_datastream.rb +9 -22
- data/lib/ddr/datastreams/metadata_datastream.rb +17 -31
- data/lib/ddr/derivatives.rb +13 -16
- data/lib/ddr/derivatives/derivative.rb +68 -0
- data/lib/ddr/derivatives/{generator.rb → generators/generator.rb} +11 -7
- data/lib/ddr/derivatives/generators/png_generator.rb +23 -0
- data/lib/ddr/derivatives/generators/ptif_generator.rb +56 -0
- data/lib/ddr/derivatives/multires_image.rb +59 -0
- data/lib/ddr/derivatives/thumbnail.rb +36 -0
- data/lib/ddr/events.rb +0 -1
- data/lib/ddr/events/deletion_event.rb +9 -5
- data/lib/ddr/events/event.rb +8 -13
- data/lib/ddr/events/fixity_check_event.rb +0 -6
- data/lib/ddr/events/ingestion_event.rb +9 -5
- data/lib/ddr/events/update_event.rb +4 -17
- data/lib/ddr/index.rb +4 -4
- data/lib/ddr/index/abstract_query_result.rb +4 -3
- data/lib/ddr/index/connection.rb +9 -28
- data/lib/ddr/index/csv_query_result.rb +32 -47
- data/lib/ddr/index/field.rb +1 -11
- data/lib/ddr/index/fields.rb +16 -99
- data/lib/ddr/index/filter.rb +30 -103
- data/lib/ddr/index/filters.rb +19 -0
- data/lib/ddr/index/query.rb +11 -58
- data/lib/ddr/index/query_builder.rb +36 -147
- data/lib/ddr/index/query_clause.rb +19 -79
- data/lib/ddr/index/query_result.rb +4 -36
- data/lib/ddr/index/query_value.rb +18 -0
- data/lib/ddr/index/response.rb +2 -19
- data/lib/ddr/jobs.rb +12 -0
- data/lib/ddr/jobs/fits_file_characterization.rb +51 -0
- data/lib/ddr/jobs/permanent_id.rb +23 -0
- data/lib/ddr/managers.rb +1 -0
- data/lib/ddr/managers/derivatives_manager.rb +53 -93
- data/lib/ddr/managers/permanent_id_manager.rb +91 -0
- data/lib/ddr/managers/technical_metadata_manager.rb +10 -24
- data/lib/ddr/managers/workflow_manager.rb +10 -29
- data/lib/ddr/models.rb +50 -101
- data/lib/ddr/models/access_controllable.rb +12 -0
- data/lib/ddr/models/admin_set.rb +5 -16
- data/lib/ddr/models/base.rb +45 -165
- data/lib/ddr/models/describable.rb +19 -21
- data/lib/ddr/models/engine.rb +11 -39
- data/lib/ddr/models/error.rb +0 -3
- data/lib/ddr/models/file_management.rb +36 -72
- data/lib/ddr/models/finding_aid.rb +2 -35
- data/lib/ddr/models/fixity_checkable.rb +4 -0
- data/lib/ddr/models/governable.rb +3 -1
- data/lib/ddr/models/has_admin_metadata.rb +82 -56
- data/lib/ddr/models/has_attachments.rb +3 -1
- data/lib/ddr/models/has_children.rb +3 -7
- data/lib/ddr/models/has_content.rb +35 -32
- data/lib/ddr/models/has_multires_image.rb +7 -12
- data/lib/ddr/models/has_struct_metadata.rb +44 -6
- data/lib/ddr/models/has_thumbnail.rb +1 -4
- data/lib/ddr/models/indexing.rb +97 -186
- data/lib/ddr/models/licenses/admin_policy_license.rb +11 -0
- data/lib/ddr/models/licenses/effective_license.rb +9 -0
- data/lib/ddr/models/licenses/inherited_license.rb +9 -0
- data/lib/ddr/models/licenses/license.rb +21 -0
- data/lib/ddr/models/licenses/parent_license.rb +11 -0
- data/lib/ddr/models/metadata/descriptive_metadata.rb +50 -0
- data/lib/ddr/models/metadata/metadata.rb +37 -0
- data/lib/ddr/models/metadata/metadata_mapper.rb +32 -0
- data/lib/ddr/models/metadata/metadata_mappers.rb +18 -0
- data/lib/ddr/models/metadata/metadata_term.rb +24 -0
- data/lib/ddr/models/metadata/metadata_vocabularies.rb +18 -0
- data/lib/ddr/models/metadata/metadata_vocabulary.rb +34 -0
- data/lib/ddr/models/solr_document.rb +24 -156
- data/lib/ddr/models/struct_div.rb +63 -0
- data/lib/ddr/models/structure.rb +39 -175
- data/lib/ddr/models/version.rb +1 -1
- data/lib/ddr/models/year_facet.rb +118 -60
- data/lib/ddr/notifications.rb +12 -10
- data/lib/ddr/utils.rb +15 -28
- data/lib/ddr/vocab.rb +17 -15
- data/lib/ddr/vocab/asset.rb +17 -42
- data/lib/ddr/vocab/contact.rb +7 -5
- data/lib/ddr/vocab/display.rb +8 -6
- data/lib/ddr/vocab/duke_terms.rb +10 -8
- data/lib/ddr/vocab/rdf_vocabulary_parser.rb +39 -37
- data/lib/ddr/vocab/roles.rb +19 -17
- data/lib/ddr/vocab/sources/duketerms.rdf +8 -22
- data/lib/ddr/vocab/vocabulary.rb +26 -26
- data/spec/auth/ability_factory_spec.rb +1 -18
- data/spec/auth/ability_spec.rb +15 -119
- data/spec/auth/effective_permissions_spec.rb +1 -1
- data/spec/auth/effective_roles_spec.rb +1 -1
- data/spec/auth/ldap_gateway_spec.rb +9 -0
- data/spec/contacts/contacts_spec.rb +26 -0
- data/spec/controllers/including_role_based_access_controls_enforcement_spec.rb +5 -5
- data/spec/derivatives/multires_image_spec.rb +48 -0
- data/spec/derivatives/png_generator_spec.rb +8 -13
- data/spec/derivatives/ptif_generator_spec.rb +11 -9
- data/spec/derivatives/thumbnail_spec.rb +48 -0
- data/spec/dummy/config/environments/test.rb +1 -1
- data/spec/dummy/db/schema.rb +23 -25
- data/spec/factories/attachment_factories.rb +2 -2
- data/spec/factories/collection_factories.rb +2 -3
- data/spec/factories/component_factories.rb +2 -2
- data/spec/factories/item_factories.rb +2 -2
- data/spec/factories/structure_factories.rb +2 -8
- data/spec/factories/test_model_factories.rb +12 -4
- data/spec/fixtures/fits/document.xml +44 -42
- data/spec/fixtures/fits/image.xml +41 -42
- data/spec/helpers/models_helper_spec.rb +11 -0
- data/spec/index/filter_spec.rb +30 -208
- data/spec/index/filters_spec.rb +17 -0
- data/spec/index/query_spec.rb +10 -82
- data/spec/jobs/fits_file_characterization_spec.rb +52 -0
- data/spec/managers/derivatives_manager_spec.rb +105 -107
- data/spec/managers/technical_metadata_manager_spec.rb +27 -34
- data/spec/models/active_fedora_base_spec.rb +105 -5
- data/spec/models/active_fedora_datastream_spec.rb +39 -106
- data/spec/models/admin_set_spec.rb +10 -43
- data/spec/models/attachment_spec.rb +2 -3
- data/spec/models/collection_spec.rb +11 -225
- data/spec/models/component_spec.rb +4 -106
- data/spec/models/descriptive_metadata_spec.rb +38 -0
- data/spec/models/effective_license_spec.rb +64 -0
- data/spec/models/events_spec.rb +59 -52
- data/spec/models/file_management_spec.rb +13 -113
- data/spec/models/finding_aid_spec.rb +8 -31
- data/spec/models/has_admin_metadata_spec.rb +122 -131
- data/spec/models/has_children_spec.rb +3 -3
- data/spec/models/has_struct_metadata_spec.rb +37 -50
- data/spec/models/indexing_spec.rb +23 -160
- data/spec/models/item_spec.rb +2 -133
- data/spec/models/license_spec.rb +24 -0
- data/spec/models/solr_document_spec.rb +47 -236
- data/spec/models/struct_div_spec.rb +70 -0
- data/spec/models/structure_spec.rb +11 -89
- data/spec/models/target_spec.rb +2 -4
- data/spec/models/year_facet_spec.rb +23 -50
- data/spec/spec_helper.rb +13 -17
- data/spec/support/ezid_mock_identifier.rb +2 -2
- data/spec/support/shared_examples_for_auth_contexts.rb +0 -33
- data/spec/support/shared_examples_for_ddr_models.rb +94 -142
- data/spec/support/shared_examples_for_describables.rb +36 -31
- data/spec/support/shared_examples_for_governables.rb +2 -3
- data/spec/support/shared_examples_for_has_content.rb +46 -101
- data/spec/support/shared_examples_for_indexing.rb +6 -6
- data/spec/support/shared_examples_for_non_collection_models.rb +1 -32
- data/spec/support/structural_metadata_helper.rb +59 -230
- data/spec/utils_spec.rb +2 -0
- metadata +96 -229
- data/.ruby-version +0 -1
- data/config/initializers/rsolr_monkey_patches.rb +0 -7
- data/config/initializers/rubydora_monkey_patch.rb +0 -11
- data/config/locales/ddr-models.en.yml +0 -81
- data/db/migrate/20161021201011_add_permanent_id_to_events.rb +0 -8
- data/lib/ddr/auth/ability_definitions/admin_set_ability_definitions.rb +0 -9
- data/lib/ddr/auth/ability_definitions/lock_ability_definitions.rb +0 -13
- data/lib/ddr/auth/ability_definitions/publication_ability_definitions.rb +0 -16
- data/lib/ddr/datastreams/administrative_metadata_datastream.rb +0 -75
- data/lib/ddr/datastreams/caption_datastream.rb +0 -5
- data/lib/ddr/datastreams/content_datastream.rb +0 -17
- data/lib/ddr/datastreams/delete_external_files.rb +0 -29
- data/lib/ddr/datastreams/external_file_datastream.rb +0 -80
- data/lib/ddr/datastreams/intermediate_file_datastream.rb +0 -5
- data/lib/ddr/datastreams/multires_image_datastream.rb +0 -5
- data/lib/ddr/datastreams/streamable_media_datastream.rb +0 -5
- data/lib/ddr/derivatives/png_generator.rb +0 -17
- data/lib/ddr/derivatives/ptif_generator.rb +0 -55
- data/lib/ddr/derivatives/update_derivatives.rb +0 -25
- data/lib/ddr/events/deaccession_event.rb +0 -8
- data/lib/ddr/index/field_attribute.rb +0 -22
- data/lib/ddr/index/query_params.rb +0 -40
- data/lib/ddr/index/sort_order.rb +0 -28
- data/lib/ddr/models/cache.rb +0 -20
- data/lib/ddr/models/captionable.rb +0 -37
- data/lib/ddr/models/contact.rb +0 -23
- data/lib/ddr/models/file_characterization.rb +0 -37
- data/lib/ddr/models/has_intermediate_file.rb +0 -41
- data/lib/ddr/models/language.rb +0 -31
- data/lib/ddr/models/media_type.rb +0 -22
- data/lib/ddr/models/permanent_id.rb +0 -240
- data/lib/ddr/models/rights_statement.rb +0 -25
- data/lib/ddr/models/streamable.rb +0 -37
- data/lib/ddr/models/structures/agent.rb +0 -49
- data/lib/ddr/models/structures/component_type_term.rb +0 -29
- data/lib/ddr/models/structures/div.rb +0 -64
- data/lib/ddr/models/structures/f_locat.rb +0 -54
- data/lib/ddr/models/structures/file.rb +0 -52
- data/lib/ddr/models/structures/file_grp.rb +0 -35
- data/lib/ddr/models/structures/file_sec.rb +0 -22
- data/lib/ddr/models/structures/fptr.rb +0 -31
- data/lib/ddr/models/structures/mets_hdr.rb +0 -37
- data/lib/ddr/models/structures/mptr.rb +0 -49
- data/lib/ddr/models/structures/struct_map.rb +0 -40
- data/lib/ddr/models/with_content_file.rb +0 -37
- data/spec/datastreams/external_file_datastream_spec.rb +0 -48
- data/spec/dummy/config/structure_component_type.yml +0 -18
- data/spec/fixtures/abcd1234.vtt +0 -38
- data/spec/fixtures/arrow1rightred_e0.gif +0 -0
- data/spec/fixtures/extractedText1.txt +0 -1
- data/spec/fixtures/extractedText2.txt +0 -1
- data/spec/fixtures/extractedText3.txt +0 -3
- data/spec/fixtures/imageA.jpg +0 -0
- data/spec/fixtures/imageB.jpg +0 -0
- data/spec/index/csv_query_result_spec.rb +0 -44
- data/spec/index/fields_spec.rb +0 -380
- data/spec/index/query_builder_spec.rb +0 -140
- data/spec/index/query_clause_spec.rb +0 -68
- data/spec/models/cache_spec.rb +0 -32
- data/spec/models/contact_spec.rb +0 -56
- data/spec/models/descriptive_metadata_datastream_spec.rb +0 -139
- data/spec/models/file_characterization_spec.rb +0 -39
- data/spec/models/language_spec.rb +0 -59
- data/spec/models/media_type_spec.rb +0 -46
- data/spec/models/permanent_id_spec.rb +0 -432
- data/spec/models/rights_statement_spec.rb +0 -55
- data/spec/models/structures/agent_spec.rb +0 -30
- data/spec/models/structures/component_type_term_spec.rb +0 -14
- data/spec/models/structures/div_spec.rb +0 -26
- data/spec/models/structures/f_locat_spec.rb +0 -78
- data/spec/models/structures/file_grp_spec.rb +0 -23
- data/spec/models/structures/file_sec_spec.rb +0 -22
- data/spec/models/structures/file_spec.rb +0 -60
- data/spec/models/structures/fptr_spec.rb +0 -23
- data/spec/models/structures/mets_hdr_spec.rb +0 -26
- data/spec/models/structures/mptr_spec.rb +0 -25
- data/spec/models/structures/struct_map_spec.rb +0 -24
- data/spec/models/with_content_file_spec.rb +0 -37
- data/spec/support/shared_examples_for_associations.rb +0 -8
- data/spec/support/shared_examples_for_captionable.rb +0 -23
- data/spec/support/shared_examples_for_has_intermediate_file.rb +0 -28
- data/spec/support/shared_examples_for_publication.rb +0 -43
- 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
|
5
|
-
|
4
|
+
module Ddr
|
5
|
+
module Models
|
6
|
+
RSpec.describe Structure, type: :model, structural_metadata: true do
|
6
7
|
|
7
|
-
|
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
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
expect(
|
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
|
data/spec/models/target_spec.rb
CHANGED
@@ -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.
|
4
|
+
subject { described_class.new(obj) }
|
5
5
|
let(:obj) { Item.new }
|
6
|
-
before { obj.
|
6
|
+
before { obj.dc_date = [ date ] }
|
7
7
|
|
8
8
|
describe "splitting on semicolons" do
|
9
9
|
let(:date) { "1935; 1936; 1937; 1938" }
|
10
|
-
|
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
|
14
|
+
%w( 1935-1940 1935/1940 ).each do |value|
|
15
15
|
describe value do
|
16
16
|
let(:date) { value }
|
17
|
-
|
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(
|
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
|
-
|
26
|
+
its(:values) { is_expected.to eq((1920..1929).to_a) }
|
55
27
|
end
|
56
28
|
end
|
57
29
|
end
|
58
30
|
|
59
|
-
describe "
|
60
|
-
|
61
|
-
|
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 "
|
69
|
-
%w(
|
36
|
+
describe "decade" do
|
37
|
+
%w( 1920s 1920s? ).each do |value|
|
70
38
|
describe value do
|
71
39
|
let(:date) { value }
|
72
|
-
|
40
|
+
its(:values) { is_expected.to eq((1920..1929).to_a) }
|
73
41
|
end
|
74
42
|
end
|
75
43
|
end
|
76
44
|
|
77
|
-
describe "
|
78
|
-
%w( 2010-
|
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
|
-
|
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
|
-
|
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
|
data/spec/spec_helper.rb
CHANGED
@@ -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
|
-
|
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::
|
118
|
-
FileUtils.
|
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
|
@@ -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 "
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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 "
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
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
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
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
|
-
|
77
|
-
before
|
78
|
-
|
79
|
-
|
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
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
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
|
-
|
117
|
-
before { subject.
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
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
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
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
|