active-fedora 9.0.2 → 9.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +5 -5
  2. data/History.txt +85 -0
  3. data/README.md +2 -4
  4. data/active-fedora.gemspec +1 -0
  5. data/lib/active_fedora.rb +5 -0
  6. data/lib/active_fedora/associations/builder/has_many.rb +1 -1
  7. data/lib/active_fedora/associations/collection_association.rb +1 -18
  8. data/lib/active_fedora/associations/contains_association.rb +3 -1
  9. data/lib/active_fedora/associations/has_and_belongs_to_many_association.rb +12 -10
  10. data/lib/active_fedora/attached_files.rb +6 -3
  11. data/lib/active_fedora/change_set.rb +2 -2
  12. data/lib/active_fedora/core.rb +26 -38
  13. data/lib/active_fedora/core/fedora_id_translator.rb +12 -0
  14. data/lib/active_fedora/core/fedora_uri_translator.rb +9 -0
  15. data/lib/active_fedora/errors.rb +4 -0
  16. data/lib/active_fedora/fedora_attributes.rb +25 -1
  17. data/lib/active_fedora/file.rb +2 -15
  18. data/lib/active_fedora/inheritable_accessors.rb +26 -0
  19. data/lib/active_fedora/nom_datastream.rb +6 -4
  20. data/lib/active_fedora/rdf/ntriples_rdf_datastream.rb +0 -4
  21. data/lib/active_fedora/reflection.rb +3 -1
  22. data/lib/active_fedora/relation/finder_methods.rb +36 -5
  23. data/lib/active_fedora/version.rb +1 -1
  24. data/lib/active_fedora/versions_graph.rb +7 -8
  25. data/spec/integration/associations_spec.rb +64 -21
  26. data/spec/integration/belongs_to_association_spec.rb +118 -47
  27. data/spec/integration/collection_association_spec.rb +46 -0
  28. data/spec/integration/has_and_belongs_to_many_associations_spec.rb +178 -139
  29. data/spec/integration/query_result_builder_spec.rb +2 -2
  30. data/spec/integration/versionable_spec.rb +38 -1
  31. data/spec/samples/samples.rb +0 -1
  32. data/spec/spec_helper.rb +1 -0
  33. data/spec/unit/base_spec.rb +98 -0
  34. data/spec/unit/change_set_spec.rb +4 -2
  35. data/spec/unit/core/fedora_id_translator_spec.rb +20 -0
  36. data/spec/unit/core/fedora_uri_translator_spec.rb +19 -0
  37. data/spec/unit/core_spec.rb +50 -0
  38. data/spec/unit/has_many_association_spec.rb +27 -2
  39. data/spec/unit/qualified_dublin_core_datastream_spec.rb +0 -6
  40. data/spec/unit/reflection_spec.rb +44 -0
  41. data/spec/unit/simple_datastream_spec.rb +32 -0
  42. metadata +23 -13
  43. data/spec/samples/marpa-dc_datastream.rb +0 -102
  44. data/spec/samples/models/audio_record.rb +0 -29
  45. data/spec/samples/models/image.rb +0 -5
  46. data/spec/samples/models/oral_history.rb +0 -36
  47. data/spec/samples/models/seminar.rb +0 -29
  48. data/spec/samples/models/seminar_audio_file.rb +0 -32
  49. data/spec/samples/oral_history_sample_model.rb +0 -30
  50. data/spec/samples/special_thing.rb +0 -44
@@ -1,3 +1,2 @@
1
1
  # require all of the files in the samples directory
2
2
  require 'samples/models/mods_article'
3
- require 'samples/special_thing'
@@ -14,6 +14,7 @@ end
14
14
 
15
15
  require 'active-fedora'
16
16
  require 'rspec'
17
+ require 'rspec/its'
17
18
  require 'equivalent-xml/rspec_matchers'
18
19
  require 'logger'
19
20
  require 'byebug' unless ENV['TRAVIS']
@@ -4,7 +4,105 @@ require 'spec_helper'
4
4
  describe ActiveFedora::Base do
5
5
  it_behaves_like "An ActiveModel"
6
6
 
7
+ describe "id=" do
8
+ before do
9
+ class FooHistory < ActiveFedora::Base
10
+ property :title, predicate: ::RDF::DC.title
11
+ end
12
+ end
13
+ after do
14
+ Object.send(:remove_const, :FooHistory)
15
+ end
16
+
17
+ subject { FooHistory.new(title: ["A good title"]) }
18
+ before { subject.id = 9 }
19
+
20
+ it "is settable" do
21
+ expect(subject.id).to eq '9'
22
+ expect(subject.title).to eq ["A good title"]
23
+ end
24
+
25
+ it "is only settable once" do
26
+ expect { subject.id = 10 }.to raise_error "ID has already been set to 9"
27
+ expect(subject.id).to eq '9'
28
+ end
29
+ end
30
+
31
+ describe ".type" do
32
+ before do
33
+ class FooHistory < ActiveFedora::Base
34
+ type ::RDF::URI.new('http://example.com/foo')
35
+ property :title, predicate: ::RDF::DC.title
36
+ end
37
+ end
38
+ after do
39
+ Object.send(:remove_const, :FooHistory)
40
+ end
41
+
42
+ subject { FooHistory.new.type }
43
+
44
+ it { is_expected.to eq [RDF::URI('http://example.com/foo')] }
45
+
46
+ context "when type is called before propertes" do
47
+ subject { FooHistory.resource_class.reflect_on_property(:title) }
48
+ it "should not wipe out the properties" do
49
+ expect(subject).to be_kind_of ActiveTriples::NodeConfig
50
+ end
51
+ end
52
+ end
53
+
54
+ describe ".rdf_label" do
55
+ context "on a concrete class" do
56
+ before do
57
+ class FooHistory < ActiveFedora::Base
58
+ rdf_label ::RDF::DC.title
59
+ property :title, predicate: ::RDF::DC.title
60
+ end
61
+ end
62
+ after do
63
+ Object.send(:remove_const, :FooHistory)
64
+ end
65
+
66
+ let(:instance) { FooHistory.new(title: ['A label']) }
67
+ subject { instance.rdf_label }
68
+
69
+ it { is_expected.to eq ['A label'] }
70
+ end
71
+
72
+ context "on an inherited class" do
73
+ before do
74
+ class Agent < ActiveFedora::Base
75
+ rdf_label ::RDF::FOAF.name
76
+ property :foaf_name, predicate: ::RDF::FOAF.name
77
+ end
78
+ class Person < Agent
79
+ rdf_label ::RDF::URI('http://example.com/foo')
80
+ property :job, predicate: ::RDF::URI('http://example.com/foo')
81
+ end
82
+ class Creator < Person
83
+ end
84
+ end
85
+ after do
86
+ Object.send(:remove_const, :Person)
87
+ Object.send(:remove_const, :Agent)
88
+ Object.send(:remove_const, :Creator)
89
+ end
90
+
91
+ let(:instance) { Creator.new(foaf_name: ['Carolyn'], job: ['Developer']) }
92
+ subject { instance.rdf_label }
93
+
94
+ it { is_expected.to eq ['Developer'] }
95
+ end
96
+ end
97
+
7
98
  describe 'descendants' do
99
+ before do
100
+ class SpecialThing < ActiveFedora::Base
101
+ end
102
+ end
103
+ after do
104
+ Object.send(:remove_const, :SpecialThing)
105
+ end
8
106
  it "should record the decendants" do
9
107
  expect(ActiveFedora::Base.descendants).to include(ModsArticle, SpecialThing)
10
108
  end
@@ -18,10 +18,12 @@ describe ActiveFedora::ChangeSet do
18
18
  class Book < ActiveFedora::Base
19
19
  belongs_to :library, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.hasConstituent
20
20
  property :title, predicate: ::RDF::DC.title
21
+ property :alt_id, predicate: ::RDF::DC.identifier
21
22
  end
22
23
 
23
24
  base.library_id = 'foo'
24
25
  base.title = ['bar']
26
+ base.alt_id = ['12345']
25
27
  end
26
28
  after do
27
29
  Object.send(:remove_const, :Library)
@@ -36,8 +38,8 @@ describe ActiveFedora::ChangeSet do
36
38
 
37
39
  it { is_expected.to be_kind_of Hash }
38
40
 
39
- it "should have two elements" do
40
- expect(subject.size).to eq 2
41
+ it "should have three elements" do
42
+ expect(subject.size).to eq 3
41
43
  end
42
44
  end
43
45
 
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe ActiveFedora::Core::FedoraIdTranslator do
4
+ describe ".call" do
5
+ let(:result) { described_class.call(id) }
6
+ context "when given an id" do
7
+ let(:good_uri) { ActiveFedora.fedora.host+ActiveFedora.fedora.base_path+"/banana" }
8
+ let(:id) { "banana" }
9
+ it "should return a fedora URI" do
10
+ expect(result).to eq good_uri
11
+ end
12
+ context "when given an id with a leading slash" do
13
+ let(:id) { "/banana" }
14
+ it "should return a good fedora URI" do
15
+ expect(result).to eq good_uri
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe ActiveFedora::Core::FedoraUriTranslator do
4
+ describe ".call" do
5
+ let(:result) { described_class.call(uri) }
6
+ context "when given a Fedora URI" do
7
+ let(:uri) { ActiveFedora.fedora.host + ActiveFedora.fedora.base_path+"/6" }
8
+ it "should return the id" do
9
+ expect(result).to eq '6'
10
+ end
11
+ end
12
+ context "when given a URI missing a slash" do
13
+ let(:uri) { ActiveFedora.fedora.host + ActiveFedora.fedora.base_path+"602-a" }
14
+ it "should return the id" do
15
+ expect(result).to eq "602-a"
16
+ end
17
+ end
18
+ end
19
+ end
@@ -88,12 +88,54 @@ describe ActiveFedora::Base do
88
88
  end
89
89
  end
90
90
 
91
+ describe "#translate_id_to_uri" do
92
+ subject { ActiveFedora::Base.translate_id_to_uri }
93
+ context "when it's not set" do
94
+ it "should be a FedoraIdTranslator" do
95
+ expect(subject).to eq ActiveFedora::Core::FedoraIdTranslator
96
+ end
97
+ end
98
+ context "when it's set to nil" do
99
+ before do
100
+ ActiveFedora::Base.translate_id_to_uri = nil
101
+ end
102
+ it "should be a FedoraIdTranslator" do
103
+ expect(subject).to eq ActiveFedora::Core::FedoraIdTranslator
104
+ end
105
+ end
106
+ end
107
+
108
+ describe "#translate_uri_to_id" do
109
+ subject { ActiveFedora::Base.translate_uri_to_id }
110
+ context "when it's not set" do
111
+ it "should be a FedoraUriTranslator" do
112
+ expect(subject).to eq ActiveFedora::Core::FedoraUriTranslator
113
+ end
114
+ end
115
+ context "when it's set to nil" do
116
+ before do
117
+ ActiveFedora::Base.translate_uri_to_id = nil
118
+ end
119
+ it "should be a FedoraIdTranslator" do
120
+ expect(subject).to eq ActiveFedora::Core::FedoraUriTranslator
121
+ end
122
+ end
123
+ end
124
+
91
125
  describe "id_to_uri" do
92
126
  let(:id) { '123456w' }
93
127
  subject { ActiveFedora::Base.id_to_uri(id) }
94
128
 
95
129
  context "with no custom proc is set" do
96
130
  it { should eq "#{ActiveFedora.fedora.host}#{ActiveFedora.fedora.base_path}/123456w" }
131
+ it "should just call #translate_id_to_uri" do
132
+ allow(ActiveFedora::Base).to receive(:translate_id_to_uri).and_call_original
133
+ allow(ActiveFedora::Core::FedoraIdTranslator).to receive(:call).and_call_original
134
+
135
+ subject
136
+
137
+ expect(ActiveFedora::Core::FedoraIdTranslator).to have_received(:call).with(id)
138
+ end
97
139
  end
98
140
 
99
141
  context "when custom proc is set" do
@@ -126,6 +168,14 @@ describe ActiveFedora::Base do
126
168
 
127
169
  context "with no custom proc is set" do
128
170
  it { should eq 'foo/123456w' }
171
+ it "should just call #translate_uri_to_id" do
172
+ allow(ActiveFedora::Base).to receive(:translate_uri_to_id).and_call_original
173
+ allow(ActiveFedora::Core::FedoraUriTranslator).to receive(:call).and_call_original
174
+
175
+ subject
176
+
177
+ expect(ActiveFedora::Core::FedoraUriTranslator).to have_received(:call).with(uri)
178
+ end
129
179
  end
130
180
 
131
181
  context "when custom proc is set" do
@@ -23,7 +23,7 @@ describe ActiveFedora::Associations::HasManyAssociation do
23
23
  end
24
24
 
25
25
  let(:reflection) { Book.create_reflection(:has_many, 'pages', { predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf }, Book) }
26
- let(:association) { ActiveFedora::Associations::HasManyAssociation.new(book, reflection) }
26
+ let(:association) { described_class.new(book, reflection) }
27
27
 
28
28
  it "should set the book_id attribute" do
29
29
  expect(association).to receive(:callback).twice
@@ -40,7 +40,7 @@ describe ActiveFedora::Associations::HasManyAssociation do
40
40
  Page.has_and_belongs_to_many :contents, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf, class_name: 'ActiveFedora::Base'
41
41
  end
42
42
  let(:book_reflection) { Book.create_reflection(:has_many, 'pages', { predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf }, Book) }
43
- let(:association) { ActiveFedora::Associations::HasManyAssociation.new(book, book_reflection) }
43
+ let(:association) { described_class.new(book, book_reflection) }
44
44
 
45
45
  subject { association.send(:find_polymorphic_inverse, page) }
46
46
 
@@ -48,4 +48,29 @@ describe ActiveFedora::Associations::HasManyAssociation do
48
48
  expect(subject.name).to eq :contents
49
49
  end
50
50
  end
51
+
52
+
53
+ context "when inverse doesn't have a predictable name" do
54
+ before do
55
+ class TimeSpan < ActiveFedora::Base
56
+ has_many :images, inverse_of: :created # predicate: ::RDF::DC.created
57
+ end
58
+
59
+ class Image < ActiveFedora::Base
60
+ has_and_belongs_to_many :created, predicate: ::RDF::DC.created, class_name: 'TimeSpan'
61
+ end
62
+ end
63
+
64
+ after do
65
+ Object.send(:remove_const, :TimeSpan)
66
+ Object.send(:remove_const, :Image)
67
+ end
68
+
69
+ let(:owner) { TimeSpan.new }
70
+ let(:reflection) { TimeSpan.reflect_on_association(:images) }
71
+
72
+ it "finds the predicate" do
73
+ expect { described_class.new(owner, reflection) }.not_to raise_error
74
+ end
75
+ end
51
76
  end
@@ -3,12 +3,6 @@ require 'spec_helper'
3
3
  describe ActiveFedora::QualifiedDublinCoreDatastream do
4
4
  DC_ELEMENTS = [:contributor, :coverage, :creator, :date, :description, :identifier, :language, :publisher, :relation, :rights, :source]
5
5
 
6
- before(:all) do
7
- # Load Sample OralHistory Model
8
- require File.join( File.dirname(__FILE__), "..", "samples","oral_history_sample_model" )
9
- @dc_terms = []
10
- end
11
-
12
6
  let(:sample_xml) do "<dc xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:dcterms='http://purl.org/dc/terms/'>
13
7
  <dcterms:type xsi:type='DCMITYPE'>sound</dcterms:type>
14
8
  <dcterms:medium>medium</dcterms:medium>
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveFedora::Reflection::AssociationReflection do
4
+ describe "#derive_foreign_key" do
5
+ let(:name) { 'dummy' }
6
+ let(:options) { { inverse_of: :default_permissions } }
7
+ let(:active_fedora) { double }
8
+ let(:instance) { described_class.new(macro, name, options, active_fedora) }
9
+ subject { instance.send :derive_foreign_key }
10
+
11
+ context "when a has_many" do
12
+ let(:macro) { :has_many }
13
+
14
+ context "and the inverse is a collection association" do
15
+ let(:inverse) { double(collection?: true) }
16
+ before { allow(instance).to receive(:inverse_of).and_return(inverse) }
17
+ it { is_expected.to eq 'default_permission_ids' }
18
+ end
19
+ end
20
+ end
21
+
22
+ describe "#automatic_inverse_of" do
23
+ before do
24
+ class Dummy < ActiveFedora::Base
25
+ belongs_to :foothing, predicate: ::RDF::DC.extent
26
+ end
27
+ end
28
+
29
+ after { Object.send(:remove_const, :Dummy) }
30
+ let(:name) { 'dummy' }
31
+ let(:options) { { as: 'foothing' } }
32
+ let(:active_fedora) { double }
33
+ let(:instance) { described_class.new(macro, name, options, active_fedora) }
34
+ subject { instance.send :automatic_inverse_of }
35
+
36
+ context "when a has_many" do
37
+ let(:macro) { :has_many }
38
+
39
+ context "and the inverse is a collection association" do
40
+ it { is_expected.to eq :foothing }
41
+ end
42
+ end
43
+ end
44
+ end
@@ -62,5 +62,37 @@ describe ActiveFedora::SimpleDatastream do
62
62
  expect(solr[ActiveFedora::SolrQueryBuilder.solr_name('creation_date', type: :date)]).to eq "2012-01-15"
63
63
  end
64
64
  end
65
+
66
+ describe "datastream configuration" do
67
+ let(:foo) do
68
+ ActiveFedora::Base.create! do |obj|
69
+ obj.add_file(%{<?xml version="1.0"?>\n<fields><fubar>test</fubar></fields>}, path:'someData')
70
+ end
71
+ end
72
+ let(:resource) { Ldp::Resource::RdfSource.new(ActiveFedora.fedora.connection, foo.uri) }
73
+ let(:orm) { Ldp::Orm.new(resource) }
74
+
75
+ before do
76
+ class FooHistory < ActiveFedora::Base
77
+ has_metadata :type=>ActiveFedora::SimpleDatastream, :name=>"someData" do |m|
78
+ m.field "fubar", :string
79
+ end
80
+ has_attributes :fubar, datastream: 'someData', multiple: false
81
+ end
82
+
83
+ orm.graph.delete([orm.resource.subject_uri, ActiveFedora::RDF::Fcrepo::Model.hasModel, nil])
84
+ orm.graph.insert([orm.resource.subject_uri, ActiveFedora::RDF::Fcrepo::Model.hasModel, 'FooHistory'])
85
+ orm.save
86
+ foo.reload
87
+ foo.update_index
88
+ end
89
+
90
+ after do
91
+ Object.send(:remove_const, :FooHistory)
92
+ end
93
+
94
+ subject { FooHistory.find(foo.id) }
95
+ its(:fubar) { is_expected.to eq 'test' }
96
+ end
65
97
 
66
98
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active-fedora
3
3
  version: !ruby/object:Gem::Version
4
- version: 9.0.2
4
+ version: 9.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Zumwalt
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-02-24 00:00:00.000000000 Z
13
+ date: 2020-06-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rsolr
@@ -222,6 +222,20 @@ dependencies:
222
222
  - - "~>"
223
223
  - !ruby/object:Gem::Version
224
224
  version: '3.0'
225
+ - !ruby/object:Gem::Dependency
226
+ name: rspec-its
227
+ requirement: !ruby/object:Gem::Requirement
228
+ requirements:
229
+ - - ">="
230
+ - !ruby/object:Gem::Version
231
+ version: '0'
232
+ type: :development
233
+ prerelease: false
234
+ version_requirements: !ruby/object:Gem::Requirement
235
+ requirements:
236
+ - - ">="
237
+ - !ruby/object:Gem::Version
238
+ version: '0'
225
239
  - !ruby/object:Gem::Dependency
226
240
  name: equivalent-xml
227
241
  requirement: !ruby/object:Gem::Requirement
@@ -324,6 +338,8 @@ files:
324
338
  - lib/active_fedora/cleaner.rb
325
339
  - lib/active_fedora/config.rb
326
340
  - lib/active_fedora/core.rb
341
+ - lib/active_fedora/core/fedora_id_translator.rb
342
+ - lib/active_fedora/core/fedora_uri_translator.rb
327
343
  - lib/active_fedora/datastream.rb
328
344
  - lib/active_fedora/datastreams.rb
329
345
  - lib/active_fedora/datastreams/nokogiri_datastreams.rb
@@ -338,6 +354,7 @@ files:
338
354
  - lib/active_fedora/fixity_service.rb
339
355
  - lib/active_fedora/indexing.rb
340
356
  - lib/active_fedora/indexing_service.rb
357
+ - lib/active_fedora/inheritable_accessors.rb
341
358
  - lib/active_fedora/ldp_cache.rb
342
359
  - lib/active_fedora/ldp_resource.rb
343
360
  - lib/active_fedora/ldp_resource_service.rb
@@ -470,18 +487,10 @@ files:
470
487
  - spec/rcov.opts
471
488
  - spec/samples/hydra-mods_article_datastream.rb
472
489
  - spec/samples/hydra-rights_metadata_datastream.rb
473
- - spec/samples/marpa-dc_datastream.rb
474
- - spec/samples/models/audio_record.rb
475
- - spec/samples/models/image.rb
476
490
  - spec/samples/models/mods_article.rb
477
- - spec/samples/models/oral_history.rb
478
- - spec/samples/models/seminar.rb
479
- - spec/samples/models/seminar_audio_file.rb
480
491
  - spec/samples/oral_history_sample.xml
481
- - spec/samples/oral_history_sample_model.rb
482
492
  - spec/samples/oral_history_xml.xml
483
493
  - spec/samples/samples.rb
484
- - spec/samples/special_thing.rb
485
494
  - spec/spec.opts
486
495
  - spec/spec_helper.rb
487
496
  - spec/support/an_active_model.rb
@@ -499,6 +508,8 @@ files:
499
508
  - spec/unit/change_set_spec.rb
500
509
  - spec/unit/code_configurator_spec.rb
501
510
  - spec/unit/config_spec.rb
511
+ - spec/unit/core/fedora_id_translator_spec.rb
512
+ - spec/unit/core/fedora_uri_translator_spec.rb
502
513
  - spec/unit/core_spec.rb
503
514
  - spec/unit/file_configurator_spec.rb
504
515
  - spec/unit/file_path_builder_spec.rb
@@ -530,6 +541,7 @@ files:
530
541
  - spec/unit/rdf_vocab_spec.rb
531
542
  - spec/unit/rdfxml_datastream_spec.rb
532
543
  - spec/unit/readonly_spec.rb
544
+ - spec/unit/reflection_spec.rb
533
545
  - spec/unit/rspec_matchers/belong_to_associated_active_fedora_object_matcher_spec.rb
534
546
  - spec/unit/rspec_matchers/have_many_associated_active_fedora_objects_matcher_spec.rb
535
547
  - spec/unit/rspec_matchers/have_predicate_matcher_spec.rb
@@ -559,10 +571,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
559
571
  - !ruby/object:Gem::Version
560
572
  version: '0'
561
573
  requirements: []
562
- rubyforge_project:
563
- rubygems_version: 2.4.5
574
+ rubygems_version: 3.1.2
564
575
  signing_key:
565
576
  specification_version: 4
566
577
  summary: A convenience libary for manipulating documents in the Fedora Repository.
567
578
  test_files: []
568
- has_rdoc: