couchrest_model 2.1.0.rc1 → 2.2.0.beta1

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.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/.travis.yml +15 -4
  4. data/Gemfile.activesupport-4.x +4 -0
  5. data/Gemfile.activesupport-5.x +4 -0
  6. data/README.md +2 -0
  7. data/VERSION +1 -1
  8. data/couchrest_model.gemspec +3 -2
  9. data/history.md +14 -1
  10. data/lib/couchrest/model/associations.rb +3 -8
  11. data/lib/couchrest/model/base.rb +15 -7
  12. data/lib/couchrest/model/casted_array.rb +22 -34
  13. data/lib/couchrest/model/configuration.rb +2 -0
  14. data/lib/couchrest/model/design.rb +4 -3
  15. data/lib/couchrest/model/designs/view.rb +37 -32
  16. data/lib/couchrest/model/dirty.rb +93 -19
  17. data/lib/couchrest/model/embeddable.rb +2 -14
  18. data/lib/couchrest/model/extended_attachments.rb +2 -4
  19. data/lib/couchrest/model/persistence.rb +14 -17
  20. data/lib/couchrest/model/properties.rb +46 -54
  21. data/lib/couchrest/model/property.rb +0 -3
  22. data/lib/couchrest/model/proxyable.rb +20 -4
  23. data/lib/couchrest/model/validations/uniqueness.rb +4 -1
  24. data/lib/couchrest_model.rb +2 -2
  25. data/spec/fixtures/models/article.rb +1 -1
  26. data/spec/fixtures/models/card.rb +2 -1
  27. data/spec/fixtures/models/person.rb +1 -0
  28. data/spec/fixtures/models/project.rb +3 -0
  29. data/spec/unit/assocations_spec.rb +73 -73
  30. data/spec/unit/attachment_spec.rb +34 -34
  31. data/spec/unit/base_spec.rb +102 -102
  32. data/spec/unit/casted_array_spec.rb +7 -7
  33. data/spec/unit/casted_spec.rb +7 -7
  34. data/spec/unit/configuration_spec.rb +11 -11
  35. data/spec/unit/connection_spec.rb +30 -30
  36. data/spec/unit/core_extensions/{time_parsing.rb → time_parsing_spec.rb} +21 -21
  37. data/spec/unit/design_spec.rb +38 -38
  38. data/spec/unit/designs/design_mapper_spec.rb +26 -26
  39. data/spec/unit/designs/migrations_spec.rb +13 -13
  40. data/spec/unit/designs/view_spec.rb +319 -274
  41. data/spec/unit/designs_spec.rb +39 -39
  42. data/spec/unit/dirty_spec.rb +188 -103
  43. data/spec/unit/embeddable_spec.rb +119 -117
  44. data/spec/unit/inherited_spec.rb +4 -4
  45. data/spec/unit/persistence_spec.rb +122 -122
  46. data/spec/unit/properties_spec.rb +466 -16
  47. data/spec/unit/property_protection_spec.rb +32 -32
  48. data/spec/unit/property_spec.rb +45 -436
  49. data/spec/unit/proxyable_spec.rb +140 -82
  50. data/spec/unit/subclass_spec.rb +14 -14
  51. data/spec/unit/translations_spec.rb +5 -5
  52. data/spec/unit/typecast_spec.rb +131 -131
  53. data/spec/unit/utils/migrate_spec.rb +2 -2
  54. data/spec/unit/validations_spec.rb +31 -31
  55. metadata +27 -12
  56. data/lib/couchrest/model/casted_hash.rb +0 -84
@@ -56,16 +56,16 @@ describe CouchRest::Model::Embeddable do
56
56
  end
57
57
  it "should automatically include the property mixin and define getters and setters" do
58
58
  @obj.name = 'Matt'
59
- @obj.name.should == 'Matt'
59
+ expect(@obj.name).to eq('Matt')
60
60
  end
61
61
 
62
62
  it "should allow override of default" do
63
63
  @obj = WithCastedModelMixin.new(:name => 'Eric', :details => {'color' => 'orange'})
64
- @obj.name.should == 'Eric'
65
- @obj.details['color'].should == 'orange'
64
+ expect(@obj.name).to eq('Eric')
65
+ expect(@obj.details['color']).to eq('orange')
66
66
  end
67
67
  it "should always return base_doc? as false" do
68
- @obj.base_doc?.should be_false
68
+ expect(@obj.base_doc?).to be_falsey
69
69
  end
70
70
  it "should call after_initialize callback if available" do
71
71
  klass = Class.new do
@@ -75,7 +75,7 @@ describe CouchRest::Model::Embeddable do
75
75
  def set_name; self.name = "foobar"; end
76
76
  end
77
77
  @obj = klass.new
78
- @obj.name.should eql("foobar")
78
+ expect(@obj.name).to eql("foobar")
79
79
  end
80
80
  it "should allow override of initialize with super" do
81
81
  klass = Class.new do
@@ -86,7 +86,7 @@ describe CouchRest::Model::Embeddable do
86
86
  def initialize(attrs = {}); super(); end
87
87
  end
88
88
  @obj = klass.new
89
- @obj.name.should eql("foobar")
89
+ expect(@obj.name).to eql("foobar")
90
90
  end
91
91
  end
92
92
 
@@ -96,7 +96,7 @@ describe CouchRest::Model::Embeddable do
96
96
  @casted_obj = @obj.casted_attribute
97
97
  end
98
98
  it "should be nil" do
99
- @casted_obj.should == nil
99
+ expect(@casted_obj).to eq(nil)
100
100
  end
101
101
  end
102
102
 
@@ -105,20 +105,20 @@ describe CouchRest::Model::Embeddable do
105
105
  @obj = DummyModel.new
106
106
  end
107
107
  it "should be empty initially" do
108
- @obj.sub_models.should_not be_nil
109
- @obj.sub_models.should be_empty
108
+ expect(@obj.sub_models).not_to be_nil
109
+ expect(@obj.sub_models).to be_empty
110
110
  end
111
111
  it "should be updatable using a hash" do
112
112
  @obj.sub_models << {:title => 'test'}
113
- @obj.sub_models.first.title.should eql('test')
113
+ expect(@obj.sub_models.first.title).to eql('test')
114
114
  end
115
115
  it "should be empty intitally (without params)" do
116
- @obj.param_free_sub_models.should_not be_nil
117
- @obj.param_free_sub_models.should be_empty
116
+ expect(@obj.param_free_sub_models).not_to be_nil
117
+ expect(@obj.param_free_sub_models).to be_empty
118
118
  end
119
119
  it "should be updatable using a hash (without params)" do
120
120
  @obj.param_free_sub_models << {:title => 'test'}
121
- @obj.param_free_sub_models.first.title.should eql('test')
121
+ expect(@obj.param_free_sub_models.first.title).to eql('test')
122
122
  end
123
123
  end
124
124
 
@@ -130,35 +130,35 @@ describe CouchRest::Model::Embeddable do
130
130
  end
131
131
 
132
132
  it "should be available from its parent" do
133
- @casted_obj.should be_an_instance_of(WithCastedModelMixin)
133
+ expect(@casted_obj).to be_an_instance_of(WithCastedModelMixin)
134
134
  end
135
135
 
136
136
  it "should have the getters defined" do
137
- @casted_obj.name.should == 'whatever'
137
+ expect(@casted_obj.name).to eq('whatever')
138
138
  end
139
139
 
140
140
  it "should know who casted it" do
141
- @casted_obj.casted_by.should == @obj
141
+ expect(@casted_obj.casted_by).to eq(@obj)
142
142
  end
143
143
 
144
144
  it "should know which property casted it" do
145
- @casted_obj.casted_by_property.should == @obj.properties.detect{|p| p.to_s == 'casted_attribute'}
145
+ expect(@casted_obj.casted_by_property).to eq(@obj.properties.detect{|p| p.to_s == 'casted_attribute'})
146
146
  end
147
147
 
148
148
  it "should return nil for the 'no_value' attribute" do
149
- @casted_obj.no_value.should be_nil
149
+ expect(@casted_obj.no_value).to be_nil
150
150
  end
151
151
 
152
152
  it "should return nil for the unknown attribute" do
153
- @casted_obj["unknown"].should be_nil
153
+ expect(@casted_obj["unknown"]).to be_nil
154
154
  end
155
155
 
156
156
  it "should return {} for the hash attribute" do
157
- @casted_obj.details.should == {}
157
+ expect(@casted_obj.details).to eq({})
158
158
  end
159
159
 
160
160
  it "should cast its own attributes" do
161
- @casted_obj.casted_attribute.should be_instance_of(WithCastedModelMixin)
161
+ expect(@casted_obj.casted_attribute).to be_instance_of(WithCastedModelMixin)
162
162
  end
163
163
 
164
164
  it "should raise an error if save or update_attributes called" do
@@ -174,23 +174,23 @@ describe CouchRest::Model::Embeddable do
174
174
  @casted_obj = @obj.old_casted_attribute
175
175
  end
176
176
  it "should be available from its parent" do
177
- @casted_obj.should be_an_instance_of(OldFashionedMixin)
177
+ expect(@casted_obj).to be_an_instance_of(OldFashionedMixin)
178
178
  end
179
179
 
180
180
  it "should have the getters defined" do
181
- @casted_obj.name.should == 'Testing'
181
+ expect(@casted_obj.name).to eq('Testing')
182
182
  end
183
183
 
184
184
  it "should know who casted it" do
185
- @casted_obj.casted_by.should == @obj
185
+ expect(@casted_obj.casted_by).to eq(@obj)
186
186
  end
187
187
 
188
188
  it "should know which property casted it" do
189
- @casted_obj.casted_by_property.should == @obj.properties.detect{|p| p.to_s == 'old_casted_attribute'}
189
+ expect(@casted_obj.casted_by_property).to eq(@obj.properties.detect{|p| p.to_s == 'old_casted_attribute'})
190
190
  end
191
191
 
192
192
  it "should return nil for the unknown attribute" do
193
- @casted_obj["unknown"].should be_nil
193
+ expect(@casted_obj["unknown"]).to be_nil
194
194
  end
195
195
  end
196
196
 
@@ -200,8 +200,8 @@ describe CouchRest::Model::Embeddable do
200
200
  end
201
201
 
202
202
  it "should cast the array properly" do
203
- @obj.keywords.should be_kind_of(Array)
204
- @obj.keywords.first.should == 'couch'
203
+ expect(@obj.keywords).to be_kind_of(Array)
204
+ expect(@obj.keywords.first).to eq('couch')
205
205
  end
206
206
  end
207
207
 
@@ -209,33 +209,35 @@ describe CouchRest::Model::Embeddable do
209
209
  before(:each) do
210
210
  @question = Question.new(:q => "What is your quest?", :a => "To seek the Holy Grail")
211
211
  end
212
- it "should work for attribute= methods" do
213
- @question.q.should == "What is your quest?"
214
- @question['a'].should == "To seek the Holy Grail"
215
- @question.update_attributes_without_saving(:q => "What is your favorite color?", 'a' => "Blue")
216
- @question['q'].should == "What is your favorite color?"
217
- @question.a.should == "Blue"
212
+ it "should work for write_attributes method" do
213
+ expect(@question.q).to eq("What is your quest?")
214
+ expect(@question['a']).to eq("To seek the Holy Grail")
215
+ @question.write_attributes(
216
+ :q => "What is your favorite color?", 'a' => "Blue"
217
+ )
218
+ expect(@question['q']).to eq("What is your favorite color?")
219
+ expect(@question.a).to eq("Blue")
218
220
  end
219
221
 
220
222
  it "should also work for attributes= alias" do
221
- @question.respond_to?(:attributes=).should be_true
223
+ expect(@question.respond_to?(:attributes=)).to be_truthy
222
224
  @question.attributes = {:q => "What is your favorite color?", 'a' => "Blue"}
223
- @question['q'].should == "What is your favorite color?"
224
- @question.a.should == "Blue"
225
+ expect(@question['q']).to eq("What is your favorite color?")
226
+ expect(@question.a).to eq("Blue")
225
227
  end
226
228
 
227
229
  it "should flip out if an attribute= method is missing" do
228
- lambda {
229
- @q.update_attributes_without_saving('foo' => "something", :a => "No green")
230
- }.should raise_error(NoMethodError)
230
+ expect {
231
+ @q.attributes = { 'foo' => "something", :a => "No green" }
232
+ }.to raise_error(NoMethodError)
231
233
  end
232
234
 
233
235
  it "should not change any attributes if there is an error" do
234
- lambda {
235
- @q.update_attributes_without_saving('foo' => "something", :a => "No green")
236
- }.should raise_error(NoMethodError)
237
- @question.q.should == "What is your quest?"
238
- @question.a.should == "To seek the Holy Grail"
236
+ expect {
237
+ @q.attributes = { 'foo' => "something", :a => "No green" }
238
+ }.to raise_error(NoMethodError)
239
+ expect(@question.q).to eq("What is your quest?")
240
+ expect(@question.a).to eq("To seek the Holy Grail")
239
241
  end
240
242
 
241
243
  end
@@ -244,25 +246,25 @@ describe CouchRest::Model::Embeddable do
244
246
  before(:each) do
245
247
  reset_test_db!
246
248
  @obj = DummyModel.new(:casted_attribute => {:name => 'whatever'})
247
- @obj.save.should be_true
249
+ expect(@obj.save).to be_truthy
248
250
  @obj = DummyModel.get(@obj.id)
249
251
  end
250
252
 
251
253
  it "should be able to load with the casted models" do
252
254
  casted_obj = @obj.casted_attribute
253
- casted_obj.should_not be_nil
254
- casted_obj.should be_an_instance_of(WithCastedModelMixin)
255
+ expect(casted_obj).not_to be_nil
256
+ expect(casted_obj).to be_an_instance_of(WithCastedModelMixin)
255
257
  end
256
258
 
257
259
  it "should have defined getters for the casted model" do
258
260
  casted_obj = @obj.casted_attribute
259
- casted_obj.name.should == "whatever"
261
+ expect(casted_obj.name).to eq("whatever")
260
262
  end
261
263
 
262
264
  it "should have defined setters for the casted model" do
263
265
  casted_obj = @obj.casted_attribute
264
266
  casted_obj.name = "test"
265
- casted_obj.name.should == "test"
267
+ expect(casted_obj.name).to eq("test")
266
268
  end
267
269
 
268
270
  it "should retain an override of a casted model attribute's default" do
@@ -270,7 +272,7 @@ describe CouchRest::Model::Embeddable do
270
272
  casted_obj.details['color'] = 'orange'
271
273
  @obj.save
272
274
  casted_obj = DummyModel.get(@obj.id).casted_attribute
273
- casted_obj.details['color'].should == 'orange'
275
+ expect(casted_obj.details['color']).to eq('orange')
274
276
  end
275
277
 
276
278
  end
@@ -284,27 +286,27 @@ describe CouchRest::Model::Embeddable do
284
286
  it "should save" do
285
287
  toy = CatToy.new :name => "Mouse"
286
288
  @cat.toys.push(toy)
287
- @cat.save.should be_true
289
+ expect(@cat.save).to be_truthy
288
290
  @cat = Cat.get @cat.id
289
- @cat.toys.class.should == CouchRest::Model::CastedArray
290
- @cat.toys.first.class.should == CatToy
291
- @cat.toys.first.should === toy
291
+ expect(@cat.toys.class).to eq(CouchRest::Model::CastedArray)
292
+ expect(@cat.toys.first.class).to eq(CatToy)
293
+ expect(@cat.toys.first).to be === toy
292
294
  end
293
295
 
294
296
  it "should fail because name is not present" do
295
297
  toy = CatToy.new
296
298
  @cat.toys.push(toy)
297
- @cat.should_not be_valid
298
- @cat.save.should be_false
299
+ expect(@cat).not_to be_valid
300
+ expect(@cat.save).to be_falsey
299
301
  end
300
302
 
301
303
  it "should not fail if the casted model doesn't have validation" do
302
304
  Cat.property :masters, [Person], :default => []
303
305
  Cat.validates_presence_of :name
304
306
  cat = Cat.new(:name => 'kitty')
305
- cat.should be_valid
307
+ expect(cat).to be_valid
306
308
  cat.masters.push Person.new
307
- cat.should be_valid
309
+ expect(cat).to be_valid
308
310
  end
309
311
  end
310
312
 
@@ -321,46 +323,46 @@ describe CouchRest::Model::Embeddable do
321
323
 
322
324
  describe "on the top document" do
323
325
  it "should put errors on all invalid casted models" do
324
- @cat.should_not be_valid
325
- @cat.errors.should_not be_empty
326
- @toy1.errors.should_not be_empty
327
- @toy2.errors.should_not be_empty
328
- @toy3.errors.should_not be_empty
326
+ expect(@cat).not_to be_valid
327
+ expect(@cat.errors).not_to be_empty
328
+ expect(@toy1.errors).not_to be_empty
329
+ expect(@toy2.errors).not_to be_empty
330
+ expect(@toy3.errors).not_to be_empty
329
331
  end
330
332
 
331
333
  it "should not put errors on valid casted models" do
332
334
  @toy1.name = "Feather"
333
335
  @toy2.name = "Twine"
334
- @cat.should_not be_valid
335
- @cat.errors.should_not be_empty
336
- @toy1.errors.should be_empty
337
- @toy2.errors.should be_empty
338
- @toy3.errors.should_not be_empty
336
+ expect(@cat).not_to be_valid
337
+ expect(@cat.errors).not_to be_empty
338
+ expect(@toy1.errors).to be_empty
339
+ expect(@toy2.errors).to be_empty
340
+ expect(@toy3.errors).not_to be_empty
339
341
  end
340
342
 
341
343
  it "should not use dperecated ActiveModel options" do
342
- ActiveSupport::Deprecation.should_not_receive(:warn)
343
- @cat.should_not be_valid
344
+ expect(ActiveSupport::Deprecation).not_to receive(:warn)
345
+ expect(@cat).not_to be_valid
344
346
  end
345
347
  end
346
348
 
347
349
  describe "on a casted model property" do
348
350
  it "should only validate itself" do
349
- @toy1.should_not be_valid
350
- @toy1.errors.should_not be_empty
351
- @cat.errors.should be_empty
352
- @toy2.errors.should be_empty
353
- @toy3.errors.should be_empty
351
+ expect(@toy1).not_to be_valid
352
+ expect(@toy1.errors).not_to be_empty
353
+ expect(@cat.errors).to be_empty
354
+ expect(@toy2.errors).to be_empty
355
+ expect(@toy3.errors).to be_empty
354
356
  end
355
357
  end
356
358
 
357
359
  describe "on a casted model inside a casted collection" do
358
360
  it "should only validate itself" do
359
- @toy2.should_not be_valid
360
- @toy2.errors.should_not be_empty
361
- @cat.errors.should be_empty
362
- @toy1.errors.should be_empty
363
- @toy3.errors.should be_empty
361
+ expect(@toy2).not_to be_valid
362
+ expect(@toy2.errors).not_to be_empty
363
+ expect(@cat.errors).to be_empty
364
+ expect(@toy1.errors).to be_empty
365
+ expect(@toy3.errors).to be_empty
364
366
  end
365
367
  end
366
368
  end
@@ -375,37 +377,37 @@ describe CouchRest::Model::Embeddable do
375
377
  end
376
378
 
377
379
  it "should be true on new" do
378
- CatToy.new.should be_new
379
- CatToy.new.new_record?.should be_true
380
+ expect(CatToy.new).to be_new
381
+ expect(CatToy.new.new_record?).to be_truthy
380
382
  end
381
383
 
382
384
  it "should be true after assignment" do
383
- @cat.should be_new
384
- @cat.favorite_toy.should be_new
385
- @cat.toys.first.should be_new
385
+ expect(@cat).to be_new
386
+ expect(@cat.favorite_toy).to be_new
387
+ expect(@cat.toys.first).to be_new
386
388
  end
387
389
 
388
390
  it "should not be true after create or save" do
389
391
  @cat.create
390
392
  @cat.save
391
- @cat.favorite_toy.should_not be_new
392
- @cat.toys.first.casted_by.should eql(@cat)
393
- @cat.toys.first.should_not be_new
393
+ expect(@cat.favorite_toy).not_to be_new
394
+ expect(@cat.toys.first.casted_by).to eql(@cat)
395
+ expect(@cat.toys.first).not_to be_new
394
396
  end
395
397
 
396
398
  it "should not be true after get from the database" do
397
399
  @cat.save
398
400
  @cat = Cat.get(@cat.id)
399
- @cat.favorite_toy.should_not be_new
400
- @cat.toys.first.should_not be_new
401
+ expect(@cat.favorite_toy).not_to be_new
402
+ expect(@cat.toys.first).not_to be_new
401
403
  end
402
404
 
403
405
  it "should still be true after a failed create or save" do
404
406
  @cat.name = nil
405
- @cat.create.should be_false
406
- @cat.save.should be_false
407
- @cat.favorite_toy.should be_new
408
- @cat.toys.first.should be_new
407
+ expect(@cat.create).to be_falsey
408
+ expect(@cat.save).to be_falsey
409
+ expect(@cat.favorite_toy).to be_new
410
+ expect(@cat.toys.first).to be_new
409
411
  end
410
412
  end
411
413
 
@@ -427,27 +429,27 @@ describe CouchRest::Model::Embeddable do
427
429
  @course.questions << question
428
430
  new_course = Course.new
429
431
  new_course.questions = @course.questions
430
- new_course.questions.should include(question)
432
+ expect(new_course.questions).to include(question)
431
433
  end
432
434
 
433
435
  it "should reference the top document for" do
434
- @course.base_doc.should === @course
435
- @professor.casted_by.should === @course
436
- @professor.base_doc.should === @course
437
- @cat.base_doc.should === @course
438
- @toy1.base_doc.should === @course
439
- @toy2.base_doc.should === @course
436
+ expect(@course.base_doc).to be === @course
437
+ expect(@professor.casted_by).to be === @course
438
+ expect(@professor.base_doc).to be === @course
439
+ expect(@cat.base_doc).to be === @course
440
+ expect(@toy1.base_doc).to be === @course
441
+ expect(@toy2.base_doc).to be === @course
440
442
  end
441
443
 
442
444
  it "should call setter on top document" do
443
- @toy1.base_doc.should_not be_nil
445
+ expect(@toy1.base_doc).not_to be_nil
444
446
  @toy1.base_doc.title = 'Tom Foolery'
445
- @course.title.should == 'Tom Foolery'
447
+ expect(@course.title).to eq('Tom Foolery')
446
448
  end
447
449
 
448
450
  it "should return nil if not yet casted" do
449
451
  person = Person.new
450
- person.base_doc.should == nil
452
+ expect(person.base_doc).to eq(nil)
451
453
  end
452
454
  end
453
455
 
@@ -460,16 +462,16 @@ describe CouchRest::Model::Embeddable do
460
462
  end
461
463
 
462
464
  it "should not save parent document when casted model is invalid" do
463
- @toy.should_not be_valid
464
- @toy.base_doc.save.should be_false
465
- lambda{@toy.base_doc.save!}.should raise_error
465
+ expect(@toy).not_to be_valid
466
+ expect(@toy.base_doc.save).to be_falsey
467
+ expect{@toy.base_doc.save!}.to raise_error(/Validation Failed/)
466
468
  end
467
469
 
468
470
  it "should save parent document when nested casted model is valid" do
469
471
  @toy.name = "Mr Squeaks"
470
- @toy.should be_valid
471
- @toy.base_doc.save.should be_true
472
- lambda{@toy.base_doc.save!}.should_not raise_error
472
+ expect(@toy).to be_valid
473
+ expect(@toy.base_doc.save).to be_truthy
474
+ expect{@toy.base_doc.save!}.not_to raise_error
473
475
  end
474
476
  end
475
477
 
@@ -482,14 +484,14 @@ describe CouchRest::Model::Embeddable do
482
484
 
483
485
  describe "validate" do
484
486
  it "should run before_validation before validating" do
485
- @model.run_before_validation.should be_nil
486
- @model.should be_valid
487
- @model.run_before_validation.should be_true
487
+ expect(@model.run_before_validation).to be_nil
488
+ expect(@model).to be_valid
489
+ expect(@model.run_before_validation).to be_truthy
488
490
  end
489
491
  it "should run after_validation after validating" do
490
- @model.run_after_validation.should be_nil
491
- @model.should be_valid
492
- @model.run_after_validation.should be_true
492
+ expect(@model.run_after_validation).to be_nil
493
+ expect(@model).to be_valid
494
+ expect(@model.run_after_validation).to be_truthy
493
495
  end
494
496
  end
495
497
  end