active-triples 0.8.1 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +8 -9
  3. data/CHANGES.md +69 -0
  4. data/Gemfile +0 -2
  5. data/Guardfile +1 -2
  6. data/active-triples.gemspec +3 -3
  7. data/lib/active/triples.rb +1 -0
  8. data/lib/active_triples.rb +4 -0
  9. data/lib/active_triples/configurable.rb +3 -1
  10. data/lib/active_triples/configuration.rb +1 -0
  11. data/lib/active_triples/configuration/item.rb +1 -0
  12. data/lib/active_triples/configuration/item_factory.rb +1 -0
  13. data/lib/active_triples/configuration/merge_item.rb +5 -2
  14. data/lib/active_triples/extension_strategy.rb +1 -0
  15. data/lib/active_triples/identifiable.rb +1 -0
  16. data/lib/active_triples/list.rb +2 -0
  17. data/lib/active_triples/nested_attributes.rb +1 -1
  18. data/lib/active_triples/node_config.rb +5 -3
  19. data/lib/active_triples/persistable.rb +1 -0
  20. data/lib/active_triples/persistence_strategies/parent_strategy.rb +104 -29
  21. data/lib/active_triples/persistence_strategies/persistence_strategy.rb +15 -7
  22. data/lib/active_triples/persistence_strategies/repository_strategy.rb +26 -22
  23. data/lib/active_triples/properties.rb +84 -6
  24. data/lib/active_triples/property.rb +35 -4
  25. data/lib/active_triples/property_builder.rb +38 -4
  26. data/lib/active_triples/rdf_source.rb +225 -75
  27. data/lib/active_triples/reflection.rb +42 -3
  28. data/lib/active_triples/relation.rb +330 -73
  29. data/lib/active_triples/repositories.rb +4 -2
  30. data/lib/active_triples/resource.rb +1 -0
  31. data/lib/active_triples/schema.rb +1 -0
  32. data/lib/active_triples/undefined_property_error.rb +27 -0
  33. data/lib/active_triples/version.rb +2 -1
  34. data/spec/active_triples/configurable_spec.rb +3 -2
  35. data/spec/active_triples/configuration_spec.rb +2 -1
  36. data/spec/active_triples/extension_strategy_spec.rb +2 -1
  37. data/spec/active_triples/identifiable_spec.rb +7 -11
  38. data/spec/active_triples/list_spec.rb +1 -4
  39. data/spec/active_triples/nested_attributes_spec.rb +4 -3
  40. data/spec/active_triples/persistable_spec.rb +4 -1
  41. data/spec/active_triples/persistence_strategies/parent_strategy_spec.rb +141 -11
  42. data/spec/active_triples/persistence_strategies/persistence_strategy_spec.rb +1 -0
  43. data/spec/active_triples/persistence_strategies/repository_strategy_spec.rb +32 -17
  44. data/spec/active_triples/properties_spec.rb +68 -33
  45. data/spec/active_triples/property_builder_spec.rb +36 -0
  46. data/spec/active_triples/property_spec.rb +15 -1
  47. data/spec/active_triples/rdf_source_spec.rb +544 -6
  48. data/spec/active_triples/reflection_spec.rb +78 -0
  49. data/spec/active_triples/relation_spec.rb +505 -3
  50. data/spec/active_triples/repositories_spec.rb +3 -1
  51. data/spec/active_triples/resource_spec.rb +90 -147
  52. data/spec/active_triples/schema_spec.rb +3 -2
  53. data/spec/active_triples_spec.rb +1 -0
  54. data/spec/integration/dummies/dummy_resource_a.rb +6 -0
  55. data/spec/integration/dummies/dummy_resource_b.rb +6 -0
  56. data/spec/integration/parent_persistence_spec.rb +18 -0
  57. data/spec/integration/reciprocal_properties_spec.rb +69 -0
  58. data/spec/pragmatic_context_spec.rb +10 -8
  59. data/spec/spec_helper.rb +5 -0
  60. data/spec/support/active_model_lint.rb +4 -6
  61. data/spec/support/dummies/basic_persistable.rb +2 -11
  62. data/spec/support/matchers.rb +11 -0
  63. data/spec/support/shared_examples/persistence_strategy.rb +3 -16
  64. metadata +20 -13
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'spec_helper'
2
3
 
3
4
  RSpec.describe ActiveTriples::Schema do
@@ -5,11 +6,11 @@ RSpec.describe ActiveTriples::Schema do
5
6
 
6
7
  describe ".property" do
7
8
  it "should define a property" do
8
- subject.property :title, :predicate => RDF::DC.title
9
+ subject.property :title, :predicate => RDF::Vocab::DC.title
9
10
 
10
11
  property = subject.properties.first
11
12
  expect(property.name).to eq :title
12
- expect(property.predicate).to eq RDF::DC.title
13
+ expect(property.predicate).to eq RDF::Vocab::DC.title
13
14
  end
14
15
  end
15
16
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'spec_helper'
2
3
 
3
4
  describe ActiveTriples do
@@ -0,0 +1,6 @@
1
+ class DummyResourceA
2
+ include ActiveTriples::RDFSource
3
+ configure :type => RDF::URI('http://example.org/type/ResourceA')
4
+ property :label, :predicate => RDF::URI('http://example.org/ontology/label')
5
+ property :has_resource, :predicate => RDF::URI('http://example.org/ontology/has_resource'), :class_name => DummyResourceB
6
+ end
@@ -0,0 +1,6 @@
1
+ class DummyResourceB
2
+ include ActiveTriples::RDFSource
3
+ configure :type => RDF::URI('http://example.org/type/ResourceB')
4
+ property :label, :predicate => RDF::URI('http://example.org/ontology/label')
5
+ property :in_resource, :predicate => RDF::URI('http://example.org/ontology/in_resource'), :class_name => DummyResourceA
6
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+
4
+ describe "When using the ParentPersistenceStrategy" do
5
+ context "a new child object" do
6
+ before do
7
+ class ParentThing < ActiveTriples::Resource
8
+ property :child, predicate: RDF::URI('http://example.org/#child')
9
+ end
10
+
11
+ class ChildThing < ActiveTriples::Resource; end
12
+ end
13
+
14
+ subject { ParentThing.new.child.build }
15
+
16
+ it { is_expected.not_to be_persisted }
17
+ end
18
+ end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+ autoload :DummyResourceA, 'integration/dummies/dummy_resource_a'
3
+ autoload :DummyResourceB, 'integration/dummies/dummy_resource_b'
4
+
5
+ describe 'reciprocal properties' do
6
+ context 'when using repository strategy for all' do
7
+ before do
8
+ ActiveTriples::Repositories.add_repository :default, RDF::Repository.new
9
+ end
10
+
11
+ let (:a) do
12
+ # a = DummyResourceA.new(RDF::URI('http://example.com/a'))
13
+ a = DummyResourceA.new
14
+ a.label = 'resource A'
15
+ a
16
+ end
17
+
18
+ let (:b) do
19
+ # b = DummyResourceB.new(RDF::URI('http://example.com/b'))
20
+ b = DummyResourceB.new
21
+ b.label = 'resource B'
22
+ b
23
+ end
24
+
25
+ it 'should allow A -> B -> A' do
26
+ expect(a.persistence_strategy).to be_kind_of ActiveTriples::RepositoryStrategy
27
+ expect(b.persistence_strategy).to be_kind_of ActiveTriples::RepositoryStrategy
28
+
29
+ a.has_resource = b
30
+ expect(a.has_resource).to eq [b]
31
+ expect(a.label).to eq ['resource A']
32
+ expect(b.label).to eq ['resource B']
33
+
34
+ b.in_resource = a
35
+ expect(b.in_resource).to eq [a]
36
+ expect(a.label).to eq ['resource A']
37
+ expect(b.label).to eq ['resource B']
38
+ end
39
+ end
40
+
41
+ context 'when using parent_strategy for some' do
42
+ let (:a) do
43
+ d = DummyResourceA.new(RDF::URI('http://example.com/a'))
44
+ d.label = 'resource A'
45
+ d
46
+ end
47
+
48
+ let (:b) do
49
+ p = DummyResourceB.new(RDF::URI('http://example.com/b'),a)
50
+ p.label = 'resource B'
51
+ p
52
+ end
53
+
54
+ it 'should allow A -> B -> A' do
55
+ expect(a.persistence_strategy).to be_kind_of ActiveTriples::RepositoryStrategy
56
+ expect(b.persistence_strategy).to be_kind_of ActiveTriples::ParentStrategy
57
+
58
+ a.has_resource = b
59
+ expect(a.has_resource).to eq [b]
60
+ expect(a.label).to eq ['resource A']
61
+ expect(b.label).to eq ['resource B']
62
+
63
+ b.in_resource = a
64
+ expect(b.in_resource).to eq [a]
65
+ expect(a.label).to eq ['resource A']
66
+ expect(b.label).to eq ['resource B']
67
+ end
68
+ end
69
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'spec_helper'
2
3
  require 'pragmatic_context'
3
4
 
@@ -6,9 +7,9 @@ describe 'PragmaticContext integration' do
6
7
  class DummyLicense
7
8
  include ActiveTriples::RDFSource
8
9
  include PragmaticContext::Contextualizable
9
- property :title, :predicate => RDF::DC.title
10
+ property :title, :predicate => RDF::Vocab::DC.title
10
11
 
11
- contextualize :title, :as => RDF::DC.title.to_s
12
+ contextualize :title, :as => RDF::Vocab::DC.title.to_s
12
13
  end
13
14
 
14
15
  class DummyResource
@@ -16,11 +17,12 @@ describe 'PragmaticContext integration' do
16
17
  include PragmaticContext::Contextualizable
17
18
 
18
19
  configure :type => RDF::URI('http://example.org/SomeClass')
19
- property :license, :predicate => RDF::DC.license, :class_name => DummyLicense
20
- property :title, :predicate => RDF::DC.title
20
+ property :license, :predicate => RDF::Vocab::DC.license,
21
+ :class_name => DummyLicense
22
+ property :title, :predicate => RDF::Vocab::DC.title
21
23
 
22
- contextualize :title, :as => RDF::DC.title.to_s
23
- contextualize :license, :as => RDF::DC.license.to_s
24
+ contextualize :title, :as => RDF::Vocab::DC.title.to_s
25
+ contextualize :license, :as => RDF::Vocab::DC.license.to_s
24
26
  end
25
27
 
26
28
  license.title = 'cc'
@@ -30,8 +32,8 @@ describe 'PragmaticContext integration' do
30
32
  end
31
33
 
32
34
  after do
33
- Object.send(:remove_const, "DummyResource") if Object
34
- Object.send(:remove_const, "DummyLicense") if Object
35
+ Object.send(:remove_const, "DummyResource")
36
+ Object.send(:remove_const, "DummyLicense")
35
37
  end
36
38
 
37
39
  subject { DummyResource.new('http://example.org/test') }
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'coveralls'
2
3
  Coveralls.wear!
3
4
 
@@ -5,12 +6,16 @@ require 'bundler/setup'
5
6
  Bundler.setup
6
7
 
7
8
  require 'rdf/spec'
9
+ require 'rdf/vocab'
10
+ require 'webmock/rspec'
8
11
  require 'active_triples'
9
12
 
10
13
  require 'pry' unless ENV["CI"]
11
14
 
12
15
  Dir['./spec/support/**/*.rb'].each { |f| require f }
13
16
 
17
+ WebMock.disable_net_connect!
18
+
14
19
  RSpec.configure do |config|
15
20
  config.color = true
16
21
  config.tty = true
@@ -1,17 +1,15 @@
1
+ # frozen_string_literal: true
1
2
  shared_examples_for "an ActiveModel" do
2
- subject { described_class.new }
3
+ subject { am_lint_class.new }
3
4
 
4
5
  describe '#to_key' do
5
6
  it 'should respond' do
6
7
  expect(subject).to respond_to :to_key
7
8
  end
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
+ it 'should return an array of keys ' do
13
11
  def subject.persisted?() false end
14
- expect(subject.to_key).to eq nil
12
+ expect(subject.to_key).to contain_exactly(subject.id)
15
13
  end
16
14
  end
17
15
 
@@ -1,13 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class BasicPersistable
2
- include ActiveTriples::Persistable
3
-
4
- attr_reader :graph
5
-
6
- def initialize
7
- @graph = RDF::Graph.new
8
- end
9
-
10
- def rdf_subject
11
- RDF::Node.new
12
- end
3
+ include ActiveTriples::RDFSource
13
4
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+
4
+ RSpec::Matchers.define :be_a_relation_containing do |*expected|
5
+ match do |actual|
6
+ expect(actual.class).to eq ActiveTriples::Relation
7
+ expect(actual).to contain_exactly(*expected)
8
+ true
9
+ end
10
+ end
11
+
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
1
2
  shared_examples 'a persistence strategy' do
2
3
  shared_context 'with changes' do
3
4
  before do
4
- subject.obj << RDF::Statement.new(RDF::Node.new, RDF::DC.title, 'moomin')
5
+ subject.source <<
6
+ RDF::Statement.new(RDF::Node.new, RDF::Vocab::DC.title, 'moomin')
5
7
  end
6
8
  end
7
9
 
@@ -18,19 +20,4 @@ shared_examples 'a persistence strategy' do
18
20
  end
19
21
  end
20
22
  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
23
  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.8.1
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Johnson
@@ -9,36 +9,36 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-06-08 00:00:00.000000000 Z
12
+ date: 2016-04-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rdf
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
18
+ - - '='
19
19
  - !ruby/object:Gem::Version
20
- version: 1.1.13
20
+ version: '1.99'
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: 1.1.13
27
+ version: '1.99'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: linkeddata
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: '1.1'
34
+ version: '1.99'
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: '1.1'
41
+ version: '1.99'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: activemodel
44
44
  requirement: !ruby/object:Gem::Requirement
@@ -113,16 +113,16 @@ dependencies:
113
113
  name: rdf-spec
114
114
  requirement: !ruby/object:Gem::Requirement
115
115
  requirements:
116
- - - ">="
116
+ - - "~>"
117
117
  - !ruby/object:Gem::Version
118
- version: '0'
118
+ version: '1.99'
119
119
  type: :development
120
120
  prerelease: false
121
121
  version_requirements: !ruby/object:Gem::Requirement
122
122
  requirements:
123
- - - ">="
123
+ - - "~>"
124
124
  - !ruby/object:Gem::Version
125
- version: '0'
125
+ version: '1.99'
126
126
  - !ruby/object:Gem::Dependency
127
127
  name: coveralls
128
128
  requirement: !ruby/object:Gem::Requirement
@@ -237,6 +237,7 @@ files:
237
237
  - lib/active_triples/repositories.rb
238
238
  - lib/active_triples/resource.rb
239
239
  - lib/active_triples/schema.rb
240
+ - lib/active_triples/undefined_property_error.rb
240
241
  - lib/active_triples/version.rb
241
242
  - spec/active_triples/configurable_spec.rb
242
243
  - spec/active_triples/configuration_spec.rb
@@ -249,17 +250,24 @@ files:
249
250
  - spec/active_triples/persistence_strategies/persistence_strategy_spec.rb
250
251
  - spec/active_triples/persistence_strategies/repository_strategy_spec.rb
251
252
  - spec/active_triples/properties_spec.rb
253
+ - spec/active_triples/property_builder_spec.rb
252
254
  - spec/active_triples/property_spec.rb
253
255
  - spec/active_triples/rdf_source_spec.rb
256
+ - spec/active_triples/reflection_spec.rb
254
257
  - spec/active_triples/relation_spec.rb
255
258
  - spec/active_triples/repositories_spec.rb
256
259
  - spec/active_triples/resource_spec.rb
257
260
  - spec/active_triples/schema_spec.rb
258
261
  - spec/active_triples_spec.rb
262
+ - spec/integration/dummies/dummy_resource_a.rb
263
+ - spec/integration/dummies/dummy_resource_b.rb
264
+ - spec/integration/parent_persistence_spec.rb
265
+ - spec/integration/reciprocal_properties_spec.rb
259
266
  - spec/pragmatic_context_spec.rb
260
267
  - spec/spec_helper.rb
261
268
  - spec/support/active_model_lint.rb
262
269
  - spec/support/dummies/basic_persistable.rb
270
+ - spec/support/matchers.rb
263
271
  - spec/support/shared_examples/persistence_strategy.rb
264
272
  homepage: https://github.com/no-reply/ActiveTriples
265
273
  licenses:
@@ -286,4 +294,3 @@ signing_key:
286
294
  specification_version: 4
287
295
  summary: RDF graphs in ActiveModel wrappers.
288
296
  test_files: []
289
- has_rdoc: