tripod 0.0.1 → 0.0.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.
@@ -0,0 +1,103 @@
1
+ require "spec_helper"
2
+
3
+ describe Tripod::Persistence do
4
+
5
+ let(:unsaved_person) do
6
+ @unsaved_uri = @uri = 'http://uri'
7
+ @graph1 = RDF::Graph.new
8
+ stmt = RDF::Statement.new
9
+ stmt.subject = RDF::URI.new(@uri)
10
+ stmt.predicate = RDF::URI.new('http://pred')
11
+ stmt.object = RDF::URI.new('http://obj')
12
+ @graph1 << stmt
13
+ p = Person.new(@uri, 'http://graph')
14
+ p.hydrate!(@graph1)
15
+ p
16
+ end
17
+
18
+ let(:saved_person) do
19
+ @saved_uri = @uri2 = 'http://uri2'
20
+ @graph2 = RDF::Graph.new
21
+ stmt = RDF::Statement.new
22
+ stmt.subject = RDF::URI.new(@uri2)
23
+ stmt.predicate = RDF::URI.new('http://pred2')
24
+ stmt.object = RDF::URI.new('http://obj2')
25
+ @graph2 << stmt
26
+ p = Person.new(@uri2, 'http://graph')
27
+ p.hydrate!(@graph2)
28
+ p.save
29
+ p
30
+ end
31
+
32
+ describe "#save" do
33
+
34
+ context 'graph not set' do
35
+ it 'should not succeed' do
36
+ unsaved_person.graph_uri = nil
37
+ unsaved_person.save.should be_false
38
+ unsaved_person.should_not be_valid
39
+ unsaved_person.errors.should_not be_empty
40
+ unsaved_person.errors[:graph_uri].length.should ==1
41
+ unsaved_person.errors[:graph_uri].should == ["can't be blank"]
42
+ end
43
+ end
44
+
45
+ context 'uri not set' do
46
+ it 'should not succeed' do
47
+ unsaved_person.uri = nil
48
+ unsaved_person.save.should be_false
49
+ unsaved_person.should_not be_valid
50
+ unsaved_person.errors.should_not be_empty
51
+ unsaved_person.errors[:uri].length.should ==1
52
+ unsaved_person.errors[:uri].should == ["can't be blank"]
53
+ end
54
+ end
55
+
56
+ context 'graph and uri set' do
57
+
58
+ it 'saves the contents to the db' do
59
+ unsaved_person.save.should be_true
60
+
61
+ # try reading the data back out.
62
+ p2 = Person.new(@uri)
63
+ p2.hydrate!
64
+ repo_statements = p2.repository.statements
65
+ repo_statements.count.should == 1
66
+ repo_statements.first.subject.should == RDF::URI.new(@uri)
67
+ repo_statements.first.predicate.should == RDF::URI.new('http://pred')
68
+ repo_statements.first.object.should == RDF::URI.new('http://obj')
69
+ end
70
+
71
+ it 'should leave other people untouched' do
72
+ # save the unsaved person
73
+ unsaved_person.save.should be_true
74
+
75
+ # read the saved person back out the db, and check he's untouched.
76
+ p2 = Person.new(saved_person.uri)
77
+ p2.hydrate!
78
+ p2.repository.dump(:ntriples).should == saved_person.repository.dump(:ntriples)
79
+ end
80
+
81
+ end
82
+ end
83
+
84
+ describe "#destroy" do
85
+
86
+ it 'removes all triples from the db' do
87
+ saved_person.destroy.should be_true
88
+
89
+ # re-load it back into memory
90
+ p2 = Person.new(@saved_uri)
91
+ p2.hydrate!
92
+ p2.repository.should be_empty # nothing there any more!
93
+ end
94
+
95
+ end
96
+
97
+ describe "#save!" do
98
+ it 'throws an exception if save fails' do
99
+ unsaved_person.uri = nil
100
+ lambda {unsaved_person.save!}.should raise_error(Tripod::Errors::Validations)
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,60 @@
1
+ require "spec_helper"
2
+
3
+ describe Tripod::Repository do
4
+
5
+ describe "#hydrate" do
6
+
7
+ context 'no uri set' do
8
+ let(:person) do
9
+ Person.new
10
+ end
11
+
12
+ it 'rasies a UriNotSet error' do
13
+ lambda { person.hydrate! }.should raise_error(Tripod::Errors::UriNotSet)
14
+ end
15
+ end
16
+
17
+ context 'uri set' do
18
+
19
+ before do
20
+ @uri = 'http://foobar'
21
+ @graph = RDF::Graph.new
22
+ @stmt = RDF::Statement.new
23
+ @stmt.subject = RDF::URI.new(@uri)
24
+ @stmt.predicate = RDF::URI.new('http://pred')
25
+ @stmt.object = RDF::URI.new('http://obj')
26
+ @graph << @stmt
27
+ @graph_nt = @graph.dump(:ntriples)
28
+ end
29
+
30
+ let(:person) do
31
+ Person.new(@uri)
32
+ end
33
+
34
+ context 'no graph passed' do
35
+ it 'populates the repository with a graph of triples from the db' do
36
+ Tripod::SparqlClient::Query.should_receive(:describe).with("DESCRIBE <#{@uri}>").and_return(@graph_nt)
37
+ person.hydrate!
38
+ person.repository.should_not be_empty
39
+ end
40
+ end
41
+
42
+ context 'graph passed' do
43
+ it 'populates the repository with the graph of triples passed in, ingoring triples not about this resource' do
44
+
45
+ @graph << RDF::Statement.new( 'http://anotherresource', 'http://pred', 'http://obj')
46
+ @graph.statements.count.should ==2
47
+
48
+ person.hydrate!(@graph)
49
+ person.repository.should_not be_empty
50
+ person.repository.statements.count.should == 1 # not the extra one.
51
+ person.repository.statements.first.should == @stmt
52
+ end
53
+ end
54
+
55
+ end
56
+
57
+ end
58
+
59
+
60
+ end
@@ -0,0 +1,63 @@
1
+ require "spec_helper"
2
+
3
+ describe Tripod::Resource do
4
+
5
+ describe "#initialize" do
6
+
7
+ let(:person) do
8
+ Person.new()
9
+ end
10
+
11
+ it "initialises an empty repo" do
12
+ person.repository.class.should == RDF::Repository
13
+ person.repository.should be_empty
14
+ end
15
+
16
+ context 'uri passed in' do
17
+
18
+ context 'graph passed in' do
19
+ let(:person) do
20
+ Person.new('http://foobar', 'http://graph')
21
+ end
22
+
23
+ it 'sets the uri instance variable' do
24
+ person.uri.should == RDF::URI.new('http://foobar')
25
+ end
26
+
27
+ it 'sets the graph_uri instance variable' do
28
+ person.graph_uri.should == RDF::URI.new('http://graph')
29
+ end
30
+ end
31
+
32
+ context 'no graph passed in' do
33
+ let(:person) do
34
+ Person.new('http://foobar')
35
+ end
36
+
37
+ it 'sets the uri instance variable' do
38
+ person.uri.should == RDF::URI.new('http://foobar')
39
+ end
40
+
41
+ it 'doesn\'t set the graph_uri instance variable' do
42
+ person.graph_uri.should be_nil
43
+ end
44
+ end
45
+
46
+ end
47
+
48
+ context 'no uri or graph passed in' do
49
+
50
+ let(:person) do
51
+ Person.new
52
+ end
53
+
54
+ it 'uri and graph should be nil' do
55
+ person.uri.should be_nil
56
+ person.graph_uri.should be_nil
57
+ end
58
+ end
59
+
60
+ end
61
+
62
+
63
+ end
@@ -0,0 +1,93 @@
1
+ require "spec_helper"
2
+
3
+ describe Tripod::State do
4
+
5
+ describe "#new_record?" do
6
+
7
+ context "when calling new on the resource" do
8
+
9
+ let(:person) do
10
+ Person.new
11
+ end
12
+
13
+ it "returns true" do
14
+ person.should be_a_new_record
15
+ end
16
+ end
17
+
18
+ context "when the object has been saved" do
19
+
20
+ let(:person) do
21
+ p = Person.new('http://uri', 'http://graph')
22
+ p.save
23
+ p
24
+ end
25
+
26
+ it "returns false" do
27
+ person.should_not be_a_new_record
28
+ end
29
+ end
30
+ end
31
+
32
+ describe "#persisted?" do
33
+
34
+ let(:person) do
35
+ Person.new('http://uri', 'http://graph')
36
+ end
37
+
38
+ it "delegates to new_record?" do
39
+ person.should_not be_persisted
40
+ end
41
+
42
+ context "when the object has been destroyed" do
43
+ before do
44
+ person.save.should == true # check it worked
45
+ person.destroy
46
+ end
47
+
48
+ it "returns false" do
49
+ person.should_not be_persisted
50
+ end
51
+ end
52
+ end
53
+
54
+ describe "destroyed?" do
55
+
56
+ let(:person) do
57
+ Person.new
58
+ end
59
+
60
+ context "when destroyed is true" do
61
+
62
+ before do
63
+ person.destroyed = true
64
+ end
65
+
66
+ it "returns true" do
67
+ person.should be_destroyed
68
+ end
69
+ end
70
+
71
+ context "when destroyed is false" do
72
+
73
+ before do
74
+ person.destroyed = false
75
+ end
76
+
77
+ it "returns true" do
78
+ person.should_not be_destroyed
79
+ end
80
+ end
81
+
82
+ context "when destroyed is nil" do
83
+
84
+ before do
85
+ person.destroyed = nil
86
+ end
87
+
88
+ it "returns false" do
89
+ person.should_not be_destroyed
90
+ end
91
+ end
92
+ end
93
+ end
data/tripod.gemspec CHANGED
@@ -14,4 +14,15 @@ Gem::Specification.new do |gem|
14
14
  gem.name = "tripod"
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = Tripod::VERSION
17
+
18
+ gem.required_rubygems_version = ">= 1.3.6"
19
+ gem.rubyforge_project = "tripod"
20
+
21
+ gem.add_dependency "rest-client"
22
+ gem.add_dependency "activemodel", "~> 3.1"
23
+ gem.add_dependency "equivalent-xml"
24
+ gem.add_dependency "rdf", "~> 0.3"
25
+ gem.add_dependency "rdf-rdfxml"
26
+ gem.add_dependency "rdf-n3"
27
+ gem.add_dependency "rdf-json"
17
28
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tripod
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,85 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-23 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2012-08-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rest-client
16
+ requirement: &70292958584520 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70292958584520
25
+ - !ruby/object:Gem::Dependency
26
+ name: activemodel
27
+ requirement: &70292958583980 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '3.1'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70292958583980
36
+ - !ruby/object:Gem::Dependency
37
+ name: equivalent-xml
38
+ requirement: &70292958583560 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70292958583560
47
+ - !ruby/object:Gem::Dependency
48
+ name: rdf
49
+ requirement: &70292958583020 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '0.3'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *70292958583020
58
+ - !ruby/object:Gem::Dependency
59
+ name: rdf-rdfxml
60
+ requirement: &70292958582600 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: *70292958582600
69
+ - !ruby/object:Gem::Dependency
70
+ name: rdf-n3
71
+ requirement: &70292958582140 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: *70292958582140
80
+ - !ruby/object:Gem::Dependency
81
+ name: rdf-json
82
+ requirement: &70292958581720 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :runtime
89
+ prerelease: false
90
+ version_requirements: *70292958581720
14
91
  description: RDF ruby ORM
15
92
  email:
16
93
  - ric@swirrl.com
@@ -24,7 +101,28 @@ files:
24
101
  - README.md
25
102
  - Rakefile
26
103
  - lib/tripod.rb
104
+ - lib/tripod/attributes.rb
105
+ - lib/tripod/components.rb
106
+ - lib/tripod/errors.rb
107
+ - lib/tripod/errors/resource_not_found.rb
108
+ - lib/tripod/errors/uri_not_set.rb
109
+ - lib/tripod/errors/validations.rb
110
+ - lib/tripod/fields.rb
111
+ - lib/tripod/finders.rb
112
+ - lib/tripod/persistence.rb
113
+ - lib/tripod/repository.rb
114
+ - lib/tripod/resource.rb
115
+ - lib/tripod/sparql_client.rb
116
+ - lib/tripod/state.rb
27
117
  - lib/tripod/version.rb
118
+ - spec/app/models/person.rb
119
+ - spec/spec_helper.rb
120
+ - spec/tripod/attributes_spec.rb
121
+ - spec/tripod/finders_spec.rb
122
+ - spec/tripod/persistence_spec.rb
123
+ - spec/tripod/repository_spec.rb
124
+ - spec/tripod/resource_spec.rb
125
+ - spec/tripod/state_spec.rb
28
126
  - tripod.gemspec
29
127
  homepage: ''
30
128
  licenses: []
@@ -43,12 +141,20 @@ required_rubygems_version: !ruby/object:Gem::Requirement
43
141
  requirements:
44
142
  - - ! '>='
45
143
  - !ruby/object:Gem::Version
46
- version: '0'
144
+ version: 1.3.6
47
145
  requirements: []
48
- rubyforge_project:
146
+ rubyforge_project: tripod
49
147
  rubygems_version: 1.8.15
50
148
  signing_key:
51
149
  specification_version: 3
52
150
  summary: Active Model style RDF ORM
53
- test_files: []
151
+ test_files:
152
+ - spec/app/models/person.rb
153
+ - spec/spec_helper.rb
154
+ - spec/tripod/attributes_spec.rb
155
+ - spec/tripod/finders_spec.rb
156
+ - spec/tripod/persistence_spec.rb
157
+ - spec/tripod/repository_spec.rb
158
+ - spec/tripod/resource_spec.rb
159
+ - spec/tripod/state_spec.rb
54
160
  has_rdoc: