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.
@@ -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
@@ -29,7 +29,7 @@ class Manager
29
29
  has_one :project
30
30
  end
31
31
 
32
- class CustomViewUser
32
+ class CustomFiewUser
33
33
  include SimplyStored::Couch
34
34
 
35
35
  property :tags
@@ -6,395 +6,398 @@ def recreate_db
6
6
  end
7
7
 
8
8
  class SimplyStoredTest < Test::Unit::TestCase
9
- context "Extended use cases for SimplyStored" do
10
- setup do
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 "storing and loading documents" do
17
- should "save and find Projects" do
18
- p = Project.new(:title => 'The title')
19
- assert p.save
20
- assert_not_nil p.id, p.inspect
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
- should "save and find Users" do
26
- p = Project.new(:title => 'The title')
27
- assert p.save
28
- u = User.new(:firstname => 'Doc', :lastname => 'Holiday', :project => p)
29
- assert u.save
30
- user = User.find(u.id)
31
- assert_equal 'Doc', user.firstname
32
- assert_equal 'Holiday', user.lastname
33
- assert_equal p.id, user.project_id
34
- assert_equal p, user.project
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
- context "Views" do
39
- setup do
40
- @manager = Manager.new(:firstname => 'Michael')
41
- assert @manager.save
41
+ context "Views" do
42
+ setup do
43
+ @manager = Manager.new(:firstname => 'Michael')
44
+ assert @manager.save
42
45
 
43
- @project = Project.new(:title => 'The title', :manager => @manager)
44
- assert @project.save
46
+ @project = Project.new(:title => 'The title', :manager => @manager)
47
+ assert @project.save
45
48
 
46
- @user = User.new(:firstname => 'Michael', :project => @project)
47
- assert @user.save
48
- end
49
+ @user = User.new(:firstname => 'Michael', :project => @project)
50
+ assert @user.save
51
+ end
49
52
 
50
- context "by_attribute views" do
53
+ context "by_attribute views" do
51
54
 
52
- should "load first" do
53
- user_1 = User.create(:firstname => 'Bart', :lastname => 'S')
54
- user_2 = User.create(:firstname => 'Homer', :lastname => 'J')
55
- assert_equal 'J', User.find_by_firstname('Homer').lastname
56
- end
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
- should "load all" do
59
- user_1 = User.create(:firstname => 'Bart', :lastname => 'S')
60
- user_2 = User.create(:firstname => 'Homer', :lastname => 'J')
61
- user_2 = User.create(:firstname => 'Homer', :lastname => 'S')
62
- assert_equal ['S', 'J'].sort, User.find_all_by_firstname('Homer').map(&:lastname).sort
63
- end
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
- should "only load objects from the correct class" do
66
- user = User.create(:firstname => 'Bart', :lastname => 'S')
67
- manager = Manager.create(:firstname => 'Bart', :lastname => 'J')
68
- assert_equal ['S'], User.find_all_by_firstname('Bart').map(&:lastname)
69
- end
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
- should "support multiple attributes" do
72
- user_1 = User.create(:firstname => 'Bart', :lastname => 'S')
73
- user_2 = User.create(:firstname => 'Homer', :lastname => 'J')
74
- user_2 = User.create(:firstname => 'Homer', :lastname => 'S')
75
- assert_equal ['J'].sort, User.find_all_by_firstname_and_lastname('Homer', 'J').map(&:lastname).sort
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
- context "belongs_to" do
80
- should "load the parent object" do
81
- assert_equal @project.id, @user.project.id
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
- context "has_one" do
86
- should "load the child object" do
87
- assert_equal @project.id, @manager.project.id
88
- assert_equal @manager.id, @project.manager.id
89
- end
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
- should "re-use existing views" do
92
- Manager.create(:firstname => 'Jochen', :lastname => 'Peter')
93
- Manager.create(:firstname => 'Another', :lastname => 'Bert')
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
- context "has_many" do
98
- setup do
99
- RockingChair::Server.reset
100
- CouchPotato::Config.database_name = 'fake_simply_stored'
101
- recreate_db
102
- end
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
- should "load all has_many objects" do
105
- user = User.new(:firstname => 'Michael', :project => @project)
106
- assert user.save
107
- assert_equal [user.id], @project.users.map(&:id)
108
- end
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
- should "support counting associated" do
111
- assert_equal 0, @project.user_count
112
- user = User.create(:firstname => 'Michael', :project => @project)
113
- assert_equal 1, @project.user_count(:force_reload => true)
114
- end
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
- should "support limiting" do
117
- 3.times{ User.create!(:firstname => 'Michael', :project => @project) }
118
- assert_equal 3, @project.users.size
119
- assert_equal 2, @project.users(:limit => 2).size
120
- end
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
- should "support mixing order and limit" do
123
- michael = User.find(User.create!(:firstname => "michael", :project => @project).id)
124
- michael.created_at = Time.local(2001)
125
- michael.save!
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
- mickey = User.find(User.create!(:firstname => "mickey", :project => @project).id)
128
- mickey.created_at = Time.local(2002)
129
- mickey.save!
130
+ mickey = User.find(User.create!(:firstname => "mickey", :project => @project).id)
131
+ mickey.created_at = Time.local(2002)
132
+ mickey.save!
130
133
 
131
- mike = User.find(User.create!(:firstname => "mike", :project => @project).id)
132
- mike.created_at = Time.local(2003)
133
- mike.save!
134
+ mike = User.find(User.create!(:firstname => "mike", :project => @project).id)
135
+ mike.created_at = Time.local(2003)
136
+ mike.save!
134
137
 
135
- assert_equal ["michael", "mickey", "mike"], @project.users(:order => :asc).map(&:firstname)
136
- assert_equal ["michael", "mickey", "mike"].reverse, @project.users(:order => :desc).map(&:firstname)
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
- context "when querying the all_documents view" do
141
- setup do
142
- RockingChair::Server.reset
143
- CouchPotato::Config.database_name = 'fake_simply_stored'
144
- recreate_db
145
- end
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
- should "load all from the same class" do
148
- User.create(:firstname => 'Michael Mann', :project => @project)
149
- User.create(:firstname => 'Peter', :project => @project)
150
- assert_equal ['Peter', 'Michael Mann'].sort, User.all.map(&:firstname).sort
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
- User.create(:firstname => 'Hulk', :project => @project)
153
- assert_equal ['Peter', 'Michael Mann', 'Hulk'].sort, User.all.map(&:firstname).sort
154
- end
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
- should "support order" do
157
- 3.times{|i| User.create!(:firstname => "user #{i}") }
158
- assert_not_equal User.all(:order => :asc).map(&:id), User.all(:order => :desc).map(&:id)
159
- assert_equal User.all(:order => :asc).reverse, User.all(:order => :desc)
160
- end
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
- should "load first" do
163
- User.create(:firstname => 'Michael Mann', :project => @project)
164
- User.create(:firstname => 'Peter', :project => @project)
165
- assert User.first.respond_to?(:firstname)
166
- end
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
- should "count" do
169
- User.create(:firstname => 'Michael the first')
171
+ should "count" do
172
+ User.create(:firstname => 'Michael the first')
170
173
 
171
- assert_equal 0, Project.count
172
- assert_equal 0, Manager.count
173
- assert_equal 1, User.count
174
+ assert_equal 0, Project.count
175
+ assert_equal 0, Manager.count
176
+ assert_equal 1, User.count
174
177
 
175
- Manager.create(:firstname => 'Jochen', :lastname => 'Peter')
176
- Project.create(:title => 'The title', :manager => @manager)
177
- Project.create(:title => 'another title', :manager => @manager)
178
- User.create(:firstname => 'Michael Mann', :project => @project)
179
- User.create(:firstname => 'Peter', :project => @project)
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
- assert_equal 2, Project.count
182
- assert_equal 1, Manager.count
183
- assert_equal 3, User.count
184
- end
184
+ assert_equal 2, Project.count
185
+ assert_equal 1, Manager.count
186
+ assert_equal 3, User.count
187
+ end
185
188
 
186
- should "count_by" do
187
- User.create(:firstname => 'michael')
189
+ should "count_by" do
190
+ User.create(:firstname => 'michael')
188
191
 
189
- assert_equal 1, User.count
190
- assert_equal 1, User.count_by_firstname('michael')
191
- end
192
+ assert_equal 1, User.count
193
+ assert_equal 1, User.count_by_firstname('michael')
194
+ end
192
195
 
193
- should "count_by with nil attributes" do
194
- Project.create(:title => nil)
196
+ should "count_by with nil attributes" do
197
+ Project.create(:title => nil)
195
198
 
196
- assert_equal 1, Project.count
197
- assert_equal 1, Project.count_by_title(nil)
199
+ assert_equal 1, Project.count
200
+ assert_equal 1, Project.count_by_title(nil)
198
201
 
199
- Project.create(:title => nil, :manager_id => 12)
202
+ Project.create(:title => nil, :manager_id => 12)
200
203
 
201
- assert_equal 2, Project.count
202
- assert_equal 2, Project.count_by_title(nil)
203
- assert_equal 1, Project.count_by_manager_id(12)
204
- assert_equal 1, Project.count_by_manager_id_and_title(12, nil)
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
- Project.create(:title => 'Hi There')
209
+ Project.create(:title => 'Hi There')
207
210
 
208
- assert_equal 3, Project.count
209
- assert_equal 2, Project.count_by_title(nil)
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
- should "ignore deleted in find all but load them in all with deleted" do
220
- user = User.new(:firstname => 'Bart', :lastname => 'S')
221
- assert user.save
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
- deleted_user = User.new(:firstname => 'Pete', :lastname => 'S')
224
- assert deleted_user.save
226
+ deleted_user = User.new(:firstname => 'Pete', :lastname => 'S')
227
+ assert deleted_user.save
225
228
 
226
- deleted_user.destroy
229
+ deleted_user.destroy
227
230
 
228
- assert_equal ['Bart'], User.all.map(&:firstname)
229
- assert_equal ['Bart', 'Pete'].sort, User.find(:all, :with_deleted => true).map(&:firstname).sort
230
- end
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
- should "ignore deleted in find first" do
233
- user = User.new(:firstname => 'Bart', :lastname => 'S')
234
- assert user.save
235
- assert_equal 'Bart', User.find(:first).firstname
236
- user.destroy
237
- assert_nil User.first
238
- assert_equal 'Bart', User.find(:first, :with_deleted => true).firstname
239
- end
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
- should "ignore deleted in belongs_to/has_many" do
242
- project = Project.new(:title => 'secret')
243
- assert project.save
244
+ should "ignore deleted in belongs_to/has_many" do
245
+ project = Project.new(:title => 'secret')
246
+ assert project.save
244
247
 
245
- user = User.new(:firstname => 'Bart', :lastname => 'S', :project => project)
246
- assert user.save
248
+ user = User.new(:firstname => 'Bart', :lastname => 'S', :project => project)
249
+ assert user.save
247
250
 
248
- assert_equal [user.id], project.users.map(&:id)
249
- user.destroy
251
+ assert_equal [user.id], project.users.map(&:id)
252
+ user.destroy
250
253
 
251
- assert_equal [], project.users(:force_reload => true, :with_deleted => false).map(&:id)
252
- assert_equal [user.id], project.users(:force_reload => true, :with_deleted => true).map(&:id)
253
- end
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
- context "With array views" do
261
+ context "With array views" do
259
262
 
260
- should "find objects with one match of the array" do
261
- CustomViewUser.create(:tags => ["agile", "cool", "extreme"])
262
- CustomViewUser.create(:tags => ["agile"])
263
- assert_equal 2, CustomViewUser.find_all_by_tags("agile").size
264
- end
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
- should "find the object when the property is not an array" do
267
- CustomViewUser.create(:tags => "agile")
268
- assert_equal 1, CustomViewUser.find_all_by_tags("agile").size
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
- context "when handling n:m relations using has_and_belongs_to_many" do
283
- should "work relations from both sides" do
284
- network_a = Network.create(:klass => "A")
285
- network_b = Network.create(:klass => "B")
286
- 3.times {
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
- should "work relations from both sides - regardless from where the add was called" do
302
- network_a = Network.create(:klass => "A")
303
- network_b = Network.create(:klass => "B")
304
- 3.times {
305
- server = Server.new
306
- network_a.add_server(server)
307
- network_b.add_server(server)
308
- }
309
- assert_equal 3, network_a.servers.size
310
- network_a.servers.each do |server|
311
- assert_equal 2, server.networks.size, server.network_ids.inspect
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
- assert_equal 3, network_b.servers.size
314
- network_b.servers.each do |server|
315
- assert_equal 2, server.networks.size
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
- should "cound correctly - regardless of the side of the relation" do
320
- network_a = Network.create(:klass => "A")
321
- network_b = Network.create(:klass => "B")
322
- 3.times {
323
- server = Server.new
324
- network_a.add_server(server)
325
- network_b.add_server(server)
326
- }
327
- assert_equal 3, network_a.server_count
328
- assert_equal 3, network_b.server_count
329
- assert_equal 2, network_a.servers.first.network_count
330
- assert_equal 2, network_b.servers.first.network_count
331
- end
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
- should "support mixing order and limit" do
334
- network_1 = Network.find(Network.create!(:klass => "A").id)
335
- network_1.created_at = Time.local(2001)
336
- network_1.save!
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
- network_2 = Network.find(Network.create!(:klass => "B").id)
339
- network_2.created_at = Time.local(2002)
340
- network_2.save!
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
- server_1 = Server.find(Server.create!(:hostname => 'www.example.com').id)
343
- server_1.created_at = Time.local(2003)
344
- network_1.add_server(server_1)
345
- network_2.add_server(server_1)
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
- server_2 = Server.find(Server.create!(:hostname => 'foo.com').id)
348
- server_2.created_at = Time.local(2004)
349
- network_1.add_server(server_2)
350
- network_2.add_server(server_2)
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
- assert_equal ['www.example.com', 'foo.com'], network_1.servers(:order => :asc).map(&:hostname)
353
- assert_equal ['www.example.com', 'foo.com'].reverse, network_1.servers(:order => :desc).map(&:hostname)
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
- assert_equal ['A', 'B'], server_2.networks(:order => :asc).map(&:klass)
356
- assert_equal ['A', 'B'].reverse, server_2.networks(:order => :desc).map(&:klass)
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
- assert_equal ['www.example.com'], network_1.servers(:order => :asc, :limit => 1).map(&:hostname)
359
- assert_equal ['foo.com'], network_1.servers(:order => :desc, :limit => 1).map(&:hostname)
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
- assert_equal ['A'], server_2.networks(:order => :asc, :limit => 1).map(&:klass)
362
- assert_equal ['B'], server_2.networks(:order => :desc, :limit => 1).map(&:klass)
363
- end
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
- should "when counting cache the result" do
366
- @network = Network.create(:klass => "C")
367
- @server = Server.create
368
- assert_equal 0, @network.server_count
369
- Server.create(:network_ids => [@network.id])
370
- assert_equal 0, @network.server_count
371
- assert_equal 0, @network.instance_variable_get("@server_count")
372
- @network.instance_variable_set("@server_count", nil)
373
- assert_equal 1, @network.server_count
374
- end
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
- should "when counting cache the result - from both directions" do
377
- @network = Network.create(:klass => "C")
378
- @server = Server.create
379
- assert_equal 0, @server.network_count
380
- @server.network_ids = [@network.id]
381
- @server.save!
382
- assert_equal 0, @server.network_count
383
- assert_equal 0, @server.instance_variable_get("@network_count")
384
- @server.instance_variable_set("@network_count", nil)
385
- assert_equal 1, @server.network_count
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
- context "when deleting all design docs" do
390
- should "reset all design docs" do
391
- User.find_all_by_firstname('a')
392
- db = "http://127.0.0.1:5984/#{CouchPotato::Config.database_name}"
393
- assert_nothing_raised do
394
- assert_equal 1, SimplyStored::Couch.delete_all_design_documents(db)
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: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 0
10
- version: 0.3.0
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-02-22 00:00:00 +01:00
18
+ date: 2011-04-04 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency