rocking_chair 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rocking_chair/view.rb +6 -2
- data/test/fixtures/simply_stored_fixtures.rb +1 -1
- data/test/simply_stored_test.rb +310 -307
- metadata +4 -4
data/lib/rocking_chair/view.rb
CHANGED
@@ -18,10 +18,10 @@ module RockingChair
|
|
18
18
|
@design_document = JSON.parse(database.storage["_design/#{design_document_name}"], :create_additions => false)
|
19
19
|
@view_document = design_document['views'][view_name] || RockingChair::Error.raise_404
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
@database = database
|
23
23
|
@keys = database.storage.keys
|
24
|
-
@design_document_name = design_document_name
|
24
|
+
@design_document_name = normalize_design_document_name(design_document_name)
|
25
25
|
@view_name = view_name
|
26
26
|
initialize_ruby_store
|
27
27
|
|
@@ -311,5 +311,9 @@ module RockingChair
|
|
311
311
|
end
|
312
312
|
end
|
313
313
|
|
314
|
+
def normalize_design_document_name(design_doc_name)
|
315
|
+
design_doc_name.to_s.gsub(/_view_\w+/, '')
|
316
|
+
end
|
317
|
+
|
314
318
|
end
|
315
319
|
end
|
data/test/simply_stored_test.rb
CHANGED
@@ -6,395 +6,398 @@ def recreate_db
|
|
6
6
|
end
|
7
7
|
|
8
8
|
class SimplyStoredTest < Test::Unit::TestCase
|
9
|
-
|
10
|
-
|
11
|
-
RockingChair::Server.reset
|
12
|
-
CouchPotato::Config.database_name = 'fake_simply_stored'
|
13
|
-
recreate_db
|
14
|
-
end
|
9
|
+
[false, true].each do |setting|
|
10
|
+
CouchPotato::Config.split_design_documents_per_view = setting
|
15
11
|
|
16
|
-
context "
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
project = Project.find(p.id)
|
22
|
-
assert_equal 'The title', project.title
|
12
|
+
context "Extended use cases for SimplyStored with split_design_documents_per_view #{setting ? 'enabled' : 'disabled'}" do
|
13
|
+
setup do
|
14
|
+
RockingChair::Server.reset
|
15
|
+
CouchPotato::Config.database_name = 'fake_simply_stored'
|
16
|
+
recreate_db
|
23
17
|
end
|
18
|
+
|
19
|
+
context "storing and loading documents" do
|
20
|
+
should "save and find Projects" do
|
21
|
+
p = Project.new(:title => 'The title')
|
22
|
+
assert p.save
|
23
|
+
assert_not_nil p.id, p.inspect
|
24
|
+
project = Project.find(p.id)
|
25
|
+
assert_equal 'The title', project.title
|
26
|
+
end
|
24
27
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
28
|
+
should "save and find Users" do
|
29
|
+
p = Project.new(:title => 'The title')
|
30
|
+
assert p.save
|
31
|
+
u = User.new(:firstname => 'Doc', :lastname => 'Holiday', :project => p)
|
32
|
+
assert u.save
|
33
|
+
user = User.find(u.id)
|
34
|
+
assert_equal 'Doc', user.firstname
|
35
|
+
assert_equal 'Holiday', user.lastname
|
36
|
+
assert_equal p.id, user.project_id
|
37
|
+
assert_equal p, user.project
|
38
|
+
end
|
35
39
|
end
|
36
|
-
end
|
37
40
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
41
|
+
context "Views" do
|
42
|
+
setup do
|
43
|
+
@manager = Manager.new(:firstname => 'Michael')
|
44
|
+
assert @manager.save
|
42
45
|
|
43
|
-
|
44
|
-
|
46
|
+
@project = Project.new(:title => 'The title', :manager => @manager)
|
47
|
+
assert @project.save
|
45
48
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
+
@user = User.new(:firstname => 'Michael', :project => @project)
|
50
|
+
assert @user.save
|
51
|
+
end
|
49
52
|
|
50
|
-
|
53
|
+
context "by_attribute views" do
|
51
54
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
55
|
+
should "load first" do
|
56
|
+
user_1 = User.create(:firstname => 'Bart', :lastname => 'S')
|
57
|
+
user_2 = User.create(:firstname => 'Homer', :lastname => 'J')
|
58
|
+
assert_equal 'J', User.find_by_firstname('Homer').lastname
|
59
|
+
end
|
57
60
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
61
|
+
should "load all" do
|
62
|
+
user_1 = User.create(:firstname => 'Bart', :lastname => 'S')
|
63
|
+
user_2 = User.create(:firstname => 'Homer', :lastname => 'J')
|
64
|
+
user_2 = User.create(:firstname => 'Homer', :lastname => 'S')
|
65
|
+
assert_equal ['S', 'J'].sort, User.find_all_by_firstname('Homer').map(&:lastname).sort
|
66
|
+
end
|
64
67
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
68
|
+
should "only load objects from the correct class" do
|
69
|
+
user = User.create(:firstname => 'Bart', :lastname => 'S')
|
70
|
+
manager = Manager.create(:firstname => 'Bart', :lastname => 'J')
|
71
|
+
assert_equal ['S'], User.find_all_by_firstname('Bart').map(&:lastname)
|
72
|
+
end
|
70
73
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
74
|
+
should "support multiple attributes" do
|
75
|
+
user_1 = User.create(:firstname => 'Bart', :lastname => 'S')
|
76
|
+
user_2 = User.create(:firstname => 'Homer', :lastname => 'J')
|
77
|
+
user_2 = User.create(:firstname => 'Homer', :lastname => 'S')
|
78
|
+
assert_equal ['J'].sort, User.find_all_by_firstname_and_lastname('Homer', 'J').map(&:lastname).sort
|
79
|
+
end
|
76
80
|
end
|
77
|
-
end
|
78
81
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
+
context "belongs_to" do
|
83
|
+
should "load the parent object" do
|
84
|
+
assert_equal @project.id, @user.project.id
|
85
|
+
end
|
82
86
|
end
|
83
|
-
end
|
84
87
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
88
|
+
context "has_one" do
|
89
|
+
should "load the child object" do
|
90
|
+
assert_equal @project.id, @manager.project.id
|
91
|
+
assert_equal @manager.id, @project.manager.id
|
92
|
+
end
|
90
93
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
+
should "re-use existing views" do
|
95
|
+
Manager.create(:firstname => 'Jochen', :lastname => 'Peter')
|
96
|
+
Manager.create(:firstname => 'Another', :lastname => 'Bert')
|
97
|
+
end
|
94
98
|
end
|
95
|
-
end
|
96
99
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
100
|
+
context "has_many" do
|
101
|
+
setup do
|
102
|
+
RockingChair::Server.reset
|
103
|
+
CouchPotato::Config.database_name = 'fake_simply_stored'
|
104
|
+
recreate_db
|
105
|
+
end
|
103
106
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
107
|
+
should "load all has_many objects" do
|
108
|
+
user = User.new(:firstname => 'Michael', :project => @project)
|
109
|
+
assert user.save
|
110
|
+
assert_equal [user.id], @project.users.map(&:id)
|
111
|
+
end
|
109
112
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
113
|
+
should "support counting associated" do
|
114
|
+
assert_equal 0, @project.user_count
|
115
|
+
user = User.create(:firstname => 'Michael', :project => @project)
|
116
|
+
assert_equal 1, @project.user_count(:force_reload => true)
|
117
|
+
end
|
115
118
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
119
|
+
should "support limiting" do
|
120
|
+
3.times{ User.create!(:firstname => 'Michael', :project => @project) }
|
121
|
+
assert_equal 3, @project.users.size
|
122
|
+
assert_equal 2, @project.users(:limit => 2).size
|
123
|
+
end
|
121
124
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
125
|
+
should "support mixing order and limit" do
|
126
|
+
michael = User.find(User.create!(:firstname => "michael", :project => @project).id)
|
127
|
+
michael.created_at = Time.local(2001)
|
128
|
+
michael.save!
|
126
129
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
+
mickey = User.find(User.create!(:firstname => "mickey", :project => @project).id)
|
131
|
+
mickey.created_at = Time.local(2002)
|
132
|
+
mickey.save!
|
130
133
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
+
mike = User.find(User.create!(:firstname => "mike", :project => @project).id)
|
135
|
+
mike.created_at = Time.local(2003)
|
136
|
+
mike.save!
|
134
137
|
|
135
|
-
|
136
|
-
|
138
|
+
assert_equal ["michael", "mickey", "mike"], @project.users(:order => :asc).map(&:firstname)
|
139
|
+
assert_equal ["michael", "mickey", "mike"].reverse, @project.users(:order => :desc).map(&:firstname)
|
140
|
+
end
|
137
141
|
end
|
138
|
-
end
|
139
142
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
143
|
+
context "when querying the all_documents view" do
|
144
|
+
setup do
|
145
|
+
RockingChair::Server.reset
|
146
|
+
CouchPotato::Config.database_name = 'fake_simply_stored'
|
147
|
+
recreate_db
|
148
|
+
end
|
146
149
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
150
|
+
should "load all from the same class" do
|
151
|
+
User.create(:firstname => 'Michael Mann', :project => @project)
|
152
|
+
User.create(:firstname => 'Peter', :project => @project)
|
153
|
+
assert_equal ['Peter', 'Michael Mann'].sort, User.all.map(&:firstname).sort
|
151
154
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
+
User.create(:firstname => 'Hulk', :project => @project)
|
156
|
+
assert_equal ['Peter', 'Michael Mann', 'Hulk'].sort, User.all.map(&:firstname).sort
|
157
|
+
end
|
155
158
|
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
159
|
+
should "support order" do
|
160
|
+
3.times{|i| User.create!(:firstname => "user #{i}") }
|
161
|
+
assert_not_equal User.all(:order => :asc).map(&:id), User.all(:order => :desc).map(&:id)
|
162
|
+
assert_equal User.all(:order => :asc).reverse, User.all(:order => :desc)
|
163
|
+
end
|
161
164
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
165
|
+
should "load first" do
|
166
|
+
User.create(:firstname => 'Michael Mann', :project => @project)
|
167
|
+
User.create(:firstname => 'Peter', :project => @project)
|
168
|
+
assert User.first.respond_to?(:firstname)
|
169
|
+
end
|
167
170
|
|
168
|
-
|
169
|
-
|
171
|
+
should "count" do
|
172
|
+
User.create(:firstname => 'Michael the first')
|
170
173
|
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
+
assert_equal 0, Project.count
|
175
|
+
assert_equal 0, Manager.count
|
176
|
+
assert_equal 1, User.count
|
174
177
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
178
|
+
Manager.create(:firstname => 'Jochen', :lastname => 'Peter')
|
179
|
+
Project.create(:title => 'The title', :manager => @manager)
|
180
|
+
Project.create(:title => 'another title', :manager => @manager)
|
181
|
+
User.create(:firstname => 'Michael Mann', :project => @project)
|
182
|
+
User.create(:firstname => 'Peter', :project => @project)
|
180
183
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
184
|
+
assert_equal 2, Project.count
|
185
|
+
assert_equal 1, Manager.count
|
186
|
+
assert_equal 3, User.count
|
187
|
+
end
|
185
188
|
|
186
|
-
|
187
|
-
|
189
|
+
should "count_by" do
|
190
|
+
User.create(:firstname => 'michael')
|
188
191
|
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
+
assert_equal 1, User.count
|
193
|
+
assert_equal 1, User.count_by_firstname('michael')
|
194
|
+
end
|
192
195
|
|
193
|
-
|
194
|
-
|
196
|
+
should "count_by with nil attributes" do
|
197
|
+
Project.create(:title => nil)
|
195
198
|
|
196
|
-
|
197
|
-
|
199
|
+
assert_equal 1, Project.count
|
200
|
+
assert_equal 1, Project.count_by_title(nil)
|
198
201
|
|
199
|
-
|
202
|
+
Project.create(:title => nil, :manager_id => 12)
|
200
203
|
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
204
|
+
assert_equal 2, Project.count
|
205
|
+
assert_equal 2, Project.count_by_title(nil)
|
206
|
+
assert_equal 1, Project.count_by_manager_id(12)
|
207
|
+
assert_equal 1, Project.count_by_manager_id_and_title(12, nil)
|
205
208
|
|
206
|
-
|
209
|
+
Project.create(:title => 'Hi There')
|
207
210
|
|
208
|
-
|
209
|
-
|
210
|
-
end
|
211
|
-
|
212
|
-
context "with deleted" do
|
213
|
-
setup do
|
214
|
-
RockingChair::Server.reset
|
215
|
-
CouchPotato::Config.database_name = 'fake_simply_stored'
|
216
|
-
recreate_db
|
211
|
+
assert_equal 3, Project.count
|
212
|
+
assert_equal 2, Project.count_by_title(nil)
|
217
213
|
end
|
214
|
+
|
215
|
+
context "with deleted" do
|
216
|
+
setup do
|
217
|
+
RockingChair::Server.reset
|
218
|
+
CouchPotato::Config.database_name = 'fake_simply_stored'
|
219
|
+
recreate_db
|
220
|
+
end
|
218
221
|
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
+
should "ignore deleted in find all but load them in all with deleted" do
|
223
|
+
user = User.new(:firstname => 'Bart', :lastname => 'S')
|
224
|
+
assert user.save
|
222
225
|
|
223
|
-
|
224
|
-
|
226
|
+
deleted_user = User.new(:firstname => 'Pete', :lastname => 'S')
|
227
|
+
assert deleted_user.save
|
225
228
|
|
226
|
-
|
229
|
+
deleted_user.destroy
|
227
230
|
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
+
assert_equal ['Bart'], User.all.map(&:firstname)
|
232
|
+
assert_equal ['Bart', 'Pete'].sort, User.find(:all, :with_deleted => true).map(&:firstname).sort
|
233
|
+
end
|
231
234
|
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
235
|
+
should "ignore deleted in find first" do
|
236
|
+
user = User.new(:firstname => 'Bart', :lastname => 'S')
|
237
|
+
assert user.save
|
238
|
+
assert_equal 'Bart', User.find(:first).firstname
|
239
|
+
user.destroy
|
240
|
+
assert_nil User.first
|
241
|
+
assert_equal 'Bart', User.find(:first, :with_deleted => true).firstname
|
242
|
+
end
|
240
243
|
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
+
should "ignore deleted in belongs_to/has_many" do
|
245
|
+
project = Project.new(:title => 'secret')
|
246
|
+
assert project.save
|
244
247
|
|
245
|
-
|
246
|
-
|
248
|
+
user = User.new(:firstname => 'Bart', :lastname => 'S', :project => project)
|
249
|
+
assert user.save
|
247
250
|
|
248
|
-
|
249
|
-
|
251
|
+
assert_equal [user.id], project.users.map(&:id)
|
252
|
+
user.destroy
|
250
253
|
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
+
assert_equal [], project.users(:force_reload => true, :with_deleted => false).map(&:id)
|
255
|
+
assert_equal [user.id], project.users(:force_reload => true, :with_deleted => true).map(&:id)
|
256
|
+
end
|
254
257
|
|
258
|
+
end
|
255
259
|
end
|
256
|
-
end
|
257
260
|
|
258
|
-
|
261
|
+
context "With array views" do
|
259
262
|
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
263
|
+
should "find objects with one match of the array" do
|
264
|
+
CustomFiewUser.create(:tags => ["agile", "cool", "extreme"])
|
265
|
+
CustomFiewUser.create(:tags => ["agile"])
|
266
|
+
assert_equal 2, CustomFiewUser.find_all_by_tags("agile").size
|
267
|
+
end
|
265
268
|
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
+
should "find the object when the property is not an array" do
|
270
|
+
CustomFiewUser.create(:tags => "agile")
|
271
|
+
assert_equal 1, CustomFiewUser.find_all_by_tags("agile").size
|
272
|
+
end
|
269
273
|
end
|
270
|
-
end
|
271
274
|
|
272
|
-
end
|
273
|
-
|
274
|
-
context "when deleting" do
|
275
|
-
should "delete the doc" do
|
276
|
-
user = User.new(:firstname => 'Bart', :lastname => 'S')
|
277
|
-
assert user.save
|
278
|
-
assert user.delete
|
279
275
|
end
|
280
|
-
end
|
281
276
|
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
server = Server.new
|
288
|
-
server.add_network(network_a)
|
289
|
-
server.add_network(network_b)
|
290
|
-
}
|
291
|
-
assert_equal 3, network_a.servers.size
|
292
|
-
network_a.servers.each do |server|
|
293
|
-
assert_equal 2, server.networks.size
|
294
|
-
end
|
295
|
-
assert_equal 3, network_b.servers.size
|
296
|
-
network_b.servers.each do |server|
|
297
|
-
assert_equal 2, server.networks.size
|
277
|
+
context "when deleting" do
|
278
|
+
should "delete the doc" do
|
279
|
+
user = User.new(:firstname => 'Bart', :lastname => 'S')
|
280
|
+
assert user.save
|
281
|
+
assert user.delete
|
298
282
|
end
|
299
283
|
end
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
284
|
+
|
285
|
+
context "when handling n:m relations using has_and_belongs_to_many" do
|
286
|
+
should "work relations from both sides" do
|
287
|
+
network_a = Network.create(:klass => "A")
|
288
|
+
network_b = Network.create(:klass => "B")
|
289
|
+
3.times {
|
290
|
+
server = Server.new
|
291
|
+
server.add_network(network_a)
|
292
|
+
server.add_network(network_b)
|
293
|
+
}
|
294
|
+
assert_equal 3, network_a.servers.size
|
295
|
+
network_a.servers.each do |server|
|
296
|
+
assert_equal 2, server.networks.size
|
297
|
+
end
|
298
|
+
assert_equal 3, network_b.servers.size
|
299
|
+
network_b.servers.each do |server|
|
300
|
+
assert_equal 2, server.networks.size
|
301
|
+
end
|
312
302
|
end
|
313
|
-
|
314
|
-
|
315
|
-
|
303
|
+
|
304
|
+
should "work relations from both sides - regardless from where the add was called" do
|
305
|
+
network_a = Network.create(:klass => "A")
|
306
|
+
network_b = Network.create(:klass => "B")
|
307
|
+
3.times {
|
308
|
+
server = Server.new
|
309
|
+
network_a.add_server(server)
|
310
|
+
network_b.add_server(server)
|
311
|
+
}
|
312
|
+
assert_equal 3, network_a.servers.size
|
313
|
+
network_a.servers.each do |server|
|
314
|
+
assert_equal 2, server.networks.size, server.network_ids.inspect
|
315
|
+
end
|
316
|
+
assert_equal 3, network_b.servers.size
|
317
|
+
network_b.servers.each do |server|
|
318
|
+
assert_equal 2, server.networks.size
|
319
|
+
end
|
316
320
|
end
|
317
|
-
end
|
318
321
|
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
322
|
+
should "cound correctly - regardless of the side of the relation" do
|
323
|
+
network_a = Network.create(:klass => "A")
|
324
|
+
network_b = Network.create(:klass => "B")
|
325
|
+
3.times {
|
326
|
+
server = Server.new
|
327
|
+
network_a.add_server(server)
|
328
|
+
network_b.add_server(server)
|
329
|
+
}
|
330
|
+
assert_equal 3, network_a.server_count
|
331
|
+
assert_equal 3, network_b.server_count
|
332
|
+
assert_equal 2, network_a.servers.first.network_count
|
333
|
+
assert_equal 2, network_b.servers.first.network_count
|
334
|
+
end
|
332
335
|
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
336
|
+
should "support mixing order and limit" do
|
337
|
+
network_1 = Network.find(Network.create!(:klass => "A").id)
|
338
|
+
network_1.created_at = Time.local(2001)
|
339
|
+
network_1.save!
|
337
340
|
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
+
network_2 = Network.find(Network.create!(:klass => "B").id)
|
342
|
+
network_2.created_at = Time.local(2002)
|
343
|
+
network_2.save!
|
341
344
|
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
345
|
+
server_1 = Server.find(Server.create!(:hostname => 'www.example.com').id)
|
346
|
+
server_1.created_at = Time.local(2003)
|
347
|
+
network_1.add_server(server_1)
|
348
|
+
network_2.add_server(server_1)
|
346
349
|
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
350
|
+
server_2 = Server.find(Server.create!(:hostname => 'foo.com').id)
|
351
|
+
server_2.created_at = Time.local(2004)
|
352
|
+
network_1.add_server(server_2)
|
353
|
+
network_2.add_server(server_2)
|
351
354
|
|
352
|
-
|
353
|
-
|
355
|
+
assert_equal ['www.example.com', 'foo.com'], network_1.servers(:order => :asc).map(&:hostname)
|
356
|
+
assert_equal ['www.example.com', 'foo.com'].reverse, network_1.servers(:order => :desc).map(&:hostname)
|
354
357
|
|
355
|
-
|
356
|
-
|
358
|
+
assert_equal ['A', 'B'], server_2.networks(:order => :asc).map(&:klass)
|
359
|
+
assert_equal ['A', 'B'].reverse, server_2.networks(:order => :desc).map(&:klass)
|
357
360
|
|
358
|
-
|
359
|
-
|
361
|
+
assert_equal ['www.example.com'], network_1.servers(:order => :asc, :limit => 1).map(&:hostname)
|
362
|
+
assert_equal ['foo.com'], network_1.servers(:order => :desc, :limit => 1).map(&:hostname)
|
360
363
|
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
+
assert_equal ['A'], server_2.networks(:order => :asc, :limit => 1).map(&:klass)
|
365
|
+
assert_equal ['B'], server_2.networks(:order => :desc, :limit => 1).map(&:klass)
|
366
|
+
end
|
364
367
|
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
368
|
+
should "when counting cache the result" do
|
369
|
+
@network = Network.create(:klass => "C")
|
370
|
+
@server = Server.create
|
371
|
+
assert_equal 0, @network.server_count
|
372
|
+
Server.create(:network_ids => [@network.id])
|
373
|
+
assert_equal 0, @network.server_count
|
374
|
+
assert_equal 0, @network.instance_variable_get("@server_count")
|
375
|
+
@network.instance_variable_set("@server_count", nil)
|
376
|
+
assert_equal 1, @network.server_count
|
377
|
+
end
|
375
378
|
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
379
|
+
should "when counting cache the result - from both directions" do
|
380
|
+
@network = Network.create(:klass => "C")
|
381
|
+
@server = Server.create
|
382
|
+
assert_equal 0, @server.network_count
|
383
|
+
@server.network_ids = [@network.id]
|
384
|
+
@server.save!
|
385
|
+
assert_equal 0, @server.network_count
|
386
|
+
assert_equal 0, @server.instance_variable_get("@network_count")
|
387
|
+
@server.instance_variable_set("@network_count", nil)
|
388
|
+
assert_equal 1, @server.network_count
|
389
|
+
end
|
386
390
|
end
|
387
|
-
end
|
388
391
|
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
392
|
+
context "when deleting all design docs" do
|
393
|
+
should "reset all design docs" do
|
394
|
+
User.find_all_by_firstname('a')
|
395
|
+
db = "http://127.0.0.1:5984/#{CouchPotato::Config.database_name}"
|
396
|
+
assert_nothing_raised do
|
397
|
+
assert_equal 1, SimplyStored::Couch.delete_all_design_documents(db)
|
398
|
+
end
|
395
399
|
end
|
396
400
|
end
|
397
401
|
end
|
398
|
-
|
399
402
|
end
|
400
403
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rocking_chair
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 1
|
10
|
+
version: 0.3.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jonathan Weiss
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-04-04 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|