ddr-models 2.7.6 → 2.8.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/app/models/collection.rb +1 -1
  3. data/app/models/component.rb +22 -31
  4. data/config/initializers/active_fedora_base.rb +8 -0
  5. data/config/locales/ddr-models.en.yml +4 -0
  6. data/lib/ddr/datastreams.rb +12 -10
  7. data/lib/ddr/datastreams/administrative_metadata_datastream.rb +6 -0
  8. data/lib/ddr/datastreams/streamable_media_datastream.rb +5 -0
  9. data/lib/ddr/index/fields.rb +7 -5
  10. data/lib/ddr/managers/derivatives_manager.rb +12 -7
  11. data/lib/ddr/models.rb +19 -9
  12. data/lib/ddr/models/base.rb +10 -3
  13. data/lib/ddr/models/file_management.rb +1 -1
  14. data/lib/ddr/models/has_admin_metadata.rb +8 -9
  15. data/lib/ddr/models/indexing.rb +18 -3
  16. data/lib/ddr/models/language.rb +31 -0
  17. data/lib/ddr/models/media_type.rb +22 -0
  18. data/lib/ddr/models/{licenses/license.rb → rights_statement.rb} +3 -7
  19. data/lib/ddr/models/solr_document.rb +22 -2
  20. data/lib/ddr/models/streamable.rb +22 -0
  21. data/lib/ddr/models/version.rb +1 -1
  22. data/lib/ddr/utils.rb +4 -4
  23. data/lib/ddr/vocab/asset.rb +8 -0
  24. data/spec/factories/collection_factories.rb +1 -0
  25. data/spec/index/fields_spec.rb +18 -0
  26. data/spec/managers/derivatives_manager_spec.rb +2 -5
  27. data/spec/models/active_fedora_base_spec.rb +3 -0
  28. data/spec/models/admin_set_spec.rb +2 -1
  29. data/spec/models/attachment_spec.rb +1 -0
  30. data/spec/models/collection_spec.rb +4 -7
  31. data/spec/models/component_spec.rb +20 -5
  32. data/spec/models/has_struct_metadata_spec.rb +0 -1
  33. data/spec/models/indexing_spec.rb +91 -44
  34. data/spec/models/item_spec.rb +1 -0
  35. data/spec/models/language_spec.rb +59 -0
  36. data/spec/models/media_type_spec.rb +46 -0
  37. data/spec/models/{license_spec.rb → rights_statement_spec.rb} +9 -12
  38. data/spec/models/solr_document_spec.rb +57 -2
  39. data/spec/models/target_spec.rb +1 -0
  40. data/spec/spec_helper.rb +11 -0
  41. data/spec/support/shared_examples_for_ddr_models.rb +12 -0
  42. data/spec/support/shared_examples_for_governables.rb +2 -1
  43. data/spec/support/shared_examples_for_streamable_media.rb +22 -0
  44. metadata +17 -13
  45. data/lib/ddr/models/licenses/admin_policy_license.rb +0 -11
  46. data/lib/ddr/models/licenses/effective_license.rb +0 -9
  47. data/lib/ddr/models/licenses/inherited_license.rb +0 -9
  48. data/lib/ddr/models/licenses/parent_license.rb +0 -11
  49. data/spec/models/effective_license_spec.rb +0 -74
@@ -5,6 +5,7 @@ RSpec.describe Item, type: :model do
5
5
  it_behaves_like "it has an association", :has_many, :children, :is_part_of, "Component"
6
6
  it_behaves_like "a non-collection model"
7
7
  it_behaves_like "a potentially publishable object"
8
+ it_behaves_like "an object that cannot be streamable"
8
9
 
9
10
  describe "indexing text" do
10
11
  let(:children) { FactoryGirl.build_list(:component, 5) }
@@ -0,0 +1,59 @@
1
+ module Ddr::Models
2
+ RSpec.describe Language, ddr_aux: true do
3
+
4
+ describe ".call" do
5
+ let(:obj) { Item.new }
6
+
7
+ describe "when the object has a language" do
8
+ before { obj.language = ["cym"] }
9
+ let(:language) {
10
+ described_class.new("id"=>1, "code"=>"cym", "title"=>"Welsh", "created_at"=>"2015-09-15T16:15:58.514Z", "updated_at"=>"2015-09-15T16:15:58.514Z")
11
+ }
12
+ describe "and the language code is found" do
13
+ before {
14
+ allow(described_class).to receive(:find_by_code).with("cym") { language }
15
+ }
16
+ it "returns a Language instance" do
17
+ expect(described_class.call(obj)).to eq([language])
18
+ end
19
+ end
20
+ describe "and the language is not found" do
21
+ before {
22
+ allow(described_class).to receive(:find_by_code).with("cym")
23
+ .and_raise(ActiveResource::ResourceNotFound, "404")
24
+ }
25
+ it "raises an exception" do
26
+ expect { described_class.call(obj) }.to raise_error(Ddr::Models::NotFoundError)
27
+ end
28
+ end
29
+ end
30
+
31
+ describe "when the object does not have language" do
32
+ it "returns empty array" do
33
+ expect(described_class).not_to receive(:find_by_code)
34
+ expect(described_class.call(obj)).to eq([])
35
+ end
36
+ end
37
+ end
38
+
39
+
40
+ describe ".codes" do
41
+ let(:entries) { [ described_class.new(id: 1, code: 'cym', label: 'Welsh'),
42
+ described_class.new(id: 2, code: 'fre', label: 'French') ] }
43
+ let(:response_collection) { ActiveResource::Collection.new }
44
+ before do
45
+ response_collection.elements = entries
46
+ allow(described_class).to receive(:all) { response_collection }
47
+ end
48
+ it "returns the defined codes" do
49
+ expect(described_class.codes).to match_array([ entries[0].code, entries[1].code ])
50
+ end
51
+ end
52
+
53
+ describe "instance methods" do
54
+ subject { described_class.new("id"=>1, "code"=>"cym", "label"=>"Welsh") }
55
+ its(:to_s) { is_expected.to eq("Welsh") }
56
+ end
57
+
58
+ end
59
+ end
@@ -0,0 +1,46 @@
1
+ module Ddr::Models
2
+ RSpec.describe MediaType do
3
+
4
+ subject { described_class.call(file) }
5
+
6
+ describe "when a preferred media type is available" do
7
+ describe "with a file path" do
8
+ let(:file) { 'foo.mp4' }
9
+ it { is_expected.to eq 'video/mp4' }
10
+ end
11
+ describe "with an object that responds to :path" do
12
+ let(:file) { double(path: 'foo.mp4') }
13
+ it { is_expected.to eq 'video/mp4' }
14
+ end
15
+ end
16
+ describe "when a preferred media type is not available" do
17
+ describe "and the file responds to :content_type" do
18
+ let(:file) { double(path: 'foo.jpg', content_type: 'foo/bar') }
19
+ it { is_expected.to eq 'foo/bar' }
20
+ end
21
+ describe "and the file does not respond to :content_type" do
22
+ describe "and MIME types are present" do
23
+ describe "with an object that responds to :path" do
24
+ let(:file) { double(path: 'foo.jpg') }
25
+ it { is_expected.to eq 'image/jpeg' }
26
+ end
27
+ describe "with a file path" do
28
+ let(:file) { 'foo.jpg' }
29
+ it { is_expected.to eq 'image/jpeg' }
30
+ end
31
+ end
32
+ describe "and MIME types are not present" do
33
+ describe "with an object that responds to :path" do
34
+ let(:file) { double(path: 'foo.bar') }
35
+ it { is_expected.to eq 'application/octet-stream' }
36
+ end
37
+ describe "with a file path" do
38
+ let(:file) { 'foo.bar' }
39
+ it { is_expected.to eq 'application/octet-stream' }
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ end
46
+ end
@@ -1,23 +1,20 @@
1
1
  module Ddr::Models
2
- RSpec.describe License, ddr_aux: true do
2
+ RSpec.describe RightsStatement, ddr_aux: true do
3
3
 
4
4
  describe ".call" do
5
- describe "when the object has a license URL" do
6
- let(:obj) { double(pid: "test:1", license: "http://example.com") }
7
- describe "and the license is found" do
5
+ describe "when the object has a rights statement URL" do
6
+ let(:obj) { double(pid: "test:1", rights: ["http://example.com"]) }
7
+ describe "and the rights statement is found" do
8
8
  before {
9
9
  allow(described_class).to receive(:get).with(:find, url: "http://example.com") {
10
- {"id"=>1, "url"=>"http://example.com", "title"=>"A License"}
10
+ {"id"=>1, "url"=>"http://example.com", "title"=>"A Rights Statement"}
11
11
  }
12
12
  }
13
- it "returns a License instance" do
13
+ it "returns a Rights Statement instance" do
14
14
  expect(described_class.call(obj)).to be_a(described_class)
15
15
  end
16
- it "sets `pid` to the object pid" do
17
- expect(described_class.call(obj).pid).to eq("test:1")
18
- end
19
16
  end
20
- describe "and the license is not found" do
17
+ describe "and the rights statement is not found" do
21
18
  before {
22
19
  allow(described_class).to receive(:get).with(:find, url: "http://example.com")
23
20
  .and_raise(ActiveResource::ResourceNotFound, "404")
@@ -28,8 +25,8 @@ module Ddr::Models
28
25
  end
29
26
  end
30
27
 
31
- describe "when the object does not have a license" do
32
- let(:obj) { double(pid: "test:1", license: nil) }
28
+ describe "when the object does not have a rights statement" do
29
+ let(:obj) { double(pid: "test:1", rights: []) }
33
30
  it "returns nil" do
34
31
  expect(described_class.call(obj)).to be_nil
35
32
  end
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  RSpec.describe SolrDocument, type: :model, contacts: true do
4
2
 
5
3
  describe "class methods" do
@@ -195,4 +193,61 @@ RSpec.describe SolrDocument, type: :model, contacts: true do
195
193
  end
196
194
  end
197
195
 
196
+ describe "datastreams" do
197
+ let(:profile) do <<-EOS
198
+ {"datastreams":{"DC":{"dsLabel":"Dublin Core Record for this object","dsVersionID":"DC1.0","dsCreateDate":"2016-02-09T12:38:56Z","dsState":"A","dsMIME":"text/xml","dsFormatURI":"http://www.openarchives.org/OAI/2.0/oai_dc/","dsControlGroup":"X","dsSize":340,"dsVersionable":true,"dsInfoType":null,"dsLocation":"duke:308221+DC+DC1.0","dsLocationType":null,"dsChecksumType":"SHA-1","dsChecksum":"69880409098d8dec1a5c41240a9daac2dd6832e0"}}}
199
+ EOS
200
+ end
201
+ before {
202
+ subject[Ddr::Index::Fields::OBJECT_PROFILE] = [ profile ]
203
+ }
204
+ specify {
205
+ expect(subject.has_datastream?("DC")).to be true
206
+ expect(subject.has_datastream?("foo")).to be false
207
+ }
208
+ end
209
+
210
+ describe "#streamable?" do
211
+ specify {
212
+ allow(subject).to receive(:has_datastream?).with(Ddr::Datastreams::STREAMABLE_MEDIA) { false }
213
+ expect(subject).not_to be_streamable
214
+ }
215
+ specify {
216
+ allow(subject).to receive(:has_datastream?).with(Ddr::Datastreams::STREAMABLE_MEDIA) { true }
217
+ expect(subject).to be_streamable
218
+ }
219
+ end
220
+
221
+ describe "#streamable_media_path" do
222
+ specify {
223
+ allow(subject).to receive(:streamable?) { false }
224
+ expect(subject.streamable_media_path).to be_nil
225
+ }
226
+ specify {
227
+ allow(subject).to receive(:datastreams) do
228
+ {"streamableMedia"=>{"dsLocation"=>"file:/foo/bar/baz.txt"}}
229
+ end
230
+ expect(subject.streamable_media_path).to eq "/foo/bar/baz.txt"
231
+ }
232
+ end
233
+
234
+ describe "#rights" do
235
+ specify {
236
+ obj = Item.create(rights: ["http://example.com"])
237
+ doc = described_class.find(obj.id)
238
+ expect(doc.rights).to eq ["http://example.com"]
239
+ }
240
+ end
241
+
242
+ describe "#rights_statement" do
243
+ let(:rights_statement) { Ddr::Models::RightsStatement.new(url: "http://example.com") }
244
+ before do
245
+ allow(Ddr::Models::RightsStatement).to receive(:get).with(:find, url: "http://example.com") do
246
+ { url: "http://example.com" }
247
+ end
248
+ allow(subject).to receive(:rights) { ["http://example.com"] }
249
+ end
250
+ its(:rights_statement) { is_expected.to eq rights_statement }
251
+ end
252
+
198
253
  end
@@ -6,5 +6,6 @@ RSpec.describe Target, type: :model, targets: true do
6
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
8
  it_behaves_like "an unpublishable object"
9
+ it_behaves_like "an object that cannot be streamable"
9
10
 
10
11
  end
@@ -119,6 +119,17 @@ RSpec.configure do |config|
119
119
  end
120
120
  end
121
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
+ end
132
+
122
133
  config.after(:each) do
123
134
  ActiveFedora::Base.destroy_all
124
135
  end
@@ -154,4 +154,16 @@ RSpec.shared_examples "a DDR model" do
154
154
  expect(subject).to have_thumbnail
155
155
  }
156
156
  end
157
+
158
+ describe "#rights_statement" do
159
+ let(:rights_statement) { Ddr::Models::RightsStatement.new(url: "http://example.com") }
160
+ before do
161
+ allow(Ddr::Models::RightsStatement).to receive(:get).with(:find, url: "http://example.com") do
162
+ { url: "http://example.com" }
163
+ end
164
+ subject.rights = ["http://example.com"]
165
+ end
166
+ its(:rights_statement) { is_expected.to eq rights_statement }
167
+ end
168
+
157
169
  end
@@ -2,6 +2,7 @@ RSpec.shared_examples "a governable object" do
2
2
  let(:object) do
3
3
  described_class.new.tap do |obj|
4
4
  obj.title = [ 'Describable' ]
5
+ obj.admin_set = "foo" if obj.is_a?(Collection)
5
6
  obj.identifier = [ 'id001' ]
6
7
  obj.save(validate: false)
7
8
  end
@@ -11,7 +12,7 @@ RSpec.shared_examples "a governable object" do
11
12
  it "should set its admin policy with #admin_policy= and get with #admin_policy" do
12
13
  object.admin_policy = coll
13
14
  object.save(validate: false)
14
- expect(ActiveFedora::Base.find(object.pid, cast: true).admin_policy).to eq(coll)
15
+ expect(ActiveFedora::Base.find(object.pid).admin_policy).to eq(coll)
15
16
  end
16
17
  end
17
18
  end
@@ -0,0 +1,22 @@
1
+ RSpec.shared_examples "an object that cannot be streamable" do
2
+ it { is_expected.to_not be_streamable }
3
+ its(:can_be_streamable?) { is_expected.to be false }
4
+ end
5
+
6
+ RSpec.shared_examples "an object that can be streamable" do
7
+ it { is_expected.to_not be_streamable }
8
+ its(:can_be_streamable?) { is_expected.to be true }
9
+
10
+ describe "when streamable media is present" do
11
+ before {
12
+ subject.add_file(fixture_file_upload('bird.jpg', 'image/jpeg'), 'streamableMedia')
13
+ subject.save!
14
+ }
15
+ specify {
16
+ expect(subject).to be_streamable
17
+ expect(subject.streamable_media_type).to eq 'image/jpeg'
18
+ expect(subject.streamable_media_path).to be_present
19
+ expect(subject.streamable_media_path).to eq subject.streamableMedia.file_path
20
+ }
21
+ end
22
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ddr-models
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.6
4
+ version: 2.8.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jim Coble
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-05-08 00:00:00.000000000 Z
12
+ date: 2017-05-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -504,6 +504,7 @@ files:
504
504
  - lib/ddr/datastreams/metadata_datastream.rb
505
505
  - lib/ddr/datastreams/multires_image_datastream.rb
506
506
  - lib/ddr/datastreams/plain_text_datastream.rb
507
+ - lib/ddr/datastreams/streamable_media_datastream.rb
507
508
  - lib/ddr/datastreams/structural_metadata_datastream.rb
508
509
  - lib/ddr/derivatives.rb
509
510
  - lib/ddr/derivatives/generator.rb
@@ -569,13 +570,12 @@ files:
569
570
  - lib/ddr/models/has_struct_metadata.rb
570
571
  - lib/ddr/models/has_thumbnail.rb
571
572
  - lib/ddr/models/indexing.rb
572
- - lib/ddr/models/licenses/admin_policy_license.rb
573
- - lib/ddr/models/licenses/effective_license.rb
574
- - lib/ddr/models/licenses/inherited_license.rb
575
- - lib/ddr/models/licenses/license.rb
576
- - lib/ddr/models/licenses/parent_license.rb
573
+ - lib/ddr/models/language.rb
574
+ - lib/ddr/models/media_type.rb
577
575
  - lib/ddr/models/permanent_id.rb
576
+ - lib/ddr/models/rights_statement.rb
578
577
  - lib/ddr/models/solr_document.rb
578
+ - lib/ddr/models/streamable.rb
579
579
  - lib/ddr/models/structure.rb
580
580
  - lib/ddr/models/structures/agent.rb
581
581
  - lib/ddr/models/structures/div.rb
@@ -715,7 +715,6 @@ files:
715
715
  - spec/models/component_spec.rb
716
716
  - spec/models/contact_spec.rb
717
717
  - spec/models/descriptive_metadata_datastream_spec.rb
718
- - spec/models/effective_license_spec.rb
719
718
  - spec/models/events_spec.rb
720
719
  - spec/models/file_characterization_spec.rb
721
720
  - spec/models/file_management_spec.rb
@@ -725,8 +724,10 @@ files:
725
724
  - spec/models/has_struct_metadata_spec.rb
726
725
  - spec/models/indexing_spec.rb
727
726
  - spec/models/item_spec.rb
728
- - spec/models/license_spec.rb
727
+ - spec/models/language_spec.rb
728
+ - spec/models/media_type_spec.rb
729
729
  - spec/models/permanent_id_spec.rb
730
+ - spec/models/rights_statement_spec.rb
730
731
  - spec/models/solr_document_spec.rb
731
732
  - spec/models/structure_spec.rb
732
733
  - spec/models/structures/agent_spec.rb
@@ -757,6 +758,7 @@ files:
757
758
  - spec/support/shared_examples_for_non_collection_models.rb
758
759
  - spec/support/shared_examples_for_publication.rb
759
760
  - spec/support/shared_examples_for_role_sets.rb
761
+ - spec/support/shared_examples_for_streamable_media.rb
760
762
  - spec/support/structural_metadata_helper.rb
761
763
  - spec/utils_spec.rb
762
764
  homepage: https://github.com/duke-libraries/ddr-models
@@ -775,9 +777,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
775
777
  version: '0'
776
778
  required_rubygems_version: !ruby/object:Gem::Requirement
777
779
  requirements:
778
- - - ">="
780
+ - - ">"
779
781
  - !ruby/object:Gem::Version
780
- version: '0'
782
+ version: 1.3.1
781
783
  requirements: []
782
784
  rubyforge_project:
783
785
  rubygems_version: 2.6.8
@@ -899,7 +901,6 @@ test_files:
899
901
  - spec/models/component_spec.rb
900
902
  - spec/models/contact_spec.rb
901
903
  - spec/models/descriptive_metadata_datastream_spec.rb
902
- - spec/models/effective_license_spec.rb
903
904
  - spec/models/events_spec.rb
904
905
  - spec/models/file_characterization_spec.rb
905
906
  - spec/models/file_management_spec.rb
@@ -909,8 +910,10 @@ test_files:
909
910
  - spec/models/has_struct_metadata_spec.rb
910
911
  - spec/models/indexing_spec.rb
911
912
  - spec/models/item_spec.rb
912
- - spec/models/license_spec.rb
913
+ - spec/models/language_spec.rb
914
+ - spec/models/media_type_spec.rb
913
915
  - spec/models/permanent_id_spec.rb
916
+ - spec/models/rights_statement_spec.rb
914
917
  - spec/models/solr_document_spec.rb
915
918
  - spec/models/structure_spec.rb
916
919
  - spec/models/structures/agent_spec.rb
@@ -941,5 +944,6 @@ test_files:
941
944
  - spec/support/shared_examples_for_non_collection_models.rb
942
945
  - spec/support/shared_examples_for_publication.rb
943
946
  - spec/support/shared_examples_for_role_sets.rb
947
+ - spec/support/shared_examples_for_streamable_media.rb
944
948
  - spec/support/structural_metadata_helper.rb
945
949
  - spec/utils_spec.rb
@@ -1,11 +0,0 @@
1
- module Ddr::Models
2
- class AdminPolicyLicense
3
-
4
- def self.call(obj)
5
- if obj.admin_policy_id && (obj.admin_policy_id != obj.id)
6
- License.call obj.admin_policy
7
- end
8
- end
9
-
10
- end
11
- end
@@ -1,9 +0,0 @@
1
- module Ddr::Models
2
- class EffectiveLicense
3
-
4
- def self.call(obj)
5
- License.call(obj) || InheritedLicense.call(obj)
6
- end
7
-
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- module Ddr::Models
2
- class InheritedLicense
3
-
4
- def self.call(obj)
5
- ParentLicense.call(obj) || AdminPolicyLicense.call(obj)
6
- end
7
-
8
- end
9
- end