active-triples 0.6.1 → 0.7.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.
@@ -1,3 +1,3 @@
1
1
  module ActiveTriples
2
- VERSION = "0.6.1"
2
+ VERSION = "0.7.0".freeze
3
3
  end
@@ -9,6 +9,13 @@ describe ActiveTriples::Configurable do
9
9
  Object.send(:remove_const, "DummyConfigurable")
10
10
  end
11
11
 
12
+ it "should be okay if not configured" do
13
+ expect(DummyConfigurable.type).to eq nil
14
+ end
15
+ it "should be okay if configured to nil" do
16
+ DummyConfigurable.configure :type => nil
17
+ expect(DummyConfigurable.type).to eq []
18
+ end
12
19
  describe '#configure' do
13
20
  before do
14
21
  DummyConfigurable.configure base_uri: "http://example.org/base", type: RDF::RDFS.Class, rdf_label: RDF::DC.title
@@ -18,12 +25,21 @@ describe ActiveTriples::Configurable do
18
25
  expect(DummyConfigurable.base_uri).to eq "http://example.org/base"
19
26
  end
20
27
 
28
+ it "should be able to set multiple types" do
29
+ DummyConfigurable.configure type: [RDF::RDFS.Container, RDF::RDFS.ContainerMembershipProperty]
30
+ expect(DummyConfigurable.type).to contain_exactly(RDF::RDFS.Class, RDF::RDFS.Container, RDF::RDFS.ContainerMembershipProperty)
31
+ end
32
+
21
33
  it 'should set an rdf_label' do
22
34
  expect(DummyConfigurable.rdf_label).to eq RDF::DC.title
23
35
  end
24
36
 
25
37
  it 'should set a type' do
26
- expect(DummyConfigurable.type).to eq RDF::RDFS.Class
38
+ expect(DummyConfigurable.type).to eq [RDF::RDFS.Class]
39
+ end
40
+ it "should be able to set multiple types" do
41
+ DummyConfigurable.configure type: RDF::RDFS.Container
42
+ expect(DummyConfigurable.type).to eq [RDF::RDFS.Class, RDF::RDFS.Container]
27
43
  end
28
44
  end
29
45
 
@@ -32,7 +48,7 @@ describe ActiveTriples::Configurable do
32
48
  expect(DummyConfigurable).to receive(:configure).with(type: RDF::RDFS.Class).and_call_original
33
49
  expect(Deprecation).to receive(:warn)
34
50
  DummyConfigurable.rdf_type(RDF::RDFS.Class)
35
- expect(DummyConfigurable.type).to eq RDF::RDFS.Class
51
+ expect(DummyConfigurable.type).to eq [RDF::RDFS.Class]
36
52
  end
37
53
  end
38
54
  end
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe ActiveTriples::Configuration do
4
+ subject { described_class.new(starting_hash) }
5
+ let(:starting_hash) { {} }
6
+ describe "[]" do
7
+ context "with bad config values" do
8
+ let(:starting_hash) { {:bad => 1} }
9
+ it "should not return them" do
10
+ expect(subject[:bad]).to be_nil
11
+ end
12
+ end
13
+ context "with good config values" do
14
+ let(:starting_hash) { {:type => 1} }
15
+ it "should return them" do
16
+ expect(subject[:type]).to eq 1
17
+ end
18
+ end
19
+ end
20
+
21
+ describe "to_h" do
22
+ context "with bad and good config" do
23
+ let(:starting_hash) do
24
+ {
25
+ :bad => 1,
26
+ :type => 2
27
+ }
28
+ end
29
+ it "should return only good ones" do
30
+ expect(subject.to_h).to eq ({:type => 2})
31
+ end
32
+ end
33
+ end
34
+
35
+ describe "#items" do
36
+ let(:starting_hash) { {:rdf_label => 1} }
37
+ it "should return a configuration item for each config" do
38
+ expect(subject.items.keys.length).to eq 1
39
+ expect(subject.items[:rdf_label]).to be_kind_of ActiveTriples::Configuration::Item
40
+ end
41
+ end
42
+
43
+ describe "#merge" do
44
+ let(:starting_hash) do
45
+ {
46
+ :rdf_label => RDF::SKOS.prefLabel,
47
+ :type => RDF::RDFS.Class
48
+ }
49
+ end
50
+ it "should override some values" do
51
+ new_hash = {:rdf_label => RDF::RDFS.label}
52
+ expect(subject.merge(new_hash)[:rdf_label]).to eq RDF::RDFS.label
53
+ end
54
+ it "should merge type" do
55
+ new_hash = {:type => RDF::RDFS.Container}
56
+ expect(subject.merge(new_hash)[:type]).to eq [RDF::RDFS.Class, RDF::RDFS.Container]
57
+ end
58
+ end
59
+ end
@@ -5,11 +5,11 @@ describe ActiveTriples::Identifiable do
5
5
  before do
6
6
  class ActiveExample
7
7
  include ActiveTriples::Identifiable
8
-
8
+
9
9
  def self.property(*args)
10
10
  prop = args.first
11
11
 
12
- define_method prop.to_s do
12
+ define_method prop.to_s do
13
13
  resource.get_values(prop)
14
14
  end
15
15
 
@@ -34,7 +34,8 @@ describe ActiveTriples::Identifiable do
34
34
  let(:parent) { MyResource.new }
35
35
 
36
36
  before do
37
- class MyResource < ActiveTriples::Resource
37
+ class MyResource
38
+ include ActiveTriples::RDFSource
38
39
  property :relation, predicate: RDF::DC.relation, class_name: 'ActiveExample'
39
40
  end
40
41
 
@@ -56,7 +57,7 @@ describe ActiveTriples::Identifiable do
56
57
  context 'without implementation' do
57
58
  describe '::from_uri' do
58
59
  it 'raises a NotImplementedError' do
59
- expect{ klass.from_uri(RDF::URI('http://example.org/blah')) }.to raise_error NotImplementedError
60
+ expect{ klass.from_uri(RDF::URI('http://example.org/blah')) }.to raise_error NotImplementedError
60
61
  end
61
62
  end
62
63
 
@@ -66,7 +67,7 @@ describe ActiveTriples::Identifiable do
66
67
  end
67
68
  end
68
69
  end
69
-
70
+
70
71
  context 'with implementation' do
71
72
  before do
72
73
  class ActiveExample
@@ -82,7 +83,7 @@ describe ActiveTriples::Identifiable do
82
83
  def self.property(*args)
83
84
  prop = args.first
84
85
 
85
- define_method prop.to_s do
86
+ define_method prop.to_s do
86
87
  resource.get_values(prop)
87
88
  end
88
89
 
@@ -97,7 +98,7 @@ describe ActiveTriples::Identifiable do
97
98
 
98
99
  subject.id = '123'
99
100
  end
100
-
101
+
101
102
  describe '::properties' do
102
103
  before do
103
104
  klass.property :title, :predicate => RDF::DC.title
@@ -115,7 +116,7 @@ describe ActiveTriples::Identifiable do
115
116
  subject.title << 'Finn Family Moomintroll'
116
117
  expect(subject.resource.title).to eq ['Finn Family Moomintroll']
117
118
  end
118
-
119
+
119
120
  it 'returns correct values in property getters' do
120
121
  subject.resource.title = 'Finn Family Moomintroll'
121
122
  expect(subject.title).to eq subject.resource.title
@@ -152,18 +153,18 @@ describe ActiveTriples::Identifiable do
152
153
 
153
154
  context 'with relationships' do
154
155
  include_context 'with data'
155
-
156
+
156
157
  it 'has a parent' do
157
158
  expect(parent.relation.first.parent).to eq parent
158
159
  end
159
-
160
+
160
161
  it 'has a parent after reload' do
161
162
  parent.relation.node_cache = {}
162
163
  expect(parent.relation.first.parent).to eq parent
163
164
  end
164
165
  end
165
166
  end
166
-
167
+
167
168
  describe '#rdf_subject' do
168
169
  it 'has a subject' do
169
170
  expect(subject.rdf_subject).to eq 'http://example.org/ns/123'
@@ -49,7 +49,7 @@ describe ActiveTriples::List do
49
49
  subject.clear
50
50
  subject << 1
51
51
  end
52
-
52
+
53
53
  it 'has a type of rdf:List' do
54
54
  expect(subject.type.first).to eq RDF.List
55
55
  end
@@ -70,17 +70,20 @@ describe ActiveTriples::List do
70
70
  property :TopicElement
71
71
  property :TemporalElement
72
72
  end
73
- class DemoList < ActiveTriples::Resource
73
+ class DemoList
74
+ include ActiveTriples::RDFSource
74
75
  property :elementList, :predicate => MADS.elementList, :class_name => 'DemoList::List'
75
76
  class List < ActiveTriples::List
76
77
  property :topicElement, :predicate => MADS.TopicElement, :class_name => 'DemoList::List::TopicElement'
77
78
  property :temporalElement, :predicate => MADS.TemporalElement, :class_name => 'DemoList::List::TemporalElement'
78
79
 
79
- class TopicElement < ActiveTriples::Resource
80
+ class TopicElement
81
+ include ActiveTriples::RDFSource
80
82
  configure :type => MADS.TopicElement
81
83
  property :elementValue, :predicate => MADS.elementValue
82
84
  end
83
- class TemporalElement < ActiveTriples::Resource
85
+ class TemporalElement
86
+ include ActiveTriples::RDFSource
84
87
  configure :type => MADS.TemporalElement
85
88
  property :elementValue, :predicate => MADS.elementValue
86
89
  end
@@ -143,7 +146,7 @@ describe ActiveTriples::List do
143
146
  end
144
147
 
145
148
  describe "an empty list" do
146
- subject { DemoList.new.elementList.build }
149
+ subject { DemoList.new.elementList.build }
147
150
  it "should have to_ary" do
148
151
  expect(subject.to_ary).to eq []
149
152
  end
@@ -151,7 +154,7 @@ describe ActiveTriples::List do
151
154
 
152
155
  describe "a list that has a constructed element" do
153
156
  let(:ds) { DemoList.new('http://example.org/foo') }
154
- let(:list) { ds.elementList.build }
157
+ let(:list) { ds.elementList.build }
155
158
  let!(:topic) { list.topicElement.build }
156
159
 
157
160
  it "should have to_ary" do
@@ -222,7 +225,10 @@ END
222
225
  it "should have each" do
223
226
  foo = []
224
227
  list.each { |n| foo << n.class }
225
- expect(foo).to eq [ActiveTriples::Resource, DemoList::List::TopicElement, ActiveTriples::Resource, DemoList::List::TemporalElement]
228
+ expect(foo).to eq [ActiveTriples::Resource,
229
+ DemoList::List::TopicElement,
230
+ ActiveTriples::Resource,
231
+ DemoList::List::TemporalElement]
226
232
  end
227
233
 
228
234
  it "should have to_ary" do
@@ -24,7 +24,8 @@ describe "nesting attribute behavior" do
24
24
  property :DateNameElement
25
25
  end
26
26
 
27
- class ComplexResource < ActiveTriples::Resource
27
+ class ComplexResource
28
+ include ActiveTriples::RDFSource
28
29
  property :topic, predicate: DummyMADS.Topic, class_name: "Topic"
29
30
  property :personalName, predicate: DummyMADS.PersonalName, class_name: "PersonalName"
30
31
  property :title, predicate: RDF::DC.title
@@ -32,11 +33,13 @@ describe "nesting attribute behavior" do
32
33
 
33
34
  accepts_nested_attributes_for :topic, :personalName
34
35
 
35
- class Topic < ActiveTriples::Resource
36
+ class Topic
37
+ include ActiveTriples::RDFSource
36
38
  property :elementList, predicate: DummyMADS.elementList, class_name: "ComplexResource::ElementList"
37
39
  accepts_nested_attributes_for :elementList
38
40
  end
39
- class PersonalName < ActiveTriples::Resource
41
+ class PersonalName
42
+ include ActiveTriples::RDFSource
40
43
  property :elementList, predicate: DummyMADS.elementList, class_name: "ComplexResource::ElementList"
41
44
  property :extraProperty, predicate: DummyMADS.elementValue, class_name: "ComplexResource::Topic"
42
45
  accepts_nested_attributes_for :elementList, :extraProperty
@@ -51,7 +54,8 @@ describe "nesting attribute behavior" do
51
54
  property :elementValue, predicate: DummyMADS.elementValue
52
55
  accepts_nested_attributes_for :topicElement
53
56
  end
54
- class MadsTopicElement < ActiveTriples::Resource
57
+ class MadsTopicElement
58
+ include ActiveTriples::RDFSource
55
59
  configure :type => DummyMADS.TopicElement
56
60
  property :elementValue, predicate: DummyMADS.elementValue
57
61
  end
@@ -143,11 +147,13 @@ describe "nesting attribute behavior" do
143
147
 
144
148
  context "a simple model" do
145
149
  before do
146
- class SpecResource < ActiveTriples::Resource
150
+ class SpecResource
151
+ include ActiveTriples::RDFSource
147
152
  property :parts, predicate: RDF::DC.hasPart, :class_name=>'Component'
148
153
  accepts_nested_attributes_for :parts, allow_destroy: true
149
154
 
150
- class Component < ActiveTriples::Resource
155
+ class Component
156
+ include ActiveTriples::RDFSource
151
157
  property :label, predicate: RDF::DC.title
152
158
  end
153
159
  end
@@ -12,11 +12,21 @@ describe ActiveTriples::Properties do
12
12
  end
13
13
 
14
14
  describe '#property' do
15
- it 'should set a property' do
15
+ it 'should set a property as a NodeConfig' do
16
16
  DummyProperties.property :title, :predicate => RDF::DC.title
17
17
  expect(DummyProperties.reflect_on_property(:title)).to be_kind_of ActiveTriples::NodeConfig
18
18
  end
19
19
 
20
+ it 'should set the correct property' do
21
+ DummyProperties.property :title, :predicate => RDF::DC.title
22
+ expect(DummyProperties.reflect_on_property(:title).predicate).to eql RDF::DC.title
23
+ end
24
+
25
+ it 'should set the correct property from string' do
26
+ DummyProperties.property :title, :predicate => RDF::DC.title.to_s
27
+ expect(DummyProperties.reflect_on_property(:title).predicate).to eql RDF::DC.title
28
+ end
29
+
20
30
  it 'should set index behaviors' do
21
31
  DummyProperties.property :title, :predicate => RDF::DC.title do |index|
22
32
  index.as :facetable, :searchable
@@ -44,6 +54,14 @@ describe ActiveTriples::Properties do
44
54
  expect { DummyProperties.property :type, :predicate => RDF::DC.type }.to raise_error ArgumentError
45
55
  end
46
56
 
57
+ it 'raises error when defining properties with no predicate' do
58
+ expect { DummyProperties.property :type }.to raise_error ArgumentError
59
+ end
60
+
61
+ it 'raises error when defining properties with a non-Roesource predicate' do
62
+ expect { DummyProperties.property :type, :predicate => 123 }.to raise_error ArgumentError
63
+ end
64
+
47
65
  it 'raises error when defining properties already have method setters' do
48
66
  DummyProperties.send :define_method, :type=, lambda { }
49
67
  expect { DummyProperties.property :type, :predicate => RDF::DC.type }.to raise_error ArgumentError
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveTriples::RDFSource do
4
+ let(:dummy_source) { Class.new { include described_class } }
5
+ end
@@ -1,14 +1,14 @@
1
1
  require 'spec_helper'
2
2
  require 'rdf/isomorphic'
3
3
 
4
- describe ActiveTriples::Term do
4
+ describe ActiveTriples::Relation do
5
5
 
6
6
  describe "#rdf_subject" do
7
7
  let(:parent_resource) { double("parent resource", reflections: {}) }
8
8
 
9
9
  subject { described_class.new(parent_resource, double("value args") ) }
10
10
 
11
- context "when term has 0 value arguments" do
11
+ context "when relation has 0 value arguments" do
12
12
  before { subject.value_arguments = double(length: 0) }
13
13
  it "should raise an error" do
14
14
  expect { subject.send(:rdf_subject) }.to raise_error
@@ -26,13 +26,13 @@ describe ActiveTriples::Term do
26
26
  expect { subject.rdf_subject }.to raise_error NoMethodError
27
27
  end
28
28
  end
29
- context "when term has 2 value arguments" do
29
+ context "when relation has 2 value arguments" do
30
30
  before { subject.value_arguments = double(length: 2, first: "first") }
31
31
  it "should return the first value argument" do
32
32
  expect(subject.send(:rdf_subject) ).to eq "first"
33
33
  end
34
34
  end
35
- context "when term has 3 value arguments" do
35
+ context "when relation has 3 value arguments" do
36
36
  before { subject.value_arguments = double(length: 3) }
37
37
  it "should raise an error" do
38
38
  expect { subject.send(:rdf_subject) }.to raise_error
@@ -69,14 +69,15 @@ describe ActiveTriples::Term do
69
69
  after { Object.send(:remove_const, :DummyResource) }
70
70
  let(:resource) { DummyResource.new }
71
71
  context "and the resource class does not include RDF::Isomorphic" do
72
- before { class DummyResource < ActiveTriples::Resource; end }
72
+ before { class DummyResource; include ActiveTriples::RDFSource; end }
73
73
  it "should be false" do
74
74
  expect(subject.send(:valid_datatype?, resource)).to be false
75
75
  end
76
76
  end
77
77
  context "and the resource class includes RDF:Isomorphic" do
78
78
  before do
79
- class DummyResource < ActiveTriples::Resource
79
+ class DummyResource
80
+ include ActiveTriples::RDFSource
80
81
  include RDF::Isomorphic
81
82
  end
82
83
  end
@@ -86,7 +87,8 @@ describe ActiveTriples::Term do
86
87
  end
87
88
  context "and the resource class includes RDF::Isomorphic and aliases :== to :isomorphic_with?" do
88
89
  before do
89
- class DummyResource < ActiveTriples::Resource
90
+ class DummyResource
91
+ include ActiveTriples::RDFSource
90
92
  include RDF::Isomorphic
91
93
  alias_method :==, :isomorphic_with?
92
94
  end
@@ -1,6 +1,6 @@
1
1
  require "spec_helper"
2
2
  describe ActiveTriples::Repositories do
3
- subject {ActiveTriples::Repositories}
3
+ subject { ActiveTriples::Repositories }
4
4
 
5
5
  after(:each) do
6
6
  subject.clear_repositories!
@@ -32,17 +32,20 @@ describe ActiveTriples::Repositories do
32
32
  end
33
33
 
34
34
  before do
35
- class DummyResource1 < ActiveTriples::Resource
35
+ class DummyResource1
36
+ include ActiveTriples::RDFSource
36
37
  configure :base_uri => "http://example.org/r1/",
37
38
  :type => RDF::URI("http://example.org/SomeClass"),
38
39
  :repository => :repo1
39
40
  end
40
- class DummyResource2 < ActiveTriples::Resource
41
+ class DummyResource2
42
+ include ActiveTriples::RDFSource
41
43
  configure :base_uri => "http://example.org/r2/",
42
44
  :type => RDF::URI("http://example.org/SomeClass"),
43
45
  :repository => :repo2
44
46
  end
45
- class DummyResource3 < ActiveTriples::Resource
47
+ class DummyResource3
48
+ include ActiveTriples::RDFSource
46
49
  configure :base_uri => "http://example.org/r3/",
47
50
  :type => RDF::URI("http://example.org/SomeClass"),
48
51
  :repository => :repo3