active-triples 0.7.6 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -3
- data/AUTHORS +1 -1
- data/CHANGES.md +12 -17
- data/Gemfile +2 -0
- data/README.md +2 -2
- data/active-triples.gemspec +6 -5
- data/lib/active_triples.rb +56 -5
- data/lib/active_triples/configurable.rb +13 -17
- data/lib/active_triples/list.rb +22 -21
- data/lib/active_triples/persistable.rb +100 -0
- data/lib/active_triples/persistence_strategies/parent_strategy.rb +89 -0
- data/lib/active_triples/persistence_strategies/persistence_strategy.rb +77 -0
- data/lib/active_triples/persistence_strategies/repository_strategy.rb +78 -0
- data/lib/active_triples/properties.rb +2 -1
- data/lib/active_triples/rdf_source.rb +94 -159
- data/lib/active_triples/relation.rb +17 -45
- data/lib/active_triples/repositories.rb +23 -9
- data/lib/active_triples/version.rb +1 -1
- data/spec/active_triples/configurable_spec.rb +5 -9
- data/spec/active_triples/identifiable_spec.rb +1 -18
- data/spec/active_triples/list_spec.rb +0 -4
- data/spec/active_triples/persistable_spec.rb +93 -0
- data/spec/active_triples/persistence_strategies/parent_strategy_spec.rb +93 -0
- data/spec/active_triples/persistence_strategies/persistence_strategy_spec.rb +24 -0
- data/spec/active_triples/persistence_strategies/repository_strategy_spec.rb +120 -0
- data/spec/active_triples/rdf_source_spec.rb +217 -9
- data/spec/active_triples/relation_spec.rb +51 -4
- data/spec/active_triples/repositories_spec.rb +17 -7
- data/spec/active_triples/resource_spec.rb +6 -53
- data/spec/active_triples_spec.rb +50 -1
- data/spec/spec_helper.rb +5 -1
- data/spec/support/active_model_lint.rb +6 -3
- data/spec/support/dummies/basic_persistable.rb +13 -0
- data/spec/support/shared_examples/persistence_strategy.rb +36 -0
- metadata +32 -9
- data/spec/active_triples/validations_spec.rb +0 -33
@@ -13,9 +13,9 @@ describe ActiveTriples::Repositories do
|
|
13
13
|
subject.add_repository :name, RDF::Repository.new
|
14
14
|
expect(subject.repositories).to include :name
|
15
15
|
end
|
16
|
+
|
16
17
|
it 'should throw an error if passed something that is not a repository' do
|
17
|
-
expect{subject.add_repository :name, :not_a_repo}
|
18
|
-
.to raise_error ArgumentError
|
18
|
+
expect{subject.add_repository :name, :not_a_repo}.to raise_error
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
@@ -74,19 +74,25 @@ describe ActiveTriples::Repositories do
|
|
74
74
|
context 'when checking only one named repository' do
|
75
75
|
context 'and rdf_subject exists in the repository' do
|
76
76
|
it 'should return true' do
|
77
|
-
expect(ActiveTriples::Repositories
|
77
|
+
expect(ActiveTriples::Repositories
|
78
|
+
.has_subject?(resource2.rdf_subject,:repo2))
|
79
|
+
.to be_truthy
|
78
80
|
end
|
79
81
|
end
|
80
82
|
|
81
83
|
context 'and rdf_subject exists in another repository' do
|
82
84
|
it 'should return false' do
|
83
|
-
expect(ActiveTriples::Repositories
|
85
|
+
expect(ActiveTriples::Repositories
|
86
|
+
.has_subject?(resource2.rdf_subject,:repo1))
|
87
|
+
.to be_falsey
|
84
88
|
end
|
85
89
|
end
|
86
90
|
|
87
91
|
context 'and rdf_subject does not exists in any repository' do
|
88
92
|
it 'should return false' do
|
89
|
-
expect(ActiveTriples::Repositories
|
93
|
+
expect(ActiveTriples::Repositories
|
94
|
+
.has_subject?("#{resource2.rdf_subject}_NOEXIST",:repo1))
|
95
|
+
.to be_falsey
|
90
96
|
end
|
91
97
|
end
|
92
98
|
end
|
@@ -94,13 +100,17 @@ describe ActiveTriples::Repositories do
|
|
94
100
|
context 'when checking all repositories' do
|
95
101
|
context 'and rdf_subject exists in one repository' do
|
96
102
|
it 'should return true' do
|
97
|
-
expect(ActiveTriples::Repositories
|
103
|
+
expect(ActiveTriples::Repositories
|
104
|
+
.has_subject?(resource2.rdf_subject))
|
105
|
+
.to be_truthy
|
98
106
|
end
|
99
107
|
end
|
100
108
|
|
101
109
|
context 'and rdf_subject does not exists in any repository' do
|
102
110
|
it 'should return false' do
|
103
|
-
expect(ActiveTriples::Repositories
|
111
|
+
expect(ActiveTriples::Repositories
|
112
|
+
.has_subject?("#{resource2.rdf_subject}_NOEXIST"))
|
113
|
+
.to be_falsey
|
104
114
|
end
|
105
115
|
end
|
106
116
|
end
|
@@ -22,9 +22,7 @@ describe ActiveTriples::Resource do
|
|
22
22
|
|
23
23
|
describe '#property' do
|
24
24
|
it 'raises error when set directly on Resource' do
|
25
|
-
expect { ActiveTriples::Resource.property :blah, predicate
|
26
|
-
.to raise_error 'Properties not definable directly on ' \
|
27
|
-
'ActiveTriples::Resource, use a subclass'
|
25
|
+
expect { ActiveTriples::Resource.property :blah, :predicate => RDF::DC.title }.to raise_error
|
28
26
|
end
|
29
27
|
end
|
30
28
|
|
@@ -69,8 +67,7 @@ describe ActiveTriples::Resource do
|
|
69
67
|
end
|
70
68
|
|
71
69
|
it 'should not be settable' do
|
72
|
-
expect{ subject.set_subject! RDF::URI('http://example.org/moomin2') }
|
73
|
-
.to raise_error "Refusing update URI when one is already assigned!"
|
70
|
+
expect{ subject.set_subject! RDF::URI('http://example.org/moomin2') }.to raise_error
|
74
71
|
end
|
75
72
|
end
|
76
73
|
|
@@ -90,46 +87,6 @@ describe ActiveTriples::Resource do
|
|
90
87
|
end
|
91
88
|
end
|
92
89
|
|
93
|
-
describe "#reload" do
|
94
|
-
context 'with a repository' do
|
95
|
-
let(:resource) { DummyResourceWithRepo.new }
|
96
|
-
let(:repository) { RDF::Repository.new }
|
97
|
-
before do
|
98
|
-
class DummyResourceWithRepo < ActiveTriples::Resource
|
99
|
-
configure repository: :default
|
100
|
-
property :title, predicate: RDF::DC.title
|
101
|
-
end
|
102
|
-
ActiveTriples::Repositories.add_repository :default, repository
|
103
|
-
|
104
|
-
resource.title = "bla"
|
105
|
-
end
|
106
|
-
after do
|
107
|
-
Object.send(:remove_const, :DummyResourceWithRepo)
|
108
|
-
ActiveTriples::Repositories.clear_repositories!
|
109
|
-
end
|
110
|
-
|
111
|
-
context "and a persisted resource" do
|
112
|
-
before do
|
113
|
-
resource.persist!
|
114
|
-
resource.title = 'Foo'
|
115
|
-
resource.reload
|
116
|
-
end
|
117
|
-
subject { resource.title }
|
118
|
-
it { is_expected.to eq ['Foo'] }
|
119
|
-
end
|
120
|
-
|
121
|
-
context "and a b-node" do
|
122
|
-
before do
|
123
|
-
expect(repository).not_to receive(:query).with(subject: resource.rdf_subject)
|
124
|
-
resource.reload
|
125
|
-
resource.title = 'Foo'
|
126
|
-
end
|
127
|
-
subject { resource.title }
|
128
|
-
it { is_expected.to eq ['Foo'] }
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
90
|
describe "#persisted?" do
|
134
91
|
context 'with a repository' do
|
135
92
|
before do
|
@@ -162,7 +119,6 @@ describe ActiveTriples::Resource do
|
|
162
119
|
expect(subject).to be_persisted
|
163
120
|
end
|
164
121
|
end
|
165
|
-
|
166
122
|
context "and then reloaded" do
|
167
123
|
before do
|
168
124
|
subject.reload
|
@@ -190,7 +146,7 @@ describe ActiveTriples::Resource do
|
|
190
146
|
before do
|
191
147
|
@repo = RDF::Repository.new
|
192
148
|
allow(subject.class).to receive(:repository).and_return(nil)
|
193
|
-
allow(subject).to receive(:repository).and_return(@repo)
|
149
|
+
allow(subject.persistence_strategy).to receive(:repository).and_return(@repo)
|
194
150
|
subject.title = "bla"
|
195
151
|
result
|
196
152
|
end
|
@@ -518,8 +474,7 @@ describe ActiveTriples::Resource do
|
|
518
474
|
end
|
519
475
|
|
520
476
|
it 'raises error when trying to set nil value' do
|
521
|
-
expect { subject.aggregates[1] = nil }
|
522
|
-
.to raise_error ActiveTriples::Relation::ValueError
|
477
|
+
expect { subject.aggregates[1] = nil }.to raise_error /value must be an RDF URI, Node, Literal, or a valid datatype/
|
523
478
|
end
|
524
479
|
|
525
480
|
it "should be changeable for multiple values" do
|
@@ -605,8 +560,7 @@ describe ActiveTriples::Resource do
|
|
605
560
|
end
|
606
561
|
|
607
562
|
it "raise an error if the value is not a URI, Node, Literal, RdfResource, or string" do
|
608
|
-
expect{subject.set_value(RDF::DC.title, Object.new)}
|
609
|
-
.to raise_error ActiveTriples::Relation::ValueError
|
563
|
+
expect{subject.set_value(RDF::DC.title, Object.new)}.to raise_error
|
610
564
|
end
|
611
565
|
|
612
566
|
it "should be able to accept a subject" do
|
@@ -629,8 +583,7 @@ describe ActiveTriples::Resource do
|
|
629
583
|
end
|
630
584
|
|
631
585
|
it "raise an error if the value is not a URI, Node, Literal, RdfResource, or string" do
|
632
|
-
expect { subject[RDF::DC.title] = Object.new }
|
633
|
-
.to raise_error ActiveTriples::Relation::ValueError
|
586
|
+
expect { subject[RDF::DC.title] = Object.new }.to raise_error
|
634
587
|
end
|
635
588
|
end
|
636
589
|
|
data/spec/active_triples_spec.rb
CHANGED
@@ -1,7 +1,56 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ActiveTriples do
|
4
|
-
describe '.
|
4
|
+
describe '.class_from_string' do
|
5
|
+
before do
|
6
|
+
module TestModule
|
7
|
+
class TestClass; end
|
8
|
+
end
|
9
|
+
|
10
|
+
class TestBase; end
|
11
|
+
end
|
12
|
+
|
13
|
+
after do
|
14
|
+
Object.send(:remove_const, :TestModule)
|
15
|
+
Object.send(:remove_const, :TestBase)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'converts classes in kernal' do
|
19
|
+
expect(subject.class_from_string('TestBase')).to eq TestBase
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'raises an error when class is undefined' do
|
23
|
+
expect { subject.class_from_string('NotDefined') }
|
24
|
+
.to raise_error NameError
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'converts classes in a module' do
|
28
|
+
expect(subject.class_from_string('TestClass', TestModule))
|
29
|
+
.to eq TestModule::TestClass
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'finds class above selected module' do
|
33
|
+
expect(subject.class_from_string('Object', TestModule)).to eq Object
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'raises an error when class is undefined in module' do
|
37
|
+
expect { subject.class_from_string('NotDefined', TestModule) }
|
38
|
+
.to raise_error NameError
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'finds class above multiple selected modules' do
|
42
|
+
expect(subject.class_from_string('Object', 'TestModule::TestClass'))
|
43
|
+
.to eq Object
|
44
|
+
end
|
45
|
+
|
46
|
+
# is this the correct behavior!?
|
47
|
+
it 'climbs up nested module contexts' do
|
48
|
+
expect(subject.class_from_string('', 'TestModule::TestClass'))
|
49
|
+
.to eq TestModule::TestClass
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe '.ActiveTripels' do
|
5
54
|
it 'outputs a string' do
|
6
55
|
expect { described_class.ActiveTripels }.to output.to_stdout
|
7
56
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -4,7 +4,9 @@ Coveralls.wear!
|
|
4
4
|
require 'bundler/setup'
|
5
5
|
Bundler.setup
|
6
6
|
|
7
|
+
require 'rdf/spec'
|
7
8
|
require 'active_triples'
|
9
|
+
|
8
10
|
require 'pry' unless ENV["CI"]
|
9
11
|
|
10
12
|
Dir['./spec/support/**/*.rb'].each { |f| require f }
|
@@ -12,7 +14,9 @@ Dir['./spec/support/**/*.rb'].each { |f| require f }
|
|
12
14
|
RSpec.configure do |config|
|
13
15
|
config.color = true
|
14
16
|
config.tty = true
|
15
|
-
|
17
|
+
|
18
|
+
config.include(RDF::Spec::Matchers)
|
19
|
+
|
16
20
|
# Uncomment the following line to get errors and backtrace for deprecation warnings
|
17
21
|
# config.raise_errors_for_deprecations!
|
18
22
|
|
@@ -6,7 +6,10 @@ shared_examples_for "an ActiveModel" do
|
|
6
6
|
expect(subject).to respond_to :to_key
|
7
7
|
end
|
8
8
|
|
9
|
-
|
9
|
+
##
|
10
|
+
# @todo FIXME: this is wrong according to
|
11
|
+
# http://api.rubyonrails.org/classes/ActiveModel/Conversion.html#method-i-to_key
|
12
|
+
xit 'should return nil when #persisted? is false ' do
|
10
13
|
def subject.persisted?() false end
|
11
14
|
expect(subject.to_key).to eq nil
|
12
15
|
end
|
@@ -73,8 +76,8 @@ shared_examples_for "an ActiveModel" do
|
|
73
76
|
end
|
74
77
|
end
|
75
78
|
|
76
|
-
private
|
77
|
-
|
79
|
+
private
|
80
|
+
|
78
81
|
def match_boolean(result)
|
79
82
|
result == true || result == false
|
80
83
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
shared_examples 'a persistence strategy' do
|
2
|
+
shared_context 'with changes' do
|
3
|
+
before do
|
4
|
+
subject.obj << RDF::Statement.new(RDF::Node.new, RDF::DC.title, 'moomin')
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '#persist!' do
|
9
|
+
it 'evaluates true on success' do
|
10
|
+
expect(subject.persist!).to be_truthy
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'with changes' do
|
14
|
+
include_context 'with changes'
|
15
|
+
|
16
|
+
it 'evaluates true on success' do
|
17
|
+
expect(subject.persist!).to be_truthy
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#persisted?' do
|
23
|
+
context 'before persist!' do
|
24
|
+
it 'returns false' do
|
25
|
+
expect(subject).not_to be_persisted
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'after persist!' do
|
30
|
+
it 'returns true' do
|
31
|
+
subject.persist!
|
32
|
+
expect(subject).to be_persisted
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active-triples
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Johnson
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2015-06-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rdf
|
@@ -17,14 +17,14 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
20
|
+
version: 1.1.13
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
27
|
+
version: 1.1.13
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: linkeddata
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -59,14 +59,14 @@ dependencies:
|
|
59
59
|
requirements:
|
60
60
|
- - "~>"
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version: '1
|
62
|
+
version: '0.1'
|
63
63
|
type: :runtime
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
67
|
- - "~>"
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: '1
|
69
|
+
version: '0.1'
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: activesupport
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
@@ -109,6 +109,20 @@ dependencies:
|
|
109
109
|
- - ">="
|
110
110
|
- !ruby/object:Gem::Version
|
111
111
|
version: '0'
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: rdf-spec
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
112
126
|
- !ruby/object:Gem::Dependency
|
113
127
|
name: coveralls
|
114
128
|
requirement: !ruby/object:Gem::Requirement
|
@@ -180,7 +194,7 @@ dependencies:
|
|
180
194
|
- !ruby/object:Gem::Version
|
181
195
|
version: 0.1.2
|
182
196
|
description: ActiveTriples provides tools for modeling RDF as discrete resources.
|
183
|
-
email:
|
197
|
+
email: tom@dp.la
|
184
198
|
executables: []
|
185
199
|
extensions: []
|
186
200
|
extra_rdoc_files:
|
@@ -210,6 +224,10 @@ files:
|
|
210
224
|
- lib/active_triples/list.rb
|
211
225
|
- lib/active_triples/nested_attributes.rb
|
212
226
|
- lib/active_triples/node_config.rb
|
227
|
+
- lib/active_triples/persistable.rb
|
228
|
+
- lib/active_triples/persistence_strategies/parent_strategy.rb
|
229
|
+
- lib/active_triples/persistence_strategies/persistence_strategy.rb
|
230
|
+
- lib/active_triples/persistence_strategies/repository_strategy.rb
|
213
231
|
- lib/active_triples/properties.rb
|
214
232
|
- lib/active_triples/property.rb
|
215
233
|
- lib/active_triples/property_builder.rb
|
@@ -226,6 +244,10 @@ files:
|
|
226
244
|
- spec/active_triples/identifiable_spec.rb
|
227
245
|
- spec/active_triples/list_spec.rb
|
228
246
|
- spec/active_triples/nested_attributes_spec.rb
|
247
|
+
- spec/active_triples/persistable_spec.rb
|
248
|
+
- spec/active_triples/persistence_strategies/parent_strategy_spec.rb
|
249
|
+
- spec/active_triples/persistence_strategies/persistence_strategy_spec.rb
|
250
|
+
- spec/active_triples/persistence_strategies/repository_strategy_spec.rb
|
229
251
|
- spec/active_triples/properties_spec.rb
|
230
252
|
- spec/active_triples/property_spec.rb
|
231
253
|
- spec/active_triples/rdf_source_spec.rb
|
@@ -233,11 +255,12 @@ files:
|
|
233
255
|
- spec/active_triples/repositories_spec.rb
|
234
256
|
- spec/active_triples/resource_spec.rb
|
235
257
|
- spec/active_triples/schema_spec.rb
|
236
|
-
- spec/active_triples/validations_spec.rb
|
237
258
|
- spec/active_triples_spec.rb
|
238
259
|
- spec/pragmatic_context_spec.rb
|
239
260
|
- spec/spec_helper.rb
|
240
261
|
- spec/support/active_model_lint.rb
|
262
|
+
- spec/support/dummies/basic_persistable.rb
|
263
|
+
- spec/support/shared_examples/persistence_strategy.rb
|
241
264
|
homepage: https://github.com/no-reply/ActiveTriples
|
242
265
|
licenses:
|
243
266
|
- APACHE2
|
@@ -258,7 +281,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
258
281
|
version: '0'
|
259
282
|
requirements: []
|
260
283
|
rubyforge_project:
|
261
|
-
rubygems_version: 2.
|
284
|
+
rubygems_version: 2.2.1
|
262
285
|
signing_key:
|
263
286
|
specification_version: 4
|
264
287
|
summary: RDF graphs in ActiveModel wrappers.
|