ddr-models 2.6.2 → 2.7.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +1 -1
- data/Gemfile +2 -3
- data/app/models/collection.rb +11 -3
- data/app/models/component.rb +54 -4
- data/app/models/item.rb +1 -2
- data/config/initializers/active_fedora_base.rb +8 -5
- data/config/initializers/rubydora_monkey_patch.rb +11 -0
- data/config/initializers/subscriptions.rb +16 -9
- data/config/locales/ddr-models.en.yml +3 -0
- data/ddr-models.gemspec +3 -2
- data/lib/ddr/actions/virus_check.rb +10 -16
- data/lib/ddr/auth.rb +0 -8
- data/lib/ddr/datastreams.rb +13 -2
- data/lib/ddr/datastreams/administrative_metadata_datastream.rb +9 -0
- data/lib/ddr/datastreams/content_datastream.rb +5 -0
- data/lib/ddr/datastreams/datastream_behavior.rb +60 -15
- data/lib/ddr/datastreams/delete_external_files.rb +29 -0
- data/lib/ddr/datastreams/descriptive_metadata_datastream.rb +33 -33
- data/lib/ddr/datastreams/external_file_datastream.rb +69 -0
- data/lib/ddr/datastreams/fits_datastream.rb +15 -5
- data/lib/ddr/datastreams/intermediate_file_datastream.rb +5 -0
- data/lib/ddr/datastreams/metadata_datastream.rb +15 -17
- data/lib/ddr/datastreams/multires_image_datastream.rb +5 -0
- data/lib/ddr/derivatives.rb +1 -0
- data/lib/ddr/derivatives/ptif_generator.rb +5 -1
- data/lib/ddr/derivatives/update_derivatives.rb +23 -0
- data/lib/ddr/events/deletion_event.rb +5 -9
- data/lib/ddr/events/event.rb +7 -9
- data/lib/ddr/events/ingestion_event.rb +5 -9
- data/lib/ddr/events/update_event.rb +12 -5
- data/lib/ddr/index.rb +0 -1
- data/lib/ddr/index/csv_query_result.rb +10 -2
- data/lib/ddr/index/fields.rb +10 -9
- data/lib/ddr/index/filter.rb +1 -0
- data/lib/ddr/managers/derivatives_manager.rb +84 -98
- data/lib/ddr/managers/technical_metadata_manager.rb +20 -5
- data/lib/ddr/models.rb +24 -24
- data/lib/ddr/models/base.rb +98 -74
- data/lib/ddr/models/cache.rb +20 -0
- data/lib/ddr/models/engine.rb +4 -6
- data/lib/ddr/models/file_management.rb +57 -152
- data/lib/ddr/models/fixity_checkable.rb +0 -5
- data/lib/ddr/models/has_admin_metadata.rb +4 -2
- data/lib/ddr/models/has_children.rb +35 -1
- data/lib/ddr/models/has_content.rb +3 -33
- data/lib/ddr/models/has_intermediate_file.rb +18 -0
- data/lib/ddr/models/has_multires_image.rb +12 -15
- data/lib/ddr/models/has_struct_metadata.rb +2 -38
- data/lib/ddr/models/indexing.rb +160 -163
- data/lib/ddr/models/permanent_id.rb +26 -49
- data/lib/ddr/models/solr_document.rb +21 -19
- data/lib/ddr/models/structure.rb +168 -41
- data/lib/ddr/models/structures/agent.rb +49 -0
- data/lib/ddr/models/structures/div.rb +64 -0
- data/lib/ddr/models/structures/f_locat.rb +54 -0
- data/lib/ddr/models/structures/file.rb +52 -0
- data/lib/ddr/models/structures/file_grp.rb +35 -0
- data/lib/ddr/models/structures/file_sec.rb +22 -0
- data/lib/ddr/models/structures/fptr.rb +31 -0
- data/lib/ddr/models/structures/mets_hdr.rb +37 -0
- data/lib/ddr/models/structures/mptr.rb +49 -0
- data/lib/ddr/models/structures/struct_map.rb +40 -0
- data/lib/ddr/models/version.rb +1 -1
- data/lib/ddr/notifications.rb +10 -12
- data/lib/ddr/utils.rb +29 -16
- data/lib/ddr/vocab.rb +15 -17
- data/lib/ddr/vocab/asset.rb +29 -19
- data/lib/ddr/vocab/contact.rb +5 -7
- data/lib/ddr/vocab/display.rb +6 -8
- data/lib/ddr/vocab/duke_terms.rb +8 -10
- data/lib/ddr/vocab/rdf_vocabulary_parser.rb +37 -39
- data/lib/ddr/vocab/roles.rb +17 -19
- data/lib/ddr/vocab/vocabulary.rb +26 -26
- data/spec/datastreams/external_file_datastream_spec.rb +37 -0
- data/spec/derivatives/png_generator_spec.rb +21 -25
- data/spec/derivatives/ptif_generator_spec.rb +22 -26
- data/spec/dummy/config/environments/test.rb +1 -1
- data/spec/dummy/db/schema.rb +23 -23
- data/spec/factories/structure_factories.rb +8 -2
- data/spec/fixtures/imageA.jpg +0 -0
- data/spec/fixtures/imageB.jpg +0 -0
- data/spec/index/csv_query_result_spec.rb +3 -3
- data/spec/index/fields_spec.rb +7 -6
- data/spec/managers/derivatives_manager_spec.rb +105 -112
- data/spec/managers/technical_metadata_manager_spec.rb +22 -18
- data/spec/models/active_fedora_base_spec.rb +0 -106
- data/spec/models/active_fedora_datastream_spec.rb +33 -2
- data/spec/models/attachment_spec.rb +0 -2
- data/spec/models/cache_spec.rb +32 -0
- data/spec/models/collection_spec.rb +43 -19
- data/spec/models/component_spec.rb +41 -51
- data/spec/models/descriptive_metadata_datastream_spec.rb +99 -87
- data/spec/models/events_spec.rb +50 -69
- data/spec/models/file_management_spec.rb +79 -187
- data/spec/models/has_children_spec.rb +54 -3
- data/spec/models/has_struct_metadata_spec.rb +32 -38
- data/spec/models/indexing_spec.rb +11 -6
- data/spec/models/item_spec.rb +21 -7
- data/spec/models/permanent_id_spec.rb +1 -5
- data/spec/models/solr_document_spec.rb +13 -41
- data/spec/models/structure_spec.rb +85 -16
- data/spec/models/structures/agent_spec.rb +30 -0
- data/spec/models/structures/div_spec.rb +26 -0
- data/spec/models/structures/f_locat_spec.rb +78 -0
- data/spec/models/structures/file_grp_spec.rb +23 -0
- data/spec/models/structures/file_sec_spec.rb +22 -0
- data/spec/models/structures/file_spec.rb +60 -0
- data/spec/models/structures/fptr_spec.rb +23 -0
- data/spec/models/structures/mets_hdr_spec.rb +26 -0
- data/spec/models/structures/mptr_spec.rb +25 -0
- data/spec/models/structures/struct_map_spec.rb +24 -0
- data/spec/models/target_spec.rb +0 -2
- data/spec/spec_helper.rb +4 -9
- data/spec/support/shared_examples_for_ddr_models.rb +96 -156
- data/spec/support/shared_examples_for_has_content.rb +56 -30
- data/spec/support/shared_examples_for_has_intermediate_spec.rb +28 -0
- data/spec/support/shared_examples_for_non_collection_models.rb +5 -0
- data/spec/support/structural_metadata_helper.rb +230 -59
- data/spec/utils_spec.rb +0 -2
- metadata +86 -44
- data/app/helpers/models_helper.rb +0 -10
- data/lib/ddr/auth/legacy/abstract_legacy_permissions.rb +0 -17
- data/lib/ddr/auth/legacy/legacy_authorization.rb +0 -44
- data/lib/ddr/auth/legacy/legacy_default_permissions.rb +0 -33
- data/lib/ddr/auth/legacy/legacy_permissions.rb +0 -33
- data/lib/ddr/auth/legacy/legacy_roles.rb +0 -25
- data/lib/ddr/index/legacy_license_fields.rb +0 -12
- data/lib/ddr/jobs.rb +0 -12
- data/lib/ddr/jobs/fits_file_characterization.rb +0 -13
- data/lib/ddr/jobs/fixity_check.rb +0 -13
- data/lib/ddr/jobs/job.rb +0 -36
- data/lib/ddr/jobs/queue.rb +0 -27
- data/lib/ddr/jobs/update_index.rb +0 -13
- data/lib/ddr/models/access_controllable.rb +0 -24
- data/lib/ddr/models/struct_div.rb +0 -63
- data/spec/auth/legacy_default_permissions_spec.rb +0 -37
- data/spec/auth/legacy_permissions_spec.rb +0 -37
- data/spec/helpers/models_helper_spec.rb +0 -11
- data/spec/jobs/fits_file_characterization_spec.rb +0 -16
- data/spec/jobs/fixity_check_spec.rb +0 -22
- data/spec/jobs/job_spec.rb +0 -40
- data/spec/jobs/update_index_spec.rb +0 -22
- data/spec/models/struct_div_spec.rb +0 -70
- data/spec/support/shared_examples_for_access_controllables.rb +0 -6
@@ -14,12 +14,12 @@ module Ddr::Models
|
|
14
14
|
let(:child2) { FactoryGirl.create(:item) }
|
15
15
|
before do
|
16
16
|
child1.local_id = "test002"
|
17
|
-
child1.save
|
17
|
+
child1.save!
|
18
18
|
child2.local_id = "test001"
|
19
|
-
child2.save
|
19
|
+
child2.save!
|
20
20
|
subject.children << child1
|
21
21
|
subject.children << child2
|
22
|
-
subject.save
|
22
|
+
subject.save!
|
23
23
|
end
|
24
24
|
it "should return the first child as sorted by local ID" do
|
25
25
|
expect(subject.first_child).to eq(child2)
|
@@ -27,5 +27,56 @@ module Ddr::Models
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
+
describe "#default_structure" do
|
31
|
+
describe "when the object has no children" do
|
32
|
+
it "should be nil" do
|
33
|
+
expect(subject.default_structure).to be_nil
|
34
|
+
end
|
35
|
+
end
|
36
|
+
describe "when the object has children" do
|
37
|
+
let(:child1) { FactoryGirl.create(:item) }
|
38
|
+
let(:child2) { FactoryGirl.create(:item) }
|
39
|
+
let(:expected) do
|
40
|
+
xml = <<-EOS
|
41
|
+
<mets xmlns="http://www.loc.gov/METS/" xmlns:xlink="http://www.w3.org/1999/xlink">
|
42
|
+
<metsHdr>
|
43
|
+
<agent ROLE="#{Ddr::Models::Structures::Agent::ROLE_CREATOR}">
|
44
|
+
<name>#{Ddr::Models::Structures::Agent::NAME_REPOSITORY_DEFAULT}</name>
|
45
|
+
</agent>
|
46
|
+
</metsHdr>
|
47
|
+
<structMap TYPE="#{Ddr::Models::Structure::TYPE_DEFAULT}">
|
48
|
+
<div ORDER="1">
|
49
|
+
<mptr LOCTYPE="ARK" xlink:href="ark:/99999/fk4bbb" />
|
50
|
+
</div>
|
51
|
+
<div ORDER="2">
|
52
|
+
<mptr LOCTYPE="ARK" xlink:href="ark:/99999/fk4aaa" />
|
53
|
+
</div>
|
54
|
+
</structMap>
|
55
|
+
</mets>
|
56
|
+
EOS
|
57
|
+
xml
|
58
|
+
end
|
59
|
+
before do
|
60
|
+
child1.local_id = "test002"
|
61
|
+
child1.permanent_id = "ark:/99999/fk4aaa"
|
62
|
+
child1.save!
|
63
|
+
child2.local_id = "test001"
|
64
|
+
child2.permanent_id = "ark:/99999/fk4bbb"
|
65
|
+
child2.save!
|
66
|
+
subject.children << child1
|
67
|
+
subject.children << child2
|
68
|
+
subject.save!
|
69
|
+
allow(SecureRandom).to receive(:uuid).and_return("abc-def", "ghi-jkl")
|
70
|
+
end
|
71
|
+
after do
|
72
|
+
child1.destroy
|
73
|
+
child2.destroy
|
74
|
+
end
|
75
|
+
it "should be the appropriate structure" do
|
76
|
+
expect(subject.default_structure.to_xml).to be_equivalent_to(expected)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
30
81
|
end
|
31
82
|
end
|
@@ -1,48 +1,42 @@
|
|
1
|
-
|
1
|
+
module Ddr::Models
|
2
|
+
RSpec.describe HasStructMetadata, type: :model, structural_metadata: true do
|
2
3
|
|
3
|
-
|
4
|
-
module Models
|
5
|
-
RSpec.describe HasStructMetadata, type: :model, structural_metadata: true do
|
4
|
+
let(:item) { Item.new(pid: 'test:2') }
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
it "should return nil" do
|
12
|
-
expect(item.structure).to eq(nil)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
context "existing structural metadata" do
|
16
|
-
before { item.datastreams[Ddr::Datastreams::STRUCT_METADATA].content = simple_structure }
|
17
|
-
it "should return the structural metadata" do
|
18
|
-
expect(item.structure.to_xml).to be_equivalent_to(simple_structure)
|
19
|
-
end
|
6
|
+
describe "#structures" do
|
7
|
+
context "no existing structural metadata" do
|
8
|
+
it "should return nil" do
|
9
|
+
expect(item.structure).to eq(nil)
|
20
10
|
end
|
21
11
|
end
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
Component.new(pid: 'test:7', identifier: [ 'abc003' ])
|
27
|
-
] }
|
28
|
-
let(:expected) { FactoryGirl.build(:simple_structure) }
|
29
|
-
before { allow(item).to receive(:find_children) { simple_structure_query_response } }
|
30
|
-
it "should build the appropriate structural metadata" do
|
31
|
-
results = item.build_default_structure
|
32
|
-
expect(results).to be_equivalent_to(expected)
|
12
|
+
context "existing structural metadata" do
|
13
|
+
before { item.datastreams[Ddr::Datastreams::STRUCT_METADATA].content = simple_structure_xml }
|
14
|
+
it "should return the structural metadata" do
|
15
|
+
expect(item.structure.to_xml).to be_equivalent_to(simple_structure_xml)
|
33
16
|
end
|
34
17
|
end
|
18
|
+
end
|
35
19
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
20
|
+
describe "indexing" do
|
21
|
+
let(:expected_json) { nested_structure_to_json }
|
22
|
+
before do
|
23
|
+
item.datastreams[Ddr::Datastreams::STRUCT_METADATA].content = nested_structure_xml
|
24
|
+
flocat_x = instance_double("Structures::FLocat", effective_use: 'foo')
|
25
|
+
flocat_y = instance_double("Structures::FLocat", effective_use: 'bar')
|
26
|
+
flocat_z = instance_double("Structures::FLocat", effective_use: 'baz')
|
27
|
+
file_a = instance_double("Structures::File", repo_ids: [ 'test:7' ], flocats: [ flocat_x ])
|
28
|
+
file_b = instance_double("Structures::File", repo_ids: [ 'test:8' ], flocats: [ flocat_y ])
|
29
|
+
file_c = instance_double("Structures::File", repo_ids: [ 'test:9' ], flocats: [ flocat_z ])
|
30
|
+
allow(Structures::File).to receive(:find).with(an_instance_of(Ddr::Models::Structure), 'abc') { file_a }
|
31
|
+
allow(Structures::File).to receive(:find).with(an_instance_of(Ddr::Models::Structure), 'def') { file_b }
|
32
|
+
allow(Structures::File).to receive(:find).with(an_instance_of(Ddr::Models::Structure), 'ghi') { file_c }
|
33
|
+
end
|
34
|
+
it "should index the JSON representation of the structures" do
|
35
|
+
indexing = item.to_solr
|
36
|
+
expect(indexing.keys).to include(Ddr::Index::Fields::STRUCTURE)
|
37
|
+
expect(indexing[Ddr::Index::Fields::STRUCTURE]).to eq(expected_json)
|
44
38
|
end
|
45
|
-
|
46
39
|
end
|
40
|
+
|
47
41
|
end
|
48
|
-
end
|
42
|
+
end
|
@@ -15,13 +15,13 @@ module Ddr::Models
|
|
15
15
|
obj.adminMetadata.doi << "http://doi.org/10.1000/182"
|
16
16
|
obj.aspace_id = "aspace_dccea43034e1b8261e14cf999e86449d"
|
17
17
|
obj.display_format = "Image"
|
18
|
+
obj.ingested_by = "foo@bar.com"
|
19
|
+
obj.ingestion_date = "2017-01-13T18:55:29Z"
|
18
20
|
obj.license = "cc-by-nc-nd-40"
|
19
21
|
obj.local_id = "foo"
|
20
22
|
obj.permanent_id = "ark:/99999/fk4zzz"
|
21
23
|
obj.permanent_url = "http://id.library.duke.edu/ark:/99999/fk4zzz"
|
22
|
-
obj.
|
23
|
-
obj.rightsMetadata.license.title = ["License Title"]
|
24
|
-
obj.rightsMetadata.license.url = ["http://library.duke.edu"]
|
24
|
+
obj.rights_note = ["Public domain"]
|
25
25
|
obj.roles.grant role1, role2, role3, role4
|
26
26
|
obj.set_desc_metadata_values(:arranger, "Arranger Value")
|
27
27
|
obj.set_desc_metadata_values(:category, "Category Value")
|
@@ -34,6 +34,8 @@ module Ddr::Models
|
|
34
34
|
obj.set_desc_metadata_values(:illustrator, "Illustrator Value")
|
35
35
|
obj.set_desc_metadata_values(:instrumentation, "Instrumentation Value")
|
36
36
|
obj.set_desc_metadata_values(:interviewer_name, "Interviewer Name Value")
|
37
|
+
obj.set_desc_metadata_values(:isFormatOf, "ark:/99999/fk4aaa")
|
38
|
+
obj.set_desc_metadata_values(:isPartOf, "RL10059CS1010")
|
37
39
|
obj.set_desc_metadata_values(:lithographer, "Lithographer Value")
|
38
40
|
obj.set_desc_metadata_values(:lyricist, "Lyricist Value")
|
39
41
|
obj.set_desc_metadata_values(:medium, "Medium Value")
|
@@ -56,6 +58,7 @@ module Ddr::Models
|
|
56
58
|
its([Indexing::CATEGORY_FACET]) { is_expected.to eq(["Category Value"]) }
|
57
59
|
its([Indexing::COMPANY_FACET]) { is_expected.to eq(["Company Value"]) }
|
58
60
|
its([Indexing::COMPOSER_FACET]) { is_expected.to eq(["Composer Value"]) }
|
61
|
+
its([Indexing::DC_IS_PART_OF]) { is_expected.to eq(["RL10059CS1010"])}
|
59
62
|
its([Indexing::DISPLAY_FORMAT]) { is_expected.to eq("Image") }
|
60
63
|
its([Indexing::DOI]) { is_expected.to eq(["http://doi.org/10.1000/182"]) }
|
61
64
|
its([Indexing::ENGRAVER_FACET]) { is_expected.to eq(["Engraver Value"]) }
|
@@ -63,12 +66,12 @@ module Ddr::Models
|
|
63
66
|
its([Indexing::GENRE_FACET]) { is_expected.to eq(["Genre Value"]) }
|
64
67
|
its([Indexing::ILLUSTRATED_FACET]) { is_expected.to eq(["Illustrated Value"]) }
|
65
68
|
its([Indexing::ILLUSTRATOR_FACET]) { is_expected.to eq(["Illustrator Value"]) }
|
69
|
+
its([Indexing::INGESTED_BY]) { is_expected.to eq("foo@bar.com") }
|
70
|
+
its([Indexing::INGESTION_DATE]) { is_expected.to eq("2017-01-13T18:55:29Z") }
|
66
71
|
its([Indexing::INSTRUMENTATION_FACET]) { is_expected.to eq(["Instrumentation Value"]) }
|
67
72
|
its([Indexing::INTERVIEWER_NAME_FACET]) { is_expected.to eq(["Interviewer Name Value"]) }
|
73
|
+
its([Indexing::IS_FORMAT_OF]) { is_expected.to eq(["ark:/99999/fk4aaa"]) }
|
68
74
|
its([Indexing::LICENSE]) { is_expected.to eq("cc-by-nc-nd-40") }
|
69
|
-
its([Indexing::LICENSE_DESCRIPTION]) { is_expected.to eq("License Description") }
|
70
|
-
its([Indexing::LICENSE_TITLE]) { is_expected.to eq("License Title") }
|
71
|
-
its([Indexing::LICENSE_URL]) { is_expected.to eq("http://library.duke.edu") }
|
72
75
|
its([Indexing::LITHOGRAPHER_FACET]) { is_expected.to eq(["Lithographer Value"]) }
|
73
76
|
its([Indexing::LOCAL_ID]) { is_expected.to eq("foo") }
|
74
77
|
its([Indexing::LYRICIST_FACET]) { is_expected.to eq(["Lyricist Value"]) }
|
@@ -82,12 +85,14 @@ module Ddr::Models
|
|
82
85
|
its([Indexing::PRODUCT_FACET]) { is_expected.to eq(["Product Value"]) }
|
83
86
|
its([Indexing::PUBLICATION_FACET]) { is_expected.to eq(["Publication Value"]) }
|
84
87
|
its([Indexing::RESOURCE_ROLE]) { is_expected.to contain_exactly(role1.agent.first) }
|
88
|
+
its([Indexing::RIGHTS_NOTE]) { is_expected.to eq(["Public domain"]) }
|
85
89
|
its([Indexing::ROLL_NUMBER_FACET]) { is_expected.to eq(["10"]) }
|
86
90
|
its([Indexing::SETTING_FACET]) { is_expected.to eq(["Setting Value"]) }
|
87
91
|
its([Indexing::SUBSERIES_FACET]) { is_expected.to eq(["Subseries Value"]) }
|
88
92
|
its([Indexing::TEMPORAL_FACET]) { is_expected.to eq(["Temporal Value"]) }
|
89
93
|
its([Indexing::TONE_FACET]) { is_expected.to eq(["Tone Value"]) }
|
90
94
|
its([Indexing::VOLUME_FACET]) { is_expected.to eq(["100"]) }
|
95
|
+
|
91
96
|
end
|
92
97
|
|
93
98
|
describe "content-bearing object indexing" do
|
data/spec/models/item_spec.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
RSpec.describe Item, type: :model do
|
4
2
|
|
5
3
|
it_behaves_like "a DDR model"
|
@@ -17,18 +15,34 @@ RSpec.describe Item, type: :model do
|
|
17
15
|
|
18
16
|
before {
|
19
17
|
children[0].extractedText.content = text1
|
20
|
-
children[0].save
|
18
|
+
children[0].save!
|
21
19
|
children[1].extractedText.content = text2
|
22
|
-
children[1].save
|
20
|
+
children[1].save!
|
23
21
|
children[2].extractedText.content = text3
|
24
|
-
children[2].save
|
22
|
+
children[2].save!
|
23
|
+
children[3].save!
|
24
|
+
children[4].save!
|
25
25
|
subject.children = children
|
26
|
-
subject.save
|
26
|
+
subject.save!
|
27
27
|
}
|
28
28
|
|
29
29
|
it "indexes the combined text of its children" do
|
30
|
-
expect(subject.index_fields[Ddr::Index::Fields::ALL_TEXT]).to contain_exactly(text1.
|
30
|
+
expect(subject.index_fields[Ddr::Index::Fields::ALL_TEXT]).to contain_exactly(File.read(text1.path), File.read(text2.path), File.read(text3.path))
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
+
describe "content" do
|
35
|
+
its(:can_have_content?) { is_expected.to be false }
|
36
|
+
it { is_expected.to_not have_content }
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "children" do
|
40
|
+
its(:can_have_children?) { is_expected.to be true }
|
41
|
+
it { is_expected.to_not have_children }
|
42
|
+
specify {
|
43
|
+
subject.children << Component.new
|
44
|
+
expect(subject).to have_children
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
34
48
|
end
|
@@ -39,12 +39,8 @@ module Ddr::Models
|
|
39
39
|
allow(described_class.identifier_class).to receive(:mint) { id }
|
40
40
|
allow(described_class.identifier_class).to receive(:find).with("foo") { id }
|
41
41
|
end
|
42
|
-
after do
|
43
|
-
obj.permanent_id = nil
|
44
|
-
obj.save!
|
45
|
-
end
|
46
42
|
it "creates an update event" do
|
47
|
-
expect { described_class.assign!(obj) }.to change(Ddr::Events::UpdateEvent, :count).
|
43
|
+
expect { described_class.assign!(obj) }.to change(Ddr::Events::UpdateEvent, :count).by(1)
|
48
44
|
end
|
49
45
|
end
|
50
46
|
|
@@ -118,37 +118,16 @@ RSpec.describe SolrDocument, type: :model, contacts: true do
|
|
118
118
|
end
|
119
119
|
end
|
120
120
|
|
121
|
-
describe "#
|
122
|
-
context "no indexed
|
123
|
-
it "should return an empty hash" do
|
124
|
-
expect(subject.struct_maps).to be_empty
|
125
|
-
end
|
126
|
-
end
|
127
|
-
context "indexed struct maps" do
|
128
|
-
before { subject[Ddr::Index::Fields::STRUCT_MAPS] = multiple_struct_maps_structure_to_json }
|
129
|
-
it "should return a hash of the struct maps" do
|
130
|
-
expect(subject.struct_maps).to eq(JSON.parse(multiple_struct_maps_structure_to_json))
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
describe "#struct_map" do
|
136
|
-
context "no indexed struct maps" do
|
121
|
+
describe "#structure" do
|
122
|
+
context "no indexed structures" do
|
137
123
|
it "should return nil" do
|
138
|
-
expect(subject.
|
124
|
+
expect(subject.structure).to be_nil
|
139
125
|
end
|
140
126
|
end
|
141
|
-
context "indexed
|
142
|
-
before { subject[Ddr::Index::Fields::
|
143
|
-
|
144
|
-
|
145
|
-
expect(subject.struct_map('default')).to eq(JSON.parse(multiple_struct_maps_structure_to_json)["default"])
|
146
|
-
end
|
147
|
-
end
|
148
|
-
context "requested struct map is not indexed" do
|
149
|
-
it "should raise a KeyError" do
|
150
|
-
expect { subject.struct_map('foo') }.to raise_error(KeyError)
|
151
|
-
end
|
127
|
+
context "indexed structure" do
|
128
|
+
before { subject[Ddr::Index::Fields::STRUCTURE] = simple_structure_to_json }
|
129
|
+
it "should return the structures map" do
|
130
|
+
expect(subject.structure).to eq(JSON.parse(simple_structure_to_json))
|
152
131
|
end
|
153
132
|
end
|
154
133
|
end
|
@@ -194,28 +173,21 @@ RSpec.describe SolrDocument, type: :model, contacts: true do
|
|
194
173
|
its(:multires_image_file_paths) { is_expected.to match([]) }
|
195
174
|
end
|
196
175
|
context "structural metadata" do
|
197
|
-
|
198
|
-
{"type"=>"default", "divs"=>
|
199
|
-
[{"id"=>"viccb010010010", "label"=>"1", "order"=>"1", "type"=>"Image", "fptrs"=>["test:5"], "divs"=>[]},
|
200
|
-
{"id"=>"viccb010020010", "label"=>"2", "order"=>"2", "type"=>"Image", "fptrs"=>["test:6"], "divs"=>[]},
|
201
|
-
{"id"=>"viccb010030010", "label"=>"3", "order"=>"3", "type"=>"Image", "fptrs"=>["test:7"], "divs"=>[]}]
|
202
|
-
}
|
203
|
-
end
|
204
|
-
before { allow(subject).to receive(:struct_map) { struct_map } }
|
176
|
+
before { allow(subject).to receive(:structure) { JSON.parse(simple_structure_to_json) } }
|
205
177
|
context "no structural objects with multi-res images" do
|
206
178
|
before do
|
207
|
-
allow(SolrDocument).to receive(:find).with('test:5') { double(multires_image_file_path: nil) }
|
208
|
-
allow(SolrDocument).to receive(:find).with('test:6') { double(multires_image_file_path: nil) }
|
209
179
|
allow(SolrDocument).to receive(:find).with('test:7') { double(multires_image_file_path: nil) }
|
180
|
+
allow(SolrDocument).to receive(:find).with('test:8') { double(multires_image_file_path: nil) }
|
181
|
+
allow(SolrDocument).to receive(:find).with('test:9') { double(multires_image_file_path: nil) }
|
210
182
|
end
|
211
183
|
its(:multires_image_file_paths) { is_expected.to match([]) }
|
212
184
|
end
|
213
185
|
context "structural objects with multi-res images" do
|
214
186
|
let(:expected_result) { [ "/path/file1.ptif", "/path/file2.ptif" ] }
|
215
187
|
before do
|
216
|
-
allow(SolrDocument).to receive(:find).with('test:
|
217
|
-
allow(SolrDocument).to receive(:find).with('test:
|
218
|
-
allow(SolrDocument).to receive(:find).with('test:
|
188
|
+
allow(SolrDocument).to receive(:find).with('test:7') { double(multires_image_file_path: "/path/file1.ptif") }
|
189
|
+
allow(SolrDocument).to receive(:find).with('test:8') { double(multires_image_file_path: nil) }
|
190
|
+
allow(SolrDocument).to receive(:find).with('test:9') { double(multires_image_file_path: "/path/file2.ptif") }
|
219
191
|
end
|
220
192
|
its(:multires_image_file_paths) { is_expected.to match(expected_result) }
|
221
193
|
end
|
@@ -1,30 +1,99 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'support/structural_metadata_helper'
|
3
3
|
|
4
|
-
module Ddr
|
5
|
-
|
6
|
-
RSpec.describe Structure, type: :model, structural_metadata: true do
|
4
|
+
module Ddr::Models
|
5
|
+
RSpec.describe Structure, type: :model, structural_metadata: true do
|
7
6
|
|
8
|
-
|
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
|
26
|
+
|
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("Sam Spade")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
describe "structure does not have a metsHdr" do
|
9
35
|
let(:structure) { FactoryGirl.build(:multiple_struct_maps_structure) }
|
10
|
-
|
11
|
-
|
12
|
-
expect(struct_maps.keys).to match_array([ 'default', 'reverse' ])
|
13
|
-
expect(struct_maps['default']).to be_a(Ddr::Models::StructDiv)
|
14
|
-
expect(struct_maps['reverse']).to be_a(Ddr::Models::StructDiv)
|
36
|
+
it "returns the creator" do
|
37
|
+
expect(structure.creator).to be nil
|
15
38
|
end
|
16
39
|
end
|
40
|
+
end
|
17
41
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
25
51
|
end
|
26
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
|
+
end
|
27
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
|
28
96
|
end
|
97
|
+
|
29
98
|
end
|
30
99
|
end
|