paulcarey-relaxdb 0.1.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.
- data/LICENSE +20 -0
- data/README.textile +98 -0
- data/Rakefile +52 -0
- data/docs/spec_results.html +602 -0
- data/lib/relaxdb/all_delegator.rb +48 -0
- data/lib/relaxdb/belongs_to_proxy.rb +29 -0
- data/lib/relaxdb/design_doc.rb +50 -0
- data/lib/relaxdb/document.rb +298 -0
- data/lib/relaxdb/has_many_proxy.rb +81 -0
- data/lib/relaxdb/has_one_proxy.rb +45 -0
- data/lib/relaxdb/query.rb +48 -0
- data/lib/relaxdb/references_many_proxy.rb +99 -0
- data/lib/relaxdb/relaxdb.rb +106 -0
- data/lib/relaxdb/server.rb +112 -0
- data/lib/relaxdb/sorted_by_view.rb +42 -0
- data/lib/relaxdb/uuid_generator.rb +21 -0
- data/lib/relaxdb/view_object.rb +34 -0
- data/lib/relaxdb/view_uploader.rb +47 -0
- data/lib/relaxdb/views.rb +42 -0
- data/lib/relaxdb.rb +33 -0
- data/spec/belongs_to_spec.rb +80 -0
- data/spec/design_doc_spec.rb +34 -0
- data/spec/document_spec.rb +301 -0
- data/spec/has_many_spec.rb +139 -0
- data/spec/has_one_spec.rb +121 -0
- data/spec/query_spec.rb +46 -0
- data/spec/references_many_spec.rb +141 -0
- data/spec/relaxdb_spec.rb +50 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/spec_models.rb +104 -0
- data/spec/view_object_spec.rb +47 -0
- metadata +111 -0
@@ -0,0 +1,141 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
require File.dirname(__FILE__) + '/spec_models.rb'
|
3
|
+
|
4
|
+
describe RelaxDB::ReferencesManyProxy do
|
5
|
+
|
6
|
+
before(:all) do
|
7
|
+
RelaxDB.configure(:host => "localhost", :port => 5984)
|
8
|
+
end
|
9
|
+
|
10
|
+
before(:each) do
|
11
|
+
RelaxDB.delete_db "relaxdb_spec_db" rescue "ok"
|
12
|
+
RelaxDB.use_db "relaxdb_spec_db"
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "references_many" do
|
16
|
+
|
17
|
+
it "is now deprecated and will be removed in the near future" do
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should preserve the relationships across the save / load boundary" do
|
21
|
+
p = Photo.new
|
22
|
+
t = Tag.new
|
23
|
+
t.photos << p
|
24
|
+
|
25
|
+
p = RelaxDB.load p._id
|
26
|
+
p.tags.size.should == 1
|
27
|
+
p.tags[0].should == t
|
28
|
+
|
29
|
+
t = RelaxDB.load t._id
|
30
|
+
t.photos.size.should == 1
|
31
|
+
t.photos[0].should == p
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "#=" do
|
35
|
+
it "should not be invoked" do
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#<<" do
|
40
|
+
|
41
|
+
it "should set the relationship on both sides" do
|
42
|
+
p = Photo.new(:name => "photo")
|
43
|
+
t = Tag.new(:name => "tag")
|
44
|
+
p.tags << t
|
45
|
+
|
46
|
+
p.tags.size.should == 1
|
47
|
+
p.tags[0].name.should == "tag"
|
48
|
+
|
49
|
+
t.photos.size.should == 1
|
50
|
+
t.photos[0].name.should == "photo"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should not create duplicates when the same object is added more than once" do
|
54
|
+
p = Photo.new
|
55
|
+
t = Tag.new
|
56
|
+
p.tags << t << t
|
57
|
+
p.tags.size.should == 1
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should not create duplicates when reciprocal objects are added from opposite sides" do
|
61
|
+
p = Photo.new
|
62
|
+
t = Tag.new
|
63
|
+
p.tags << t
|
64
|
+
t.photos << p
|
65
|
+
p.tags.size.should == 1
|
66
|
+
t.photos.size.should == 1
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "#delete" do
|
72
|
+
|
73
|
+
it "should nullify relationship on both sides" do
|
74
|
+
p = Photo.new
|
75
|
+
t = Tag.new
|
76
|
+
p.tags << t
|
77
|
+
|
78
|
+
p.tags.delete(t)
|
79
|
+
p.tags.should be_empty
|
80
|
+
t.photos.should be_empty
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "owner#destroy" do
|
86
|
+
|
87
|
+
it "will not remove its membership from its peers in memory" do
|
88
|
+
# Documentating behaviour, not stating that this behaviour is desired
|
89
|
+
p = Photo.new
|
90
|
+
t = Tag.new
|
91
|
+
p.tags << t
|
92
|
+
|
93
|
+
p.destroy!
|
94
|
+
t.photos.size.should == 1
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should remove its membership from its peers in CouchDB" do
|
98
|
+
p = Photo.new
|
99
|
+
t = Tag.new
|
100
|
+
p.tags << t
|
101
|
+
|
102
|
+
p.destroy!
|
103
|
+
RelaxDB.load(t._id).photos.should be_empty
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
# Leaving this test as a reminder of problems with all.destroy and a self referential
|
109
|
+
# references_many until references_many is removed
|
110
|
+
#
|
111
|
+
# This test more complex than it needs to be to prove the point
|
112
|
+
# It also serves as a proof of a self referential references_many, but there are better places for that
|
113
|
+
# it "all.destroy should play nice with self referential references_many" do
|
114
|
+
# u1 = TwitterUser.new(:name => "u1")
|
115
|
+
# u2 = TwitterUser.new(:name => "u2")
|
116
|
+
# u3 = TwitterUser.new(:name => "u3")
|
117
|
+
#
|
118
|
+
# u1.followers << u2
|
119
|
+
# u1.followers << u3
|
120
|
+
# u3.leaders << u2
|
121
|
+
#
|
122
|
+
# u1f = u1.followers.map { |u| u.name }
|
123
|
+
# u1f.sort.should == ["u2", "u3"]
|
124
|
+
# u1.leaders.should be_empty
|
125
|
+
#
|
126
|
+
# u2.leaders.size.should == 1
|
127
|
+
# u2.leaders[0].name.should == "u1"
|
128
|
+
# u2.followers.size.should == 1
|
129
|
+
# u2.followers[0].name.should == "u3"
|
130
|
+
#
|
131
|
+
# u3l = u3.leaders.map { |u| u.name }
|
132
|
+
# u3l.sort.should == ["u1", "u2"]
|
133
|
+
# u3.followers.should be_empty
|
134
|
+
#
|
135
|
+
# TwitterUser.all.destroy!
|
136
|
+
# TwitterUser.all.should be_empty
|
137
|
+
# end
|
138
|
+
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
require File.dirname(__FILE__) + '/spec_models.rb'
|
3
|
+
|
4
|
+
describe RelaxDB do
|
5
|
+
|
6
|
+
before(:all) do
|
7
|
+
RelaxDB.configure(:host => "localhost", :port => 5984)
|
8
|
+
end
|
9
|
+
|
10
|
+
before(:each) do
|
11
|
+
RelaxDB.delete_db "relaxdb_spec_db" rescue "ok"
|
12
|
+
RelaxDB.use_db "relaxdb_spec_db"
|
13
|
+
end
|
14
|
+
|
15
|
+
describe ".create_object" do
|
16
|
+
|
17
|
+
it "should return an instance of a known object if passed a hash with a class key" do
|
18
|
+
data = { "class" => "Item" }
|
19
|
+
obj = RelaxDB.create_object(data)
|
20
|
+
obj.should be_instance_of(Item)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should return an instance of a dynamically created object if no class key is provided" do
|
24
|
+
data = { "name" => "tesla coil", "strength" => 5000 }
|
25
|
+
obj = RelaxDB.create_object(data)
|
26
|
+
obj.name.should == "tesla coil"
|
27
|
+
obj.strength.should == 5000
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
describe ".bulk_save" do
|
33
|
+
|
34
|
+
it "should be invokable multiple times" do
|
35
|
+
t1 = Tag.new(:name => "t1")
|
36
|
+
t2 = Tag.new(:name => "t2")
|
37
|
+
RelaxDB.bulk_save(t1, t2)
|
38
|
+
RelaxDB.bulk_save(t1, t2)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should succeed when passed no args" do
|
42
|
+
RelaxDB.bulk_save
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should offer an example where behaviour is different with caching enabled and caching disabled" do
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
data/spec/spec_models.rb
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
class Atom < RelaxDB::Document
|
2
|
+
end
|
3
|
+
|
4
|
+
class Primitives < RelaxDB::Document
|
5
|
+
|
6
|
+
property :str
|
7
|
+
property :num
|
8
|
+
property :true_bool
|
9
|
+
property :false_bool
|
10
|
+
property :created_at
|
11
|
+
property :empty
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
class Invite < RelaxDB::Document
|
16
|
+
|
17
|
+
property :message
|
18
|
+
|
19
|
+
belongs_to :sender
|
20
|
+
belongs_to :recipient
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
class Item < RelaxDB::Document
|
25
|
+
|
26
|
+
property :name
|
27
|
+
belongs_to :user
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
class User < RelaxDB::Document
|
32
|
+
|
33
|
+
property :name
|
34
|
+
property :age
|
35
|
+
|
36
|
+
has_many :items, :class => "Item"
|
37
|
+
|
38
|
+
has_many :invites_received, :class => "Invite", :known_as => :recipient
|
39
|
+
has_many :invites_sent, :class => "Invite", :known_as => :sender
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
class Post < RelaxDB::Document
|
44
|
+
|
45
|
+
property :subject
|
46
|
+
property :content
|
47
|
+
property :created_at
|
48
|
+
property :viewed_at
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
class Rating < RelaxDB::Document
|
53
|
+
|
54
|
+
property :stars, :default => 5
|
55
|
+
belongs_to :photo
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
class Photo < RelaxDB::Document
|
60
|
+
|
61
|
+
property :name
|
62
|
+
|
63
|
+
has_one :rating
|
64
|
+
|
65
|
+
references_many :tags, :class => "Tag", :known_as => :photos
|
66
|
+
|
67
|
+
has_many :taggings, :class => "Tagging"
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
class Tag < RelaxDB::Document
|
72
|
+
|
73
|
+
property :name
|
74
|
+
references_many :photos, :class => "Photo", :known_as => :tags
|
75
|
+
|
76
|
+
has_many :taggings, :class => "Tagging"
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
class Tagging < RelaxDB::Document
|
81
|
+
|
82
|
+
belongs_to :photo
|
83
|
+
belongs_to :tag
|
84
|
+
property :relevance
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
class TwitterUser < RelaxDB::Document
|
89
|
+
|
90
|
+
property :name
|
91
|
+
references_many :followers, :class => "User", :known_as => :leaders
|
92
|
+
references_many :leaders, :class => "User", :known_as => :followers
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
class Dysfunctional < RelaxDB::Document
|
97
|
+
has_one :failure
|
98
|
+
has_many :failures, :class => "Failure"
|
99
|
+
end
|
100
|
+
|
101
|
+
class Failure < RelaxDB::Document
|
102
|
+
property :pathological, :validator => lambda { false }
|
103
|
+
belongs_to :dysfunctional
|
104
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
require File.dirname(__FILE__) + '/spec_models.rb'
|
3
|
+
|
4
|
+
describe RelaxDB::ViewObject do
|
5
|
+
|
6
|
+
describe ".new" do
|
7
|
+
|
8
|
+
it "should provide readers for the object passed in the hash" do
|
9
|
+
data = { :name => "chaise", :variety => "longue" }
|
10
|
+
obj = RelaxDB::ViewObject.new(data)
|
11
|
+
obj.name.should == "chaise"
|
12
|
+
obj.variety.should == "longue"
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should try to convert objects ending in _at to a time" do
|
16
|
+
now = Time.now
|
17
|
+
data = { :ends_at => now.to_s }
|
18
|
+
obj = RelaxDB::ViewObject.new(data)
|
19
|
+
obj.ends_at.should be_close(now, 1)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
describe ".create" do
|
25
|
+
|
26
|
+
it "should return an array of view objects when passed an array" do
|
27
|
+
data = [ {:half_life => 2}, {:half_life => 16} ]
|
28
|
+
obj = RelaxDB::ViewObject.create(data)
|
29
|
+
obj.size.should == 2
|
30
|
+
obj[0].half_life.should == 2
|
31
|
+
obj[1].half_life.should == 16
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should return a view object when passed a hash" do
|
35
|
+
data = {:half_life => 32}
|
36
|
+
obj = RelaxDB::ViewObject.create(data)
|
37
|
+
obj.half_life.should == 32
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should return a simple value when passed a primitive" do
|
41
|
+
obj = RelaxDB::ViewObject.create(10)
|
42
|
+
obj.should == 10
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: paulcarey-relaxdb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Paul Carey
|
8
|
+
autorequire: relaxdb
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-08-25 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: extlib
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.9.4
|
23
|
+
version:
|
24
|
+
- !ruby/object:Gem::Dependency
|
25
|
+
name: json
|
26
|
+
version_requirement:
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: "0"
|
32
|
+
version:
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: uuid
|
35
|
+
version_requirement:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: "0"
|
41
|
+
version:
|
42
|
+
description:
|
43
|
+
email: paul.p.carey@gmail.com
|
44
|
+
executables: []
|
45
|
+
|
46
|
+
extensions: []
|
47
|
+
|
48
|
+
extra_rdoc_files: []
|
49
|
+
|
50
|
+
files:
|
51
|
+
- LICENSE
|
52
|
+
- README.textile
|
53
|
+
- Rakefile
|
54
|
+
- docs/spec_results.html
|
55
|
+
- lib/relaxdb
|
56
|
+
- lib/relaxdb/all_delegator.rb
|
57
|
+
- lib/relaxdb/belongs_to_proxy.rb
|
58
|
+
- lib/relaxdb/design_doc.rb
|
59
|
+
- lib/relaxdb/document.rb
|
60
|
+
- lib/relaxdb/has_many_proxy.rb
|
61
|
+
- lib/relaxdb/has_one_proxy.rb
|
62
|
+
- lib/relaxdb/query.rb
|
63
|
+
- lib/relaxdb/references_many_proxy.rb
|
64
|
+
- lib/relaxdb/relaxdb.rb
|
65
|
+
- lib/relaxdb/server.rb
|
66
|
+
- lib/relaxdb/sorted_by_view.rb
|
67
|
+
- lib/relaxdb/uuid_generator.rb
|
68
|
+
- lib/relaxdb/view_object.rb
|
69
|
+
- lib/relaxdb/view_uploader.rb
|
70
|
+
- lib/relaxdb/views.rb
|
71
|
+
- lib/relaxdb.rb
|
72
|
+
- spec/belongs_to_spec.rb
|
73
|
+
- spec/design_doc_spec.rb
|
74
|
+
- spec/document_spec.rb
|
75
|
+
- spec/has_many_spec.rb
|
76
|
+
- spec/has_one_spec.rb
|
77
|
+
- spec/query_spec.rb
|
78
|
+
- spec/references_many_spec.rb
|
79
|
+
- spec/relaxdb_spec.rb
|
80
|
+
- spec/spec.opts
|
81
|
+
- spec/spec_helper.rb
|
82
|
+
- spec/spec_models.rb
|
83
|
+
- spec/view_object_spec.rb
|
84
|
+
has_rdoc: false
|
85
|
+
homepage: http://github.com/paulcarey/relaxdb/
|
86
|
+
post_install_message:
|
87
|
+
rdoc_options: []
|
88
|
+
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: "0"
|
96
|
+
version:
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: "0"
|
102
|
+
version:
|
103
|
+
requirements: []
|
104
|
+
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 1.2.0
|
107
|
+
signing_key:
|
108
|
+
specification_version: 2
|
109
|
+
summary: RelaxDB provides a simple interface to CouchDB
|
110
|
+
test_files: []
|
111
|
+
|