active-fedora 9.0.0 → 9.1.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 +4 -4
- data/History.txt +97 -0
- data/README.md +40 -28
- data/active-fedora.gemspec +2 -1
- data/lib/active_fedora/associations/builder/contains.rb +5 -1
- data/lib/active_fedora/associations/builder/has_many.rb +1 -1
- data/lib/active_fedora/associations/collection_association.rb +1 -18
- data/lib/active_fedora/associations/contains_association.rb +3 -1
- data/lib/active_fedora/associations/has_and_belongs_to_many_association.rb +12 -10
- data/lib/active_fedora/associations.rb +1 -1
- data/lib/active_fedora/attached_files.rb +7 -4
- data/lib/active_fedora/attributes/property_builder.rb +1 -0
- data/lib/active_fedora/attributes.rb +36 -9
- data/lib/active_fedora/change_set.rb +2 -2
- data/lib/active_fedora/clean_connection.rb +40 -0
- data/lib/active_fedora/core/fedora_id_translator.rb +12 -0
- data/lib/active_fedora/core/fedora_uri_translator.rb +9 -0
- data/lib/active_fedora/core.rb +26 -38
- data/lib/active_fedora/errors.rb +4 -0
- data/lib/active_fedora/fedora.rb +22 -4
- data/lib/active_fedora/fedora_attributes.rb +25 -1
- data/lib/active_fedora/file.rb +30 -24
- data/lib/active_fedora/indexing/map.rb +46 -0
- data/lib/active_fedora/indexing.rb +14 -0
- data/lib/active_fedora/inheritable_accessors.rb +26 -0
- data/lib/active_fedora/loadable_from_json.rb +5 -1
- data/lib/active_fedora/nom_datastream.rb +6 -4
- data/lib/active_fedora/persistence.rb +11 -7
- data/lib/active_fedora/rdf/datastream_indexing.rb +4 -0
- data/lib/active_fedora/rdf/fcrepo4.rb +1 -0
- data/lib/active_fedora/rdf/indexing_service.rb +18 -11
- data/lib/active_fedora/rdf/ldp.rb +3 -0
- data/lib/active_fedora/rdf/ntriples_rdf_datastream.rb +0 -4
- data/lib/active_fedora/rdf/rdf_datastream.rb +12 -1
- data/lib/active_fedora/reflection.rb +3 -1
- data/lib/active_fedora/relation/finder_methods.rb +36 -5
- data/lib/active_fedora/solr_query_builder.rb +1 -1
- data/lib/active_fedora/solr_service.rb +1 -1
- data/lib/active_fedora/version.rb +1 -1
- data/lib/active_fedora/versions_graph.rb +7 -8
- data/lib/active_fedora.rb +6 -0
- data/spec/integration/associations_spec.rb +64 -21
- data/spec/integration/attached_files_spec.rb +24 -0
- data/spec/integration/attributes_spec.rb +49 -3
- data/spec/integration/belongs_to_association_spec.rb +118 -47
- data/spec/integration/clean_connection_spec.rb +21 -0
- data/spec/integration/collection_association_spec.rb +46 -0
- data/spec/integration/field_to_solr_name_spec.rb +11 -7
- data/spec/integration/has_and_belongs_to_many_associations_spec.rb +180 -137
- data/spec/integration/has_many_associations_spec.rb +6 -2
- data/spec/integration/json_serialization_spec.rb +11 -5
- data/spec/integration/nested_attribute_spec.rb +3 -1
- data/spec/integration/ntriples_datastream_spec.rb +23 -17
- data/spec/integration/persistence_spec.rb +3 -1
- data/spec/integration/query_result_builder_spec.rb +2 -2
- data/spec/integration/relation_delegation_spec.rb +3 -1
- data/spec/integration/scoped_query_spec.rb +3 -1
- data/spec/integration/solr_instance_loader_spec.rb +4 -2
- data/spec/integration/versionable_spec.rb +38 -1
- data/spec/samples/samples.rb +0 -1
- data/spec/spec_helper.rb +1 -0
- data/spec/unit/active_fedora_spec.rb +4 -2
- data/spec/unit/attributes_spec.rb +52 -12
- data/spec/unit/base_active_model_spec.rb +5 -3
- data/spec/unit/base_spec.rb +102 -2
- data/spec/unit/callback_spec.rb +4 -2
- data/spec/unit/change_set_spec.rb +4 -2
- data/spec/unit/core/fedora_id_translator_spec.rb +20 -0
- data/spec/unit/core/fedora_uri_translator_spec.rb +19 -0
- data/spec/unit/core_spec.rb +54 -2
- data/spec/unit/has_many_association_spec.rb +27 -2
- data/spec/unit/ntriples_datastream_spec.rb +24 -20
- data/spec/unit/qualified_dublin_core_datastream_spec.rb +0 -6
- data/spec/unit/query_result_builder_spec.rb +1 -1
- data/spec/unit/rdf/indexing_service_spec.rb +19 -17
- data/spec/unit/rdf_resource_datastream_spec.rb +14 -10
- data/spec/unit/reflection_spec.rb +44 -0
- data/spec/unit/simple_datastream_spec.rb +34 -0
- data/spec/unit/solr_query_builder_spec.rb +1 -1
- data/spec/unit/validations_spec.rb +4 -2
- metadata +28 -13
- data/spec/samples/marpa-dc_datastream.rb +0 -102
- data/spec/samples/models/audio_record.rb +0 -29
- data/spec/samples/models/image.rb +0 -5
- data/spec/samples/models/oral_history.rb +0 -36
- data/spec/samples/models/seminar.rb +0 -29
- data/spec/samples/models/seminar_audio_file.rb +0 -32
- data/spec/samples/oral_history_sample_model.rb +0 -30
- data/spec/samples/special_thing.rb +0 -44
|
@@ -18,6 +18,43 @@ describe "a versionable class" do
|
|
|
18
18
|
|
|
19
19
|
it { is_expected.to be_versionable }
|
|
20
20
|
|
|
21
|
+
describe 'sorting versions' do
|
|
22
|
+
before do
|
|
23
|
+
allow(subject).to receive(:fedora_versions) { versions }
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
let(:version1) { double('version1', uri: 'http://localhost:8983/fedora/rest/test/84/61/63/98/84616398-f63a-4572-ba01-0689339e4fcb/fcr:versions/87a0a8c317f1e711aa993d-e1d2-4a65-93ee-3a12fc9541ab', label: 'version1', created: '2015-04-02T19:54:45.962Z') }
|
|
27
|
+
let(:version2) { double('version2', uri: 'http://localhost:8983/fedora/rest/test/84/61/63/98/84616398-f63a-4572-ba01-0689339e4fcb/fcr:versions/87a0a8c317f1e790373a67-c9ee-447d-b740-4faa882b1a1f', label: 'version2', created: '2015-04-02T19:54:45.96Z') }
|
|
28
|
+
let(:versions) { [version1, version2] }
|
|
29
|
+
|
|
30
|
+
subject { ActiveFedora::VersionsGraph.new }
|
|
31
|
+
|
|
32
|
+
it 'sorts by DateTime' do
|
|
33
|
+
expect(subject.first).to eq version2
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
context 'with an unparseable created date' do
|
|
37
|
+
let(:version2) { double('version2', uri: 'http://localhost:8983/fedora/rest/test/84/61/63/98/84616398-f63a-4572-ba01-0689339e4fcb/fcr:versions/87a0a8c317f1e790373a67-c9ee-447d-b740-4faa882b1a1f', label: 'version2', created: '') }
|
|
38
|
+
|
|
39
|
+
it 'raises an exception' do
|
|
40
|
+
expect { subject.first }.to raise_error(ActiveFedora::VersionLacksCreateDate)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
context 'with a missing created date' do
|
|
45
|
+
before do
|
|
46
|
+
# Because mocks raise RSpec::Mocks::MockExpectationError instead
|
|
47
|
+
allow(version2).to receive(:created) { raise NoMethodError }
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
let(:version2) { double('version2', uri: 'http://localhost:8983/fedora/rest/test/84/61/63/98/84616398-f63a-4572-ba01-0689339e4fcb/fcr:versions/87a0a8c317f1e790373a67-c9ee-447d-b740-4faa882b1a1f', label: 'version2') }
|
|
51
|
+
|
|
52
|
+
it 'raises an exception' do
|
|
53
|
+
expect { subject.first }.to raise_error(ActiveFedora::VersionLacksCreateDate)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
21
58
|
context "after saving" do
|
|
22
59
|
before do
|
|
23
60
|
subject.title = ["Greetings Earthlings"]
|
|
@@ -175,7 +212,7 @@ describe "a versionable rdf datastream" do
|
|
|
175
212
|
end
|
|
176
213
|
|
|
177
214
|
it "should have two unique versions" do
|
|
178
|
-
expect(subject.versions.all.size).to eq 2
|
|
215
|
+
expect(subject.versions.all.size).to eq 2
|
|
179
216
|
end
|
|
180
217
|
|
|
181
218
|
it "should load the restored datastream's content" do
|
data/spec/samples/samples.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
|
@@ -19,16 +19,18 @@ describe ActiveFedora do
|
|
|
19
19
|
|
|
20
20
|
let(:good_url) { ActiveFedora.fedora_config.credentials[:url] }
|
|
21
21
|
let(:bad_url) { good_url.gsub('/rest', '/') }
|
|
22
|
+
let(:user) { ActiveFedora.fedora_config.credentials[:user] }
|
|
23
|
+
let(:password) { ActiveFedora.fedora_config.credentials[:password] }
|
|
22
24
|
|
|
23
25
|
it "should connect OK" do
|
|
24
26
|
expect(ActiveFedora::Base.logger).to_not receive(:warn)
|
|
25
|
-
ActiveFedora::Fedora.new(url: good_url, base_path: '/test')
|
|
27
|
+
ActiveFedora::Fedora.new(url: good_url, base_path: '/test', user: user, password: password)
|
|
26
28
|
end
|
|
27
29
|
|
|
28
30
|
it "should not connect and warn" do
|
|
29
31
|
expect(ActiveFedora::Base.logger).to receive(:warn)
|
|
30
32
|
expect {
|
|
31
|
-
ActiveFedora::Fedora.new(url: bad_url, base_path: '/test')
|
|
33
|
+
ActiveFedora::Fedora.new(url: bad_url, base_path: '/test', user: user, password: password)
|
|
32
34
|
}.to raise_error Ldp::HttpError
|
|
33
35
|
end
|
|
34
36
|
end
|
|
@@ -33,6 +33,34 @@ describe ActiveFedora::Base do
|
|
|
33
33
|
Object.send(:remove_const, :BarStream2)
|
|
34
34
|
end
|
|
35
35
|
|
|
36
|
+
describe "#property" do
|
|
37
|
+
context "with an xml property" do
|
|
38
|
+
before do
|
|
39
|
+
class BarHistory4 < ActiveFedora::Base
|
|
40
|
+
has_metadata type: BarStream2, name: "xmlish"
|
|
41
|
+
property :cow, delegate_to: 'xmlish'
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
after do
|
|
45
|
+
Object.send(:remove_const, :BarHistory4)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
let(:obj) { BarHistory4.new }
|
|
49
|
+
|
|
50
|
+
before { obj.cow = ['one', 'two'] }
|
|
51
|
+
describe "the object accessor" do
|
|
52
|
+
subject { obj.cow }
|
|
53
|
+
it { is_expected.to eq ['one', 'two'] }
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
describe "the datastream accessor" do
|
|
57
|
+
subject { obj.xmlish.cow }
|
|
58
|
+
it { is_expected.to eq ['one', 'two'] }
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
36
64
|
describe "first level delegation" do
|
|
37
65
|
before :all do
|
|
38
66
|
class BarHistory2 < ActiveFedora::Base
|
|
@@ -50,12 +78,14 @@ describe ActiveFedora::Base do
|
|
|
50
78
|
end
|
|
51
79
|
|
|
52
80
|
has_metadata :type=>BarStream2, :name=>"xmlish"
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
81
|
+
Deprecation.silence(ActiveFedora::Attributes) do
|
|
82
|
+
has_attributes :cow, datastream: 'xmlish' # for testing the default value of multiple
|
|
83
|
+
has_attributes :fubar, datastream: 'withText', multiple: true # test alternate datastream
|
|
84
|
+
has_attributes :pig, datastream: 'xmlish', multiple: false
|
|
85
|
+
has_attributes :horse, datastream: 'xmlish', multiple: true
|
|
86
|
+
has_attributes :duck, datastream: 'xmlish', :at=>[:waterfowl, :ducks, :duck], multiple: true
|
|
87
|
+
has_attributes :animal_id, datastream: 'someData', multiple: false
|
|
88
|
+
end
|
|
59
89
|
|
|
60
90
|
property :goose, predicate: ::RDF::URI.new('http://example.com#hasGoose')
|
|
61
91
|
|
|
@@ -253,7 +283,9 @@ describe ActiveFedora::Base do
|
|
|
253
283
|
before :all do
|
|
254
284
|
class BarHistory2 < ActiveFedora::Base
|
|
255
285
|
has_metadata 'xmlish', :type=>BarStream2
|
|
256
|
-
|
|
286
|
+
Deprecation.silence(ActiveFedora::Attributes) do
|
|
287
|
+
has_attributes :donkey, :cow, datastream: 'xmlish', multiple: true
|
|
288
|
+
end
|
|
257
289
|
end
|
|
258
290
|
class BarHistory3 < BarHistory2
|
|
259
291
|
end
|
|
@@ -287,8 +319,10 @@ describe ActiveFedora::Base do
|
|
|
287
319
|
end
|
|
288
320
|
class BarHistory4 < ActiveFedora::Base
|
|
289
321
|
has_metadata 'rdfish', :type=>BarRdfDatastream
|
|
290
|
-
|
|
291
|
-
|
|
322
|
+
Deprecation.silence(ActiveFedora::Attributes) do
|
|
323
|
+
has_attributes :title, datastream: 'rdfish', multiple: true
|
|
324
|
+
has_attributes :description, datastream: 'rdfish', multiple: false
|
|
325
|
+
end
|
|
292
326
|
end
|
|
293
327
|
end
|
|
294
328
|
|
|
@@ -330,7 +364,9 @@ describe ActiveFedora::Base do
|
|
|
330
364
|
|
|
331
365
|
describe "has_attributes" do
|
|
332
366
|
it "should raise an error" do
|
|
333
|
-
|
|
367
|
+
Deprecation.silence(ActiveFedora::Attributes) do
|
|
368
|
+
expect {subject.has_attributes :title, :description, multiple: true}.to raise_error
|
|
369
|
+
end
|
|
334
370
|
end
|
|
335
371
|
end
|
|
336
372
|
end
|
|
@@ -339,7 +375,9 @@ describe ActiveFedora::Base do
|
|
|
339
375
|
context "when an unknown datastream is specified" do
|
|
340
376
|
before :all do
|
|
341
377
|
class BarHistory4 < ActiveFedora::Base
|
|
342
|
-
|
|
378
|
+
Deprecation.silence(ActiveFedora::Attributes) do
|
|
379
|
+
has_attributes :description, datastream: 'rdfish', multiple: true
|
|
380
|
+
end
|
|
343
381
|
end
|
|
344
382
|
end
|
|
345
383
|
|
|
@@ -372,7 +410,9 @@ describe ActiveFedora::Base do
|
|
|
372
410
|
end
|
|
373
411
|
class BarHistory4 < ActiveFedora::Base
|
|
374
412
|
has_metadata 'rdfish', :type=>BarRdfDatastream
|
|
375
|
-
|
|
413
|
+
Deprecation.silence(ActiveFedora::Attributes) do
|
|
414
|
+
has_attributes :description, datastream: :rdfish
|
|
415
|
+
end
|
|
376
416
|
end
|
|
377
417
|
end
|
|
378
418
|
|
|
@@ -25,11 +25,13 @@ describe ActiveFedora::Base do
|
|
|
25
25
|
end
|
|
26
26
|
has_metadata :type=>ActiveFedora::SimpleDatastream, :name=>"withText2" do |m|
|
|
27
27
|
m.field "fubar", :text
|
|
28
|
-
end
|
|
28
|
+
end
|
|
29
29
|
|
|
30
30
|
has_metadata :type=>BarStream, :name=>"xmlish"
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
Deprecation.silence(ActiveFedora::Attributes) do
|
|
32
|
+
has_attributes :fubar, datastream: 'withText', multiple: false
|
|
33
|
+
has_attributes :duck, datastream: 'xmlish', multiple: false
|
|
34
|
+
end
|
|
33
35
|
end
|
|
34
36
|
before :each do
|
|
35
37
|
@n = BarHistory.new()
|
data/spec/unit/base_spec.rb
CHANGED
|
@@ -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
|
|
@@ -23,8 +121,10 @@ describe ActiveFedora::Base do
|
|
|
23
121
|
has_metadata "withText2", type: ActiveFedora::SimpleDatastream, autocreate: true do |m|
|
|
24
122
|
m.field "fubar", :text
|
|
25
123
|
end
|
|
26
|
-
|
|
27
|
-
|
|
124
|
+
Deprecation.silence(ActiveFedora::Attributes) do
|
|
125
|
+
has_attributes :fubar, datastream: 'withText', multiple: true
|
|
126
|
+
has_attributes :swank, datastream: 'someData', multiple: true
|
|
127
|
+
end
|
|
28
128
|
end
|
|
29
129
|
|
|
30
130
|
class FooAdaptation < ActiveFedora::Base
|
data/spec/unit/callback_spec.rb
CHANGED
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
|
2
2
|
|
|
3
3
|
describe ActiveFedora::Base do
|
|
4
4
|
before :each do
|
|
5
|
-
begin
|
|
5
|
+
begin
|
|
6
6
|
ActiveFedora::Base.find('test:123').delete
|
|
7
7
|
rescue
|
|
8
8
|
end
|
|
@@ -12,7 +12,9 @@ describe ActiveFedora::Base do
|
|
|
12
12
|
m.field "fubar", :string
|
|
13
13
|
m.field "swank", :text
|
|
14
14
|
end
|
|
15
|
-
|
|
15
|
+
Deprecation.silence(ActiveFedora::Attributes) do
|
|
16
|
+
has_attributes :fubar, :swank, datastream: 'someData', multiple: true
|
|
17
|
+
end
|
|
16
18
|
|
|
17
19
|
after_initialize :a_init
|
|
18
20
|
before_save :b_save
|
|
@@ -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
|
|
40
|
-
expect(subject.size).to eq
|
|
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
|
data/spec/unit/core_spec.rb
CHANGED
|
@@ -13,8 +13,10 @@ describe ActiveFedora::Base do
|
|
|
13
13
|
m.field "title", :string
|
|
14
14
|
end
|
|
15
15
|
has_metadata "bar", type: MyDatastream
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
Deprecation.silence(ActiveFedora::Attributes) do
|
|
17
|
+
has_attributes :title, datastream: 'foo' # Om backed property
|
|
18
|
+
has_attributes :publisher, datastream: 'bar' # RDF backed property
|
|
19
|
+
end
|
|
18
20
|
end
|
|
19
21
|
end
|
|
20
22
|
|
|
@@ -88,12 +90,54 @@ describe ActiveFedora::Base do
|
|
|
88
90
|
end
|
|
89
91
|
end
|
|
90
92
|
|
|
93
|
+
describe "#translate_id_to_uri" do
|
|
94
|
+
subject { ActiveFedora::Base.translate_id_to_uri }
|
|
95
|
+
context "when it's not set" do
|
|
96
|
+
it "should be a FedoraIdTranslator" do
|
|
97
|
+
expect(subject).to eq ActiveFedora::Core::FedoraIdTranslator
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
context "when it's set to nil" do
|
|
101
|
+
before do
|
|
102
|
+
ActiveFedora::Base.translate_id_to_uri = nil
|
|
103
|
+
end
|
|
104
|
+
it "should be a FedoraIdTranslator" do
|
|
105
|
+
expect(subject).to eq ActiveFedora::Core::FedoraIdTranslator
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
describe "#translate_uri_to_id" do
|
|
111
|
+
subject { ActiveFedora::Base.translate_uri_to_id }
|
|
112
|
+
context "when it's not set" do
|
|
113
|
+
it "should be a FedoraUriTranslator" do
|
|
114
|
+
expect(subject).to eq ActiveFedora::Core::FedoraUriTranslator
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
context "when it's set to nil" do
|
|
118
|
+
before do
|
|
119
|
+
ActiveFedora::Base.translate_uri_to_id = nil
|
|
120
|
+
end
|
|
121
|
+
it "should be a FedoraIdTranslator" do
|
|
122
|
+
expect(subject).to eq ActiveFedora::Core::FedoraUriTranslator
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
91
127
|
describe "id_to_uri" do
|
|
92
128
|
let(:id) { '123456w' }
|
|
93
129
|
subject { ActiveFedora::Base.id_to_uri(id) }
|
|
94
130
|
|
|
95
131
|
context "with no custom proc is set" do
|
|
96
132
|
it { should eq "#{ActiveFedora.fedora.host}#{ActiveFedora.fedora.base_path}/123456w" }
|
|
133
|
+
it "should just call #translate_id_to_uri" do
|
|
134
|
+
allow(ActiveFedora::Base).to receive(:translate_id_to_uri).and_call_original
|
|
135
|
+
allow(ActiveFedora::Core::FedoraIdTranslator).to receive(:call).and_call_original
|
|
136
|
+
|
|
137
|
+
subject
|
|
138
|
+
|
|
139
|
+
expect(ActiveFedora::Core::FedoraIdTranslator).to have_received(:call).with(id)
|
|
140
|
+
end
|
|
97
141
|
end
|
|
98
142
|
|
|
99
143
|
context "when custom proc is set" do
|
|
@@ -126,6 +170,14 @@ describe ActiveFedora::Base do
|
|
|
126
170
|
|
|
127
171
|
context "with no custom proc is set" do
|
|
128
172
|
it { should eq 'foo/123456w' }
|
|
173
|
+
it "should just call #translate_uri_to_id" do
|
|
174
|
+
allow(ActiveFedora::Base).to receive(:translate_uri_to_id).and_call_original
|
|
175
|
+
allow(ActiveFedora::Core::FedoraUriTranslator).to receive(:call).and_call_original
|
|
176
|
+
|
|
177
|
+
subject
|
|
178
|
+
|
|
179
|
+
expect(ActiveFedora::Core::FedoraUriTranslator).to have_received(:call).with(uri)
|
|
180
|
+
end
|
|
129
181
|
end
|
|
130
182
|
|
|
131
183
|
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) {
|
|
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) {
|
|
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
|
|
@@ -134,26 +134,28 @@ describe ActiveFedora::NtriplesRDFDatastream do
|
|
|
134
134
|
|
|
135
135
|
describe "solr integration" do
|
|
136
136
|
before(:all) do
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
137
|
+
Deprecation.silence(ActiveFedora::RDFDatastream) do
|
|
138
|
+
class MyDatastream < ActiveFedora::NtriplesRDFDatastream
|
|
139
|
+
property :created, predicate: ::RDF::DC.created do |index|
|
|
140
|
+
index.as :sortable, :displayable
|
|
141
|
+
index.type :date
|
|
142
|
+
end
|
|
143
|
+
property :title, predicate: ::RDF::DC.title do |index|
|
|
144
|
+
index.as :stored_searchable, :sortable
|
|
145
|
+
index.type :text
|
|
146
|
+
end
|
|
147
|
+
property :publisher, predicate: ::RDF::DC.publisher do |index|
|
|
148
|
+
index.as :facetable, :sortable, :stored_searchable
|
|
149
|
+
end
|
|
150
|
+
property :based_near, predicate: ::RDF::FOAF.based_near do |index|
|
|
151
|
+
index.as :facetable, :stored_searchable
|
|
152
|
+
index.type :text
|
|
153
|
+
end
|
|
154
|
+
property :related_url, predicate: ::RDF::RDFS.seeAlso do |index|
|
|
155
|
+
index.as :stored_searchable
|
|
156
|
+
end
|
|
157
|
+
property :rights, predicate: ::RDF::DC.rights
|
|
155
158
|
end
|
|
156
|
-
property :rights, predicate: ::RDF::DC.rights
|
|
157
159
|
end
|
|
158
160
|
end
|
|
159
161
|
|
|
@@ -185,7 +187,9 @@ describe ActiveFedora::NtriplesRDFDatastream do
|
|
|
185
187
|
before(:each) do
|
|
186
188
|
class Foo < ActiveFedora::Base
|
|
187
189
|
has_metadata "descMetadata", type: MyDatastream
|
|
188
|
-
|
|
190
|
+
Deprecation.silence(ActiveFedora::Attributes) do
|
|
191
|
+
has_attributes :created, :title, :publisher, :based_near, :related_url, :rights, datastream: :descMetadata, multiple: true
|
|
192
|
+
end
|
|
189
193
|
end
|
|
190
194
|
@obj = MyDatastream.new
|
|
191
195
|
@obj.created = Date.parse("2012-03-04")
|
|
@@ -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>
|