active-fedora 9.12.0 → 9.13.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/.rubocop.yml +1 -1
- data/active-fedora.gemspec +1 -0
- data/lib/active_fedora.rb +1 -0
- data/lib/active_fedora/associations.rb +38 -3
- data/lib/active_fedora/associations/basic_contains_association.rb +12 -51
- data/lib/active_fedora/associations/builder/aggregation.rb +1 -1
- data/lib/active_fedora/associations/builder/basic_contains.rb +7 -0
- data/lib/active_fedora/associations/builder/{contains.rb → has_subresource.rb} +2 -2
- data/lib/active_fedora/associations/contains_association.rb +19 -1
- data/lib/active_fedora/associations/directly_contains_association.rb +1 -15
- data/lib/active_fedora/associations/has_subresource_association.rb +61 -0
- data/lib/active_fedora/attached_files.rb +6 -9
- data/lib/active_fedora/autosave_association.rb +1 -1
- data/lib/active_fedora/base.rb +0 -1
- data/lib/active_fedora/common.rb +1 -0
- data/lib/active_fedora/fedora.rb +14 -19
- data/lib/active_fedora/file.rb +1 -1
- data/lib/active_fedora/file/attributes.rb +4 -0
- data/lib/active_fedora/file_persistence.rb +9 -1
- data/lib/active_fedora/initializing_connection.rb +64 -0
- data/lib/active_fedora/ldp_cache.rb +1 -2
- data/lib/active_fedora/ldp_resource_service.rb +7 -1
- data/lib/active_fedora/persistence.rb +12 -1
- data/lib/active_fedora/reflection.rb +22 -6
- data/lib/active_fedora/simple_datastream.rb +2 -0
- data/lib/active_fedora/version.rb +1 -1
- data/lib/generators/active_fedora/config/fedora/fedora_generator.rb +1 -0
- data/lib/generators/active_fedora/config/fedora/templates/.fcrepo_wrapper +1 -0
- data/lib/generators/active_fedora/config/fedora/templates/fcrepo_wrapper_test.yml +4 -0
- data/lib/generators/active_fedora/config/solr/solr_generator.rb +1 -0
- data/lib/generators/active_fedora/config/solr/templates/.solr_wrapper +3 -0
- data/lib/generators/active_fedora/config/solr/templates/solr_wrapper_test.yml +8 -0
- data/spec/integration/attached_files_spec.rb +77 -18
- data/spec/integration/attributes_spec.rb +3 -4
- data/spec/integration/autosave_association_spec.rb +0 -1
- data/spec/integration/base_spec.rb +19 -66
- data/spec/integration/basic_contains_association_spec.rb +108 -0
- data/spec/integration/complex_rdf_datastream_spec.rb +1 -1
- data/spec/integration/field_to_solr_name_spec.rb +12 -11
- data/spec/integration/file_fixity_spec.rb +1 -1
- data/spec/integration/file_spec.rb +4 -1
- data/spec/integration/generators/fedora_generator_spec.rb +26 -0
- data/spec/integration/generators/solr_generator_spec.rb +26 -0
- data/spec/integration/has_and_belongs_to_many_associations_spec.rb +6 -16
- data/spec/integration/has_many_associations_spec.rb +6 -16
- data/spec/integration/{contains_association_spec.rb → has_subresource_spec.rb} +1 -1
- data/spec/integration/json_serialization_spec.rb +11 -5
- data/spec/integration/model_spec.rb +7 -13
- data/spec/integration/ntriples_datastream_spec.rb +2 -2
- data/spec/integration/om_datastream_spec.rb +1 -1
- data/spec/integration/persistence_spec.rb +0 -3
- data/spec/integration/query_result_builder_spec.rb +1 -1
- data/spec/integration/relation_delegation_spec.rb +3 -8
- data/spec/integration/scoped_query_spec.rb +5 -7
- data/spec/integration/solr_hit_spec.rb +10 -4
- data/spec/integration/solr_instance_loader_spec.rb +11 -4
- data/spec/integration/versionable_spec.rb +3 -3
- data/spec/spec_helper.rb +5 -1
- data/spec/unit/active_fedora_spec.rb +1 -1
- data/spec/unit/attached_files_spec.rb +32 -21
- data/spec/unit/attributes_spec.rb +21 -23
- data/spec/unit/base_active_model_spec.rb +13 -10
- data/spec/unit/base_spec.rb +2 -24
- data/spec/unit/callback_spec.rb +0 -8
- data/spec/unit/core_spec.rb +3 -5
- data/spec/unit/inheritance_spec.rb +15 -9
- data/spec/unit/ntriples_datastream_spec.rb +1 -1
- data/spec/unit/om_datastream_spec.rb +1 -1
- data/spec/unit/persistence_spec.rb +21 -0
- data/spec/unit/query_spec.rb +8 -0
- data/spec/unit/rdf_datastream_spec.rb +1 -1
- data/spec/unit/rdf_resource_datastream_spec.rb +1 -1
- data/spec/unit/simple_datastream_spec.rb +8 -2
- data/spec/unit/solr_config_options_spec.rb +1 -1
- data/spec/unit/validations_spec.rb +2 -8
- metadata +27 -6
- data/spec/integration/bug_spec.rb +0 -40
- data/spec/integration/full_featured_model_spec.rb +0 -160
@@ -1,79 +1,32 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ActiveFedora::Base do
|
4
|
-
describe
|
5
|
-
before
|
6
|
-
class
|
7
|
-
|
4
|
+
describe '#reload' do
|
5
|
+
before do
|
6
|
+
class Foo < ActiveFedora::Base
|
7
|
+
property :person, predicate: ::RDF::Vocab::DC.creator
|
8
8
|
end
|
9
9
|
end
|
10
|
-
after
|
11
|
-
Object.send(:remove_const, :
|
10
|
+
after do
|
11
|
+
Object.send(:remove_const, :Foo)
|
12
12
|
end
|
13
|
-
|
13
|
+
context "when persisted" do
|
14
|
+
let(:object) { Foo.create(person: ['bob']) }
|
15
|
+
let(:object2) { Foo.find(object.id) }
|
14
16
|
before do
|
15
|
-
|
16
|
-
|
17
|
-
@obj.foo.person = "bob"
|
18
|
-
@obj.save
|
19
|
-
end
|
20
|
-
|
21
|
-
it "saves the datastream." do
|
22
|
-
obj = described_class.find(@obj.id)
|
23
|
-
expect(obj.foo).to_not be_new_record
|
24
|
-
expect(obj.foo.person).to eq ['bob']
|
25
|
-
person_field = ActiveFedora.index_field_mapper.solr_name('foo__person', type: :string)
|
26
|
-
solr_result = ActiveFedora::SolrService.query("{!field f=id}#{@obj.id}", fl: "id #{person_field}").first
|
27
|
-
expect(solr_result).to eq("id" => @obj.id, person_field => ['bob'])
|
17
|
+
object2.update(person: ['dave'])
|
28
18
|
end
|
29
|
-
end
|
30
19
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
@release.foo.person = "test foo content"
|
35
|
-
@release.save
|
36
|
-
end
|
37
|
-
describe "and has been changed" do
|
38
|
-
before do
|
39
|
-
@release.foo.person = 'frank'
|
40
|
-
@release.save!
|
41
|
-
end
|
42
|
-
it "saves the datastream." do
|
43
|
-
expect(MockAFBaseRelationship.find(@release.id).foo.person).to eq ['frank']
|
44
|
-
person_field = ActiveFedora.index_field_mapper.solr_name('foo__person', type: :string)
|
45
|
-
expect(ActiveFedora::SolrService.query("id:\"#{@release.id}\"", fl: "id #{person_field}").first).to eq("id" => @release.id, person_field => ['frank'])
|
46
|
-
end
|
47
|
-
end
|
48
|
-
describe "when trying to create it again" do
|
49
|
-
it "raises an error" do
|
50
|
-
expect { MockAFBaseRelationship.create(id: @release.id) }.to raise_error(ActiveFedora::IllegalOperation, "Attempting to recreate existing ldp_source: `#{@release.uri}'")
|
51
|
-
@release.reload
|
52
|
-
expect(@release.foo.person).to include('test foo content')
|
53
|
-
end
|
20
|
+
it 're-queries Fedora' do
|
21
|
+
object.reload
|
22
|
+
expect(object.person).to eq ['dave']
|
54
23
|
end
|
55
24
|
end
|
56
25
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
@object.save
|
62
|
-
|
63
|
-
@object2 = @object.class.find(@object.id)
|
64
|
-
|
65
|
-
@object2.foo.person = 'dave'
|
66
|
-
@object2.save
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'requeries Fedora' do
|
70
|
-
@object.reload
|
71
|
-
expect(@object.foo.person).to eq ['dave']
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'raises an error if not persisted' do
|
75
|
-
@object = MockAFBaseRelationship.new
|
76
|
-
expect { @object.reload }.to raise_error(ActiveFedora::ObjectNotFoundError)
|
26
|
+
context "when not persisted" do
|
27
|
+
let(:object) { Foo.new }
|
28
|
+
it 'raises an error' do
|
29
|
+
expect { object.reload }.to raise_error(ActiveFedora::ObjectNotFoundError)
|
77
30
|
end
|
78
31
|
end
|
79
32
|
end
|
@@ -93,12 +46,12 @@ describe ActiveFedora::Base do
|
|
93
46
|
|
94
47
|
after { obj.destroy unless obj.destroyed? }
|
95
48
|
|
96
|
-
describe "errors" do
|
49
|
+
describe "#errors" do
|
97
50
|
subject { obj.errors }
|
98
51
|
it { should be_empty }
|
99
52
|
end
|
100
53
|
|
101
|
-
describe "id" do
|
54
|
+
describe "#id" do
|
102
55
|
subject { obj.id }
|
103
56
|
it { should_not be_nil }
|
104
57
|
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ActiveFedora::Base do
|
4
|
+
let(:model) { Source.new }
|
5
|
+
|
6
|
+
context "with a file" do
|
7
|
+
before do
|
8
|
+
class Source < ActiveFedora::Base
|
9
|
+
is_a_container
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
after do
|
14
|
+
Object.send(:remove_const, :Source)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'is empty' do
|
18
|
+
expect(model.contains).to eq []
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'can build a child' do
|
22
|
+
child = model.contains.build
|
23
|
+
expect(child).to be_kind_of ActiveFedora::File
|
24
|
+
child.content = "hello"
|
25
|
+
model.save!
|
26
|
+
expect(child).to be_persisted
|
27
|
+
expect(child.uri.to_s).to include model.uri.to_s
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'can create a child on a persisted parent' do
|
31
|
+
model.save!
|
32
|
+
child = model.contains.build
|
33
|
+
expect(child).to be_kind_of ActiveFedora::File
|
34
|
+
child.content = "hello"
|
35
|
+
model.save!
|
36
|
+
expect(child).to be_persisted
|
37
|
+
expect(child.uri.to_s).to include model.uri.to_s
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "with an AF::Base object" do
|
42
|
+
before do
|
43
|
+
class Thing < ActiveFedora::Base
|
44
|
+
property :title, predicate: ::RDF::Vocab::DC.title
|
45
|
+
end
|
46
|
+
class Source < ActiveFedora::Base
|
47
|
+
is_a_container class_name: 'Thing'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
after do
|
51
|
+
Object.send(:remove_const, :Source)
|
52
|
+
Object.send(:remove_const, :Thing)
|
53
|
+
end
|
54
|
+
|
55
|
+
let(:model) { Source.new }
|
56
|
+
|
57
|
+
it 'is empty' do
|
58
|
+
expect(model.contains).to eq []
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "creating" do
|
62
|
+
it 'can build a child' do
|
63
|
+
child = model.contains.build
|
64
|
+
expect(model.contains.build(title: ['my title'])).to be_kind_of Thing
|
65
|
+
model.save!
|
66
|
+
expect(child).to be_persisted
|
67
|
+
expect(child.uri.to_s).to include model.uri.to_s
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'can create a child on a persisted parent' do
|
71
|
+
model.save!
|
72
|
+
child = model.contains.create(title: ['my title'])
|
73
|
+
expect(child).to be_kind_of Thing
|
74
|
+
expect(child).to be_persisted
|
75
|
+
expect(child.uri.to_s).to include model.uri.to_s
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "loading" do
|
80
|
+
before do
|
81
|
+
model.save!
|
82
|
+
model.contains.create(title: ['title 1'])
|
83
|
+
model.contains.create(title: ['title 2'])
|
84
|
+
model.reload
|
85
|
+
end
|
86
|
+
|
87
|
+
it "has the two contained objects" do
|
88
|
+
expect(model.contains.size).to eq 2
|
89
|
+
expect(model.contains.map(&:title)).to eq [['title 1'], ['title 2']]
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "#destroy_all" do
|
94
|
+
before do
|
95
|
+
model.save!
|
96
|
+
model.contains.create(title: ['title 1'])
|
97
|
+
model.contains.create(title: ['title 2'])
|
98
|
+
model.reload
|
99
|
+
end
|
100
|
+
|
101
|
+
it "destroys the two contained objects" do
|
102
|
+
expect { model.contains.destroy_all }
|
103
|
+
.to change { model.contains.size }.by(-2)
|
104
|
+
.and change { Thing.count }.by(-2)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -2,19 +2,19 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe "An object with RDF backed attributes" do
|
4
4
|
before do
|
5
|
-
class
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
index.as :stored_searchable, :sortable
|
14
|
-
end
|
5
|
+
class MyMetadata < ActiveFedora::NtriplesRDFDatastream
|
6
|
+
Deprecation.silence(ActiveFedora::RDFDatastream) do
|
7
|
+
property :title, predicate: ::RDF::Vocab::DC.title do |index|
|
8
|
+
index.as :stored_searchable
|
9
|
+
end
|
10
|
+
property :date_uploaded, predicate: ::RDF::Vocab::DC.dateSubmitted do |index|
|
11
|
+
index.type :date
|
12
|
+
index.as :stored_searchable, :sortable
|
15
13
|
end
|
16
14
|
end
|
17
|
-
|
15
|
+
end
|
16
|
+
class TestOne < ActiveFedora::Base
|
17
|
+
has_subresource 'descMetadata', class_name: 'MyMetadata'
|
18
18
|
Deprecation.silence(ActiveFedora::Attributes) do
|
19
19
|
has_attributes :title, :date_uploaded, datastream: 'descMetadata'
|
20
20
|
end
|
@@ -23,6 +23,7 @@ describe "An object with RDF backed attributes" do
|
|
23
23
|
|
24
24
|
after do
|
25
25
|
Object.send(:remove_const, :TestOne)
|
26
|
+
Object.send(:remove_const, :MyMetadata)
|
26
27
|
end
|
27
28
|
|
28
29
|
it "is able to grab the solr name" do
|
@@ -53,7 +53,10 @@ describe ActiveFedora::File do
|
|
53
53
|
context "when autocreate is true" do
|
54
54
|
before do
|
55
55
|
class MockAFBase < ActiveFedora::Base
|
56
|
-
|
56
|
+
extend Deprecation
|
57
|
+
Deprecation.silence(MockAFBase) do
|
58
|
+
has_metadata "descMetadata", type: ActiveFedora::QualifiedDublinCoreDatastream, autocreate: true
|
59
|
+
end
|
57
60
|
end
|
58
61
|
end
|
59
62
|
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'generators/active_fedora/config/fedora/fedora_generator'
|
3
|
+
|
4
|
+
describe ActiveFedora::Config::FedoraGenerator do
|
5
|
+
describe "#fcrepo_wrapper_config" do
|
6
|
+
let(:generator) { described_class.new }
|
7
|
+
let(:files_to_test) {[
|
8
|
+
'config/fcrepo_wrapper_test.yml',
|
9
|
+
'.fcrepo_wrapper'
|
10
|
+
]}
|
11
|
+
|
12
|
+
before do
|
13
|
+
generator.fcrepo_wrapper_config
|
14
|
+
end
|
15
|
+
|
16
|
+
after do
|
17
|
+
files_to_test.each { |file| File.delete(file) if File.exist?(file) }
|
18
|
+
end
|
19
|
+
|
20
|
+
it "creates config files" do
|
21
|
+
files_to_test.each do |file|
|
22
|
+
expect(File).to exist(file), "Expected #{file} to exist"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'generators/active_fedora/config/solr/solr_generator'
|
3
|
+
|
4
|
+
describe ActiveFedora::Config::SolrGenerator do
|
5
|
+
describe "#solr_wrapper_config" do
|
6
|
+
let(:generator) { described_class.new }
|
7
|
+
let(:files_to_test) {[
|
8
|
+
'config/solr_wrapper_test.yml',
|
9
|
+
'.solr_wrapper'
|
10
|
+
]}
|
11
|
+
|
12
|
+
before do
|
13
|
+
generator.solr_wrapper_config
|
14
|
+
end
|
15
|
+
|
16
|
+
after do
|
17
|
+
files_to_test.each { |file| File.delete(file) if File.exist?(file) }
|
18
|
+
end
|
19
|
+
|
20
|
+
it "creates config files" do
|
21
|
+
files_to_test.each do |file|
|
22
|
+
expect(File).to exist(file), "Expected #{file} to exist"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -350,22 +350,12 @@ describe ActiveFedora::Base do
|
|
350
350
|
before do
|
351
351
|
class Item < ActiveFedora::Base
|
352
352
|
has_many :components
|
353
|
-
|
354
|
-
m.field "title", :string
|
355
|
-
end
|
356
|
-
Deprecation.silence(ActiveFedora::Attributes) do
|
357
|
-
has_attributes :title, datastream: 'foo'
|
358
|
-
end
|
353
|
+
property :title, predicate: ::RDF::Vocab::DC.title
|
359
354
|
end
|
360
355
|
|
361
356
|
class Component < ActiveFedora::Base
|
362
357
|
has_and_belongs_to_many :items, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf
|
363
|
-
|
364
|
-
m.field "description", :string
|
365
|
-
end
|
366
|
-
Deprecation.silence(ActiveFedora::Attributes) do
|
367
|
-
has_attributes :description, datastream: 'foo'
|
368
|
-
end
|
358
|
+
property :description, predicate: ::RDF::Vocab::DC.description
|
369
359
|
end
|
370
360
|
end
|
371
361
|
|
@@ -376,11 +366,11 @@ describe ActiveFedora::Base do
|
|
376
366
|
|
377
367
|
describe "From the has_and_belongs_to_many side" do
|
378
368
|
describe "dependent records" do
|
379
|
-
let(:component) { Component.create(items: [Item.new(title: 'my title')]) }
|
369
|
+
let(:component) { Component.create(items: [Item.new(title: ['my title'])]) }
|
380
370
|
|
381
371
|
it "is saved" do
|
382
372
|
component.reload
|
383
|
-
expect(component.items.first.title).to eq 'my title'
|
373
|
+
expect(component.items.first.title).to eq ['my title']
|
384
374
|
end
|
385
375
|
end
|
386
376
|
|
@@ -413,11 +403,11 @@ describe ActiveFedora::Base do
|
|
413
403
|
end
|
414
404
|
|
415
405
|
describe "From the has_many side" do
|
416
|
-
let(:item) { Item.create(components: [Component.new(description: 'my description')]) }
|
406
|
+
let(:item) { Item.create(components: [Component.new(description: ['my description'])]) }
|
417
407
|
|
418
408
|
it "saves dependent records" do
|
419
409
|
item.reload
|
420
|
-
expect(item.components.first.description).to eq 'my description'
|
410
|
+
expect(item.components.first.description).to eq ['my description']
|
421
411
|
end
|
422
412
|
end
|
423
413
|
end
|
@@ -314,21 +314,11 @@ describe ActiveFedora::Associations::HasManyAssociation do
|
|
314
314
|
before do
|
315
315
|
class Item < ActiveFedora::Base
|
316
316
|
has_many :components
|
317
|
-
|
318
|
-
m.field "title", :string
|
319
|
-
end
|
320
|
-
Deprecation.silence(ActiveFedora::Attributes) do
|
321
|
-
has_attributes :title, datastream: 'foo'
|
322
|
-
end
|
317
|
+
property :title, predicate: ::RDF::Vocab::DC.title
|
323
318
|
end
|
324
319
|
class Component < ActiveFedora::Base
|
325
320
|
belongs_to :item, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf
|
326
|
-
|
327
|
-
m.field "description", :string
|
328
|
-
end
|
329
|
-
Deprecation.silence(ActiveFedora::Attributes) do
|
330
|
-
has_attributes :description, datastream: 'foo'
|
331
|
-
end
|
321
|
+
property :description, predicate: ::RDF::Vocab::DC.description
|
332
322
|
end
|
333
323
|
end
|
334
324
|
|
@@ -338,20 +328,20 @@ describe ActiveFedora::Associations::HasManyAssociation do
|
|
338
328
|
end
|
339
329
|
|
340
330
|
context "From the belongs_to side" do
|
341
|
-
let(:component) { Component.create(item: Item.new(title: 'my title')) }
|
331
|
+
let(:component) { Component.create(item: Item.new(title: ['my title'])) }
|
342
332
|
|
343
333
|
it "saves dependent records" do
|
344
334
|
component.reload
|
345
|
-
expect(component.item.title).to eq 'my title'
|
335
|
+
expect(component.item.title).to eq ['my title']
|
346
336
|
end
|
347
337
|
end
|
348
338
|
|
349
339
|
context "From the has_many side" do
|
350
|
-
let(:item) { Item.create(components: [Component.new(description: 'my description')]) }
|
340
|
+
let(:item) { Item.create(components: [Component.new(description: ['my description'])]) }
|
351
341
|
|
352
342
|
it "saves dependent records" do
|
353
343
|
item.reload
|
354
|
-
expect(item.components.first.description).to eq 'my description'
|
344
|
+
expect(item.components.first.description).to eq ['my description']
|
355
345
|
end
|
356
346
|
end
|
357
347
|
end
|