simply_stored 0.3.6 → 0.3.7
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/CHANGELOG.md +3 -0
- data/lib/simply_stored/couch/has_many.rb +10 -1
- data/lib/simply_stored/couch/has_one.rb +9 -1
- data/lib/simply_stored/instance_methods.rb +1 -1
- data/lib/simply_stored.rb +1 -1
- data/test/couchdb/couch_active_model_compatibility_test.rb +23 -0
- data/test/couchdb/couch_belongs_to_test.rb +163 -0
- data/test/couchdb/couch_conflict_handling_test.rb +96 -0
- data/test/couchdb/couch_finder_test.rb +183 -0
- data/test/couchdb/couch_has_many_test.rb +470 -0
- data/test/couchdb/couch_has_one_test.rb +135 -0
- data/test/couchdb/couch_instance_lifecycle_test.rb +240 -0
- data/test/couchdb/couch_mass_assignment_protection_test.rb +77 -0
- data/test/couchdb/couch_s3_test.rb +256 -0
- data/test/couchdb/couch_soft_deletable_test.rb +457 -0
- data/test/couchdb/couch_validations_test.rb +142 -0
- data/test/{custom_views_test.rb → couchdb/custom_views_test.rb} +3 -3
- data/test/simply_stored_simpledb_test.rb +1 -1
- metadata +28 -8
- data/test/simply_stored_couch_test.rb +0 -2111
@@ -0,0 +1,457 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../fixtures/couch')
|
3
|
+
|
4
|
+
class CouchSoftDeletableTest < Test::Unit::TestCase
|
5
|
+
context "when using soft deletable" do
|
6
|
+
setup do
|
7
|
+
CouchPotato::Config.database_name = 'simply_stored_test'
|
8
|
+
recreate_db
|
9
|
+
end
|
10
|
+
should "know when it is enabled" do
|
11
|
+
assert Hemorrhoid.soft_deleting_enabled?
|
12
|
+
assert !User.soft_deleting_enabled?
|
13
|
+
end
|
14
|
+
|
15
|
+
should "define a :deleted_at attribute" do
|
16
|
+
h = Hemorrhoid.new
|
17
|
+
assert h.respond_to?(:deleted_at)
|
18
|
+
assert h.respond_to?(:deleted_at=)
|
19
|
+
assert_equal :deleted_at, Hemorrhoid.soft_delete_attribute
|
20
|
+
end
|
21
|
+
|
22
|
+
should "define a hard delete methods" do
|
23
|
+
h = Hemorrhoid.new
|
24
|
+
assert h.respond_to?(:destroy!)
|
25
|
+
assert h.respond_to?(:delete!)
|
26
|
+
end
|
27
|
+
|
28
|
+
context "when deleting" do
|
29
|
+
setup do
|
30
|
+
@user = User.new(:name => 'BigT', :title => 'Dr.')
|
31
|
+
@user.save!
|
32
|
+
@hemorrhoid = Hemorrhoid.new
|
33
|
+
@hemorrhoid.user = @user
|
34
|
+
@hemorrhoid.save!
|
35
|
+
end
|
36
|
+
|
37
|
+
should "not delete the object but populate the soft_delete_attribute" do
|
38
|
+
now = Time.now
|
39
|
+
Time.stubs(:now).returns(now)
|
40
|
+
assert_nil @hemorrhoid.deleted_at
|
41
|
+
assert @hemorrhoid.delete
|
42
|
+
assert_equal now, @hemorrhoid.deleted_at
|
43
|
+
end
|
44
|
+
|
45
|
+
should "survive reloads with the new attribute" do
|
46
|
+
assert_nil @hemorrhoid.deleted_at
|
47
|
+
assert @hemorrhoid.delete
|
48
|
+
@hemorrhoid.reload
|
49
|
+
assert_not_nil @hemorrhoid.deleted_at
|
50
|
+
end
|
51
|
+
|
52
|
+
should "know when it is deleted" do
|
53
|
+
assert !@hemorrhoid.deleted?
|
54
|
+
@hemorrhoid.delete
|
55
|
+
assert @hemorrhoid.deleted?
|
56
|
+
end
|
57
|
+
|
58
|
+
should "not consider objects without soft-deleted as deleted" do
|
59
|
+
assert !@user.deleted?
|
60
|
+
@user.delete
|
61
|
+
assert !@user.deleted?
|
62
|
+
end
|
63
|
+
|
64
|
+
should "not delete in DB" do
|
65
|
+
CouchPotato.database.expects(:destroy_document).never
|
66
|
+
@hemorrhoid.destroy
|
67
|
+
end
|
68
|
+
|
69
|
+
should "really delete if asked to" do
|
70
|
+
CouchPotato.database.expects(:destroy_document).with(@hemorrhoid)
|
71
|
+
@hemorrhoid.destroy!
|
72
|
+
end
|
73
|
+
|
74
|
+
context "callbacks" do
|
75
|
+
|
76
|
+
should "still fire the callbacks" do
|
77
|
+
@hemorrhoid = Hemorrhoid.create
|
78
|
+
$before = nil
|
79
|
+
$after = nil
|
80
|
+
def @hemorrhoid.before_destroy_callback
|
81
|
+
$before = "now"
|
82
|
+
end
|
83
|
+
|
84
|
+
def @hemorrhoid.after_destroy_callback
|
85
|
+
$after = "now"
|
86
|
+
end
|
87
|
+
|
88
|
+
@hemorrhoid.destroy
|
89
|
+
|
90
|
+
assert_not_nil $before
|
91
|
+
assert_not_nil $after
|
92
|
+
end
|
93
|
+
|
94
|
+
should "not fire the callbacks on the real destroy if the object is already deleted" do
|
95
|
+
@hemorrhoid = Hemorrhoid.create
|
96
|
+
def @hemorrhoid.before_destroy_callback
|
97
|
+
raise "Callback called even though #{skip_callbacks.inspect}"
|
98
|
+
end
|
99
|
+
|
100
|
+
def @hemorrhoid.after_destroy_callback
|
101
|
+
raise "Callback called even though #{skip_callbacks.inspect}"
|
102
|
+
end
|
103
|
+
|
104
|
+
def @hemorrhoid.deleted?
|
105
|
+
true
|
106
|
+
end
|
107
|
+
|
108
|
+
assert_nothing_raised do
|
109
|
+
@hemorrhoid.destroy!
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
should "not fire the callbacks on the real destroy if the object is not deleted" do
|
114
|
+
@hemorrhoid = Hemorrhoid.create
|
115
|
+
$before = nil
|
116
|
+
$after = nil
|
117
|
+
def @hemorrhoid.before_destroy_callback
|
118
|
+
$before = "now"
|
119
|
+
end
|
120
|
+
|
121
|
+
def @hemorrhoid.after_destroy_callback
|
122
|
+
$after = "now"
|
123
|
+
end
|
124
|
+
|
125
|
+
@hemorrhoid.destroy!
|
126
|
+
|
127
|
+
assert_not_nil $before
|
128
|
+
assert_not_nil $after
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
context "when handling the dependent objects" do
|
133
|
+
setup do
|
134
|
+
@sub = SubHemorrhoid.new
|
135
|
+
@sub.hemorrhoid = @hemorrhoid
|
136
|
+
@sub.save!
|
137
|
+
|
138
|
+
@easy_sub = EasySubHemorrhoid.new
|
139
|
+
@easy_sub.hemorrhoid = @hemorrhoid
|
140
|
+
@easy_sub.save!
|
141
|
+
|
142
|
+
@rash = Rash.new
|
143
|
+
@rash.hemorrhoid = @hemorrhoid
|
144
|
+
@rash.save!
|
145
|
+
|
146
|
+
@hemorrhoid.reload
|
147
|
+
end
|
148
|
+
|
149
|
+
should "delete them" do
|
150
|
+
@hemorrhoid.delete
|
151
|
+
@sub.reload
|
152
|
+
assert @sub.deleted?
|
153
|
+
assert_raise(SimplyStored::RecordNotFound) do
|
154
|
+
EasySubHemorrhoid.find(@easy_sub.id, :with_deleted => true)
|
155
|
+
end
|
156
|
+
@rash = Rash.find(@rash.id)
|
157
|
+
assert_nil @rash.hemorrhoid_id
|
158
|
+
end
|
159
|
+
|
160
|
+
should "really delete them if the parent is really deleted" do
|
161
|
+
@hemorrhoid.delete!
|
162
|
+
assert_raise(SimplyStored::RecordNotFound) do
|
163
|
+
EasySubHemorrhoid.find(@sub.id, :with_deleted => true)
|
164
|
+
end
|
165
|
+
|
166
|
+
assert_raise(SimplyStored::RecordNotFound) do
|
167
|
+
EasySubHemorrhoid.find(@easy_sub.id, :with_deleted => true)
|
168
|
+
end
|
169
|
+
|
170
|
+
@rash = Rash.find(@rash.id)
|
171
|
+
assert_nil @rash.hemorrhoid_id
|
172
|
+
end
|
173
|
+
|
174
|
+
should "not nullify dependents if they are soft-deletable" do
|
175
|
+
small_rash = SmallRash.create(:hemorrhoid => @hemorrhoid)
|
176
|
+
@hemorrhoid.reload
|
177
|
+
@hemorrhoid.destroy
|
178
|
+
small_rash = SmallRash.find(small_rash.id)
|
179
|
+
assert_not_nil small_rash.hemorrhoid_id
|
180
|
+
assert_equal @hemorrhoid.id, small_rash.hemorrhoid_id
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
end
|
185
|
+
|
186
|
+
context "when loading" do
|
187
|
+
setup do
|
188
|
+
@user = User.new(:name => 'BigT', :title => 'Dr.')
|
189
|
+
@user.save!
|
190
|
+
@hemorrhoid = Hemorrhoid.new
|
191
|
+
@hemorrhoid.user = @user
|
192
|
+
@hemorrhoid.save!
|
193
|
+
end
|
194
|
+
|
195
|
+
context "by id" do
|
196
|
+
should "not be found by default" do
|
197
|
+
@hemorrhoid.destroy
|
198
|
+
assert_raise(SimplyStored::RecordNotFound) do
|
199
|
+
Hemorrhoid.find(@hemorrhoid.id)
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
should "be found if supplied with :with_deleted" do
|
204
|
+
@hemorrhoid.destroy
|
205
|
+
|
206
|
+
assert_not_nil Hemorrhoid.find(@hemorrhoid.id, :with_deleted => true)
|
207
|
+
end
|
208
|
+
|
209
|
+
should "not be found if it is really gone" do
|
210
|
+
old_id = @hemorrhoid.id
|
211
|
+
@hemorrhoid.destroy!
|
212
|
+
|
213
|
+
assert_raise(SimplyStored::RecordNotFound) do
|
214
|
+
Hemorrhoid.find(old_id)
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
should "always reload" do
|
219
|
+
@hemorrhoid.destroy
|
220
|
+
assert_nothing_raised do
|
221
|
+
@hemorrhoid.reload
|
222
|
+
end
|
223
|
+
assert_not_nil @hemorrhoid.deleted_at
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
context "all" do
|
228
|
+
setup do
|
229
|
+
recreate_db
|
230
|
+
@hemorrhoid = Hemorrhoid.create
|
231
|
+
assert @hemorrhoid.destroy
|
232
|
+
assert @hemorrhoid.reload.deleted?
|
233
|
+
end
|
234
|
+
|
235
|
+
should "not load deleted" do
|
236
|
+
assert_equal [], Hemorrhoid.find(:all)
|
237
|
+
assert_equal [], Hemorrhoid.find(:all, :with_deleted => false)
|
238
|
+
end
|
239
|
+
|
240
|
+
should "load non-deleted" do
|
241
|
+
hemorrhoid = Hemorrhoid.create
|
242
|
+
assert_not_equal [], Hemorrhoid.find(:all)
|
243
|
+
assert_not_equal [], Hemorrhoid.find(:all, :with_deleted => false)
|
244
|
+
end
|
245
|
+
|
246
|
+
should "load deleted if asked to" do
|
247
|
+
assert_equal [@hemorrhoid.id], Hemorrhoid.find(:all, :with_deleted => true).map(&:id)
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
context "first" do
|
252
|
+
setup do
|
253
|
+
recreate_db
|
254
|
+
@hemorrhoid = Hemorrhoid.create
|
255
|
+
assert @hemorrhoid.destroy
|
256
|
+
assert @hemorrhoid.reload.deleted?
|
257
|
+
end
|
258
|
+
|
259
|
+
should "not load deleted" do
|
260
|
+
assert_nil Hemorrhoid.find(:first)
|
261
|
+
assert_nil Hemorrhoid.find(:first, :with_deleted => false)
|
262
|
+
end
|
263
|
+
|
264
|
+
should "load non-deleted" do
|
265
|
+
hemorrhoid = Hemorrhoid.create
|
266
|
+
assert_not_nil Hemorrhoid.find(:first)
|
267
|
+
assert_not_nil Hemorrhoid.find(:first, :with_deleted => false)
|
268
|
+
end
|
269
|
+
|
270
|
+
should "load deleted if asked to" do
|
271
|
+
assert_equal @hemorrhoid, Hemorrhoid.find(:first, :with_deleted => true)
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
context "find_by and find_all_by" do
|
276
|
+
setup do
|
277
|
+
recreate_db
|
278
|
+
@hemorrhoid = Hemorrhoid.create(:nickname => 'Claas', :size => 3)
|
279
|
+
@hemorrhoid.destroy
|
280
|
+
end
|
281
|
+
|
282
|
+
context "find_by" do
|
283
|
+
should "not load deleted" do
|
284
|
+
assert_nil Hemorrhoid.find_by_nickname('Claas')
|
285
|
+
assert_nil Hemorrhoid.find_by_nickname('Claas', :with_deleted => false)
|
286
|
+
|
287
|
+
assert_nil Hemorrhoid.find_by_nickname_and_size('Claas', 3)
|
288
|
+
assert_nil Hemorrhoid.find_by_nickname_and_size('Claas', 3, :with_deleted => false)
|
289
|
+
end
|
290
|
+
|
291
|
+
should "load non-deleted" do
|
292
|
+
hemorrhoid = Hemorrhoid.create(:nickname => 'OtherNick', :size => 3)
|
293
|
+
assert_equal hemorrhoid.id, Hemorrhoid.find_by_nickname('OtherNick', :with_deleted => true).id
|
294
|
+
assert_equal hemorrhoid.id, Hemorrhoid.find_by_nickname('OtherNick').id
|
295
|
+
end
|
296
|
+
|
297
|
+
should "load deleted if asked to" do
|
298
|
+
assert_not_nil Hemorrhoid.find_by_nickname('Claas', :with_deleted => true)
|
299
|
+
assert_equal @hemorrhoid.id, Hemorrhoid.find_by_nickname('Claas', :with_deleted => true).id
|
300
|
+
|
301
|
+
assert_not_nil Hemorrhoid.find_by_nickname_and_size('Claas', 3, :with_deleted => true)
|
302
|
+
assert_equal @hemorrhoid.id, Hemorrhoid.find_by_nickname_and_size('Claas', 3, :with_deleted => true).id
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
context "find_all_by" do
|
307
|
+
should "not load deleted" do
|
308
|
+
assert_equal [], Hemorrhoid.find_all_by_nickname('Claas')
|
309
|
+
assert_equal [], Hemorrhoid.find_all_by_nickname('Claas', :with_deleted => false)
|
310
|
+
|
311
|
+
assert_equal [], Hemorrhoid.find_all_by_nickname_and_size('Claas', 3)
|
312
|
+
assert_equal [], Hemorrhoid.find_all_by_nickname_and_size('Claas', 3, :with_deleted => false)
|
313
|
+
end
|
314
|
+
|
315
|
+
should "load non-deleted" do
|
316
|
+
hemorrhoid = Hemorrhoid.create(:nickname => 'Lampe', :size => 4)
|
317
|
+
assert_equal [hemorrhoid.id], Hemorrhoid.find_all_by_nickname('Lampe').map(&:id)
|
318
|
+
end
|
319
|
+
|
320
|
+
should "load deleted if asked to" do
|
321
|
+
assert_equal [@hemorrhoid.id], Hemorrhoid.find_all_by_nickname('Claas', :with_deleted => true).map(&:id)
|
322
|
+
assert_equal [@hemorrhoid.id], Hemorrhoid.find_all_by_nickname_and_size('Claas', 3, :with_deleted => true).map(&:id)
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
326
|
+
should "reuse the same view - when find_all_by is called first" do
|
327
|
+
assert_equal [], Hemorrhoid.find_all_by_nickname('Claas')
|
328
|
+
assert_nil Hemorrhoid.find_by_nickname('Claas')
|
329
|
+
end
|
330
|
+
|
331
|
+
should "reuse the same view - when find_by is called first" do
|
332
|
+
assert_nil Hemorrhoid.find_by_nickname('Claas')
|
333
|
+
assert_equal [], Hemorrhoid.find_all_by_nickname('Claas')
|
334
|
+
end
|
335
|
+
end
|
336
|
+
|
337
|
+
context "by relation" do
|
338
|
+
setup do
|
339
|
+
@hemorrhoid.destroy
|
340
|
+
end
|
341
|
+
|
342
|
+
context "has_many" do
|
343
|
+
should "not load deleted by default" do
|
344
|
+
assert_equal [], @user.hemorrhoids
|
345
|
+
end
|
346
|
+
|
347
|
+
should "load deleted if asked to" do
|
348
|
+
assert_equal [@hemorrhoid.id], @user.hemorrhoids(:with_deleted => true).map(&:id)
|
349
|
+
end
|
350
|
+
end
|
351
|
+
|
352
|
+
context "has_many :through" do
|
353
|
+
setup do
|
354
|
+
@user = User.create(:name => 'BigT', :title => 'Dr.')
|
355
|
+
@pain = Pain.create
|
356
|
+
|
357
|
+
@hemorrhoid = Hemorrhoid.new
|
358
|
+
@hemorrhoid.user = @user
|
359
|
+
@hemorrhoid.pain = @pain
|
360
|
+
@hemorrhoid.save!
|
361
|
+
|
362
|
+
@hemorrhoid.destroy
|
363
|
+
end
|
364
|
+
|
365
|
+
should "not load deleted by default" do
|
366
|
+
assert_equal [], @user.pains
|
367
|
+
end
|
368
|
+
|
369
|
+
should "load deleted if asked to" do
|
370
|
+
assert_equal [@pain.id], @user.pains(:with_deleted => true).map(&:id)
|
371
|
+
end
|
372
|
+
end
|
373
|
+
|
374
|
+
context "has_one" do
|
375
|
+
setup do
|
376
|
+
@spot = Spot.create
|
377
|
+
|
378
|
+
@hemorrhoid = Hemorrhoid.new
|
379
|
+
@hemorrhoid.spot = @spot
|
380
|
+
@hemorrhoid.save!
|
381
|
+
|
382
|
+
@hemorrhoid.destroy
|
383
|
+
end
|
384
|
+
|
385
|
+
should "not load deleted by default" do
|
386
|
+
assert_nil @spot.hemorrhoid
|
387
|
+
end
|
388
|
+
|
389
|
+
should "load deleted if asked to" do
|
390
|
+
assert_equal @hemorrhoid.id, @spot.hemorrhoid(:with_deleted => true).id
|
391
|
+
end
|
392
|
+
end
|
393
|
+
|
394
|
+
context "belongs_to" do
|
395
|
+
setup do
|
396
|
+
@hemorrhoid = Hemorrhoid.new
|
397
|
+
@hemorrhoid.save!
|
398
|
+
|
399
|
+
@sub = SubHemorrhoid.new
|
400
|
+
@sub.hemorrhoid = @hemorrhoid
|
401
|
+
@sub.save!
|
402
|
+
|
403
|
+
@hemorrhoid.destroy
|
404
|
+
end
|
405
|
+
|
406
|
+
should "not load deleted by default" do
|
407
|
+
@sub.reload
|
408
|
+
assert_raise(SimplyStored::RecordNotFound) do
|
409
|
+
assert_nil @sub.hemorrhoid
|
410
|
+
end
|
411
|
+
end
|
412
|
+
|
413
|
+
should "load deleted if asked to" do
|
414
|
+
@sub.reload
|
415
|
+
assert_equal @hemorrhoid.id, @sub.hemorrhoid(:with_deleted => true).id
|
416
|
+
end
|
417
|
+
end
|
418
|
+
|
419
|
+
end
|
420
|
+
|
421
|
+
end
|
422
|
+
|
423
|
+
context "when counting" do
|
424
|
+
setup do
|
425
|
+
@hemorrhoid = Hemorrhoid.create(:nickname => 'Claas')
|
426
|
+
assert @hemorrhoid.destroy
|
427
|
+
assert @hemorrhoid.reload.deleted?
|
428
|
+
end
|
429
|
+
|
430
|
+
should "not count deleted" do
|
431
|
+
assert_equal 0, Hemorrhoid.count
|
432
|
+
assert_equal 0, Hemorrhoid.count(:with_deleted => false)
|
433
|
+
end
|
434
|
+
|
435
|
+
should "count non-deleted" do
|
436
|
+
hemorrhoid = Hemorrhoid.create(:nickname => 'Claas')
|
437
|
+
assert_equal 1, Hemorrhoid.count
|
438
|
+
assert_equal 1, Hemorrhoid.count(:with_deleted => false)
|
439
|
+
end
|
440
|
+
|
441
|
+
should "count deleted if asked to" do
|
442
|
+
assert_equal 1, Hemorrhoid.count(:with_deleted => true)
|
443
|
+
end
|
444
|
+
|
445
|
+
context "count_by" do
|
446
|
+
should "not count deleted" do
|
447
|
+
assert_equal 0, Hemorrhoid.count_by_nickname('Claas')
|
448
|
+
assert_equal 0, Hemorrhoid.count_by_nickname('Claas', :with_deleted => false)
|
449
|
+
end
|
450
|
+
|
451
|
+
should "count deleted if asked to" do
|
452
|
+
assert_equal 1, Hemorrhoid.count_by_nickname('Claas', :with_deleted => true)
|
453
|
+
end
|
454
|
+
end
|
455
|
+
end
|
456
|
+
end
|
457
|
+
end
|
@@ -0,0 +1,142 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../fixtures/couch')
|
3
|
+
|
4
|
+
class CouchValidationsTest < Test::Unit::TestCase
|
5
|
+
context "with additional validations" do
|
6
|
+
setup do
|
7
|
+
CouchPotato::Config.database_name = 'simply_stored_test'
|
8
|
+
recreate_db
|
9
|
+
end
|
10
|
+
|
11
|
+
context "with validates_inclusion_of" do
|
12
|
+
should "validate inclusion of an attribute in an array" do
|
13
|
+
category = Category.new(:name => "other")
|
14
|
+
assert !category.save
|
15
|
+
end
|
16
|
+
|
17
|
+
should "validate when the attribute is an array" do
|
18
|
+
category = Category.new(:name => ['drinks', 'food'])
|
19
|
+
assert_nothing_raised do
|
20
|
+
category.save!
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
should "add an error message" do
|
25
|
+
category = Category.new(:name => "other")
|
26
|
+
category.valid?
|
27
|
+
assert_match(/must be one or more of food, drinks, party/, category.errors.full_messages.first)
|
28
|
+
end
|
29
|
+
|
30
|
+
should "allow blank" do
|
31
|
+
category = Category.new(:name => nil)
|
32
|
+
assert category.valid?
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "with validates_format_of" do
|
37
|
+
class ValidatedUser
|
38
|
+
include SimplyStored::Couch
|
39
|
+
property :name
|
40
|
+
validates_format_of :name, :with => /Paul/
|
41
|
+
end
|
42
|
+
|
43
|
+
should 'validate the format and fail when not matched' do
|
44
|
+
user = ValidatedUser.new(:name => "John")
|
45
|
+
assert !user.valid?
|
46
|
+
end
|
47
|
+
|
48
|
+
should 'succeed when matched' do
|
49
|
+
user = ValidatedUser.new(:name => "Paul")
|
50
|
+
assert user.valid?
|
51
|
+
end
|
52
|
+
|
53
|
+
should 'fail when empty' do
|
54
|
+
user = ValidatedUser.new(:name => nil)
|
55
|
+
assert !user.valid?
|
56
|
+
end
|
57
|
+
|
58
|
+
context "with allow_blank" do
|
59
|
+
class ValidatedBlankUser
|
60
|
+
include SimplyStored::Couch
|
61
|
+
property :name
|
62
|
+
validates_format_of :name, :with => /Paul/, :allow_blank => true
|
63
|
+
end
|
64
|
+
|
65
|
+
should 'not fail when nil' do
|
66
|
+
user = ValidatedBlankUser.new(:name => nil)
|
67
|
+
assert user.valid?
|
68
|
+
end
|
69
|
+
|
70
|
+
should 'not fail when empty string' do
|
71
|
+
user = ValidatedBlankUser.new(:name => '')
|
72
|
+
assert user.valid?
|
73
|
+
end
|
74
|
+
|
75
|
+
should 'fail when not matching' do
|
76
|
+
user = ValidatedBlankUser.new(:name => 'John')
|
77
|
+
assert !user.valid?
|
78
|
+
end
|
79
|
+
|
80
|
+
should 'not fail when matching' do
|
81
|
+
user = ValidatedBlankUser.new(:name => 'Paul')
|
82
|
+
assert user.valid?
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context "with validates_uniqueness_of" do
|
89
|
+
should "add a view on the unique attribute" do
|
90
|
+
assert UniqueUser.by_name
|
91
|
+
end
|
92
|
+
|
93
|
+
should "set an error when a different with the same instance exists" do
|
94
|
+
assert UniqueUser.create(:name => "Host Master")
|
95
|
+
user = UniqueUser.create(:name => "Host Master")
|
96
|
+
assert !user.valid?
|
97
|
+
end
|
98
|
+
|
99
|
+
should "not have an error when we're the only one around" do
|
100
|
+
user = UniqueUser.create(:name => "Host Master")
|
101
|
+
assert !user.new_record?
|
102
|
+
end
|
103
|
+
|
104
|
+
should "not have an error when it's the same instance" do
|
105
|
+
user = UniqueUser.create(:name => "Host Master")
|
106
|
+
user = UniqueUser.find(user.id)
|
107
|
+
assert user.valid?
|
108
|
+
end
|
109
|
+
|
110
|
+
should 'have a nice error message' do
|
111
|
+
assert UniqueUser.create(:name => "Host Master")
|
112
|
+
user = UniqueUser.create(:name => "Host Master")
|
113
|
+
assert_equal "Name is already taken", user.errors.on(:name)
|
114
|
+
end
|
115
|
+
|
116
|
+
should 'create a view to check with' do
|
117
|
+
assert UniqueUser.respond_to?(:by_name)
|
118
|
+
assert_equal :name, UniqueUser.by_name.send(:options)[:key]
|
119
|
+
end
|
120
|
+
|
121
|
+
should 'not overwrite the view when a custom one already exists' do
|
122
|
+
assert_equal :email, UniqueUserWithAView.by_name.send(:options)[:key]
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
context "equality" do
|
127
|
+
should "know when two objects are equal" do
|
128
|
+
user = UniqueUser.create(:name => "Host Master")
|
129
|
+
other_user = UniqueUser.create(:name => "The other one")
|
130
|
+
assert user == user
|
131
|
+
assert user != other_user
|
132
|
+
end
|
133
|
+
|
134
|
+
should "not bail when comparing with non-SimplyStored objects" do
|
135
|
+
user = UniqueUser.create(:name => "Host Master")
|
136
|
+
assert 5 != user
|
137
|
+
assert user != 5
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
142
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '
|
2
|
-
require File.expand_path(File.dirname(__FILE__) + '
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../fixtures/couch')
|
3
3
|
|
4
4
|
class CustomViewUser
|
5
5
|
include SimplyStored::Couch
|
@@ -30,4 +30,4 @@ class CustomViewsTest < Test::Unit::TestCase
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
33
|
-
end
|
33
|
+
end
|
@@ -1310,7 +1310,7 @@ class SimplyStoredTest < Test::Unit::TestCase
|
|
1310
1310
|
@log_item._s3_options[:log_data][:location] = :us
|
1311
1311
|
@log_item._s3_options[:log_data][:permissions] = 'private'
|
1312
1312
|
@log_item.save
|
1313
|
-
assert @log_item.log_data_url.include?("https://bucket-for-monsieur.s3.amazonaws.com:443/#{@log_item.s3_attachment_key(:log_data)}")
|
1313
|
+
assert @log_item.log_data_url.gsub("%2F", '/').include?("https://bucket-for-monsieur.s3.amazonaws.com:443/#{@log_item.s3_attachment_key(:log_data)}")
|
1314
1314
|
assert @log_item.log_data_url.include?("Signature=")
|
1315
1315
|
assert @log_item.log_data_url.include?("Expires=")
|
1316
1316
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simply_stored
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 7
|
10
|
+
version: 0.3.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Mathias Meyer, Jonathan Weiss
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-09-23 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -111,7 +111,18 @@ files:
|
|
111
111
|
- lib/simply_stored/simpledb/storag.rb
|
112
112
|
- lib/simply_stored/simpledb/validations.rb
|
113
113
|
- lib/simply_stored/storage.rb
|
114
|
-
- test/
|
114
|
+
- test/couchdb/couch_active_model_compatibility_test.rb
|
115
|
+
- test/couchdb/couch_belongs_to_test.rb
|
116
|
+
- test/couchdb/couch_conflict_handling_test.rb
|
117
|
+
- test/couchdb/couch_finder_test.rb
|
118
|
+
- test/couchdb/couch_has_many_test.rb
|
119
|
+
- test/couchdb/couch_has_one_test.rb
|
120
|
+
- test/couchdb/couch_instance_lifecycle_test.rb
|
121
|
+
- test/couchdb/couch_mass_assignment_protection_test.rb
|
122
|
+
- test/couchdb/couch_s3_test.rb
|
123
|
+
- test/couchdb/couch_soft_deletable_test.rb
|
124
|
+
- test/couchdb/couch_validations_test.rb
|
125
|
+
- test/couchdb/custom_views_test.rb
|
115
126
|
- test/fixtures/couch.rb
|
116
127
|
- test/fixtures/simpledb/item.rb
|
117
128
|
- test/fixtures/simpledb/item_daddy.rb
|
@@ -119,7 +130,6 @@ files:
|
|
119
130
|
- test/fixtures/simpledb/namespace_bar.rb
|
120
131
|
- test/fixtures/simpledb/namespace_foo.rb
|
121
132
|
- test/fixtures/simpledb/protected_item.rb
|
122
|
-
- test/simply_stored_couch_test.rb
|
123
133
|
- test/simply_stored_simpledb_test.rb
|
124
134
|
- test/test_helper.rb
|
125
135
|
- test/vendor/dhaka-2.2.1/lib/dhaka/dot/dot.rb
|
@@ -249,7 +259,18 @@ signing_key:
|
|
249
259
|
specification_version: 3
|
250
260
|
summary: Convenience layer for CouchDB and SimpleDB
|
251
261
|
test_files:
|
252
|
-
- test/
|
262
|
+
- test/couchdb/couch_active_model_compatibility_test.rb
|
263
|
+
- test/couchdb/couch_belongs_to_test.rb
|
264
|
+
- test/couchdb/couch_conflict_handling_test.rb
|
265
|
+
- test/couchdb/couch_finder_test.rb
|
266
|
+
- test/couchdb/couch_has_many_test.rb
|
267
|
+
- test/couchdb/couch_has_one_test.rb
|
268
|
+
- test/couchdb/couch_instance_lifecycle_test.rb
|
269
|
+
- test/couchdb/couch_mass_assignment_protection_test.rb
|
270
|
+
- test/couchdb/couch_s3_test.rb
|
271
|
+
- test/couchdb/couch_soft_deletable_test.rb
|
272
|
+
- test/couchdb/couch_validations_test.rb
|
273
|
+
- test/couchdb/custom_views_test.rb
|
253
274
|
- test/fixtures/couch.rb
|
254
275
|
- test/fixtures/simpledb/item.rb
|
255
276
|
- test/fixtures/simpledb/item_daddy.rb
|
@@ -257,7 +278,6 @@ test_files:
|
|
257
278
|
- test/fixtures/simpledb/namespace_bar.rb
|
258
279
|
- test/fixtures/simpledb/namespace_foo.rb
|
259
280
|
- test/fixtures/simpledb/protected_item.rb
|
260
|
-
- test/simply_stored_couch_test.rb
|
261
281
|
- test/simply_stored_simpledb_test.rb
|
262
282
|
- test/test_helper.rb
|
263
283
|
- test/vendor/dhaka-2.2.1/lib/dhaka/dot/dot.rb
|