ddr-models 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.shared_examples "a repository external file" do
|
4
|
+
it "should be owned by the effective user" do
|
5
|
+
expect(File.owned?(file_path)).to be true
|
6
|
+
end
|
7
|
+
it "should be readable by the effective user" do
|
8
|
+
expect(File.readable?(file_path)).to be true
|
9
|
+
end
|
10
|
+
it "should be writable by the effective user" do
|
11
|
+
expect(File.writable?(file_path)).to be true
|
12
|
+
end
|
13
|
+
it "should not have the sticky bit set" do
|
14
|
+
expect(File.sticky?(file_path)).to be false
|
15
|
+
end
|
16
|
+
it "should have 644 mode" do
|
17
|
+
expect("%o" % File.world_readable?(file_path)).to eq "644"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
module Ddr
|
22
|
+
module Models
|
23
|
+
RSpec.describe FileManagement, :type => :model do
|
24
|
+
|
25
|
+
let(:object) { FileManageable.new }
|
26
|
+
let(:file) { fixture_file_upload("library-devil.tiff", "image/tiff") }
|
27
|
+
|
28
|
+
before(:all) do
|
29
|
+
class FileManageable < ActiveFedora::Base
|
30
|
+
include Ddr::Models::FileManagement
|
31
|
+
has_file_datastream name: "e_content", control_group: "E"
|
32
|
+
has_file_datastream name: "m_content", control_group: "M"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#add_file" do
|
37
|
+
it "should run a virus scan on the file" do
|
38
|
+
expect(object).to receive(:virus_scan)
|
39
|
+
object.add_file file, "m_content"
|
40
|
+
end
|
41
|
+
it "should call add_file_datastream by default" do
|
42
|
+
expect(object).to receive(:add_file_datastream)
|
43
|
+
object.add_file file, "random_ds_1"
|
44
|
+
end
|
45
|
+
it "should call add_file_datastream when dsid spec is managed" do
|
46
|
+
expect(object).to receive(:add_file_datastream)
|
47
|
+
object.add_file file, "m_content"
|
48
|
+
end
|
49
|
+
it "should call add_external_file when dsid spec is external" do
|
50
|
+
expect(object).to receive(:add_external_file).with(file, "e_content", {mime_type: file.content_type})
|
51
|
+
object.add_file file, "e_content"
|
52
|
+
end
|
53
|
+
it "should call add_external_file when :external => true option passed" do
|
54
|
+
expect(object).to receive(:add_external_file).with(file, "random_ds_2", {mime_type: file.content_type})
|
55
|
+
object.add_file file, "random_ds_2", external: true
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "#add_external_file" do
|
60
|
+
it "should call add_external_datastream if no spec for dsid" do
|
61
|
+
expect(object).to receive(:add_external_datastream).with("random_ds_3").and_call_original
|
62
|
+
object.add_external_file(file, "random_ds_3")
|
63
|
+
end
|
64
|
+
it "should raise an error if datastream is not external" do
|
65
|
+
expect { object.add_external_file(file, "m_content") }.to raise_error
|
66
|
+
end
|
67
|
+
it "should raise an error if dsLocation has changed" do
|
68
|
+
allow(object.e_content).to receive(:dsLocation_changed?) { true }
|
69
|
+
expect { object.add_external_file(file, "e_content") }.to raise_error
|
70
|
+
end
|
71
|
+
it "should set the mimeType" do
|
72
|
+
expect(object.e_content).to receive(:mimeType=).with("image/tiff")
|
73
|
+
object.add_external_file(file, "e_content")
|
74
|
+
end
|
75
|
+
context "storage path generation" do
|
76
|
+
it "should generate a UUID for the for the file name" do
|
77
|
+
expect(SecureRandom).to receive(:uuid).and_call_original
|
78
|
+
object.add_external_file(file, "e_content")
|
79
|
+
end
|
80
|
+
it "should set the file name to the UUID" do
|
81
|
+
uuid = "dfa9fd19-3ec6-4d59-ac34-f7a796902397"
|
82
|
+
allow(object).to receive(:generate_external_file_name) { uuid }
|
83
|
+
object.add_external_file(file, "e_content")
|
84
|
+
expect(object.e_content.file_name).to eq uuid
|
85
|
+
end
|
86
|
+
it "should prepend the configured external file store base directory" do
|
87
|
+
object.add_external_file(file, "e_content")
|
88
|
+
expect(object.e_content.file_path.start_with?(Ddr::Models.external_file_store)).to be true
|
89
|
+
end
|
90
|
+
it "should add a subpath using the configured pattern" do
|
91
|
+
uuid = "dfa9fd19-3ec6-4d59-ac34-f7a796902397"
|
92
|
+
allow(object).to receive(:generate_external_file_name) { uuid }
|
93
|
+
object.add_external_file(file, "e_content")
|
94
|
+
path = object.e_content.file_path
|
95
|
+
subpath = File.dirname(path.sub(Ddr::Models.external_file_store, "").sub("/", ""))
|
96
|
+
expect(Ddr::Models.external_file_subpath_regexp.match(uuid)[0]).to eq subpath
|
97
|
+
end
|
98
|
+
end
|
99
|
+
it "should set dsLocation to URI for generated file path by default" do
|
100
|
+
object.add_external_file(file, "e_content")
|
101
|
+
expect(object.e_content.dsLocation).not_to eq URI.escape("file:#{file.path}")
|
102
|
+
expect(object.e_content.dsLocation).not_to be_nil
|
103
|
+
expect(File.exists?(object.e_content.file_path)).to be true
|
104
|
+
end
|
105
|
+
it "should set dsLocation to URI for original file path if :use_original => true option" do
|
106
|
+
expect(object.e_content).to receive(:dsLocation=).with(URI.escape("file:#{file.path}"))
|
107
|
+
object.add_external_file(file, "e_content", use_original: true)
|
108
|
+
end
|
109
|
+
it "should raise an error if using original file not owned by effective user" do
|
110
|
+
allow(File).to receive(:owned?).with(file.path) { false }
|
111
|
+
expect { object.add_external_file(file, "e_content", use_original: true) }.to raise_error
|
112
|
+
end
|
113
|
+
context "external file permissions" do
|
114
|
+
context "for a generated file" do
|
115
|
+
before { object.add_external_file(file, "e_content") }
|
116
|
+
it_should_behave_like "a repository external file" do
|
117
|
+
let(:file_path) { object.e_content.file_path }
|
118
|
+
end
|
119
|
+
end
|
120
|
+
context "for an original file" do
|
121
|
+
before { object.add_external_file(file, "e_content", use_original: true) }
|
122
|
+
it_should_behave_like "a repository external file" do
|
123
|
+
let(:file_path) { object.e_content.file_path }
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
describe "#add_external_datastream" do
|
130
|
+
it "should return a new external datastream" do
|
131
|
+
ds = object.add_external_datastream("random_ds_27")
|
132
|
+
expect(ds.controlGroup).to eq "E"
|
133
|
+
expect(object.datastreams["random_ds_27"]).to eq ds
|
134
|
+
expect(object.random_ds_27).to eq ds
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
describe "#external_datastream_file_paths" do
|
139
|
+
let(:file1) { fixture_file_upload("image1.tiff", "image/tiff") }
|
140
|
+
let(:file2) { fixture_file_upload("image2.tiff", "image/tiff") }
|
141
|
+
let(:file3) { fixture_file_upload("image3.tiff", "image/tiff") }
|
142
|
+
before do
|
143
|
+
object.add_file(file1, "e_content")
|
144
|
+
object.save
|
145
|
+
object.add_file(file2, "e_content")
|
146
|
+
object.save
|
147
|
+
object.add_file(file3, "e_content_2", external: true)
|
148
|
+
object.save
|
149
|
+
end
|
150
|
+
it "should return a list of file paths for all versions of all external datastreams for the object" do
|
151
|
+
paths = object.external_datastream_file_paths
|
152
|
+
expect(paths.size).to eq 3
|
153
|
+
paths.each do |path|
|
154
|
+
expect(File.exists?(path)).to be true
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
describe "cleanup on destroy" do
|
160
|
+
let(:file1) { fixture_file_upload("image1.tiff", "image/tiff") }
|
161
|
+
let(:file2) { fixture_file_upload("image2.tiff", "image/tiff") }
|
162
|
+
let(:file3) { fixture_file_upload("image3.tiff", "image/tiff") }
|
163
|
+
before do
|
164
|
+
object.add_file(file1, "e_content")
|
165
|
+
object.save
|
166
|
+
object.add_file(file2, "e_content")
|
167
|
+
object.save
|
168
|
+
object.add_file(file3, "e_content_2", external: true)
|
169
|
+
object.save
|
170
|
+
end
|
171
|
+
it "should delete all files for all versions of all external datastreams" do
|
172
|
+
expect(File).to receive(:unlink).with(*object.external_datastream_file_paths)
|
173
|
+
object.destroy
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Ddr
|
4
|
+
module Models
|
5
|
+
RSpec.describe HasRoleAssignments, type: :model do
|
6
|
+
|
7
|
+
before(:all) do
|
8
|
+
class RoleAssignable < ActiveFedora::Base
|
9
|
+
include HasRoleAssignments
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
subject { RoleAssignable.new }
|
14
|
+
|
15
|
+
describe "#principal_has_role?" do
|
16
|
+
it "should respond when given a list of principals and a valid role" do
|
17
|
+
expect { subject.principal_has_role?(["bob", "admins"], :administrator) }.not_to raise_error
|
18
|
+
end
|
19
|
+
it "should respond when given a principal name and a valid role" do
|
20
|
+
expect { subject.principal_has_role?("bob", :administrator) }.not_to raise_error
|
21
|
+
end
|
22
|
+
it "should raise an error when given an invalid role" do
|
23
|
+
expect { subject.principal_has_role?("bob", :foo) }.to raise_error
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Ddr
|
4
|
+
module Models
|
5
|
+
RSpec.describe HasWorkflow, type: :model do
|
6
|
+
|
7
|
+
before(:all) do
|
8
|
+
class Workflowable < ActiveFedora::Base
|
9
|
+
include HasWorkflow
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
subject { Workflowable.new(pid: 'test:1') }
|
14
|
+
|
15
|
+
describe "#published?" do
|
16
|
+
context "object is published" do
|
17
|
+
before { Ddr::Workflow::WorkflowState.create(pid: subject.pid, workflow_state: Ddr::Workflow::WorkflowState::PUBLISHED) }
|
18
|
+
it "should return true" do
|
19
|
+
expect(subject.published?).to eql(true)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
context "object is not published" do
|
23
|
+
context "has never been published" do
|
24
|
+
it "should return false" do
|
25
|
+
expect(subject.published?).to eql(false)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
context "has been published and unpublished" do
|
29
|
+
before { Ddr::Workflow::WorkflowState.create(pid: subject.pid, workflow_state: nil) }
|
30
|
+
it "should return false" do
|
31
|
+
expect(subject.published?).to eql(false)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "#publish!" do
|
38
|
+
it "should publish the object" do
|
39
|
+
subject.publish!
|
40
|
+
expect(subject.published?).to eql(true)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "#unpublish!" do
|
45
|
+
before { subject.publish! }
|
46
|
+
it "should unpublish the object" do
|
47
|
+
subject.unpublish!
|
48
|
+
expect(subject.published?).to eql(false)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Item, :type => :model do
|
4
|
+
it_behaves_like "a DDR model"
|
5
|
+
it_behaves_like "an object that has content metadata"
|
6
|
+
it_behaves_like "it has an association", :belongs_to, :parent, :is_member_of_collection, "Collection"
|
7
|
+
it_behaves_like "it has an association", :has_many, :children, :is_part_of, "Component"
|
8
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Ddr
|
4
|
+
module Models
|
5
|
+
|
6
|
+
RSpec.shared_examples "a permanently identified object" do
|
7
|
+
it "should have a permanent id" do
|
8
|
+
expect(object.permanent_id).to_not be_nil
|
9
|
+
end
|
10
|
+
it "should have an appropriate update event" do
|
11
|
+
expect(object.update_events.map(&:summary)).to include("Assigned permanent ID")
|
12
|
+
end
|
13
|
+
it "should be a referent for the permanent id" do
|
14
|
+
expect(Ddr::Models::MintedId.find_by(minted_id: object.permanent_id).referent).to eql(object.pid)
|
15
|
+
end
|
16
|
+
it "should have a permlink" do
|
17
|
+
expect(object.permalink).to eql(Ddr::Models::PermanentIdentification::PERMALINK_BASE_URL + object.permanent_id)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
RSpec.describe PermanentIdentification, type: :model do
|
22
|
+
|
23
|
+
before(:all) do
|
24
|
+
class PermanentlyIdentifiable < ActiveFedora::Base
|
25
|
+
include Ddr::Models::Describable
|
26
|
+
include Ddr::Models::HasProperties
|
27
|
+
include Ddr::Models::PermanentIdentification
|
28
|
+
include Ddr::Models::EventLoggable
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "creating new object" do
|
33
|
+
let(:object) { PermanentlyIdentifiable.create }
|
34
|
+
it_behaves_like "a permanently identified object"
|
35
|
+
end
|
36
|
+
|
37
|
+
context "saving new object" do
|
38
|
+
let(:object) { PermanentlyIdentifiable.new }
|
39
|
+
before { object.save }
|
40
|
+
it_behaves_like "a permanently identified object"
|
41
|
+
end
|
42
|
+
|
43
|
+
context "saving an existing object" do
|
44
|
+
let(:object) { PermanentlyIdentifiable.create }
|
45
|
+
it "should keep its existing permanent id" do
|
46
|
+
perm_id = object.permanent_id
|
47
|
+
object.title = [ "New Title" ]
|
48
|
+
object.save
|
49
|
+
expect(object.permanent_id).to eq(perm_id)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "exception during permanent id minting" do
|
54
|
+
let(:object) { PermanentlyIdentifiable.create }
|
55
|
+
before { allow(Ddr::Services::IdService).to receive(:mint).and_raise(Exception) }
|
56
|
+
it "should have a failure update event" do
|
57
|
+
expect(object.update_events.last.summary).to eq("Assigned permanent ID")
|
58
|
+
expect(object.update_events.last.outcome).to eq(Ddr::Events::Event::FAILURE)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Ddr
|
4
|
+
module Datastreams
|
5
|
+
RSpec.describe RoleAssignmentsDatastream do
|
6
|
+
|
7
|
+
subject { described_class.new(nil) }
|
8
|
+
|
9
|
+
describe "#principal_has_role?" do
|
10
|
+
before do
|
11
|
+
subject.administrator = ["bob", "sally"]
|
12
|
+
end
|
13
|
+
it "should accept a single principal" do
|
14
|
+
expect(subject.principal_has_role?("sally", :administrator)).to be true
|
15
|
+
expect(subject.principal_has_role?("fred", :administrator)).to be false
|
16
|
+
end
|
17
|
+
it "should accept a list of principals and return if at least one of the principals has the role" do
|
18
|
+
expect(subject.principal_has_role?(["sally", "fred"], :administrator)).to be true
|
19
|
+
expect(subject.principal_has_role?(["wendy", "fred"], :administrator)).to be false
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'cancan/matchers'
|
3
|
+
|
4
|
+
module Ddr
|
5
|
+
module Auth
|
6
|
+
RSpec.describe Superuser, type: :model, abilities: true do
|
7
|
+
subject { described_class.new }
|
8
|
+
it "should be able to manage all" do
|
9
|
+
expect(subject).to be_able_to(:manage, :all)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'cancan/matchers'
|
3
|
+
|
4
|
+
module Ddr
|
5
|
+
module Auth
|
6
|
+
describe Superuser, type: :model, abilities: true do
|
7
|
+
subject { described_class.new }
|
8
|
+
it "should be able to manage all" do
|
9
|
+
expect(subject).to be_able_to(:manage, :all)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Target, type: :model, targets: true do
|
4
|
+
it_behaves_like "a DDR model"
|
5
|
+
it_behaves_like "an object that can have content"
|
6
|
+
it_behaves_like "it has an association", :has_many, :components, :has_external_target, "Component"
|
7
|
+
it_behaves_like "it has an association", :belongs_to, :collection, :is_external_target_for, "Collection"
|
8
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Ddr
|
4
|
+
module Auth
|
5
|
+
RSpec.describe User, :type => :model do
|
6
|
+
|
7
|
+
subject { FactoryGirl.build(:user) }
|
8
|
+
|
9
|
+
describe "#member_of?" do
|
10
|
+
it "should return true if the user is a member of the group" do
|
11
|
+
allow(subject).to receive(:groups).and_return(["foo", "bar"])
|
12
|
+
expect(subject).to be_member_of("foo")
|
13
|
+
end
|
14
|
+
it "should return false if the user is not a member of the group" do
|
15
|
+
allow(subject).to receive(:groups).and_return(["foo", "bar"])
|
16
|
+
expect(subject).not_to be_member_of("baz")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#authorized_to_act_as_superuser?" do
|
21
|
+
it "should return false if the superuser group is not defined (nil)" do
|
22
|
+
Ddr::Auth.superuser_group = nil
|
23
|
+
expect(subject).not_to be_authorized_to_act_as_superuser
|
24
|
+
end
|
25
|
+
it "should return false if the user is not a member of the superuser group" do
|
26
|
+
Ddr::Auth.superuser_group = "superusers"
|
27
|
+
allow(subject).to receive(:groups).and_return(["normal"])
|
28
|
+
expect(subject).not_to be_authorized_to_act_as_superuser
|
29
|
+
end
|
30
|
+
it "should return true if the user is a member of the superuser group" do
|
31
|
+
Ddr::Auth.superuser_group = "superusers"
|
32
|
+
allow(subject).to receive(:groups).and_return(["superusers"])
|
33
|
+
expect(subject).to be_authorized_to_act_as_superuser
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "#principal_name" do
|
38
|
+
it "should return the principal name for the user" do
|
39
|
+
expect(subject.principal_name).to eq subject.user_key
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "#principals" do
|
44
|
+
it "should be a list of the user's groups + the user's principal_name" do
|
45
|
+
allow(subject).to receive(:groups) { ["foo", "bar"] }
|
46
|
+
expect(subject.principals).to match_array ["foo", "bar", subject.principal_name]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "#has_role?" do
|
51
|
+
let(:obj) { double }
|
52
|
+
it "should send :principal_has_role? to the object with the user's principals" do
|
53
|
+
expect(obj).to receive(:principal_has_role?).with(subject.principals, :administrator)
|
54
|
+
subject.has_role?(obj, :administrator)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|