ddr-models 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE.txt +12 -0
- data/README.md +5 -0
- data/Rakefile +37 -0
- data/app/models/attachment.rb +7 -0
- data/app/models/collection.rb +54 -0
- data/app/models/component.rb +15 -0
- data/app/models/item.rb +19 -0
- data/app/models/solr_document.rb +36 -0
- data/app/models/target.rb +8 -0
- data/config/initializers/active_fedora_base.rb +77 -0
- data/config/initializers/active_fedora_datastream.rb +5 -0
- data/config/initializers/ddr.rb +8 -0
- data/config/initializers/devise.rb +245 -0
- data/config/initializers/devise.rb~ +245 -0
- data/config/initializers/subscriptions.rb +15 -0
- data/config/routes.rb +2 -0
- data/db/migrate/20141021233359_create_events.rb +28 -0
- data/db/migrate/20141021234156_create_minted_ids.rb +19 -0
- data/db/migrate/20141103192146_create_workflow_state.rb +13 -0
- data/db/migrate/20141104181418_create_users.rb +34 -0
- data/db/migrate/20141104181418_create_users.rb~ +6 -0
- data/lib/ddr-models.rb +1 -0
- data/lib/ddr/actions.rb +8 -0
- data/lib/ddr/actions/fixity_check.rb +35 -0
- data/lib/ddr/auth.rb +45 -0
- data/lib/ddr/auth.rb~ +47 -0
- data/lib/ddr/auth/ability.rb +204 -0
- data/lib/ddr/auth/ability.rb~ +204 -0
- data/lib/ddr/auth/group_service.rb +53 -0
- data/lib/ddr/auth/group_service.rb~ +53 -0
- data/lib/ddr/auth/grouper_service.rb +76 -0
- data/lib/ddr/auth/grouper_service.rb~ +77 -0
- data/lib/ddr/auth/remote_group_service.rb +35 -0
- data/lib/ddr/auth/remote_group_service.rb~ +35 -0
- data/lib/ddr/auth/superuser.rb +13 -0
- data/lib/ddr/auth/superuser.rb~ +9 -0
- data/lib/ddr/auth/user.rb +71 -0
- data/lib/ddr/auth/user.rb~ +65 -0
- data/lib/ddr/configurable.rb +34 -0
- data/lib/ddr/datastreams.rb +32 -0
- data/lib/ddr/datastreams/content_metadata_datastream.rb +147 -0
- data/lib/ddr/datastreams/datastream_behavior.rb +95 -0
- data/lib/ddr/datastreams/descriptive_metadata_datastream.rb +84 -0
- data/lib/ddr/datastreams/properties_datastream.rb +25 -0
- data/lib/ddr/datastreams/role_assignments_datastream.rb +19 -0
- data/lib/ddr/events.rb +17 -0
- data/lib/ddr/events/creation_event.rb +12 -0
- data/lib/ddr/events/event.rb +163 -0
- data/lib/ddr/events/fixity_check_event.rb +43 -0
- data/lib/ddr/events/ingestion_event.rb +12 -0
- data/lib/ddr/events/preservation_event_behavior.rb +37 -0
- data/lib/ddr/events/preservation_event_type.rb +24 -0
- data/lib/ddr/events/reindex_object_after_save.rb +18 -0
- data/lib/ddr/events/update_event.rb +9 -0
- data/lib/ddr/events/validation_event.rb +11 -0
- data/lib/ddr/events/virus_check_event.rb +30 -0
- data/lib/ddr/index_fields.rb +39 -0
- data/lib/ddr/metadata.rb +22 -0
- data/lib/ddr/metadata/duke_terms.rb +15 -0
- data/lib/ddr/metadata/premis_event.rb +59 -0
- data/lib/ddr/metadata/rdf_vocabulary_parser.rb +45 -0
- data/lib/ddr/metadata/roles_vocabulary.rb +10 -0
- data/lib/ddr/metadata/sources/duketerms.rdf.xml +856 -0
- data/lib/ddr/metadata/vocabulary.rb +37 -0
- data/lib/ddr/models.rb +60 -0
- data/lib/ddr/models/access_controllable.rb +23 -0
- data/lib/ddr/models/base.rb +37 -0
- data/lib/ddr/models/describable.rb +81 -0
- data/lib/ddr/models/engine.rb +58 -0
- data/lib/ddr/models/error.rb +12 -0
- data/lib/ddr/models/event_loggable.rb +36 -0
- data/lib/ddr/models/file_management.rb +183 -0
- data/lib/ddr/models/fixity_checkable.rb +20 -0
- data/lib/ddr/models/governable.rb +48 -0
- data/lib/ddr/models/has_attachments.rb +12 -0
- data/lib/ddr/models/has_children.rb +21 -0
- data/lib/ddr/models/has_content.rb +114 -0
- data/lib/ddr/models/has_content_metadata.rb +16 -0
- data/lib/ddr/models/has_properties.rb +15 -0
- data/lib/ddr/models/has_role_assignments.rb +17 -0
- data/lib/ddr/models/has_thumbnail.rb +27 -0
- data/lib/ddr/models/has_workflow.rb +29 -0
- data/lib/ddr/models/indexing.rb +53 -0
- data/lib/ddr/models/licensable.rb +28 -0
- data/lib/ddr/models/minted_id.rb +10 -0
- data/lib/ddr/models/permanent_identification.rb +48 -0
- data/lib/ddr/models/solr_document.rb +193 -0
- data/lib/ddr/models/version.rb +5 -0
- data/lib/ddr/notifications.rb +15 -0
- data/lib/ddr/services.rb +8 -0
- data/lib/ddr/services/id_service.rb +48 -0
- data/lib/ddr/utils.rb +153 -0
- data/lib/ddr/workflow.rb +8 -0
- data/lib/ddr/workflow/workflow_state.rb +39 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/models/user.rb +5 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +29 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +78 -0
- data/spec/dummy/config/environments/test.rb +39 -0
- data/spec/dummy/config/initializers/assets.rb +8 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +56 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/schema.rb +80 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +4974 -0
- data/spec/dummy/log/test.log +55627 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/factories/attachment_factories.rb +15 -0
- data/spec/factories/collection_factories.rb +16 -0
- data/spec/factories/component_factories.rb +15 -0
- data/spec/factories/event_factories.rb +7 -0
- data/spec/factories/item_factories.rb +16 -0
- data/spec/factories/target_factories.rb +11 -0
- data/spec/factories/test_model_factories.rb +133 -0
- data/spec/factories/user_factories.rb +7 -0
- data/spec/factories/user_factories.rb~ +7 -0
- data/spec/features/grouper_integration_spec.rb~ +21 -0
- data/spec/fixtures/contentMetadata.xml +37 -0
- data/spec/fixtures/image1.tiff +0 -0
- data/spec/fixtures/image2.tiff +0 -0
- data/spec/fixtures/image3.tiff +0 -0
- data/spec/fixtures/library-devil.tiff +0 -0
- data/spec/fixtures/sample.docx +0 -0
- data/spec/fixtures/sample.pdf +0 -0
- data/spec/fixtures/target.png +0 -0
- data/spec/models/ability_spec.rb +248 -0
- data/spec/models/ability_spec.rb~ +245 -0
- data/spec/models/active_fedora_base_spec.rb +107 -0
- data/spec/models/active_fedora_datastream_spec.rb +121 -0
- data/spec/models/attachment_spec.rb +13 -0
- data/spec/models/collection_spec.rb +33 -0
- data/spec/models/component_spec.rb +8 -0
- data/spec/models/descriptive_metadata_datastream_spec.rb +102 -0
- data/spec/models/events_spec.rb +64 -0
- data/spec/models/file_management_spec.rb +179 -0
- data/spec/models/has_role_assignments_spec.rb +29 -0
- data/spec/models/has_workflow_spec.rb +54 -0
- data/spec/models/item_spec.rb +8 -0
- data/spec/models/permanent_identification_spec.rb +65 -0
- data/spec/models/role_assignments_datastream_spec.rb +25 -0
- data/spec/models/superuser_spec.rb +13 -0
- data/spec/models/superuser_spec.rb~ +13 -0
- data/spec/models/target_spec.rb +8 -0
- data/spec/models/user_spec.rb +60 -0
- data/spec/models/user_spec.rb~ +56 -0
- data/spec/services/group_service_spec.rb +75 -0
- data/spec/services/group_service_spec.rb~ +71 -0
- data/spec/services/id_service_spec.rb +33 -0
- data/spec/spec_helper.rb +125 -0
- data/spec/support/shared_examples_for_access_controllables.rb +6 -0
- data/spec/support/shared_examples_for_associations.rb +8 -0
- data/spec/support/shared_examples_for_ddr_models.rb +7 -0
- data/spec/support/shared_examples_for_describables.rb +63 -0
- data/spec/support/shared_examples_for_event_loggables.rb +3 -0
- data/spec/support/shared_examples_for_events.rb +179 -0
- data/spec/support/shared_examples_for_governables.rb +17 -0
- data/spec/support/shared_examples_for_has_content.rb +136 -0
- data/spec/support/shared_examples_for_has_content_metadata.rb +74 -0
- data/spec/support/shared_examples_for_has_properties.rb +5 -0
- data/spec/support/shared_examples_for_indexing.rb +36 -0
- metadata +562 -0
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
def mock_object(opts={})
|
|
2
|
+
double("object", {create_date: "2014-01-01T01:01:01.000Z", modified_date: "2014-06-01T01:01:01.000Z"}.merge(opts))
|
|
3
|
+
end
|
|
4
|
+
|
|
5
|
+
RSpec.shared_examples "a preservation-related event" do
|
|
6
|
+
subject { described_class.new }
|
|
7
|
+
it "should have an event_type" do
|
|
8
|
+
expect(subject.preservation_event_type).not_to be_nil
|
|
9
|
+
end
|
|
10
|
+
it "should have a PREMIS representation" do
|
|
11
|
+
expect(subject).to respond_to :as_premis
|
|
12
|
+
expect(subject).to respond_to :to_xml
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
RSpec.shared_examples "an event that reindexes its object after save" do
|
|
17
|
+
it "should implement the reindexing concern" do
|
|
18
|
+
expect(subject).to be_a Ddr::Events::ReindexObjectAfterSave
|
|
19
|
+
end
|
|
20
|
+
context "when object is present" do
|
|
21
|
+
let(:object) { mock_object }
|
|
22
|
+
before do
|
|
23
|
+
allow(subject).to receive(:object) { object }
|
|
24
|
+
end
|
|
25
|
+
it "should reindex its object after save" do
|
|
26
|
+
expect(object).to receive(:update_index)
|
|
27
|
+
subject.save(validate: false)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
RSpec.shared_examples "an event" do
|
|
33
|
+
describe "validation" do
|
|
34
|
+
context "of pid" do
|
|
35
|
+
it "should require presence" do
|
|
36
|
+
expect(subject).not_to be_valid
|
|
37
|
+
expect(subject.errors[:pid]).to include "can't be blank"
|
|
38
|
+
end
|
|
39
|
+
context "when the object exists" do
|
|
40
|
+
before { subject.pid = ActiveFedora::Base.create.pid }
|
|
41
|
+
it "should be valid" do
|
|
42
|
+
expect(subject).to be_valid
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
context "when the object doesn't exist" do
|
|
46
|
+
before { subject.pid = "test:123" }
|
|
47
|
+
it "should not be valid" do
|
|
48
|
+
expect(subject).not_to be_valid
|
|
49
|
+
expect(subject.errors).to have_key :pid
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
it "should require an event_date_time" do
|
|
54
|
+
subject.event_date_time = nil # reset b/c set to default after init
|
|
55
|
+
expect(subject).not_to be_valid
|
|
56
|
+
expect(subject.errors[:event_date_time]).to include "can't be blank"
|
|
57
|
+
end
|
|
58
|
+
it "should require a valid outcome" do
|
|
59
|
+
subject.outcome = Ddr::Events::Event::SUCCESS
|
|
60
|
+
subject.valid?
|
|
61
|
+
expect(subject.errors).not_to have_key :outcome
|
|
62
|
+
subject.outcome = Ddr::Events::Event::FAILURE
|
|
63
|
+
subject.valid?
|
|
64
|
+
expect(subject.errors).not_to have_key :outcome
|
|
65
|
+
subject.outcome = "Some other value"
|
|
66
|
+
expect(subject).not_to be_valid
|
|
67
|
+
expect(subject.errors[:outcome]).to include "\"Some other value\" is not a valid event outcome"
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
describe "outcome setters and getters" do
|
|
72
|
+
it "should encapsulate access" do
|
|
73
|
+
subject.success!
|
|
74
|
+
expect(subject.outcome).to eq Ddr::Events::Event::SUCCESS
|
|
75
|
+
expect(subject).to be_success
|
|
76
|
+
subject.failure!
|
|
77
|
+
expect(subject.outcome).to eq Ddr::Events::Event::FAILURE
|
|
78
|
+
expect(subject).to be_failure
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
describe "setting defaults" do
|
|
83
|
+
context "after initialization" do
|
|
84
|
+
it "should set outcome to 'success'" do
|
|
85
|
+
expect(subject.outcome).to eq Ddr::Events::Event::SUCCESS
|
|
86
|
+
end
|
|
87
|
+
it "should set event_date_time" do
|
|
88
|
+
expect(subject.event_date_time).to be_present
|
|
89
|
+
end
|
|
90
|
+
it "should set software" do
|
|
91
|
+
expect(subject.software).to be_present
|
|
92
|
+
expect(subject.software).to eq subject.send(:default_software)
|
|
93
|
+
end
|
|
94
|
+
it "should set summary" do
|
|
95
|
+
expect(subject.summary).to eq subject.send(:default_summary)
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
context "when attributes are set" do
|
|
99
|
+
let(:obj) { ActiveFedora::Base.create }
|
|
100
|
+
let(:event) { described_class.new(pid: obj.pid, outcome: Ddr::Events::Event::FAILURE, event_date_time: Time.utc(2013), software: "Test", summary: "A terrible disaster") }
|
|
101
|
+
it "should not overwrite attributes" do
|
|
102
|
+
expect { event.send(:set_defaults) }.not_to change { event.outcome }
|
|
103
|
+
expect { event.send(:set_defaults) }.not_to change { event.event_date_time }
|
|
104
|
+
expect { event.send(:set_defaults) }.not_to change { event.software }
|
|
105
|
+
expect { event.send(:set_defaults) }.not_to change { event.summary }
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
describe "object getter" do
|
|
111
|
+
subject { described_class.new(pid: "test:123") }
|
|
112
|
+
let(:object) { mock_object }
|
|
113
|
+
before { allow(ActiveFedora::Base).to receive(:find).with("test:123") { object } }
|
|
114
|
+
it "should retrieve the object" do
|
|
115
|
+
expect(subject.object).to eq object
|
|
116
|
+
end
|
|
117
|
+
it "should cache the object" do
|
|
118
|
+
expect(ActiveFedora::Base).to receive(:find).with("test:123").once
|
|
119
|
+
subject.object
|
|
120
|
+
subject.object
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
describe "object setter" do
|
|
125
|
+
let(:object) { mock_object(pid: "test:123") }
|
|
126
|
+
it "should set the event pid and object" do
|
|
127
|
+
allow(object).to receive(:new_record?) { false }
|
|
128
|
+
subject.object = object
|
|
129
|
+
expect(subject.pid).to eq "test:123"
|
|
130
|
+
expect(subject.object).to eq object
|
|
131
|
+
end
|
|
132
|
+
it "should raise an ArgumentError if object is a new record" do
|
|
133
|
+
allow(object).to receive(:new_record?) { true }
|
|
134
|
+
expect { subject.object = object }.to raise_error ArgumentError
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
describe "object existence" do
|
|
139
|
+
it "should be false if pid is nil" do
|
|
140
|
+
expect(subject.object_exists?).to be_falsey
|
|
141
|
+
end
|
|
142
|
+
it "should be false if pid not found in repository" do
|
|
143
|
+
subject.pid = "test:123"
|
|
144
|
+
expect(subject.object_exists?).to be_falsey
|
|
145
|
+
end
|
|
146
|
+
it "should be true if object exists in repository" do
|
|
147
|
+
allow(ActiveFedora::Base).to receive(:find).with("test:123") { mock_object }
|
|
148
|
+
subject.pid = "test:123"
|
|
149
|
+
expect(subject.object_exists?).to be_truthy
|
|
150
|
+
end
|
|
151
|
+
it "should be true if object instance variable is set" do
|
|
152
|
+
obj = mock_object(pid: "test:123")
|
|
153
|
+
allow(obj).to receive(:new_record?) { false }
|
|
154
|
+
subject.object = obj
|
|
155
|
+
expect(subject.object_exists?).to be_truthy
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
describe "event_date_time string representation" do
|
|
160
|
+
subject { described_class.new(event_date_time: Time.utc(2014, 6, 4, 11, 7, 35)) }
|
|
161
|
+
it "should conform to the specified format" do
|
|
162
|
+
expect(subject.event_date_time_s).to eq "2014-06-04T11:07:35.000Z"
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
describe "rendering who/what performed the action" do
|
|
167
|
+
context "when performed by a user" do
|
|
168
|
+
before { subject.user = User.new(username: "bob") }
|
|
169
|
+
it "should render the user" do
|
|
170
|
+
expect(subject.performed_by).to eq "bob"
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
context "when not performed by a user" do
|
|
174
|
+
it "should render 'SYSTEM'" do
|
|
175
|
+
expect(subject.performed_by).to eq "SYSTEM"
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
RSpec.shared_examples "a governable object" do
|
|
2
|
+
let(:object) do
|
|
3
|
+
described_class.new.tap do |obj|
|
|
4
|
+
obj.title = [ 'Describable' ]
|
|
5
|
+
obj.identifier = [ 'id001' ]
|
|
6
|
+
obj.save(validate: false)
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
describe "can have an admin policy" do
|
|
10
|
+
let(:coll) { FactoryGirl.create(:collection) }
|
|
11
|
+
it "should set its admin policy with #admin_policy= and get with #admin_policy" do
|
|
12
|
+
object.admin_policy = coll
|
|
13
|
+
object.save(validate: false)
|
|
14
|
+
expect(ActiveFedora::Base.find(object.pid, cast: true).admin_policy).to eq(coll)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'openssl'
|
|
3
|
+
|
|
4
|
+
RSpec.shared_examples "an object that can have content" do
|
|
5
|
+
|
|
6
|
+
let(:object) { described_class.new(title: [ "I Have Content!" ]) }
|
|
7
|
+
|
|
8
|
+
it "should delegate :validate_checksum! to :content" do
|
|
9
|
+
checksum = "dea56f15b309e47b74fa24797f85245dda0ca3d274644a96804438bbd659555a"
|
|
10
|
+
expect(object.content).to receive(:validate_checksum!).with(checksum, "SHA-256")
|
|
11
|
+
object.validate_checksum!(checksum, "SHA-256")
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
describe "indexing" do
|
|
15
|
+
let(:file) { fixture_file_upload("library-devil.tiff", "image/tiff") }
|
|
16
|
+
before { object.upload file }
|
|
17
|
+
it "should index the content ds control group" do
|
|
18
|
+
expect(object.to_solr).to include(Ddr::IndexFields::CONTENT_CONTROL_GROUP)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
describe "adding a file" do
|
|
23
|
+
let(:file) { fixture_file_upload("library-devil.tiff", "image/tiff") }
|
|
24
|
+
context "defaults" do
|
|
25
|
+
before { object.add_file file, "content" }
|
|
26
|
+
it "should have an original_filename" do
|
|
27
|
+
expect(object.original_filename).to eq("library-devil.tiff")
|
|
28
|
+
end
|
|
29
|
+
it "should have a content_type" do
|
|
30
|
+
expect(object.content_type).to eq("image/tiff")
|
|
31
|
+
end
|
|
32
|
+
it "should create a 'virus check' event for the object" do
|
|
33
|
+
expect { object.save }.to change { object.virus_checks.count }.by(1)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
context "with option `:original_name=>false`" do
|
|
37
|
+
before { object.add_file file, "content", original_name: false }
|
|
38
|
+
it "should not have an original_filename" do
|
|
39
|
+
expect(object.original_filename).to be_nil
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
context "with `:original_name` option set to a string" do
|
|
43
|
+
before { object.add_file file, "content", original_name: "another-name.tiff" }
|
|
44
|
+
it "should have an original_filename" do
|
|
45
|
+
expect(object.original_filename).to eq("another-name.tiff")
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
describe "save" do
|
|
51
|
+
|
|
52
|
+
describe "when content is not present" do
|
|
53
|
+
it "should not save" do
|
|
54
|
+
expect(object.save).to be false
|
|
55
|
+
expect(object.errors[:content]).to include "can't be blank"
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
describe "when new content is present" do
|
|
60
|
+
|
|
61
|
+
context "and it's a new object" do
|
|
62
|
+
before { object.add_file file, "content" }
|
|
63
|
+
|
|
64
|
+
context "and the content is an image" do
|
|
65
|
+
let(:file) { fixture_file_upload("library-devil.tiff", "image/tiff") }
|
|
66
|
+
it "should generate a thumbnail" do
|
|
67
|
+
expect(object.thumbnail).not_to be_present
|
|
68
|
+
object.save
|
|
69
|
+
expect(object.thumbnail).to be_present
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
context "and the content is a pdf" do
|
|
73
|
+
let(:file) { fixture_file_upload("sample.pdf", "application/pdf") }
|
|
74
|
+
it "should generate a thumbnail" do
|
|
75
|
+
expect(object.thumbnail).not_to be_present
|
|
76
|
+
object.save
|
|
77
|
+
expect(object.thumbnail).to be_present
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
context "and the content is neither an image nor a pdf" do
|
|
81
|
+
let(:file) { fixture_file_upload("sample.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document") }
|
|
82
|
+
it "should not generate a thumbnail" do
|
|
83
|
+
expect(object.thumbnail).not_to be_present
|
|
84
|
+
object.save
|
|
85
|
+
expect(object.thumbnail).not_to be_present
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
context "and it's an existing object with content" do
|
|
91
|
+
before { object.upload! fixture_file_upload('library-devil.tiff', 'image/tiff') }
|
|
92
|
+
|
|
93
|
+
context "and the content is an image" do
|
|
94
|
+
let(:file) { fixture_file_upload("image1.tiff", "image/tiff") }
|
|
95
|
+
it "should generate a new thumbnail" do
|
|
96
|
+
expect(object.thumbnail).to be_present
|
|
97
|
+
expect { object.upload! file }.to change { object.thumbnail.content }
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
context "and the content is a pdf" do
|
|
101
|
+
let(:file) { fixture_file_upload("sample.pdf", "application/pdf") }
|
|
102
|
+
it "should generate a new thumbnail" do
|
|
103
|
+
expect(object.thumbnail).to be_present
|
|
104
|
+
expect { object.upload! file }.to change { object.thumbnail.content }
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
context "and the content is neither an image nor a pdf" do
|
|
108
|
+
let(:file) { fixture_file_upload("sample.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document") }
|
|
109
|
+
it "should delete the thumbnail" do
|
|
110
|
+
expect(object.thumbnail).to be_present
|
|
111
|
+
object.upload! file
|
|
112
|
+
expect(object.thumbnail).to_not be_present
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
describe "#upload" do
|
|
120
|
+
let(:file) { fixture_file_upload("library-devil.tiff", "image/tiff") }
|
|
121
|
+
it "should add the file to the content datastream" do
|
|
122
|
+
expect(object).to receive(:add_file).with(file, "content", {})
|
|
123
|
+
object.upload(file)
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
describe "#upload!" do
|
|
128
|
+
let(:file) { fixture_file_upload("library-devil.tiff", "image/tiff") }
|
|
129
|
+
it "should add the file to the content datastream and save the object" do
|
|
130
|
+
expect(object).to receive(:add_file).with(file, "content", {}).and_call_original
|
|
131
|
+
expect(object).to receive(:save)
|
|
132
|
+
object.upload!(file)
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
end
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'tempfile'
|
|
3
|
+
|
|
4
|
+
RSpec.shared_examples "an object that has content metadata" do
|
|
5
|
+
let!(:object) { described_class.create! }
|
|
6
|
+
let(:file_path) { File.join(File.dirname(__FILE__), '..', 'fixtures', 'contentMetadata.xml') }
|
|
7
|
+
before do
|
|
8
|
+
object.contentMetadata.content = File.new(file_path, "r")
|
|
9
|
+
object.save!
|
|
10
|
+
end
|
|
11
|
+
context "contentMetadata datastream" do
|
|
12
|
+
let(:expected_result) do
|
|
13
|
+
[
|
|
14
|
+
{
|
|
15
|
+
"div" => [
|
|
16
|
+
{
|
|
17
|
+
"type" => "image",
|
|
18
|
+
"label" => "Images",
|
|
19
|
+
"div" => [
|
|
20
|
+
{
|
|
21
|
+
"pids" => [
|
|
22
|
+
{
|
|
23
|
+
"pid" => "test:1",
|
|
24
|
+
"use" => "Master Image"
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"pids" => [
|
|
30
|
+
{
|
|
31
|
+
"pid" => "test:2",
|
|
32
|
+
"use" => "Master Image"
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"pids" => [
|
|
38
|
+
{
|
|
39
|
+
"pid" => "test:3",
|
|
40
|
+
"use" => "Master Image"
|
|
41
|
+
}
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
]
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"type" => "pdf",
|
|
48
|
+
"label" => "PDF",
|
|
49
|
+
"pids" => [
|
|
50
|
+
{
|
|
51
|
+
"pid" => "test:4",
|
|
52
|
+
"use" => "Composite PDF"
|
|
53
|
+
}
|
|
54
|
+
]
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
]
|
|
58
|
+
}
|
|
59
|
+
]
|
|
60
|
+
end
|
|
61
|
+
context "#parse" do
|
|
62
|
+
it "should produce the appropriate result" do
|
|
63
|
+
result = object.contentMetadata.parse
|
|
64
|
+
expect(result).to eq(expected_result)
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
context "#to_solr" do
|
|
68
|
+
let(:solr_result) { ActiveFedora::SolrService.query("id:#{object.pid.gsub(':', '\\:')}").first }
|
|
69
|
+
it "should add the parsed contentMetadata to the index" do
|
|
70
|
+
expect(JSON.parse(solr_result[ActiveFedora::SolrService.solr_name(:content_metadata_parsed, :symbol)].first)).to eq(expected_result)
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
RSpec.shared_examples "an object that has a display title" do
|
|
2
|
+
describe "#title_display" do
|
|
3
|
+
let(:object) { described_class.new }
|
|
4
|
+
subject { object.title_display }
|
|
5
|
+
context "has title" do
|
|
6
|
+
before { object.title = [ 'Title' ] }
|
|
7
|
+
it "should return the first title" do
|
|
8
|
+
expect(subject).to eq('Title')
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
context "has no title, has identifier" do
|
|
12
|
+
before { object.identifier = [ 'id001' ] }
|
|
13
|
+
it "should return the first identifier" do
|
|
14
|
+
expect(subject).to eq('id001')
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
# Only objects with content implement :original_filename
|
|
18
|
+
# This test worked before b/c allowing rspec to stub methods
|
|
19
|
+
# that aren't defined on object. This rspec-mocks config setting prevents that:
|
|
20
|
+
#
|
|
21
|
+
# verify_partial_doubles = true
|
|
22
|
+
#
|
|
23
|
+
# context "has no title, no identifier, has original_filename" do
|
|
24
|
+
# before { allow(object).to receive(:original_filename) { "file.txt" } }
|
|
25
|
+
# it "should return original_filename" do
|
|
26
|
+
# expect(subject).to eq "file.txt"
|
|
27
|
+
# end
|
|
28
|
+
# end
|
|
29
|
+
context "has no title, no identifier, no original_filename" do
|
|
30
|
+
let(:object) { described_class.new(:pid => 'duke:test') }
|
|
31
|
+
it "should return the PID in square brackets" do
|
|
32
|
+
expect(subject).to eq "[duke:test]"
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|