dbd 0.0.5 → 0.0.6

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.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/Guardfile +3 -2
  3. data/HISTORY.txt +5 -0
  4. data/dbd.gemspec +1 -1
  5. data/docs/stories/013_read_graph_from_CSV.txt +10 -0
  6. data/lib/dbd.rb +1 -1
  7. data/lib/dbd/fact.rb +23 -1
  8. data/lib/dbd/fact/id.rb +3 -3
  9. data/lib/dbd/fact/subject.rb +3 -3
  10. data/lib/dbd/graph.rb +25 -4
  11. data/lib/dbd/provenance_fact.rb +5 -8
  12. data/lib/dbd/provenance_resource.rb +21 -13
  13. data/lib/dbd/{rdf.rb → rdf_base.rb} +0 -0
  14. data/lib/dbd/resource.rb +25 -23
  15. data/lib/dbd/time_stamp.rb +13 -2
  16. data/lib/dbd/version.rb +1 -1
  17. data/spec/factories/fact.rb +23 -0
  18. data/spec/factories/fact/id.rb +14 -0
  19. data/spec/factories/fact/subject.rb +18 -0
  20. data/spec/factories/graph.rb +23 -0
  21. data/spec/factories/provenance_resource.rb +3 -3
  22. data/spec/factories/time_stamp.rb +12 -0
  23. data/spec/lib/dbd/fact/{collection_spec.rb → collection/collection_spec.rb} +0 -0
  24. data/spec/lib/dbd/fact/factory_spec.rb +82 -0
  25. data/spec/lib/dbd/fact/id/factory_spec.rb +20 -0
  26. data/spec/lib/dbd/fact/id/id_spec.rb +27 -0
  27. data/spec/lib/dbd/fact/methods_spec.rb +117 -0
  28. data/spec/lib/dbd/fact/new_spec.rb +91 -0
  29. data/spec/lib/dbd/fact/subject/factory_spec.rb +33 -0
  30. data/spec/lib/dbd/fact/subject/subject_spec.rb +27 -0
  31. data/spec/lib/dbd/graph/add_to_graph_spec.rb +139 -0
  32. data/spec/lib/dbd/graph/factory_spec.rb +33 -0
  33. data/spec/lib/dbd/graph/from_csv_spec.rb +29 -0
  34. data/spec/lib/dbd/{graph_spec.rb → graph/to_csv_spec.rb} +0 -120
  35. data/spec/lib/dbd/helpers/{ordered_set_collection_spec.rb → ordered_set_collection/ordered_set_collection_spec.rb} +0 -0
  36. data/spec/lib/dbd/helpers/{uuid_spec.rb → uuid/uuid_spec.rb} +0 -0
  37. data/spec/lib/dbd/performance_spec.rb +3 -1
  38. data/spec/lib/dbd/provenance_fact/factory_spec.rb +24 -0
  39. data/spec/lib/dbd/provenance_fact/methods_spec.rb +78 -0
  40. data/spec/lib/dbd/provenance_fact/new_spec.rb +51 -0
  41. data/spec/lib/dbd/{provenance_resource_spec.rb → provenance_resource/provenance_resource_spec.rb} +6 -10
  42. data/spec/lib/dbd/{rdf_base_spec.rb → rdf_base/rdf_base_spec.rb} +0 -0
  43. data/spec/lib/dbd/{resource_spec.rb → resource/collection_spec.rb} +8 -47
  44. data/spec/lib/dbd/resource/factory_spec.rb +14 -0
  45. data/spec/lib/dbd/resource/new_spec.rb +44 -0
  46. data/spec/lib/dbd/time_stamp/comparisons_spec.rb +64 -0
  47. data/spec/lib/dbd/time_stamp/factory_spec.rb +17 -0
  48. data/spec/lib/dbd/time_stamp/methods_spec.rb +37 -0
  49. data/spec/lib/dbd/time_stamp/new_spec.rb +38 -0
  50. metadata +66 -29
  51. data/spec/lib/dbd/fact/id_spec.rb +0 -19
  52. data/spec/lib/dbd/fact/subject_spec.rb +0 -19
  53. data/spec/lib/dbd/fact_spec.rb +0 -216
  54. data/spec/lib/dbd/provenance_fact_spec.rb +0 -120
  55. data/spec/lib/dbd/time_stamp_spec.rb +0 -115
@@ -0,0 +1,14 @@
1
+ module Factories
2
+ module Fact
3
+ module ID
4
+
5
+ def self.factory_for
6
+ ::Dbd::Fact::ID
7
+ end
8
+
9
+ def self.fixed_id
10
+ factory_for.new(uuid: "825e44d5-af33-4858-8047-549bd813daa8")
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,18 @@
1
+ module Factories
2
+ module Fact
3
+ module Subject
4
+
5
+ def self.factory_for
6
+ ::Dbd::Fact::Subject
7
+ end
8
+
9
+ def self.fixed_subject
10
+ factory_for.new(uuid: "2e9fbc87-2e94-47e9-a8fd-121cc4bc3e8f")
11
+ end
12
+
13
+ def self.fixed_provenance_subject
14
+ factory_for.new(uuid: "40fab407-9b04-4a51-9a52-d978abfcbb1f")
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,23 @@
1
+ module Factories
2
+ module Graph
3
+
4
+ def self.factory_for
5
+ ::Dbd::Graph
6
+ end
7
+
8
+ def self.new_subject
9
+ ::Dbd::ProvenanceFact.new_subject
10
+ end
11
+
12
+ def self.only_provenance
13
+ factory_for.new << Factories::Fact::Collection.provenance_facts(new_subject)
14
+ end
15
+
16
+ def self.full
17
+ provenance_resource = Factories::ProvenanceResource.provenance_resource
18
+ resource = Factories::Resource.facts_resource(provenance_resource.subject)
19
+ factory_for.new << provenance_resource << resource
20
+ end
21
+
22
+ end
23
+ end
@@ -6,9 +6,9 @@ module Factories
6
6
  end
7
7
 
8
8
  def self.provenance_resource
9
- factory_for.new.tap do |resource|
10
- resource << Factories::ProvenanceFact.context
11
- resource << Factories::ProvenanceFact.created_by
9
+ factory_for.new.tap do |provenance_resource|
10
+ provenance_resource << Factories::ProvenanceFact.context
11
+ provenance_resource << Factories::ProvenanceFact.created_by
12
12
  end
13
13
  end
14
14
 
@@ -0,0 +1,12 @@
1
+ module Factories
2
+ module TimeStamp
3
+
4
+ def self.factory_for
5
+ ::Dbd::TimeStamp
6
+ end
7
+
8
+ def self.fixed_time_stamp
9
+ factory_for.from_s("2013-06-17 21:55:09.967653012 UTC")
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,82 @@
1
+ require 'spec_helper'
2
+
3
+ module Dbd
4
+ describe Fact do
5
+ let(:provenance_subject) { ProvenanceFact.new_subject }
6
+ let(:subject) { described_class.new_subject }
7
+ let(:data_predicate) { "http://example.org/test/name" }
8
+ let(:string_object_1) { "Gandhi" }
9
+ let(:fact_2_with_subject) { Factories::Fact.fact_2_with_subject(provenance_subject) }
10
+ let(:full_fact) { Factories::Fact.full_fact }
11
+
12
+ describe "factory works" do
13
+ it "with explicit provenance_subject" do
14
+ fact_2_with_subject.provenance_subject.should be_a(provenance_subject.class)
15
+ fact_2_with_subject.subject.should be_a(subject.class)
16
+ fact_2_with_subject.predicate.should be_a(data_predicate.class)
17
+ fact_2_with_subject.object.should be_a(string_object_1.class)
18
+ end
19
+
20
+ it "without explicit provenance_subject" do
21
+ Factories::Fact.fact_1.provenance_subject.should be_nil
22
+ end
23
+
24
+ it "fact_2_with_subject should not raise_error" do
25
+ Factories::Fact.fact_2_with_subject
26
+ end
27
+
28
+ it "fact_3_with_subject should not raise_error" do
29
+ Factories::Fact.fact_3_with_subject
30
+ end
31
+
32
+ describe "data_fact" do
33
+ describe "without arguments" do
34
+ it "has empty provenance_subject" do
35
+ Factories::Fact.data_fact.provenance_subject.should be_nil
36
+ end
37
+
38
+ it "has empty subject" do
39
+ Factories::Fact.data_fact.subject.should be_nil
40
+ end
41
+ end
42
+
43
+ describe "with provenance_subject" do
44
+ it "has provenance_subject" do
45
+ Factories::Fact.data_fact(provenance_subject).
46
+ provenance_subject.should == provenance_subject
47
+ end
48
+
49
+ it "has empty subject" do
50
+ Factories::Fact.data_fact(provenance_subject).subject.should be_nil
51
+ end
52
+ end
53
+
54
+ describe "with provenance_subject and subject" do
55
+ it "has provenance_subject" do
56
+ Factories::Fact.data_fact(provenance_subject, subject).
57
+ provenance_subject.should == provenance_subject
58
+ end
59
+
60
+ it "has subject" do
61
+ Factories::Fact.data_fact(provenance_subject, subject).
62
+ subject.should == subject
63
+ end
64
+ end
65
+ end
66
+
67
+ describe "full_fact" do
68
+ it "does not fail" do
69
+ full_fact
70
+ end
71
+
72
+ it "has values for all attributes" do
73
+ full_fact.values.all?.should be_true
74
+ end
75
+
76
+ it "is valid (no errors)" do
77
+ full_fact.errors.should be_empty
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ module Dbd
4
+ class Fact
5
+ describe ID do
6
+ describe "Factory" do
7
+
8
+ let(:fixed_id) { Factories::Fact::ID.fixed_id }
9
+
10
+ it "fixed_id is an Fact::ID" do
11
+ fixed_id.should be_a(described_class)
12
+ end
13
+
14
+ it "fixed_id is exactly this fixed id" do
15
+ fixed_id.to_s.should == "825e44d5-af33-4858-8047-549bd813daa8"
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ module Dbd
4
+ class Fact
5
+ describe ID do
6
+ describe ".new" do
7
+ it "creates an ID with a random uuid" do
8
+ subject.should be_a(described_class)
9
+ end
10
+
11
+ it "optionally takes an options hash with :uuid key" do
12
+ uuid = "825e44d5-af33-4858-8047-549bd813daa8"
13
+ id = described_class.new(uuid: uuid)
14
+ id.to_s.should == uuid
15
+ end
16
+ end
17
+
18
+ it "#to_s is a UUID string" do
19
+ subject.to_s.should match(Helpers::UUID.regexp)
20
+ end
21
+
22
+ it ".regexp has a regexp for the to_s" do
23
+ described_class.regexp.should == Helpers::UUID.regexp
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,117 @@
1
+ require 'spec_helper'
2
+
3
+ module Dbd
4
+ describe Fact do
5
+
6
+ let(:provenance_subject) { ProvenanceFact.new_subject }
7
+ let(:subject) { described_class.new_subject }
8
+ let(:fact_1) { Factories::Fact.fact_1(provenance_subject) }
9
+ let(:fact_2_with_subject) { Factories::Fact.fact_2_with_subject(provenance_subject) }
10
+ let(:fact_with_newline) { Factories::Fact.fact_with_newline(provenance_subject) }
11
+
12
+ describe "time_stamp=" do
13
+ it "checks the type (too easy to try to give a Time arg)" do
14
+ lambda{ fact_1.time_stamp = Time.now }.should raise_error(ArgumentError)
15
+ end
16
+
17
+ describe "set_once" do
18
+
19
+ let(:time_stamp_now) { TimeStamp.new }
20
+
21
+ it "can be set when nil" do
22
+ fact_1.time_stamp = time_stamp_now
23
+ fact_1.time_stamp.should == time_stamp_now
24
+ end
25
+
26
+ describe "setting it two times" do
27
+ it "with the value succeeds" do
28
+ fact_1.time_stamp = time_stamp_now
29
+ fact_1.time_stamp = time_stamp_now
30
+ end
31
+
32
+ it "with a different value raises a SetOnceError" do
33
+ fact_1.time_stamp = time_stamp_now
34
+ lambda{ fact_1.time_stamp = (time_stamp_now+1) }.should raise_error(RubyPeterV::SetOnceError)
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ describe "short" do
41
+ it "for a base fact shows provenance, subject, predicate, object" do
42
+ fact_1.subject = subject
43
+ fact_1.time_stamp = TimeStamp.new
44
+ fact_1.short.should match(/^[0-9a-f]{8} : [0-9a-f]{8} : http:\/\/example\.org\/test\/ : Gandhi$/)
45
+ end
46
+
47
+ it "for a fact with a newline replaces it with a underscore" do
48
+ fact_with_newline.subject = subject
49
+ fact_with_newline.short.should match(/^[0-9a-f]{8} : [0-9a-f]{8} : http:\/\/example\.org\/test\/ : A long story_really.$/)
50
+ end
51
+ end
52
+
53
+ describe "errors" do
54
+ it "the factory has no errors" do
55
+ fact_2_with_subject.errors.should be_empty
56
+ end
57
+
58
+ describe "without provenance_subject" do
59
+
60
+ before(:each) do
61
+ fact_2_with_subject.stub(:provenance_subject).and_return(nil)
62
+ end
63
+
64
+ it "errors returns an array with 1 error message" do
65
+ fact_2_with_subject.errors.single.should match(/Provenance subject is missing/)
66
+ end
67
+ end
68
+
69
+ describe "without subject" do
70
+
71
+ before(:each) do
72
+ fact_2_with_subject.stub(:subject).and_return(nil)
73
+ end
74
+
75
+ it "errors returns an array with an errorm message" do
76
+ fact_2_with_subject.errors.single.should match(/Subject is missing/)
77
+ end
78
+ end
79
+ end
80
+
81
+ describe "attributes and values" do
82
+ it "there are 6 attributes" do
83
+ described_class.attributes.size.should == 6
84
+ end
85
+
86
+ it "first attribute is :id" do
87
+ described_class.attributes.first.should == :id
88
+ end
89
+
90
+ it "there are 6 values" do
91
+ fact_1.values.size.should == 6
92
+ end
93
+ end
94
+
95
+ def values
96
+ ["825e44d5-af33-4858-8047-549bd813daa8",
97
+ "2013-06-17 21:55:09.967653012 UTC",
98
+ "40fab407-9b04-4a51-9a52-d978abfcbb1f",
99
+ "2e9fbc87-2e94-47e9-a8fd-121cc4bc3e8f",
100
+ "http://example.org/test/name",
101
+ "Gandhi"]
102
+ end
103
+
104
+ describe "from_values" do
105
+ it "reads the values correctly" do
106
+ fact = described_class.from_values(values)
107
+ fact.values.should == values
108
+ end
109
+ end
110
+
111
+ describe "provenance_fact?" do
112
+ it "is false for a base fact or derived from it that is not a ProvenanceFact " do
113
+ fact_1.provenance_fact?.should be_false
114
+ end
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,91 @@
1
+ require 'spec_helper'
2
+
3
+ module Dbd
4
+ describe Fact do
5
+ let(:fact_1) { Factories::Fact.fact_1(provenance_subject) }
6
+ let(:fact_2_with_subject) { Factories::Fact.fact_2_with_subject(provenance_subject) }
7
+ let(:provenance_subject) { ProvenanceFact.new_subject }
8
+ let(:data_predicate) { "http://example.org/test/name" }
9
+ let(:string_object_1) { "Gandhi" }
10
+ let(:id_class) { Fact::ID }
11
+ let(:subject_class) { Fact::Subject }
12
+ let(:forced_id) { described_class.new_id }
13
+ let(:fact_with_forced_id) { Factories::Fact.fact_with_forced_id(forced_id) }
14
+ let(:time_stamp) { TimeStamp.new }
15
+ let(:fact_with_time_stamp) { Factories::Fact.fact_with_time_stamp(time_stamp) }
16
+
17
+ describe ".new_subject" do
18
+ it "creates a new (random) subject" do
19
+ described_class.new_subject.should be_a(subject_class)
20
+ end
21
+
22
+ it "creating a second one is different" do
23
+ subject_1 = described_class.new_subject
24
+ subject_2 = described_class.new_subject
25
+ subject_1.should_not == subject_2
26
+ end
27
+ end
28
+
29
+ describe "create a fact" do
30
+ it "has a unique id (id_class)" do
31
+ fact_1.id.should be_a(id_class)
32
+ end
33
+
34
+ it "two facts have different id" do
35
+ fact_1.id.should_not == fact_2_with_subject.id
36
+ end
37
+
38
+ it "optionally sets the id" do
39
+ fact_with_forced_id.id.should == forced_id
40
+ end
41
+
42
+ it "optionally sets the time_stamp" do
43
+ fact_with_time_stamp.time_stamp.should == time_stamp
44
+ end
45
+
46
+ it "new sets the provenance_subject" do
47
+ fact_1.provenance_subject.should == provenance_subject
48
+ end
49
+
50
+ it "new sets the subject" do
51
+ fact_2_with_subject.subject.should be_a(subject_class)
52
+ end
53
+
54
+ it "a nil predicate raises PredicateError" do
55
+ lambda do
56
+ described_class.new(
57
+ predicate: nil,
58
+ object: string_object_1)
59
+ end.should raise_error(PredicateError)
60
+ end
61
+
62
+ it "a nil object raises ObjectError" do
63
+ lambda do
64
+ described_class.new(
65
+ predicate: data_predicate,
66
+ object: nil)
67
+ end.should raise_error(ObjectError)
68
+ end
69
+ end
70
+
71
+ describe "create fact_1" do
72
+ describe "with a string object type" do
73
+ it "new sets the predicate" do
74
+ fact_1.predicate.should == data_predicate
75
+ end
76
+
77
+ it "new sets the object" do
78
+ fact_1.object.should == string_object_1
79
+ end
80
+ end
81
+ end
82
+
83
+ describe "update_used_provenance_subjects" do
84
+ it "sets the value for provenance_subject to true for a fact" do
85
+ h = {}
86
+ fact_1.update_used_provenance_subjects(h)
87
+ h[fact_1.provenance_subject].should == true
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ module Dbd
4
+ class Fact
5
+ describe Subject do
6
+ describe "Factory" do
7
+
8
+ let(:fixed_subject) { Factories::Fact::Subject.fixed_subject }
9
+ let(:fixed_provenance_subject) { Factories::Fact::Subject.fixed_provenance_subject }
10
+
11
+ describe "fixed_subject" do
12
+ it "is an Fact::Subject" do
13
+ fixed_subject.should be_a(described_class)
14
+ end
15
+
16
+ it "fixed_subject is exactly this fixed id" do
17
+ fixed_subject.to_s.should == "2e9fbc87-2e94-47e9-a8fd-121cc4bc3e8f"
18
+ end
19
+ end
20
+
21
+ describe "fixed_provenance_subject" do
22
+ it "is an Fact::Subject" do
23
+ fixed_provenance_subject.should be_a(described_class)
24
+ end
25
+
26
+ it "fixed_provenance_subject is exactly this fixed id" do
27
+ fixed_provenance_subject.to_s.should == "40fab407-9b04-4a51-9a52-d978abfcbb1f"
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end