dbd 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -78,35 +78,37 @@ module Dbd
78
78
  end
79
79
 
80
80
  describe "when the subject of the fact is not equal to the resource_subject" do
81
- it "raises a SubjectError" do
82
- lambda {resource << fact_2_with_subject } . should raise_error SubjectError
81
+ it "raises a SetOnceError" do
82
+ lambda {resource << fact_2_with_subject } . should raise_error(
83
+ SetOnceError,
84
+ "Value of subject was #{fact_2_with_subject.subject}, " \
85
+ "trying to set it to #{resource.subject}")
83
86
  end
84
87
  end
85
88
  end
86
89
 
87
90
  describe "adding a fact without subject" do
88
91
 
89
- let (:new_fact) do
92
+ before(:each) do
90
93
  resource << fact_with_provenance
91
- resource.first
92
94
  end
93
95
 
94
- it "insert a different instance" do
95
- new_fact.should_not be_equal(fact_with_provenance)
96
+ let(:fact_in_resource) do
97
+ resource.single
96
98
  end
97
99
 
98
- it "is from the same class" do
99
- new_fact.should be_a(fact_with_provenance.class)
100
+ it "insert the same instance" do
101
+ fact_in_resource.should be_equal(fact_with_provenance)
100
102
  end
101
103
 
102
- it "has copied over the other attributes except :id" do
103
- (fact_with_provenance.class.attributes - [:id,:subject]).each do |attr|
104
- new_fact.send(attr).should == fact_with_provenance.send(attr)
104
+ it "has kept the other attributes" do
105
+ (fact_with_provenance.class.attributes - [:subject]).each do |attr|
106
+ fact_in_resource.send(attr).should == fact_with_provenance.send(attr)
105
107
  end
106
108
  end
107
109
 
108
110
  it "has set the subject to the Resource subject" do
109
- new_fact.subject.should == resource_subject
111
+ fact_in_resource.subject.should == resource_subject
110
112
  end
111
113
  end
112
114
  end
@@ -116,44 +118,40 @@ module Dbd
116
118
  describe "when the provenance_subject of the fact is equal to the provenance_subject of the resource" do
117
119
  it "inserts the fact unaltered" do
118
120
  resource << fact_with_provenance_and_resource_subject
119
- resource.first.should be_equal(fact_with_provenance_and_resource_subject)
121
+ resource.single.should be_equal(fact_with_provenance_and_resource_subject)
120
122
  end
121
123
  end
122
124
 
123
125
  describe "when the provenance_subject of the fact is not equal to the resource" do
124
126
  it "raises a ProvenanceError" do
125
- lambda {resource << fact_with_incorrect_provenance } . should raise_error ProvenanceError
127
+ lambda { resource << fact_with_incorrect_provenance } . should raise_error(
128
+ SetOnceError,
129
+ "Value of provenance_subject was #{fact_with_incorrect_provenance.provenance_subject}, " \
130
+ "trying to set it to #{resource.provenance_subject}")
126
131
  end
127
132
  end
128
133
  end
129
134
 
130
135
  describe "adding a fact without provenance_subject" do
131
136
 
132
- let (:new_fact) do
137
+ before(:each) do
133
138
  resource << fact_with_resource_subject
134
- resource.first
135
139
  end
136
140
 
137
- it "insert a different instance" do
138
- new_fact.should_not be_equal(fact_with_resource_subject)
141
+ let(:fact_in_resource) do
142
+ resource.single
139
143
  end
140
144
 
141
- it "is from the same class" do
142
- new_fact.should be_a(fact_with_resource_subject.class)
145
+ it "inserts the same instance" do
146
+ fact_in_resource.should be_equal(fact_with_resource_subject)
143
147
  end
144
148
 
145
- it "has copied over the other attributes except :id" do
146
- (new_fact.class.attributes - [:id,:provenance_subject]).each do |attr|
147
- new_fact.send(attr).should == fact_with_resource_subject.send(attr)
148
- end
149
- end
150
-
151
- it "has set the subject to the Resource subject" do
152
- new_fact.provenance_subject.should == provenance_subject
149
+ it "has set the provenance_subject to the Resource provenance_subject" do
150
+ fact_in_resource.provenance_subject.should == provenance_subject
153
151
  end
154
152
  end
155
- end
156
153
 
154
+ end
157
155
  end
158
156
  end
159
157
 
@@ -0,0 +1,110 @@
1
+ require 'spec_helper'
2
+
3
+ module Dbd
4
+ describe TimeStamp do
5
+ describe ".new" do
6
+
7
+ let(:time) { Time.now.utc }
8
+
9
+ before(:each) do
10
+ time
11
+ Time.stub(:now).and_return(time)
12
+ end
13
+
14
+ it "creates a new (random) time_stamp" do
15
+ subject # should_not raise_error
16
+ end
17
+
18
+ it "with :time option, sets that to time" do
19
+ near_future = time + 100
20
+ time_stamp = described_class.new(time: near_future)
21
+ time_stamp.time.should == near_future
22
+ end
23
+
24
+ it "with :larger_than, sets a time that is strictly and slightly larger than this" do
25
+ larger_than = described_class.new(time: time + Rational('500/1000_000')) # 0.5 ms
26
+ time_stamp = described_class.new(larger_than: larger_than)
27
+ time_stamp.time.should > larger_than.time
28
+ (time_stamp.time - larger_than.time).should < Rational('1/1000_000') # 1 us
29
+ end
30
+
31
+ it "without :larger_than adds some random time to the generated time" do
32
+ time_stamp = described_class.new
33
+ time_stamp.time.should > time
34
+ (time_stamp.time - time).should < Rational('1/1000_000') # 1 us
35
+ end
36
+ end
37
+
38
+ describe ".time_format_regexp" do
39
+ it "matches an example string" do
40
+ a_time_stamp = "2013-05-16 23:52:38.123456789 UTC"
41
+ a_time_stamp.should match(described_class.to_s_regexp)
42
+ end
43
+ end
44
+
45
+ describe "#time to allow comparison" do
46
+ it "responds with a time" do
47
+ described_class.new.time.should be_a(Time)
48
+ end
49
+ end
50
+
51
+ describe "#to_s" do
52
+ it "returns a Time format string" do
53
+ subject.to_s.should match(described_class.to_s_regexp)
54
+ end
55
+ end
56
+
57
+ let(:time_stamp_0) { described_class.new(time: Time.new(2013,5,18,12,0,0)) }
58
+ let(:time_stamp_1) { described_class.new(time: Time.new(2013,5,18,12,0,0)) }
59
+ let(:time_stamp_2) { described_class.new(time: Time.new(2013,5,18,12,0,1)) }
60
+
61
+ describe "==" do
62
+ it "should be ==" do
63
+ time_stamp_0.should == time_stamp_1
64
+ end
65
+
66
+ it "hash should also be equal" do
67
+ time_stamp_0.hash.should == time_stamp_1.hash
68
+ end
69
+ end
70
+
71
+ describe ">" do
72
+ it "is true if time_stamp is really larger" do
73
+ time_stamp_2.should > time_stamp_1
74
+ end
75
+ end
76
+
77
+ describe "<" do
78
+ it "is true if time_stamp is really smaller" do
79
+ time_stamp_1.should < time_stamp_2
80
+ end
81
+ end
82
+
83
+ describe "<=" do
84
+
85
+ it "is true if time_stamp_1 is really smaller" do
86
+ time_stamp_1.should <= time_stamp_2
87
+ end
88
+ end
89
+
90
+ describe "+" do
91
+ it "returns a larger time_stamp" do
92
+ (subject + 1).should > subject
93
+ end
94
+
95
+ it "sees a difference of 1 nanosecond" do
96
+ (subject + Rational('1/1000_000_000')).should > subject
97
+ end
98
+ end
99
+
100
+ describe "-" do
101
+ it "returns the time difference" do
102
+ ((subject + 1) - subject).should == 1
103
+ end
104
+
105
+ it "sees a difference of 1 nanosecond" do
106
+ ((subject + Rational('1/1000_000_000')) - subject).should == Rational('1/1_000_000_000')
107
+ end
108
+ end
109
+ end
110
+ end
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dbd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
4
+ version: 0.0.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Peter Vandenabeele
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-05-12 00:00:00.000000000 Z
11
+ date: 2013-05-22 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: bundler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - '>'
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - '>'
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - '>='
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - '>='
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: guard-rspec
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - '>='
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - '>='
60
53
  - !ruby/object:Gem::Version
@@ -62,7 +55,6 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rb-fsevent
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ~>
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ~>
76
67
  - !ruby/object:Gem::Version
@@ -78,7 +69,6 @@ dependencies:
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: terminal-notifier-guard
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
73
  - - '>='
84
74
  - !ruby/object:Gem::Version
@@ -86,7 +76,6 @@ dependencies:
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
80
  - - '>='
92
81
  - !ruby/object:Gem::Version
@@ -94,7 +83,6 @@ dependencies:
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: yard
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
87
  - - '>='
100
88
  - !ruby/object:Gem::Version
@@ -102,7 +90,6 @@ dependencies:
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
94
  - - '>='
108
95
  - !ruby/object:Gem::Version
@@ -110,7 +97,6 @@ dependencies:
110
97
  - !ruby/object:Gem::Dependency
111
98
  name: neography
112
99
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
100
  requirements:
115
101
  - - '>='
116
102
  - !ruby/object:Gem::Version
@@ -118,7 +104,6 @@ dependencies:
118
104
  type: :runtime
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
107
  requirements:
123
108
  - - '>='
124
109
  - !ruby/object:Gem::Version
@@ -126,7 +111,6 @@ dependencies:
126
111
  - !ruby/object:Gem::Dependency
127
112
  name: rdf
128
113
  requirement: !ruby/object:Gem::Requirement
129
- none: false
130
114
  requirements:
131
115
  - - ~>
132
116
  - !ruby/object:Gem::Version
@@ -134,7 +118,6 @@ dependencies:
134
118
  type: :runtime
135
119
  prerelease: false
136
120
  version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
121
  requirements:
139
122
  - - ~>
140
123
  - !ruby/object:Gem::Version
@@ -142,19 +125,17 @@ dependencies:
142
125
  - !ruby/object:Gem::Dependency
143
126
  name: ruby_peter_v
144
127
  requirement: !ruby/object:Gem::Requirement
145
- none: false
146
128
  requirements:
147
129
  - - '>='
148
130
  - !ruby/object:Gem::Version
149
- version: '0'
131
+ version: 0.0.4
150
132
  type: :runtime
151
133
  prerelease: false
152
134
  version_requirements: !ruby/object:Gem::Requirement
153
- none: false
154
135
  requirements:
155
136
  - - '>='
156
137
  - !ruby/object:Gem::Version
157
- version: '0'
138
+ version: 0.0.4
158
139
  description: A data store that (almost) never forgets
159
140
  email:
160
141
  - peter@vandenabeele.com
@@ -168,6 +149,7 @@ files:
168
149
  - .travis.yml
169
150
  - Gemfile
170
151
  - Guardfile
152
+ - HISTORY.txt
171
153
  - LICENSE.txt
172
154
  - README.md
173
155
  - Rakefile
@@ -182,7 +164,9 @@ files:
182
164
  - docs/stories/007_rename_property_to_predicate.txt
183
165
  - docs/stories/008_testing_different_ruby_versions.txt
184
166
  - docs/stories/009_build_and_store_resources_with_provenance.txt
185
- - docs/stories/010_provenance_fact_properties_from_provenance_ontology.txt
167
+ - docs/stories/010_time_class.txt
168
+ - docs/stories/011_store_resource_in_graph.txt
169
+ - docs/stories/012_provenance_fact_properties_from_provenance_ontology.txt
186
170
  - docs/test.rb
187
171
  - lib/dbd.rb
188
172
  - lib/dbd/errors.rb
@@ -200,6 +184,7 @@ files:
200
184
  - lib/dbd/repo/neo4j_repo.rb
201
185
  - lib/dbd/repo/neo4j_repo/base.rb
202
186
  - lib/dbd/resource.rb
187
+ - lib/dbd/time_stamp.rb
203
188
  - lib/dbd/version.rb
204
189
  - spec/factories/fact.rb
205
190
  - spec/factories/provenance_fact.rb
@@ -212,43 +197,38 @@ files:
212
197
  - spec/lib/dbd/graph_spec.rb
213
198
  - spec/lib/dbd/helpers/ordered_set_collection_spec.rb
214
199
  - spec/lib/dbd/helpers/uuid_spec.rb
200
+ - spec/lib/dbd/performance_spec.rb
215
201
  - spec/lib/dbd/provenance_fact_spec.rb
216
202
  - spec/lib/dbd/provenance_resource_spec.rb
217
203
  - spec/lib/dbd/rdf_base_spec.rb
218
204
  - spec/lib/dbd/repo/neo4j_repo/base_spec.rb
219
205
  - spec/lib/dbd/repo/neo4j_repo/performance_spec.rb
220
206
  - spec/lib/dbd/resource_spec.rb
207
+ - spec/lib/dbd/time_stamp_spec.rb
221
208
  - spec/spec_helper.rb
222
209
  homepage: ''
223
210
  licenses:
224
211
  - MIT
212
+ metadata: {}
225
213
  post_install_message:
226
214
  rdoc_options: []
227
215
  require_paths:
228
216
  - lib
229
217
  required_ruby_version: !ruby/object:Gem::Requirement
230
- none: false
231
218
  requirements:
232
219
  - - '>='
233
220
  - !ruby/object:Gem::Version
234
221
  version: '0'
235
- segments:
236
- - 0
237
- hash: 1715906838071100046
238
222
  required_rubygems_version: !ruby/object:Gem::Requirement
239
- none: false
240
223
  requirements:
241
224
  - - '>='
242
225
  - !ruby/object:Gem::Version
243
226
  version: '0'
244
- segments:
245
- - 0
246
- hash: 1715906838071100046
247
227
  requirements: []
248
228
  rubyforge_project:
249
- rubygems_version: 1.8.25
229
+ rubygems_version: 2.0.3
250
230
  signing_key:
251
- specification_version: 3
231
+ specification_version: 4
252
232
  summary: A data store that (almost) never forgets
253
233
  test_files:
254
234
  - spec/factories/fact.rb
@@ -262,11 +242,13 @@ test_files:
262
242
  - spec/lib/dbd/graph_spec.rb
263
243
  - spec/lib/dbd/helpers/ordered_set_collection_spec.rb
264
244
  - spec/lib/dbd/helpers/uuid_spec.rb
245
+ - spec/lib/dbd/performance_spec.rb
265
246
  - spec/lib/dbd/provenance_fact_spec.rb
266
247
  - spec/lib/dbd/provenance_resource_spec.rb
267
248
  - spec/lib/dbd/rdf_base_spec.rb
268
249
  - spec/lib/dbd/repo/neo4j_repo/base_spec.rb
269
250
  - spec/lib/dbd/repo/neo4j_repo/performance_spec.rb
270
251
  - spec/lib/dbd/resource_spec.rb
252
+ - spec/lib/dbd/time_stamp_spec.rb
271
253
  - spec/spec_helper.rb
272
254
  has_rdoc: