relaxdb 0.3.5 → 0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +21 -23
- data/Rakefile +2 -7
- data/docs/spec_results.html +5 -5
- data/lib/more/grapher.rb +1 -1
- data/lib/relaxdb.rb +3 -5
- data/lib/relaxdb/all_delegator.rb +19 -13
- data/lib/relaxdb/document.rb +150 -218
- data/lib/relaxdb/extlib.rb +7 -1
- data/lib/relaxdb/migration.rb +11 -8
- data/lib/relaxdb/net_http_server.rb +19 -1
- data/lib/relaxdb/paginator.rb +30 -11
- data/lib/relaxdb/query.rb +1 -1
- data/lib/relaxdb/{belongs_to_proxy.rb → references_proxy.rb} +3 -3
- data/lib/relaxdb/relaxdb.rb +87 -7
- data/lib/relaxdb/server.rb +8 -2
- data/lib/relaxdb/taf2_curb_server.rb +2 -1
- data/lib/relaxdb/uuid_generator.rb +38 -2
- data/lib/relaxdb/view_by_delegator.rb +34 -0
- data/lib/relaxdb/view_object.rb +1 -1
- data/lib/relaxdb/view_uploader.rb +16 -2
- data/lib/relaxdb/views.rb +23 -55
- data/readme.rb +3 -3
- data/spec/all_delegator_spec.rb +52 -0
- data/spec/callbacks_spec.rb +4 -4
- data/spec/derived_properties_spec.rb +4 -4
- data/spec/design_doc_spec.rb +2 -2
- data/spec/doc_inheritable_spec.rb +2 -2
- data/spec/document_spec.rb +47 -25
- data/spec/migration_spec.rb +12 -10
- data/spec/qpaginate_spec.rb +88 -0
- data/spec/query_spec.rb +2 -2
- data/spec/references_proxy_spec.rb +94 -0
- data/spec/relaxdb_spec.rb +29 -21
- data/spec/server_spec.rb +4 -3
- data/spec/spec_helper.rb +1 -0
- data/spec/spec_models.rb +48 -57
- data/spec/uuid_generator_spec.rb +34 -0
- data/spec/view_by_spec.rb +62 -54
- data/spec/view_docs_by_spec.rb +85 -0
- metadata +38 -27
- data/lib/more/atomic_bulk_save_support.rb +0 -18
- data/lib/relaxdb/has_many_proxy.rb +0 -101
- data/lib/relaxdb/has_one_proxy.rb +0 -42
- data/lib/relaxdb/references_many_proxy.rb +0 -97
- data/spec/belongs_to_spec.rb +0 -124
- data/spec/has_many_spec.rb +0 -202
- data/spec/has_one_spec.rb +0 -123
- data/spec/references_many_spec.rb +0 -173
- data/spec/view_spec.rb +0 -23
data/spec/has_one_spec.rb
DELETED
@@ -1,123 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
-
require File.dirname(__FILE__) + '/spec_models.rb'
|
3
|
-
|
4
|
-
describe RelaxDB::HasOneProxy do
|
5
|
-
|
6
|
-
before(:each) do
|
7
|
-
setup_test_db
|
8
|
-
end
|
9
|
-
|
10
|
-
describe "has_one" do
|
11
|
-
|
12
|
-
it "should return nil when accessed before assignment" do
|
13
|
-
p = Photo.new
|
14
|
-
p.rating.should == nil
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should be establishable via a constructor attribute" do
|
18
|
-
r = Rating.new
|
19
|
-
p = Photo.new :rating => r
|
20
|
-
p.rating.should == r
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should be establishable via assignment" do
|
24
|
-
p = Photo.new
|
25
|
-
r = Rating.new
|
26
|
-
p.rating = r
|
27
|
-
p.rating.should == r
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should return the same object on repeated invocations" do
|
31
|
-
p = Photo.new.save
|
32
|
-
p.rating = Rating.new
|
33
|
-
p = RelaxDB.load(p._id)
|
34
|
-
p.rating.object_id.should == p.rating.object_id
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should be preserved across load / save boundary" do
|
38
|
-
r = Rating.new
|
39
|
-
p = Photo.new(:rating => r).save
|
40
|
-
p = RelaxDB.load p._id
|
41
|
-
p.rating.should == r
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should be able reference itself via its child" do
|
45
|
-
r = Rating.new
|
46
|
-
p = Photo.new(:rating => r).save
|
47
|
-
p = RelaxDB.load p._id
|
48
|
-
p.rating.photo.should == p
|
49
|
-
end
|
50
|
-
|
51
|
-
it "should work with MultiWordClassNames" do
|
52
|
-
c = MultiWordChild.new
|
53
|
-
m = MultiWordClass.new(:multi_word_child => c).save
|
54
|
-
m = RelaxDB.load m._id
|
55
|
-
m.multi_word_child.should == c
|
56
|
-
end
|
57
|
-
|
58
|
-
describe "#=" do
|
59
|
-
|
60
|
-
it "should create a reference from the child to the parent" do
|
61
|
-
p = Photo.new
|
62
|
-
r = Rating.new
|
63
|
-
p.rating = r
|
64
|
-
r.photo.should == p
|
65
|
-
end
|
66
|
-
|
67
|
-
it "should save the assigned object" do
|
68
|
-
p = Photo.new
|
69
|
-
r = Rating.new
|
70
|
-
p.rating = r
|
71
|
-
r.should_not be_unsaved
|
72
|
-
end
|
73
|
-
|
74
|
-
it "will not save the parent" do
|
75
|
-
p = Photo.new
|
76
|
-
r = Rating.new
|
77
|
-
p.rating = r
|
78
|
-
p.should be_unsaved
|
79
|
-
end
|
80
|
-
|
81
|
-
it "should set the target to nil when nil is assigned" do
|
82
|
-
p = Photo.new
|
83
|
-
p.rating = nil
|
84
|
-
p.rating.should be_nil
|
85
|
-
end
|
86
|
-
|
87
|
-
it "should nullify any existing relationship in the database" do
|
88
|
-
p = Photo.new
|
89
|
-
r = Rating.new
|
90
|
-
p.rating = r
|
91
|
-
p.rating = nil
|
92
|
-
RelaxDB.load(r._id).photo.should be_nil
|
93
|
-
end
|
94
|
-
|
95
|
-
it "should nullify any existing relationship on a known in-memory object" do
|
96
|
-
p = Photo.new
|
97
|
-
r = Rating.new
|
98
|
-
p.rating = r
|
99
|
-
p.rating = nil
|
100
|
-
r.photo.should be_nil
|
101
|
-
end
|
102
|
-
|
103
|
-
it "will not nullify any existing relationship on unknown in-memory objects" do
|
104
|
-
p = Photo.new.save
|
105
|
-
r = Rating.new
|
106
|
-
p.rating = r
|
107
|
-
r_copy = RelaxDB.load(r._id)
|
108
|
-
p.rating = nil
|
109
|
-
r_copy.photo.should_not be_nil
|
110
|
-
end
|
111
|
-
|
112
|
-
it "will not throw an error when the rhs fails validation" do
|
113
|
-
d = Dysfunctional.new.save
|
114
|
-
f = Failure.new
|
115
|
-
d.failure = f
|
116
|
-
d.failure.should == f
|
117
|
-
end
|
118
|
-
|
119
|
-
end
|
120
|
-
|
121
|
-
end
|
122
|
-
|
123
|
-
end
|
@@ -1,173 +0,0 @@
|
|
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
|
-
setup_test_db
|
8
|
-
end
|
9
|
-
|
10
|
-
describe "references_many" do
|
11
|
-
|
12
|
-
it "should preserve the relationships across the save / load boundary" do
|
13
|
-
p = Photo.new
|
14
|
-
t = Tag.new
|
15
|
-
t.photos << p
|
16
|
-
|
17
|
-
p = RelaxDB.load p._id
|
18
|
-
p.tags.size.should == 1
|
19
|
-
p.tags[0].should == t
|
20
|
-
|
21
|
-
t = RelaxDB.load t._id
|
22
|
-
t.photos.size.should == 1
|
23
|
-
t.photos[0].should == p
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should issue only a single request to resolve the relationship" do
|
27
|
-
p, t = Photo.new, Tag.new
|
28
|
-
p.tags << t
|
29
|
-
|
30
|
-
# Create the views
|
31
|
-
p.tags.map { |t| t._id }
|
32
|
-
|
33
|
-
p = RelaxDB.load p._id
|
34
|
-
RelaxDB.db.get_count = 0
|
35
|
-
p.tags.map { |t| t._id }
|
36
|
-
p.tags.map { |t| t._id }
|
37
|
-
RelaxDB.db.get_count.should == 1
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should not resolve the relationship when an object is instantiated" do
|
41
|
-
p, t = Photo.new, Tag.new
|
42
|
-
p.tags << t
|
43
|
-
|
44
|
-
RelaxDB.db.get_count = 0
|
45
|
-
p = RelaxDB.load p._id
|
46
|
-
RelaxDB.db.get_count.should == 1
|
47
|
-
end
|
48
|
-
|
49
|
-
it "should make the ids available as a property" do
|
50
|
-
p, t = Photo.new, Tag.new
|
51
|
-
p.tags << t
|
52
|
-
|
53
|
-
p.tags_ids.should == [t._id]
|
54
|
-
end
|
55
|
-
|
56
|
-
describe "#=" do
|
57
|
-
it "should not be invoked" do
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe "#<<" do
|
62
|
-
|
63
|
-
it "should set the relationship on both sides" do
|
64
|
-
p = Photo.new(:name => "photo")
|
65
|
-
t = Tag.new(:name => "tag")
|
66
|
-
p.tags << t
|
67
|
-
|
68
|
-
p.tags.size.should == 1
|
69
|
-
p.tags[0].name.should == "tag"
|
70
|
-
|
71
|
-
t.photos.size.should == 1
|
72
|
-
t.photos[0].name.should == "photo"
|
73
|
-
end
|
74
|
-
|
75
|
-
it "should not create duplicates when the same object is added more than once" do
|
76
|
-
p = Photo.new
|
77
|
-
t = Tag.new
|
78
|
-
p.tags << t << t
|
79
|
-
p.tags.size.should == 1
|
80
|
-
end
|
81
|
-
|
82
|
-
it "should not create duplicates when reciprocal objects are added from opposite sides" do
|
83
|
-
p = Photo.new
|
84
|
-
t = Tag.new
|
85
|
-
p.tags << t
|
86
|
-
t.photos << p
|
87
|
-
p.tags.size.should == 1
|
88
|
-
t.photos.size.should == 1
|
89
|
-
end
|
90
|
-
|
91
|
-
it "will resolve the reciprocal relationship" do
|
92
|
-
# Create the views
|
93
|
-
p, t = Photo.new, Tag.new
|
94
|
-
p.tags << t
|
95
|
-
|
96
|
-
p, t = Photo.new, Tag.new
|
97
|
-
RelaxDB.db.get_count = 0
|
98
|
-
p.tags << t
|
99
|
-
RelaxDB.db.get_count.should == 2
|
100
|
-
end
|
101
|
-
|
102
|
-
end
|
103
|
-
|
104
|
-
describe "#delete" do
|
105
|
-
|
106
|
-
it "should nullify relationship on both sides" do
|
107
|
-
p = Photo.new
|
108
|
-
t = Tag.new
|
109
|
-
p.tags << t
|
110
|
-
|
111
|
-
p.tags.delete(t)
|
112
|
-
p.tags.should be_empty
|
113
|
-
t.photos.should be_empty
|
114
|
-
end
|
115
|
-
|
116
|
-
end
|
117
|
-
|
118
|
-
describe "owner#destroy" do
|
119
|
-
|
120
|
-
it "should remove its membership from its peers in memory" do
|
121
|
-
p = Photo.new
|
122
|
-
t = Tag.new
|
123
|
-
p.tags << t
|
124
|
-
|
125
|
-
p.destroy!
|
126
|
-
t.photos.size.should == 0
|
127
|
-
end
|
128
|
-
|
129
|
-
it "should remove its membership from its peers in CouchDB" do
|
130
|
-
p = Photo.new
|
131
|
-
t = Tag.new
|
132
|
-
p.tags << t
|
133
|
-
|
134
|
-
p.destroy!
|
135
|
-
RelaxDB.load(t._id).photos.should be_empty
|
136
|
-
end
|
137
|
-
|
138
|
-
end
|
139
|
-
|
140
|
-
# Leaving this test as a reminder of problems with all.destroy and a self referential
|
141
|
-
# references_many
|
142
|
-
#
|
143
|
-
# This test more complex than it needs to be to prove the point
|
144
|
-
# It also serves as a proof of a self referential references_many, but there are better places for that
|
145
|
-
# it "all.destroy should play nice with self referential references_many" do
|
146
|
-
# u1 = TwitterUser.new(:name => "u1")
|
147
|
-
# u2 = TwitterUser.new(:name => "u2")
|
148
|
-
# u3 = TwitterUser.new(:name => "u3")
|
149
|
-
#
|
150
|
-
# u1.followers << u2
|
151
|
-
# u1.followers << u3
|
152
|
-
# u3.leaders << u2
|
153
|
-
#
|
154
|
-
# u1f = u1.followers.map { |u| u.name }
|
155
|
-
# u1f.sort.should == ["u2", "u3"]
|
156
|
-
# u1.leaders.should be_empty
|
157
|
-
#
|
158
|
-
# u2.leaders.size.should == 1
|
159
|
-
# u2.leaders[0].name.should == "u1"
|
160
|
-
# u2.followers.size.should == 1
|
161
|
-
# u2.followers[0].name.should == "u3"
|
162
|
-
#
|
163
|
-
# u3l = u3.leaders.map { |u| u.name }
|
164
|
-
# u3l.sort.should == ["u1", "u2"]
|
165
|
-
# u3.followers.should be_empty
|
166
|
-
#
|
167
|
-
# TwitterUser.all.destroy!
|
168
|
-
# TwitterUser.all.should be_empty
|
169
|
-
# end
|
170
|
-
|
171
|
-
end
|
172
|
-
|
173
|
-
end
|
data/spec/view_spec.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
-
require File.dirname(__FILE__) + '/spec_models.rb'
|
3
|
-
|
4
|
-
describe RelaxDB::View do
|
5
|
-
|
6
|
-
describe "exists" do
|
7
|
-
|
8
|
-
before(:each) do
|
9
|
-
create_test_db
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should return nil if a view doesnt exist" do
|
13
|
-
RelaxDB::ViewCreator.all([Atom]).should_not be_exists
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should return the view if it exits" do
|
17
|
-
RelaxDB::ViewCreator.all([Atom]).save
|
18
|
-
RelaxDB::ViewCreator.all([Atom]).should be_exists
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|