active-fedora 9.13.0 → 10.0.0.beta1
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/README.md +0 -19
- data/lib/active_fedora.rb +0 -17
- data/lib/active_fedora/associations.rb +0 -16
- data/lib/active_fedora/associations/builder/association.rb +3 -19
- data/lib/active_fedora/associations/builder/has_and_belongs_to_many.rb +1 -3
- data/lib/active_fedora/attached_files.rb +2 -108
- data/lib/active_fedora/attributes.rb +4 -100
- data/lib/active_fedora/core.rb +0 -6
- data/lib/active_fedora/datastreams.rb +0 -2
- data/lib/active_fedora/errors.rb +0 -9
- data/lib/active_fedora/file.rb +9 -22
- data/lib/active_fedora/file_configurator.rb +1 -32
- data/lib/active_fedora/identifiable.rb +0 -6
- data/lib/active_fedora/ldp_resource.rb +0 -12
- data/lib/active_fedora/qualified_dublin_core_datastream.rb +1 -1
- data/lib/active_fedora/query_result_builder.rb +0 -17
- data/lib/active_fedora/rdf/datastream_indexing.rb +0 -11
- data/lib/active_fedora/rdf/indexing_service.rb +1 -1
- data/lib/active_fedora/rdf/rdf_datastream.rb +0 -10
- data/lib/active_fedora/relation/finder_methods.rb +2 -21
- data/lib/active_fedora/solr_query_builder.rb +0 -16
- data/lib/active_fedora/solr_service.rb +2 -89
- data/lib/active_fedora/version.rb +1 -1
- data/lib/active_fedora/versionable.rb +0 -8
- data/spec/config_helper.rb +0 -4
- data/spec/integration/attached_files_spec.rb +1 -108
- data/spec/integration/attributes_spec.rb +14 -94
- data/spec/integration/direct_container_spec.rb +2 -2
- data/spec/integration/file_spec.rb +23 -13
- data/spec/integration/indexing_spec.rb +4 -4
- data/spec/integration/json_serialization_spec.rb +4 -57
- data/spec/integration/ntriples_datastream_spec.rb +77 -139
- data/spec/integration/relation_delegation_spec.rb +16 -18
- data/spec/integration/{model_spec.rb → scoping_spec.rb} +10 -14
- data/spec/integration/solr_hit_spec.rb +4 -20
- data/spec/integration/solr_instance_loader_spec.rb +1 -13
- data/spec/integration/versionable_spec.rb +0 -9
- data/spec/samples/models/mods_article.rb +1 -6
- data/spec/spec_helper.rb +0 -3
- data/spec/unit/attached_files_spec.rb +29 -127
- data/spec/unit/attributes_spec.rb +51 -475
- data/spec/unit/base_active_model_spec.rb +12 -47
- data/spec/unit/base_extra_spec.rb +1 -1
- data/spec/unit/code_configurator_spec.rb +2 -10
- data/spec/unit/core_spec.rb +3 -18
- data/spec/unit/file_configurator_spec.rb +0 -80
- data/spec/unit/file_spec.rb +0 -6
- data/spec/unit/has_and_belongs_to_many_association_spec.rb +0 -7
- data/spec/unit/inheritance_spec.rb +0 -12
- data/spec/unit/ntriples_datastream_spec.rb +2 -74
- data/spec/unit/property_spec.rb +0 -3
- data/spec/unit/query_spec.rb +0 -7
- data/spec/unit/querying_spec.rb +24 -0
- data/spec/unit/rdf/indexing_service_spec.rb +32 -20
- data/spec/unit/rdf_resource_datastream_spec.rb +37 -97
- data/spec/unit/solr_query_builder_spec.rb +0 -8
- data/spec/unit/solr_service_spec.rb +0 -13
- metadata +6 -19
- data/config/predicate_mappings.yml +0 -51
- data/lib/active_fedora/attributes/om_attribute.rb +0 -26
- data/lib/active_fedora/attributes/rdf_datastream_attribute.rb +0 -44
- data/lib/active_fedora/attributes/stream_attribute.rb +0 -43
- data/lib/active_fedora/datastream.rb +0 -9
- data/lib/active_fedora/model.rb +0 -31
- data/lib/active_fedora/predicates.rb +0 -122
- data/lib/active_fedora/simple_datastream.rb +0 -92
- data/spec/fixtures/rails_root/config/predicate_mappings.yml +0 -31
- data/spec/integration/field_to_solr_name_spec.rb +0 -36
- data/spec/unit/base_datastream_management_spec.rb +0 -19
- data/spec/unit/model_spec.rb +0 -30
- data/spec/unit/predicates_spec.rb +0 -126
- data/spec/unit/simple_datastream_spec.rb +0 -101
@@ -11,12 +11,7 @@ describe ActiveFedora::SolrInstanceLoader do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
class Foo < ActiveFedora::Base
|
14
|
-
extend Deprecation
|
15
14
|
has_subresource 'descMetadata', class_name: 'MyDS'
|
16
|
-
Deprecation.silence(ActiveFedora::Attributes) do
|
17
|
-
has_attributes :foo, datastream: 'descMetadata', multiple: true
|
18
|
-
has_attributes :bar, datastream: 'descMetadata', multiple: false
|
19
|
-
end
|
20
15
|
property :title, predicate: ::RDF::Vocab::DC.title, multiple: false
|
21
16
|
property :description, predicate: ::RDF::Vocab::DC.description
|
22
17
|
belongs_to :another, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf, class_name: 'Foo'
|
@@ -33,8 +28,6 @@ describe ActiveFedora::SolrInstanceLoader do
|
|
33
28
|
|
34
29
|
let!(:obj) { Foo.create!(
|
35
30
|
id: 'test-123',
|
36
|
-
foo: ["baz"],
|
37
|
-
bar: 'quix',
|
38
31
|
title: 'My Title',
|
39
32
|
description: ['first desc', 'second desc'],
|
40
33
|
another_id: another.id,
|
@@ -58,7 +51,6 @@ describe ActiveFedora::SolrInstanceLoader do
|
|
58
51
|
expect(subject.title).to eq 'My Title'
|
59
52
|
expect(subject.description).to match_array ['first desc', 'second desc']
|
60
53
|
expect(subject.another_id).to eq another.id
|
61
|
-
expect(subject.bar).to eq 'quix'
|
62
54
|
end
|
63
55
|
|
64
56
|
it "does not be mutable" do
|
@@ -78,19 +70,15 @@ describe ActiveFedora::SolrInstanceLoader do
|
|
78
70
|
let(:loader) { described_class.new(ActiveFedora::Base, obj.id) }
|
79
71
|
|
80
72
|
it "finds the document in solr" do
|
81
|
-
expect_any_instance_of(ActiveFedora::
|
73
|
+
expect_any_instance_of(ActiveFedora::File).to_not receive(:retrieve_content)
|
82
74
|
expect_any_instance_of(Ldp::Client).to_not receive(:get)
|
83
75
|
object = loader.object
|
84
76
|
expect(object).to be_instance_of Foo
|
85
77
|
expect(object.title).to eq 'My Title' # object assertion
|
86
|
-
expect(object.foo).to eq ['baz'] # datastream assertion
|
87
78
|
|
88
79
|
# and it's frozen
|
89
80
|
expect { object.title = 'changed' }.to raise_error ActiveFedora::ReadOnlyRecord
|
90
81
|
expect(object.title).to eq 'My Title'
|
91
|
-
|
92
|
-
expect { object.foo = ['changed'] }.to raise_error ActiveFedora::ReadOnlyRecord
|
93
|
-
expect(object.foo).to eq ['baz']
|
94
82
|
end
|
95
83
|
end
|
96
84
|
|
@@ -124,15 +124,6 @@ describe ActiveFedora::Versionable do
|
|
124
124
|
end
|
125
125
|
end
|
126
126
|
end
|
127
|
-
|
128
|
-
describe ".has_many_versions" do
|
129
|
-
it "has a warning" do
|
130
|
-
expect(Deprecation).to receive(:warn)
|
131
|
-
class WithVersions < ActiveFedora::Base
|
132
|
-
has_many_versions
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
127
|
end
|
137
128
|
|
138
129
|
describe ActiveFedora::NtriplesRDFDatastream do
|
@@ -5,10 +5,5 @@ require_relative '../hydra-mods_article_datastream.rb'
|
|
5
5
|
#
|
6
6
|
# See lib/samples/sample_thing.rb for a fuller, annotated example of an ActiveFedora Model
|
7
7
|
class ModsArticle < ActiveFedora::Base
|
8
|
-
|
9
|
-
@original_behavior = Deprecation.default_deprecation_behavior
|
10
|
-
Deprecation.default_deprecation_behavior = :silence
|
11
|
-
has_metadata name: "descMetadata", type: Hydra::ModsArticleDatastream
|
12
|
-
has_metadata name: "properties", type: ActiveFedora::SimpleDatastream
|
13
|
-
Deprecation.default_deprecation_behavior = @original_behavior
|
8
|
+
has_subresource "descMetadata", class_name: 'Hydra::ModsArticleDatastream'
|
14
9
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -35,9 +35,6 @@ def restore_spec_configuration
|
|
35
35
|
end
|
36
36
|
restore_spec_configuration
|
37
37
|
|
38
|
-
# Shut those Rails deprecation warnings up
|
39
|
-
ActiveSupport::Deprecation.behavior = proc { |_message, _callstack| }
|
40
|
-
|
41
38
|
require 'active_fedora/cleaner'
|
42
39
|
RSpec.configure do |config|
|
43
40
|
# Stub out test stuff.
|
@@ -35,82 +35,6 @@ describe ActiveFedora::AttachedFiles do
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
describe '.has_metadata' do
|
39
|
-
before do
|
40
|
-
class Z < ActiveFedora::File
|
41
|
-
end
|
42
|
-
class FooHistory < ActiveFedora::Base
|
43
|
-
extend Deprecation
|
44
|
-
Deprecation.silence(FooHistory) do
|
45
|
-
has_metadata name: 'dsid', type: ActiveFedora::QualifiedDublinCoreDatastream
|
46
|
-
has_metadata 'complex_ds', autocreate: true, type: 'Z'
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
after do
|
51
|
-
Object.send(:remove_const, :FooHistory)
|
52
|
-
Object.send(:remove_const, :Z)
|
53
|
-
end
|
54
|
-
|
55
|
-
it "has a child_resource_reflection" do
|
56
|
-
expect(FooHistory.child_resource_reflections).to have_key(:dsid)
|
57
|
-
end
|
58
|
-
|
59
|
-
it "has reasonable defaults" do
|
60
|
-
expect(FooHistory.child_resource_reflections[:dsid].options).to include(class_name: 'ActiveFedora::QualifiedDublinCoreDatastream')
|
61
|
-
end
|
62
|
-
|
63
|
-
it "lets you override defaults" do
|
64
|
-
expect(FooHistory.child_resource_reflections[:complex_ds].options).to include(autocreate: true)
|
65
|
-
expect(FooHistory.child_resource_reflections[:complex_ds].class_name).to eq 'Z'
|
66
|
-
end
|
67
|
-
|
68
|
-
it "raises an error if you don't give a type" do
|
69
|
-
expect {
|
70
|
-
Deprecation.silence(FooHistory) do
|
71
|
-
FooHistory.has_metadata "bob"
|
72
|
-
end
|
73
|
-
}.to raise_error ArgumentError,
|
74
|
-
"You must provide a :type property for the datastream 'bob'"
|
75
|
-
end
|
76
|
-
|
77
|
-
it "raises an error if you don't give a dsid" do
|
78
|
-
expect {
|
79
|
-
Deprecation.silence(FooHistory) do
|
80
|
-
FooHistory.has_metadata type: ActiveFedora::QualifiedDublinCoreDatastream
|
81
|
-
end
|
82
|
-
}.to raise_error ArgumentError,
|
83
|
-
"You must provide a path name (f.k.a. dsid) for the resource"
|
84
|
-
end
|
85
|
-
|
86
|
-
describe "creates accessors" do
|
87
|
-
subject { FooHistory.new }
|
88
|
-
it "exists on the instance" do
|
89
|
-
expect(subject.dsid).to eq subject.attached_files['dsid']
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
describe '.has_file_datastream' do
|
95
|
-
before do
|
96
|
-
class FooHistory < ActiveFedora::Base
|
97
|
-
extend Deprecation
|
98
|
-
Deprecation.silence(FooHistory) do
|
99
|
-
has_file_datastream name: 'dsid'
|
100
|
-
has_file_datastream 'another'
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
after do
|
105
|
-
Object.send(:remove_const, :FooHistory)
|
106
|
-
end
|
107
|
-
|
108
|
-
it "has reasonable defaults" do
|
109
|
-
expect(FooHistory.child_resource_reflections[:dsid].klass).to eq ActiveFedora::File
|
110
|
-
expect(FooHistory.child_resource_reflections[:another].klass).to eq ActiveFedora::File
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
38
|
describe "#add_file" do
|
115
39
|
before do
|
116
40
|
class Bar < ActiveFedora::File; end
|
@@ -126,24 +50,6 @@ describe ActiveFedora::AttachedFiles do
|
|
126
50
|
end
|
127
51
|
let(:container) { FooHistory.new }
|
128
52
|
|
129
|
-
describe "#add_file_datastream" do
|
130
|
-
context "a reflection matches the :dsid property" do
|
131
|
-
it "builds the reflection" do
|
132
|
-
expect(Deprecation).to receive(:warn)
|
133
|
-
container.add_file_datastream('blah', path: 'content')
|
134
|
-
expect(container.content).to be_instance_of Bar
|
135
|
-
expect(container.content.content).to eq 'blah'
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
context "with the deprecated :dsid property" do
|
140
|
-
it "builds the reflection" do
|
141
|
-
expect(Deprecation).to receive(:warn)
|
142
|
-
container.add_file('blah', dsid: 'content')
|
143
|
-
expect(container.content).to be_instance_of Bar
|
144
|
-
expect(container.content.content).to eq 'blah'
|
145
|
-
end
|
146
|
-
end
|
147
53
|
context "a reflection matches the :path property" do
|
148
54
|
it "builds the reflection" do
|
149
55
|
container.add_file('blah', path: 'content')
|
@@ -152,24 +58,6 @@ describe ActiveFedora::AttachedFiles do
|
|
152
58
|
end
|
153
59
|
end
|
154
60
|
|
155
|
-
context "the deprecated 3 args erasure" do
|
156
|
-
it "builds the reflection" do
|
157
|
-
expect(Deprecation).to receive(:warn)
|
158
|
-
container.add_file('blah', 'content', 'name.png')
|
159
|
-
expect(container.content).to be_instance_of Bar
|
160
|
-
expect(container.content.content).to eq 'blah'
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
context "the deprecated 4 args erasure" do
|
165
|
-
it "builds the reflection" do
|
166
|
-
expect(Deprecation).to receive(:warn)
|
167
|
-
container.add_file('blah', 'content', 'name.png', 'image/png')
|
168
|
-
expect(container.content).to be_instance_of Bar
|
169
|
-
expect(container.content.content).to eq 'blah'
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
61
|
context "no reflection matches the :path property" do
|
174
62
|
it "creates a singleton reflection and build it" do
|
175
63
|
container.add_file('blah', path: 'fizz')
|
@@ -244,28 +132,42 @@ describe ActiveFedora::AttachedFiles do
|
|
244
132
|
end
|
245
133
|
|
246
134
|
describe "#attach_file" do
|
247
|
-
let(:dsid) { 'Abc' }
|
248
135
|
let(:file) { ActiveFedora::File.new }
|
249
|
-
|
250
|
-
|
136
|
+
|
137
|
+
it "does not call save on the file" do
|
138
|
+
expect(file).to receive(:save).never
|
139
|
+
subject.attach_file(file, 'part1')
|
251
140
|
end
|
252
141
|
|
253
|
-
it "adds the
|
254
|
-
expect
|
142
|
+
it "adds the file to the attached_files hash" do
|
143
|
+
expect {
|
144
|
+
subject.attach_file(file, 'part1')
|
145
|
+
}.to change { subject.attached_files.key?(:part1) }.from(false).to(true)
|
255
146
|
end
|
256
147
|
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
expect(subject.eac_cpf).to eq file
|
262
|
-
end
|
148
|
+
context "after attaching the file" do
|
149
|
+
let(:dsid) { 'Abc' }
|
150
|
+
before do
|
151
|
+
subject.attach_file(file, dsid)
|
263
152
|
end
|
264
153
|
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
154
|
+
it "adds the datastream to the object" do
|
155
|
+
expect(subject.attached_files['Abc']).to eq file
|
156
|
+
end
|
157
|
+
|
158
|
+
describe "dynamic accessors" do
|
159
|
+
context "when the file is named with dash" do
|
160
|
+
let(:dsid) { 'eac-cpf' }
|
161
|
+
it "converts dashes to underscores" do
|
162
|
+
expect(subject.eac_cpf).to eq file
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
context "when the file is named with underscore" do
|
167
|
+
let(:dsid) { 'foo_bar' }
|
168
|
+
it "preserves the underscore" do
|
169
|
+
expect(subject.foo_bar).to eq file
|
170
|
+
end
|
269
171
|
end
|
270
172
|
end
|
271
173
|
end
|
@@ -1,517 +1,85 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ActiveFedora::Base do
|
4
|
-
context "
|
4
|
+
context "when properties are defined on an object" do
|
5
5
|
before :all do
|
6
|
-
class
|
7
|
-
|
8
|
-
|
9
|
-
t.waterfowl do
|
10
|
-
t.ducks do
|
11
|
-
t.duck
|
12
|
-
end
|
13
|
-
end
|
14
|
-
t.donkey
|
15
|
-
t.cow
|
16
|
-
t.pig
|
17
|
-
t.horse
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.xml_template
|
21
|
-
Nokogiri::XML::Document.parse '<animals xmlns="urn:zoobar">
|
22
|
-
<waterfowl>
|
23
|
-
<ducks>
|
24
|
-
<duck/>
|
25
|
-
</ducks>
|
26
|
-
</waterfowl>
|
27
|
-
<cow></cow>
|
28
|
-
</animals>'
|
6
|
+
class BarHistory4 < ActiveFedora::Base
|
7
|
+
property :title, predicate: ::RDF::Vocab::DC.title do |index|
|
8
|
+
index.as :symbol
|
29
9
|
end
|
10
|
+
property :abstract, predicate: ::RDF::Vocab::DC.abstract, multiple: false
|
30
11
|
end
|
31
12
|
end
|
13
|
+
|
32
14
|
after :all do
|
33
|
-
Object.send(:remove_const, :
|
15
|
+
Object.send(:remove_const, :BarHistory4)
|
34
16
|
end
|
35
17
|
|
36
|
-
|
37
|
-
|
38
|
-
before do
|
39
|
-
class BarHistory4 < ActiveFedora::Base
|
40
|
-
has_subresource 'xmlish', class_name: 'BarStream2'
|
41
|
-
Deprecation.silence(ActiveFedora::Attributes) do
|
42
|
-
property :cow, delegate_to: 'xmlish'
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
after do
|
47
|
-
Object.send(:remove_const, :BarHistory4)
|
48
|
-
end
|
49
|
-
|
50
|
-
let(:obj) { BarHistory4.new }
|
51
|
-
|
52
|
-
before { obj.cow = ['one', 'two'] }
|
53
|
-
describe "the object accessor" do
|
54
|
-
subject { obj.cow }
|
55
|
-
it { is_expected.to eq ['one', 'two'] }
|
56
|
-
end
|
57
|
-
|
58
|
-
describe "the datastream accessor" do
|
59
|
-
subject { obj.xmlish.cow }
|
60
|
-
it { is_expected.to eq ['one', 'two'] }
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
context "with multiple set to false" do
|
65
|
-
before do
|
66
|
-
class BarHistory4 < ActiveFedora::Base
|
67
|
-
has_subresource 'xmlish', class_name: 'BarStream2'
|
68
|
-
Deprecation.silence(ActiveFedora::Attributes) do
|
69
|
-
property :cow, delegate_to: 'xmlish', multiple: false
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
after do
|
74
|
-
Object.send(:remove_const, :BarHistory4)
|
75
|
-
end
|
76
|
-
|
77
|
-
let(:obj) { BarHistory4.new }
|
18
|
+
let(:obj) { BarHistory4.new(title: ['test1']) }
|
19
|
+
subject { obj }
|
78
20
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
21
|
+
describe "#attribute_names" do
|
22
|
+
context "on an instance" do
|
23
|
+
it "lists the attributes" do
|
24
|
+
expect(subject.attribute_names).to eq ["title", "abstract"]
|
83
25
|
end
|
84
26
|
end
|
85
27
|
|
86
|
-
context "
|
87
|
-
|
88
|
-
|
89
|
-
has_subresource 'xmlish', class_name: 'BarStream2'
|
90
|
-
Deprecation.silence(ActiveFedora::Attributes) do
|
91
|
-
property :cow, delegate_to: 'xmlish', multiple: false
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
after do
|
96
|
-
Object.send(:remove_const, :BarHistory4)
|
97
|
-
end
|
98
|
-
|
99
|
-
let(:obj) { BarHistory4.new }
|
100
|
-
|
101
|
-
before do
|
102
|
-
obj.cow = 'two'
|
103
|
-
obj.save
|
104
|
-
obj.attached_files[:xmlish].content
|
105
|
-
obj.cow = 'three'
|
106
|
-
obj.save
|
107
|
-
end
|
108
|
-
describe "the attached datastream" do
|
109
|
-
subject { obj.attached_files[:xmlish].content }
|
110
|
-
it { is_expected.to include '<cow>three</cow>' }
|
28
|
+
context "on a class" do
|
29
|
+
it "lists the attributes" do
|
30
|
+
expect(BarHistory4.attribute_names).to eq ["title", "abstract"]
|
111
31
|
end
|
112
32
|
end
|
113
33
|
end
|
114
34
|
|
115
|
-
describe "
|
116
|
-
|
117
|
-
|
118
|
-
property :animal_id, predicate: ::RDF::Vocab::DC.publisher
|
119
|
-
end
|
120
|
-
class MyDS2 < ActiveFedora::OmDatastream
|
121
|
-
set_terminology do |t|
|
122
|
-
t.root(path: "durh")
|
123
|
-
t.fubar
|
124
|
-
end
|
125
|
-
end
|
126
|
-
class BarHistory2 < ActiveFedora::Base
|
127
|
-
has_subresource 'someData', class_name: 'MyDS1'
|
128
|
-
has_subresource "withText", class_name: 'MyDS2'
|
129
|
-
has_subresource 'xmlish', class_name: 'BarStream2'
|
130
|
-
Deprecation.silence(ActiveFedora::Attributes) do
|
131
|
-
has_attributes :cow, datastream: 'xmlish' # for testing the default value of multiple
|
132
|
-
has_attributes :fubar, datastream: 'withText', multiple: true # test alternate datastream
|
133
|
-
has_attributes :pig, datastream: 'xmlish', multiple: false
|
134
|
-
has_attributes :horse, datastream: 'xmlish', multiple: true
|
135
|
-
has_attributes :duck, datastream: 'xmlish', at: [:waterfowl, :ducks, :duck], multiple: true
|
136
|
-
has_attributes :animal_id, datastream: 'someData', multiple: false
|
137
|
-
end
|
138
|
-
|
139
|
-
property :goose, predicate: ::RDF::URI.new('http://example.com#hasGoose')
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
after do
|
144
|
-
Object.send(:remove_const, :BarHistory2)
|
145
|
-
end
|
146
|
-
|
147
|
-
subject { BarHistory2.new }
|
148
|
-
|
149
|
-
describe "#attribute_names" do
|
150
|
-
context "on an instance" do
|
151
|
-
it "lists the attributes" do
|
152
|
-
expect(subject.attribute_names).to eq ["cow", "fubar", "pig", "horse", "duck", "animal_id", "goose"]
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
context "on a class" do
|
157
|
-
it "lists the attributes" do
|
158
|
-
expect(BarHistory2.attribute_names).to eq ["cow", "fubar", "pig", "horse", "duck", "animal_id", "goose"]
|
159
|
-
end
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
describe "inspect" do
|
164
|
-
it "shows the attributes" do
|
165
|
-
expect(subject.inspect).to eq "#<BarHistory2 id: nil, cow: \"\", fubar: [], pig: nil, horse: [], duck: [\"\"], animal_id: nil, goose: []>"
|
166
|
-
end
|
167
|
-
|
168
|
-
describe "with a id" do
|
169
|
-
before { allow(subject).to receive(:id).and_return('test:123') }
|
170
|
-
|
171
|
-
it "shows a id" do
|
172
|
-
expect(subject.inspect).to eq "#<BarHistory2 id: \"test:123\", cow: \"\", fubar: [], pig: nil, horse: [], duck: [\"\"], animal_id: nil, goose: []>"
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
describe "with no attributes" do
|
177
|
-
subject { described_class.new }
|
178
|
-
it "shows a id" do
|
179
|
-
expect(subject.inspect).to eq "#<ActiveFedora::Base id: nil>"
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
describe "with relationships" do
|
184
|
-
before do
|
185
|
-
class BarHistory3 < BarHistory2
|
186
|
-
belongs_to :library, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.hasConstituent, class_name: 'BarHistory2'
|
187
|
-
end
|
188
|
-
subject.library = library
|
189
|
-
end
|
190
|
-
|
191
|
-
let(:library) { BarHistory2.create }
|
192
|
-
subject { BarHistory3.new }
|
193
|
-
|
194
|
-
after do
|
195
|
-
Object.send(:remove_const, :BarHistory3)
|
196
|
-
end
|
197
|
-
|
198
|
-
it "shows the library_id" do
|
199
|
-
expect(subject.inspect).to eq "#<BarHistory3 id: nil, cow: \"\", fubar: [], pig: nil, horse: [], duck: [\"\"], animal_id: nil, goose: [], library_id: \"#{library.id}\">"
|
200
|
-
end
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
it "reveals the unique properties" do
|
205
|
-
expect(BarHistory2.unique?(:horse)).to be false
|
206
|
-
expect(BarHistory2.unique?(:pig)).to be true
|
207
|
-
expect(BarHistory2.unique?(:cow)).to be true
|
208
|
-
end
|
209
|
-
|
210
|
-
it "saves a delegated property" do
|
211
|
-
subject.fubar = ["Quack"]
|
212
|
-
expect(subject.fubar).to eq ["Quack"]
|
213
|
-
expect(subject.withText.get_values(:fubar).first).to eq 'Quack'
|
214
|
-
subject.cow = "Low"
|
215
|
-
expect(subject.cow).to eq "Low"
|
216
|
-
expect(subject.xmlish.term_values(:cow).first).to eq 'Low'
|
217
|
-
|
218
|
-
subject.pig = "Oink"
|
219
|
-
expect(subject.pig).to eq "Oink"
|
220
|
-
end
|
221
|
-
|
222
|
-
it "allows passing parameters to the delegate accessor" do
|
223
|
-
subject.fubar = ["one", "two"]
|
224
|
-
expect(subject.fubar(1)).to eq ['two']
|
225
|
-
end
|
226
|
-
|
227
|
-
describe "assigning wrong cardinality" do
|
228
|
-
it "does not allow passing a string to a multiple attribute writer" do
|
229
|
-
expect { subject.fubar = "Quack" }.to raise_error ArgumentError
|
230
|
-
expect { subject.fubar = ["Quack"] }.not_to raise_error
|
231
|
-
expect { subject.fubar = nil }.not_to raise_error
|
232
|
-
end
|
233
|
-
|
234
|
-
it "does not allow passing an enumerable to a unique attribute writer" do
|
235
|
-
expect { subject.cow = "Low" }.not_to raise_error
|
236
|
-
expect { subject.cow = ["Low"]
|
237
|
-
}.to raise_error ArgumentError, "You attempted to set the attribute `cow' on `BarHistory2' to an enumerable value. However, this attribute is declared as being singular."
|
238
|
-
expect { subject.cow = nil }.not_to raise_error
|
239
|
-
end
|
240
|
-
end
|
241
|
-
|
242
|
-
it "returns an array if marked as multiple" do
|
243
|
-
subject.horse = ["neigh", "whinny"]
|
244
|
-
expect(subject.horse).to eq ["neigh", "whinny"]
|
35
|
+
describe "#inspect" do
|
36
|
+
it "shows the attributes" do
|
37
|
+
expect(subject.inspect).to eq "#<BarHistory4 id: nil, title: [\"test1\"], abstract: nil>"
|
245
38
|
end
|
246
39
|
|
247
|
-
|
248
|
-
subject.
|
249
|
-
expect(subject.duck).to eq ["Quack", "Peep"]
|
250
|
-
end
|
40
|
+
describe "with a id" do
|
41
|
+
before { allow(subject).to receive(:id).and_return('test:123') }
|
251
42
|
|
252
|
-
|
253
|
-
|
254
|
-
expect {
|
255
|
-
subject.fubar = ["Meow"]
|
256
|
-
}.to change { subject.fubar_changed? }.from(false).to(true)
|
257
|
-
end
|
258
|
-
|
259
|
-
context "when a change is made to a property" do
|
260
|
-
it "is marked changed" do
|
261
|
-
expect {
|
262
|
-
subject.goose = ["honk!"]
|
263
|
-
}.to change { subject.goose_changed? }.from(false).to(true)
|
264
|
-
end
|
265
|
-
end
|
266
|
-
|
267
|
-
context "when a property is set to the same value" do
|
268
|
-
before do
|
269
|
-
subject.goose = ['honk!', 'Honk']
|
270
|
-
if ActiveModel.version < Gem::Version.new('4.2.0')
|
271
|
-
subject.send(:reset_changes)
|
272
|
-
else
|
273
|
-
subject.send(:clear_changes_information)
|
274
|
-
end
|
275
|
-
end
|
276
|
-
|
277
|
-
it "is not marked changed" do
|
278
|
-
subject.goose = ['honk!', 'Honk']
|
279
|
-
expect(subject.goose_changed?).to be false
|
280
|
-
end
|
281
|
-
end
|
282
|
-
end
|
283
|
-
|
284
|
-
describe "hash getters and setters" do
|
285
|
-
it "accepts symbol keys" do
|
286
|
-
subject[:duck] = ["Cluck", "Gobble"]
|
287
|
-
expect(subject[:duck]).to eq ["Cluck", "Gobble"]
|
288
|
-
end
|
289
|
-
|
290
|
-
it "accepts string keys" do
|
291
|
-
subject['duck'] = ["Cluck", "Gobble"]
|
292
|
-
expect(subject['duck']).to eq ["Cluck", "Gobble"]
|
293
|
-
end
|
294
|
-
|
295
|
-
it "accepts field names with _id that are not associations" do
|
296
|
-
subject['animal_id'] = "lemur"
|
297
|
-
expect(subject['animal_id']).to eq "lemur"
|
298
|
-
end
|
299
|
-
|
300
|
-
it "raises an error on the reader when the field isn't delegated" do
|
301
|
-
expect { subject['donkey'] }.to raise_error ActiveFedora::UnknownAttributeError, "unknown attribute 'donkey' for BarHistory2."
|
302
|
-
end
|
303
|
-
|
304
|
-
it "raises an error on the setter when the field isn't delegated" do
|
305
|
-
expect { subject['donkey'] = "bray" }.to raise_error ActiveFedora::UnknownAttributeError, "unknown attribute 'donkey' for BarHistory2."
|
43
|
+
it "shows a id" do
|
44
|
+
expect(subject.inspect).to eq "#<BarHistory4 id: \"test:123\", title: [\"test1\"], abstract: nil>"
|
306
45
|
end
|
307
46
|
end
|
308
47
|
|
309
|
-
describe "attributes
|
310
|
-
|
311
|
-
|
48
|
+
describe "with no attributes" do
|
49
|
+
subject { described_class.new }
|
50
|
+
it "shows a id" do
|
51
|
+
expect(subject.inspect).to eq "#<ActiveFedora::Base id: nil>"
|
312
52
|
end
|
313
53
|
end
|
314
54
|
|
315
|
-
describe "
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
expect(subject.attributes).to eq(vals.merge('id' => nil))
|
320
|
-
end
|
321
|
-
end
|
322
|
-
|
323
|
-
describe '.multiple?', focus: true do
|
324
|
-
it 'returns false if attribute has not been defined as multi-valued' do
|
325
|
-
expect(BarHistory2.multiple?(:pig)).to be false
|
326
|
-
end
|
327
|
-
|
328
|
-
it 'returns true if attribute is a ActiveTriples property' do
|
329
|
-
expect(BarHistory2.multiple?(:goose)).to be true
|
330
|
-
end
|
331
|
-
|
332
|
-
it 'returns true if attribute has been defined as multi-valued' do
|
333
|
-
expect(BarHistory2.multiple?(:horse)).to be true
|
334
|
-
end
|
335
|
-
|
336
|
-
it 'raises an error if the attribute does not exist' do
|
337
|
-
expect { BarHistory2.multiple?(:arbitrary_nonexistent_attribute) }.to raise_error ActiveFedora::UnknownAttributeError, "unknown attribute 'arbitrary_nonexistent_attribute' for BarHistory2."
|
338
|
-
end
|
339
|
-
end
|
340
|
-
|
341
|
-
describe ".datastream_class_for_name" do
|
342
|
-
it "returns the specifed class" do
|
343
|
-
expect(BarHistory2.send(:datastream_class_for_name, 'someData')).to eq MyDS1
|
344
|
-
end
|
345
|
-
end
|
346
|
-
end
|
347
|
-
|
348
|
-
describe "with a superclass" do
|
349
|
-
before :all do
|
350
|
-
class BarHistory2 < ActiveFedora::Base
|
351
|
-
has_subresource 'xmlish', class_name: 'BarStream2'
|
352
|
-
Deprecation.silence(ActiveFedora::Attributes) do
|
353
|
-
has_attributes :donkey, :cow, datastream: 'xmlish', multiple: true
|
55
|
+
describe "with relationships" do
|
56
|
+
before do
|
57
|
+
class BarHistory2 < BarHistory4
|
58
|
+
belongs_to :library, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.hasConstituent, class_name: 'BarHistory4'
|
354
59
|
end
|
60
|
+
subject.library = library
|
355
61
|
end
|
356
|
-
class BarHistory3 < BarHistory2
|
357
|
-
end
|
358
|
-
end
|
359
|
-
|
360
|
-
after :all do
|
361
|
-
Object.send(:remove_const, :BarHistory3)
|
362
|
-
Object.send(:remove_const, :BarHistory2)
|
363
|
-
end
|
364
|
-
|
365
|
-
subject { BarHistory3.new }
|
366
|
-
|
367
|
-
it "is able to delegate deeply into the terminology" do
|
368
|
-
subject.donkey = ["Bray", "Hee-haw"]
|
369
|
-
expect(subject.donkey).to eq ["Bray", "Hee-haw"]
|
370
|
-
end
|
371
|
-
|
372
|
-
it "is able to track change status" do
|
373
|
-
expect {
|
374
|
-
subject.cow = ["Moo"]
|
375
|
-
}.to change { subject.cow_changed? }.from(false).to(true)
|
376
|
-
end
|
377
|
-
end
|
378
|
-
end
|
379
|
-
|
380
|
-
context "with a RDF datastream" do
|
381
|
-
before :all do
|
382
|
-
class BarRdfDatastream < ActiveFedora::NtriplesRDFDatastream
|
383
|
-
property :title, predicate: ::RDF::Vocab::DC.title
|
384
|
-
property :description, predicate: ::RDF::Vocab::DC.description
|
385
|
-
end
|
386
|
-
class BarHistory4 < ActiveFedora::Base
|
387
|
-
has_subresource 'rdfish', class_name: 'BarRdfDatastream'
|
388
|
-
Deprecation.silence(ActiveFedora::Attributes) do
|
389
|
-
has_attributes :title, datastream: 'rdfish', multiple: true
|
390
|
-
has_attributes :description, datastream: 'rdfish', multiple: false
|
391
|
-
end
|
392
|
-
end
|
393
|
-
end
|
394
62
|
|
395
|
-
|
396
|
-
|
397
|
-
Object.send(:remove_const, :BarRdfDatastream)
|
398
|
-
end
|
399
|
-
|
400
|
-
subject { BarHistory4.new }
|
401
|
-
|
402
|
-
context "with a multivalued field" do
|
403
|
-
it "is able to track change status" do
|
404
|
-
expect {
|
405
|
-
subject.title = ["Title1", "Title2"]
|
406
|
-
}.to change { subject.title_changed? }.from(false).to(true)
|
407
|
-
end
|
408
|
-
end
|
63
|
+
let(:library) { BarHistory4.create }
|
64
|
+
subject { BarHistory2.new }
|
409
65
|
|
410
|
-
|
411
|
-
|
412
|
-
expect {
|
413
|
-
subject.description = "A brief description"
|
414
|
-
}.to change { subject.description_changed? }.from(false).to(true)
|
415
|
-
end
|
416
|
-
end
|
417
|
-
end
|
418
|
-
|
419
|
-
context "without a datastream" do
|
420
|
-
before :all do
|
421
|
-
class BarHistory4 < ActiveFedora::Base
|
422
|
-
end
|
423
|
-
end
|
424
|
-
|
425
|
-
after :all do
|
426
|
-
Object.send(:remove_const, :BarHistory4)
|
427
|
-
end
|
428
|
-
|
429
|
-
subject { BarHistory4 }
|
430
|
-
|
431
|
-
describe "has_attributes" do
|
432
|
-
it "raises an error" do
|
433
|
-
Deprecation.silence(ActiveFedora::Attributes) do
|
434
|
-
expect { subject.has_attributes :title, :description, multiple: true }.to raise_error
|
435
|
-
end
|
436
|
-
end
|
437
|
-
end
|
438
|
-
end
|
439
|
-
|
440
|
-
context "when an unknown datastream is specified" do
|
441
|
-
before :all do
|
442
|
-
class BarHistory4 < ActiveFedora::Base
|
443
|
-
Deprecation.silence(ActiveFedora::Attributes) do
|
444
|
-
has_attributes :description, datastream: 'rdfish', multiple: true
|
66
|
+
after do
|
67
|
+
Object.send(:remove_const, :BarHistory2)
|
445
68
|
end
|
446
|
-
end
|
447
|
-
end
|
448
69
|
|
449
|
-
|
450
|
-
|
451
|
-
end
|
452
|
-
|
453
|
-
subject { BarHistory4.new }
|
454
|
-
|
455
|
-
let(:error_message) { "Undefined file: `rdfish' in property description" }
|
456
|
-
|
457
|
-
it "raises an error on get" do
|
458
|
-
expect { subject.description }.to raise_error(ArgumentError, error_message)
|
459
|
-
end
|
460
|
-
|
461
|
-
it "raises an error on set" do
|
462
|
-
expect { subject.description = ['Neat'] }.to raise_error(ArgumentError, error_message)
|
463
|
-
end
|
464
|
-
|
465
|
-
describe ".datastream_class_for_name" do
|
466
|
-
it "returns the default class" do
|
467
|
-
expect(BarHistory4.send(:datastream_class_for_name, 'content')).to eq ActiveFedora::File
|
468
|
-
end
|
469
|
-
end
|
470
|
-
end
|
471
|
-
|
472
|
-
context "when a datastream is specified as a symbol" do
|
473
|
-
before :all do
|
474
|
-
class BarRdfDatastream < ActiveFedora::NtriplesRDFDatastream
|
475
|
-
property :title, predicate: ::RDF::Vocab::DC.title
|
476
|
-
property :description, predicate: ::RDF::Vocab::DC.description
|
477
|
-
end
|
478
|
-
class BarHistory4 < ActiveFedora::Base
|
479
|
-
has_subresource 'rdfish', class_name: 'BarRdfDatastream'
|
480
|
-
Deprecation.silence(ActiveFedora::Attributes) do
|
481
|
-
has_attributes :description, datastream: :rdfish
|
70
|
+
it "shows the library_id" do
|
71
|
+
expect(subject.inspect).to eq "#<BarHistory2 id: nil, title: [], abstract: nil, library_id: \"#{library.id}\">"
|
482
72
|
end
|
483
73
|
end
|
484
74
|
end
|
485
75
|
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
subject { BarHistory4.new(description: 'test1') }
|
492
|
-
|
493
|
-
it "is able to access the attributes" do
|
494
|
-
expect(subject.description).to eq 'test1'
|
495
|
-
end
|
496
|
-
end
|
497
|
-
|
498
|
-
context "when properties are defined on an object" do
|
499
|
-
before :all do
|
500
|
-
class BarHistory4 < ActiveFedora::Base
|
501
|
-
property :title, predicate: ::RDF::Vocab::DC.title do |index|
|
502
|
-
index.as :symbol
|
503
|
-
end
|
504
|
-
property :abstract, predicate: ::RDF::Vocab::DC.abstract, multiple: false
|
76
|
+
describe "#unique?" do
|
77
|
+
it "reveals the unique properties" do
|
78
|
+
expect(BarHistory4.unique?(:abstract)).to be true
|
79
|
+
expect(BarHistory4.unique?(:title)).to be false
|
505
80
|
end
|
506
81
|
end
|
507
82
|
|
508
|
-
after :all do
|
509
|
-
Object.send(:remove_const, :BarHistory4)
|
510
|
-
end
|
511
|
-
|
512
|
-
let(:obj) { BarHistory4.new(title: ['test1']) }
|
513
|
-
subject { obj }
|
514
|
-
|
515
83
|
describe "accessing attributes" do
|
516
84
|
context "using generated methods" do
|
517
85
|
it "returns values" do
|
@@ -550,7 +118,15 @@ describe ActiveFedora::Base do
|
|
550
118
|
end
|
551
119
|
end
|
552
120
|
|
553
|
-
|
121
|
+
describe 'change tracking' do
|
122
|
+
it "is able to track change status" do
|
123
|
+
expect {
|
124
|
+
subject.abstract = "Moo"
|
125
|
+
}.to change { subject.abstract_changed? }.from(false).to(true)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
describe "indexing" do
|
554
130
|
let(:solr_doc) { obj.to_solr }
|
555
131
|
|
556
132
|
it "indexs the attributes" do
|