active-triples 0.8.1 → 0.8.2
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/.travis.yml +8 -9
- data/CHANGES.md +69 -0
- data/Gemfile +0 -2
- data/Guardfile +1 -2
- data/active-triples.gemspec +3 -3
- data/lib/active/triples.rb +1 -0
- data/lib/active_triples.rb +4 -0
- data/lib/active_triples/configurable.rb +3 -1
- data/lib/active_triples/configuration.rb +1 -0
- data/lib/active_triples/configuration/item.rb +1 -0
- data/lib/active_triples/configuration/item_factory.rb +1 -0
- data/lib/active_triples/configuration/merge_item.rb +5 -2
- data/lib/active_triples/extension_strategy.rb +1 -0
- data/lib/active_triples/identifiable.rb +1 -0
- data/lib/active_triples/list.rb +2 -0
- data/lib/active_triples/nested_attributes.rb +1 -1
- data/lib/active_triples/node_config.rb +5 -3
- data/lib/active_triples/persistable.rb +1 -0
- data/lib/active_triples/persistence_strategies/parent_strategy.rb +104 -29
- data/lib/active_triples/persistence_strategies/persistence_strategy.rb +15 -7
- data/lib/active_triples/persistence_strategies/repository_strategy.rb +26 -22
- data/lib/active_triples/properties.rb +84 -6
- data/lib/active_triples/property.rb +35 -4
- data/lib/active_triples/property_builder.rb +38 -4
- data/lib/active_triples/rdf_source.rb +225 -75
- data/lib/active_triples/reflection.rb +42 -3
- data/lib/active_triples/relation.rb +330 -73
- data/lib/active_triples/repositories.rb +4 -2
- data/lib/active_triples/resource.rb +1 -0
- data/lib/active_triples/schema.rb +1 -0
- data/lib/active_triples/undefined_property_error.rb +27 -0
- data/lib/active_triples/version.rb +2 -1
- data/spec/active_triples/configurable_spec.rb +3 -2
- data/spec/active_triples/configuration_spec.rb +2 -1
- data/spec/active_triples/extension_strategy_spec.rb +2 -1
- data/spec/active_triples/identifiable_spec.rb +7 -11
- data/spec/active_triples/list_spec.rb +1 -4
- data/spec/active_triples/nested_attributes_spec.rb +4 -3
- data/spec/active_triples/persistable_spec.rb +4 -1
- data/spec/active_triples/persistence_strategies/parent_strategy_spec.rb +141 -11
- data/spec/active_triples/persistence_strategies/persistence_strategy_spec.rb +1 -0
- data/spec/active_triples/persistence_strategies/repository_strategy_spec.rb +32 -17
- data/spec/active_triples/properties_spec.rb +68 -33
- data/spec/active_triples/property_builder_spec.rb +36 -0
- data/spec/active_triples/property_spec.rb +15 -1
- data/spec/active_triples/rdf_source_spec.rb +544 -6
- data/spec/active_triples/reflection_spec.rb +78 -0
- data/spec/active_triples/relation_spec.rb +505 -3
- data/spec/active_triples/repositories_spec.rb +3 -1
- data/spec/active_triples/resource_spec.rb +90 -147
- data/spec/active_triples/schema_spec.rb +3 -2
- data/spec/active_triples_spec.rb +1 -0
- data/spec/integration/dummies/dummy_resource_a.rb +6 -0
- data/spec/integration/dummies/dummy_resource_b.rb +6 -0
- data/spec/integration/parent_persistence_spec.rb +18 -0
- data/spec/integration/reciprocal_properties_spec.rb +69 -0
- data/spec/pragmatic_context_spec.rb +10 -8
- data/spec/spec_helper.rb +5 -0
- data/spec/support/active_model_lint.rb +4 -6
- data/spec/support/dummies/basic_persistable.rb +2 -11
- data/spec/support/matchers.rb +11 -0
- data/spec/support/shared_examples/persistence_strategy.rb +3 -16
- metadata +20 -13
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module ActiveTriples
|
2
3
|
##
|
3
4
|
# Defines module methods for registering an RDF::Repository for
|
@@ -26,9 +27,10 @@ module ActiveTriples
|
|
26
27
|
#
|
27
28
|
# @return [RDF::Repository] gives the original repository on success
|
28
29
|
#
|
29
|
-
# @raise [
|
30
|
+
# @raise [ArgumentError] raised if the repository is not an `RDF::Repository`
|
30
31
|
def add_repository(name, repo)
|
31
|
-
raise "Repositories must be an RDF::Repository" unless
|
32
|
+
raise ArgumentError, "Repositories must be an RDF::Repository" unless
|
33
|
+
repo.kind_of? RDF::Repository
|
32
34
|
repositories[name] = repo
|
33
35
|
end
|
34
36
|
module_function :add_repository
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module ActiveTriples
|
3
|
+
##
|
4
|
+
# An error class to be raised when attempting to reflect on an undefined
|
5
|
+
# property.
|
6
|
+
#
|
7
|
+
# @example
|
8
|
+
# begin
|
9
|
+
# my_source.set_value(:fake_property, 'blah')
|
10
|
+
# rescue ActiveTriples::UndefinedPropertyError => e
|
11
|
+
# e.property => 'fake_property'
|
12
|
+
# e.klass => 'MySourceClass'
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
class UndefinedPropertyError < ArgumentError
|
16
|
+
attr_reader :property, :klass
|
17
|
+
|
18
|
+
def initialize(property, klass)
|
19
|
+
@property = property
|
20
|
+
@klass = klass
|
21
|
+
end
|
22
|
+
|
23
|
+
def message
|
24
|
+
"The property `#{@property}` is not defined on class '#{@klass}'"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require "spec_helper"
|
2
3
|
|
3
4
|
describe ActiveTriples::Configurable do
|
@@ -22,7 +23,7 @@ describe ActiveTriples::Configurable do
|
|
22
23
|
|
23
24
|
describe '#configure' do
|
24
25
|
before do
|
25
|
-
DummyConfigurable.configure base_uri: "http://example.org/base", type: RDF::RDFS.Class, rdf_label: RDF::DC.title
|
26
|
+
DummyConfigurable.configure base_uri: "http://example.org/base", type: RDF::RDFS.Class, rdf_label: RDF::Vocab::DC.title
|
26
27
|
end
|
27
28
|
|
28
29
|
it 'should set a base uri' do
|
@@ -35,7 +36,7 @@ describe ActiveTriples::Configurable do
|
|
35
36
|
end
|
36
37
|
|
37
38
|
it 'should set an rdf_label' do
|
38
|
-
expect(DummyConfigurable.rdf_label).to eq RDF::DC.title
|
39
|
+
expect(DummyConfigurable.rdf_label).to eq RDF::Vocab::DC.title
|
39
40
|
end
|
40
41
|
|
41
42
|
it 'should set a type' do
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
RSpec.describe ActiveTriples::Configuration do
|
@@ -43,7 +44,7 @@ RSpec.describe ActiveTriples::Configuration do
|
|
43
44
|
describe "#merge" do
|
44
45
|
let(:starting_hash) do
|
45
46
|
{
|
46
|
-
:rdf_label => RDF::SKOS.prefLabel,
|
47
|
+
:rdf_label => RDF::Vocab::SKOS.prefLabel,
|
47
48
|
:type => RDF::RDFS.Class
|
48
49
|
}
|
49
50
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
RSpec.describe ActiveTriples::ExtensionStrategy do
|
@@ -6,7 +7,7 @@ RSpec.describe ActiveTriples::ExtensionStrategy do
|
|
6
7
|
describe ".apply" do
|
7
8
|
it "should copy the property to the asset" do
|
8
9
|
asset = build_asset
|
9
|
-
property = build_property("name", {:predicate => RDF::DC.title})
|
10
|
+
property = build_property("name", {:predicate => RDF::Vocab::DC.title})
|
10
11
|
|
11
12
|
subject.apply(asset, property)
|
12
13
|
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
require 'active_model'
|
3
4
|
|
@@ -19,12 +20,12 @@ describe ActiveTriples::Identifiable do
|
|
19
20
|
before do
|
20
21
|
class MyResource
|
21
22
|
include ActiveTriples::RDFSource
|
22
|
-
property :relation, predicate: RDF::DC.relation, class_name: 'ActiveExample'
|
23
|
+
property :relation, predicate: RDF::Vocab::DC.relation, class_name: 'ActiveExample'
|
23
24
|
end
|
24
25
|
|
25
|
-
klass.property :title, predicate: RDF::DC.title
|
26
|
-
klass.property :identifier, predicate: RDF::DC.identifier
|
27
|
-
klass.property :description, predicate: RDF::DC.description
|
26
|
+
klass.property :title, predicate: RDF::Vocab::DC.title
|
27
|
+
klass.property :identifier, predicate: RDF::Vocab::DC.identifier
|
28
|
+
klass.property :description, predicate: RDF::Vocab::DC.description
|
28
29
|
|
29
30
|
subject.resource.title = 'Moomin Valley in November'
|
30
31
|
subject.resource.identifier = 'moomvember'
|
@@ -84,7 +85,7 @@ describe ActiveTriples::Identifiable do
|
|
84
85
|
|
85
86
|
describe '::properties' do
|
86
87
|
before do
|
87
|
-
klass.property :title, :predicate => RDF::DC.title
|
88
|
+
klass.property :title, :predicate => RDF::Vocab::DC.title
|
88
89
|
end
|
89
90
|
it 'can be set' do
|
90
91
|
expect(klass.properties).to include 'title'
|
@@ -116,7 +117,7 @@ describe ActiveTriples::Identifiable do
|
|
116
117
|
end
|
117
118
|
|
118
119
|
it 'does not effect other classes' do
|
119
|
-
klass.property :identifier, :predicate => RDF::DC.identifier
|
120
|
+
klass.property :identifier, :predicate => RDF::Vocab::DC.identifier
|
120
121
|
expect(ActiveExampleTwo.properties).to be_empty
|
121
122
|
end
|
122
123
|
end
|
@@ -140,11 +141,6 @@ describe ActiveTriples::Identifiable do
|
|
140
141
|
it 'has a parent' do
|
141
142
|
expect(parent.relation.first.parent).to eq parent
|
142
143
|
end
|
143
|
-
|
144
|
-
it 'has a parent after reload' do
|
145
|
-
parent.relation.node_cache = {}
|
146
|
-
expect(parent.relation.first.parent).to eq parent
|
147
|
-
end
|
148
144
|
end
|
149
145
|
end
|
150
146
|
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
require 'nokogiri'
|
3
4
|
require 'linkeddata'
|
@@ -31,10 +32,6 @@ describe ActiveTriples::List do
|
|
31
32
|
expect(subject.subject).not_to eq RDF.nil
|
32
33
|
end
|
33
34
|
|
34
|
-
it 'has a non-nil subject' do
|
35
|
-
expect(subject.subject).not_to eq RDF.nil
|
36
|
-
end
|
37
|
-
|
38
35
|
it 'has type of rdf:List' do
|
39
36
|
expect(subject.type.first).to eq RDF.List
|
40
37
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe "nesting attribute behavior" do
|
@@ -28,7 +29,7 @@ describe "nesting attribute behavior" do
|
|
28
29
|
include ActiveTriples::RDFSource
|
29
30
|
property :topic, predicate: DummyMADS.Topic, class_name: "Topic"
|
30
31
|
property :personalName, predicate: DummyMADS.PersonalName, class_name: "PersonalName"
|
31
|
-
property :title, predicate: RDF::DC.title
|
32
|
+
property :title, predicate: RDF::Vocab::DC.title
|
32
33
|
|
33
34
|
|
34
35
|
accepts_nested_attributes_for :topic, :personalName
|
@@ -149,12 +150,12 @@ describe "nesting attribute behavior" do
|
|
149
150
|
before do
|
150
151
|
class SpecResource
|
151
152
|
include ActiveTriples::RDFSource
|
152
|
-
property :parts, predicate: RDF::DC.hasPart, :class_name=>'Component'
|
153
|
+
property :parts, predicate: RDF::Vocab::DC.hasPart, :class_name=>'Component'
|
153
154
|
accepts_nested_attributes_for :parts, allow_destroy: true
|
154
155
|
|
155
156
|
class Component
|
156
157
|
include ActiveTriples::RDFSource
|
157
|
-
property :label, predicate: RDF::DC.title
|
158
|
+
property :label, predicate: RDF::Vocab::DC.title
|
158
159
|
end
|
159
160
|
end
|
160
161
|
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe ActiveTriples::Persistable do
|
@@ -5,7 +6,9 @@ describe ActiveTriples::Persistable do
|
|
5
6
|
|
6
7
|
let(:klass) { Class.new { include ActiveTriples::Persistable } }
|
7
8
|
|
8
|
-
let(:statement)
|
9
|
+
let(:statement) do
|
10
|
+
RDF::Statement(RDF::Node.new, RDF::Vocab::DC.title, 'Moomin')
|
11
|
+
end
|
9
12
|
|
10
13
|
it 'raises an error with no #graph implementation' do
|
11
14
|
expect { subject << statement }.to raise_error(NameError, /graph/)
|
@@ -1,25 +1,121 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe ActiveTriples::ParentStrategy do
|
4
5
|
subject { described_class.new(rdf_source) }
|
5
6
|
let(:rdf_source) { BasicPersistable.new }
|
6
|
-
|
7
|
+
|
7
8
|
shared_context 'with a parent' do
|
9
|
+
let(:parent) { BasicPersistable.new }
|
10
|
+
|
8
11
|
before do
|
9
12
|
subject.parent = parent
|
10
|
-
end
|
11
13
|
|
12
|
-
|
14
|
+
rdf_source.set_persistence_strategy(described_class)
|
15
|
+
rdf_source.persistence_strategy.parent = parent
|
16
|
+
end
|
13
17
|
end
|
14
18
|
|
15
19
|
context 'with a parent' do
|
16
20
|
include_context 'with a parent'
|
17
21
|
it_behaves_like 'a persistence strategy'
|
22
|
+
|
23
|
+
describe '#persisted?' do
|
24
|
+
context 'before persist!' do
|
25
|
+
it 'returns false' do
|
26
|
+
expect(subject).not_to be_persisted
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'after persist!' do
|
31
|
+
context "when the parent is not persisted" do
|
32
|
+
before { subject.persist! }
|
33
|
+
it { is_expected.not_to be_persisted }
|
34
|
+
end
|
35
|
+
|
36
|
+
context "when the parent is persisted" do
|
37
|
+
before do
|
38
|
+
allow(parent).to receive(:persisted?).and_return(true)
|
39
|
+
subject.persist!
|
40
|
+
end
|
41
|
+
it { is_expected.to be_persisted }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '#destroy' do
|
48
|
+
include_context 'with a parent'
|
49
|
+
|
50
|
+
before do
|
51
|
+
rdf_source.insert(*statements)
|
52
|
+
subject.persist!
|
53
|
+
end
|
54
|
+
|
55
|
+
let(:statements) do
|
56
|
+
[RDF::Statement(subject.source.rdf_subject, RDF::Vocab::DC.title, 'moomin'),
|
57
|
+
RDF::Statement(:node, RDF::Vocab::DC.relation, subject.source.rdf_subject),
|
58
|
+
RDF::Statement(:node, RDF::Vocab::DC.relation, :other_node)]
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'removes graph from the parent' do
|
62
|
+
subject.destroy
|
63
|
+
|
64
|
+
statements.each do |statement|
|
65
|
+
expect(subject.parent.statements).not_to have_statement statement
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'removes subjects from parent' do
|
70
|
+
subject.destroy
|
71
|
+
expect(subject.parent).not_to have_subject(rdf_source)
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'removes objects from parent' do
|
75
|
+
subject.destroy
|
76
|
+
expect(subject.parent).not_to have_object(rdf_source)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe '#ancestors' do
|
81
|
+
it 'raises NilParentError when enumerating' do
|
82
|
+
expect { subject.ancestors.next }
|
83
|
+
.to raise_error described_class::NilParentError
|
84
|
+
end
|
85
|
+
|
86
|
+
context 'with parent' do
|
87
|
+
include_context 'with a parent'
|
88
|
+
|
89
|
+
it 'gives the parent' do
|
90
|
+
expect(subject.ancestors).to contain_exactly(parent)
|
91
|
+
end
|
92
|
+
|
93
|
+
context 'and nested parents' do
|
94
|
+
let(:parents) do
|
95
|
+
[double('second', persistence_strategy: double('strategy2')),
|
96
|
+
double('third', persistence_strategy: double('strategy3'))]
|
97
|
+
end
|
98
|
+
let(:last) { double('last', persistence_strategy: double('last_strategy')) }
|
99
|
+
|
100
|
+
it 'gives all ancestors' do
|
101
|
+
allow(parent.persistence_strategy)
|
102
|
+
.to receive(:parent).and_return(parents.first)
|
103
|
+
allow(parents.first.persistence_strategy)
|
104
|
+
.to receive(:parent).and_return(parents[1])
|
105
|
+
allow(parents[1].persistence_strategy)
|
106
|
+
.to receive(:parent).and_return(last)
|
107
|
+
|
108
|
+
expect(subject.ancestors)
|
109
|
+
.to contain_exactly(*(parents << parent << last))
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
18
113
|
end
|
19
114
|
|
20
115
|
describe '#final_parent' do
|
21
116
|
it 'raises an error with no parent' do
|
22
|
-
expect { subject.final_parent }
|
117
|
+
expect { subject.final_parent }
|
118
|
+
.to raise_error described_class::NilParentError
|
23
119
|
end
|
24
120
|
|
25
121
|
context 'with single parent' do
|
@@ -32,22 +128,20 @@ describe ActiveTriples::ParentStrategy do
|
|
32
128
|
|
33
129
|
context 'with parent chain' do
|
34
130
|
include_context 'with a parent'
|
35
|
-
let(:last) { double('last') }
|
131
|
+
let(:last) { double('last', persistence_strategy: nil) }
|
36
132
|
|
37
133
|
it 'gives last parent terminating when no futher parents given' do
|
38
|
-
allow(parent).to receive(:parent).and_return(last)
|
134
|
+
allow(parent.persistence_strategy).to receive(:parent).and_return(last)
|
39
135
|
expect(subject.final_parent).to eq last
|
40
136
|
end
|
41
137
|
|
42
138
|
it 'gives last parent terminating parent is nil' do
|
43
|
-
allow(parent).to receive(:parent).and_return(last)
|
44
|
-
allow(last).to receive(:parentt).and_return(nil)
|
139
|
+
allow(parent.persistence_strategy).to receive(:parent).and_return(last)
|
45
140
|
expect(subject.final_parent).to eq last
|
46
141
|
end
|
47
142
|
|
48
143
|
it 'gives last parent terminating parent is same as current' do
|
49
|
-
allow(parent).to receive(:parent).and_return(last)
|
50
|
-
allow(last).to receive(:parentt).and_return(last)
|
144
|
+
allow(parent.persistence_strategy).to receive(:parent).and_return(last)
|
51
145
|
expect(subject.final_parent).to eq last
|
52
146
|
end
|
53
147
|
end
|
@@ -83,7 +177,8 @@ describe ActiveTriples::ParentStrategy do
|
|
83
177
|
include_context 'with a parent'
|
84
178
|
|
85
179
|
it 'writes to #final_parent graph' do
|
86
|
-
rdf_source << RDF::
|
180
|
+
rdf_source << [RDF::Node.new, RDF::Vocab::DC.title, 'moomin']
|
181
|
+
|
87
182
|
subject.persist!
|
88
183
|
expect(subject.final_parent.statements)
|
89
184
|
.to contain_exactly *rdf_source.statements
|
@@ -91,3 +186,38 @@ describe ActiveTriples::ParentStrategy do
|
|
91
186
|
end
|
92
187
|
end
|
93
188
|
end
|
189
|
+
|
190
|
+
describe ActiveTriples::ParentStrategy::Ancestors do
|
191
|
+
subject { described_class.new(rdf_source) }
|
192
|
+
|
193
|
+
let(:rdf_source) { BasicPersistable.new }
|
194
|
+
|
195
|
+
describe '#each' do
|
196
|
+
it 'raises NilParentError' do
|
197
|
+
expect { subject.each }
|
198
|
+
.to raise_error ActiveTriples::ParentStrategy::NilParentError
|
199
|
+
end
|
200
|
+
|
201
|
+
context 'with parents' do
|
202
|
+
let(:parent) { BasicPersistable.new }
|
203
|
+
let(:last) { BasicPersistable.new }
|
204
|
+
|
205
|
+
before do
|
206
|
+
parent.set_persistence_strategy(ActiveTriples::ParentStrategy)
|
207
|
+
parent.persistence_strategy.parent = last
|
208
|
+
rdf_source.set_persistence_strategy(ActiveTriples::ParentStrategy)
|
209
|
+
rdf_source.persistence_strategy.parent = parent
|
210
|
+
end
|
211
|
+
|
212
|
+
it { expect(subject.each).to be_a Enumerator }
|
213
|
+
|
214
|
+
it 'enumerates ancestors' do
|
215
|
+
expect(subject.each).to contain_exactly(parent, last)
|
216
|
+
end
|
217
|
+
|
218
|
+
it 'yields ancestors' do
|
219
|
+
expect { |b| subject.each(&b) }.to yield_successive_args(parent, last)
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
@@ -1,19 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe ActiveTriples::RepositoryStrategy do
|
4
5
|
subject { described_class.new(rdf_source) }
|
5
|
-
let(:
|
6
|
+
let(:source_class) { class MySource; include ActiveTriples::RDFSource; end }
|
7
|
+
let(:rdf_source) { source_class.new }
|
6
8
|
|
7
9
|
let(:statement) do
|
8
|
-
RDF::Statement.new(rdf_source.to_term, RDF::DC.title, 'moomin')
|
10
|
+
RDF::Statement.new(rdf_source.to_term, RDF::Vocab::DC.title, 'moomin')
|
9
11
|
end
|
10
12
|
|
11
13
|
it_behaves_like 'a persistence strategy'
|
12
14
|
|
15
|
+
|
16
|
+
describe '#persisted?' do
|
17
|
+
context 'before persist!' do
|
18
|
+
it 'returns false' do
|
19
|
+
expect(subject).not_to be_persisted
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'after persist!' do
|
24
|
+
it 'returns true' do
|
25
|
+
subject.persist!
|
26
|
+
expect(subject).to be_persisted
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
13
31
|
shared_context 'with repository' do
|
32
|
+
let(:repo) { RDF::Repository.new }
|
14
33
|
before do
|
15
|
-
|
16
|
-
|
34
|
+
source_class.configure repository: :my_repo
|
35
|
+
|
36
|
+
allow(ActiveTriples::Repositories.repositories)
|
37
|
+
.to receive(:[]).with(:my_repo).and_return(repo)
|
17
38
|
end
|
18
39
|
end
|
19
40
|
|
@@ -33,7 +54,7 @@ describe ActiveTriples::RepositoryStrategy do
|
|
33
54
|
|
34
55
|
it 'leaves other resources unchanged' do
|
35
56
|
subject.repository <<
|
36
|
-
RDF::Statement(RDF::Node.new, RDF::DC.title, 'snorkmaiden')
|
57
|
+
RDF::Statement(RDF::Node.new, RDF::Vocab::DC.title, 'snorkmaiden')
|
37
58
|
expect { subject.destroy }
|
38
59
|
.not_to change { subject.repository.count }
|
39
60
|
end
|
@@ -45,7 +66,7 @@ describe ActiveTriples::RepositoryStrategy do
|
|
45
66
|
|
46
67
|
context 'with subjects' do
|
47
68
|
before do
|
48
|
-
subject.
|
69
|
+
subject.source.set_subject! RDF::URI('http://example.org/moomin')
|
49
70
|
end
|
50
71
|
|
51
72
|
include_examples 'destroy resource'
|
@@ -80,13 +101,7 @@ describe ActiveTriples::RepositoryStrategy do
|
|
80
101
|
|
81
102
|
context 'with unknown content in repo' do
|
82
103
|
include_context 'with repository' do
|
83
|
-
before
|
84
|
-
allow(ActiveTriples::Repositories.repositories)
|
85
|
-
.to receive(:[]).with(:my_repo).and_return(repo)
|
86
|
-
repo << statement
|
87
|
-
end
|
88
|
-
|
89
|
-
let(:repo) { RDF::Repository.new }
|
104
|
+
before { repo << statement }
|
90
105
|
end
|
91
106
|
end
|
92
107
|
end
|
@@ -103,16 +118,16 @@ describe ActiveTriples::RepositoryStrategy do
|
|
103
118
|
context 'with repository configured' do
|
104
119
|
include_context 'with repository'
|
105
120
|
|
106
|
-
let(:repo) { double('repo') }
|
107
|
-
|
108
121
|
it 'when repository is not registered raises an error' do
|
122
|
+
source_class.configure repository: :no_repo
|
123
|
+
|
124
|
+
allow(ActiveTriples::Repositories.repositories)
|
125
|
+
.to receive(:[]).with(:no_repo).and_call_original
|
109
126
|
expect { subject.repository }
|
110
127
|
.to raise_error ActiveTriples::RepositoryNotFoundError
|
111
128
|
end
|
112
129
|
|
113
130
|
it 'gets repository' do
|
114
|
-
allow(ActiveTriples::Repositories.repositories)
|
115
|
-
.to receive(:[]).with(:my_repo).and_return(repo)
|
116
131
|
expect(subject.repository).to eq repo
|
117
132
|
end
|
118
133
|
end
|