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.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/.travis.yml +15 -4
- data/Gemfile.activesupport-4.x +4 -0
- data/Gemfile.activesupport-5.x +4 -0
- data/README.md +2 -0
- data/VERSION +1 -1
- data/couchrest_model.gemspec +3 -2
- data/history.md +14 -1
- data/lib/couchrest/model/associations.rb +3 -8
- data/lib/couchrest/model/base.rb +15 -7
- data/lib/couchrest/model/casted_array.rb +22 -34
- data/lib/couchrest/model/configuration.rb +2 -0
- data/lib/couchrest/model/design.rb +4 -3
- data/lib/couchrest/model/designs/view.rb +37 -32
- data/lib/couchrest/model/dirty.rb +93 -19
- data/lib/couchrest/model/embeddable.rb +2 -14
- data/lib/couchrest/model/extended_attachments.rb +2 -4
- data/lib/couchrest/model/persistence.rb +14 -17
- data/lib/couchrest/model/properties.rb +46 -54
- data/lib/couchrest/model/property.rb +0 -3
- data/lib/couchrest/model/proxyable.rb +20 -4
- data/lib/couchrest/model/validations/uniqueness.rb +4 -1
- data/lib/couchrest_model.rb +2 -2
- data/spec/fixtures/models/article.rb +1 -1
- data/spec/fixtures/models/card.rb +2 -1
- data/spec/fixtures/models/person.rb +1 -0
- data/spec/fixtures/models/project.rb +3 -0
- data/spec/unit/assocations_spec.rb +73 -73
- data/spec/unit/attachment_spec.rb +34 -34
- data/spec/unit/base_spec.rb +102 -102
- data/spec/unit/casted_array_spec.rb +7 -7
- data/spec/unit/casted_spec.rb +7 -7
- data/spec/unit/configuration_spec.rb +11 -11
- data/spec/unit/connection_spec.rb +30 -30
- data/spec/unit/core_extensions/{time_parsing.rb → time_parsing_spec.rb} +21 -21
- data/spec/unit/design_spec.rb +38 -38
- data/spec/unit/designs/design_mapper_spec.rb +26 -26
- data/spec/unit/designs/migrations_spec.rb +13 -13
- data/spec/unit/designs/view_spec.rb +319 -274
- data/spec/unit/designs_spec.rb +39 -39
- data/spec/unit/dirty_spec.rb +188 -103
- data/spec/unit/embeddable_spec.rb +119 -117
- data/spec/unit/inherited_spec.rb +4 -4
- data/spec/unit/persistence_spec.rb +122 -122
- data/spec/unit/properties_spec.rb +466 -16
- data/spec/unit/property_protection_spec.rb +32 -32
- data/spec/unit/property_spec.rb +45 -436
- data/spec/unit/proxyable_spec.rb +140 -82
- data/spec/unit/subclass_spec.rb +14 -14
- data/spec/unit/translations_spec.rb +5 -5
- data/spec/unit/typecast_spec.rb +131 -131
- data/spec/unit/utils/migrate_spec.rb +2 -2
- data/spec/unit/validations_spec.rb +31 -31
- metadata +27 -12
- data/lib/couchrest/model/casted_hash.rb +0 -84
data/spec/unit/base_spec.rb
CHANGED
@@ -9,7 +9,7 @@ describe "Model Base" do
|
|
9
9
|
|
10
10
|
describe "instance database connection" do
|
11
11
|
it "should use the default database" do
|
12
|
-
@obj.database.name.
|
12
|
+
expect(@obj.database.name).to eq('couchrest-model-test')
|
13
13
|
end
|
14
14
|
|
15
15
|
it "should override the default db" do
|
@@ -22,52 +22,52 @@ describe "Model Base" do
|
|
22
22
|
describe "a new model" do
|
23
23
|
it "should be a new document" do
|
24
24
|
@obj = Basic.new
|
25
|
-
@obj.rev.
|
26
|
-
@obj.
|
27
|
-
@obj.
|
28
|
-
@obj.
|
25
|
+
expect(@obj.rev).to be_nil
|
26
|
+
expect(@obj).to be_new
|
27
|
+
expect(@obj).to be_new_document
|
28
|
+
expect(@obj).to be_new_record
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should not fail with nil argument" do
|
32
32
|
@obj = Basic.new(nil)
|
33
|
-
@obj.
|
33
|
+
expect(@obj).not_to be_nil
|
34
34
|
end
|
35
35
|
|
36
36
|
it "should allow the database to be set" do
|
37
37
|
@obj = Basic.new(nil, :database => 'database')
|
38
|
-
@obj.database.
|
38
|
+
expect(@obj.database).to eql('database')
|
39
39
|
end
|
40
40
|
|
41
41
|
it "should support initialization block" do
|
42
42
|
@obj = Basic.new {|b| b.database = 'database'}
|
43
|
-
@obj.database.
|
43
|
+
expect(@obj.database).to eql('database')
|
44
44
|
end
|
45
45
|
|
46
46
|
it "should only set defined properties" do
|
47
47
|
@doc = WithDefaultValues.new(:name => 'test', :foo => 'bar')
|
48
|
-
@doc['name'].
|
49
|
-
@doc['foo'].
|
48
|
+
expect(@doc['name']).to eql('test')
|
49
|
+
expect(@doc['foo']).to be_nil
|
50
50
|
end
|
51
51
|
|
52
|
-
it "should set all properties with :
|
53
|
-
@doc = WithDefaultValues.new({:name => 'test', :foo => 'bar'}, :
|
54
|
-
@doc['name'].
|
55
|
-
@doc['foo'].
|
52
|
+
it "should set all properties with :write_all_attributes option" do
|
53
|
+
@doc = WithDefaultValues.new({:name => 'test', :foo => 'bar'}, :write_all_attributes => true)
|
54
|
+
expect(@doc['name']).to eql('test')
|
55
|
+
expect(@doc['foo']).to eql('bar')
|
56
56
|
end
|
57
57
|
|
58
58
|
it "should set the model type" do
|
59
59
|
@doc = WithDefaultValues.new()
|
60
|
-
@doc[WithDefaultValues.model_type_key].
|
60
|
+
expect(@doc[WithDefaultValues.model_type_key]).to eql('WithDefaultValues')
|
61
61
|
end
|
62
62
|
|
63
63
|
it "should call after_initialize method if available" do
|
64
64
|
@doc = WithAfterInitializeMethod.new
|
65
|
-
@doc['some_value'].
|
65
|
+
expect(@doc['some_value']).to eql('value')
|
66
66
|
end
|
67
67
|
|
68
68
|
it "should call after_initialize after block" do
|
69
69
|
@doc = WithAfterInitializeMethod.new {|d| d.some_value = "foo"}
|
70
|
-
@doc['some_value'].
|
70
|
+
expect(@doc['some_value']).to eql('foo')
|
71
71
|
end
|
72
72
|
|
73
73
|
it "should call after_initialize callback if available" do
|
@@ -78,7 +78,7 @@ describe "Model Base" do
|
|
78
78
|
def set_name; self.name = "foobar"; end
|
79
79
|
end
|
80
80
|
@doc = klass.new
|
81
|
-
@doc.name.
|
81
|
+
expect(@doc.name).to eql("foobar")
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
@@ -91,14 +91,14 @@ describe "Model Base" do
|
|
91
91
|
describe "#to_key" do
|
92
92
|
context "when the document is new" do
|
93
93
|
it "returns nil" do
|
94
|
-
@obj.to_key.
|
94
|
+
expect(@obj.to_key).to be_nil
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
98
98
|
context "when the document is not new" do
|
99
99
|
it "returns id in an array" do
|
100
100
|
@obj.save
|
101
|
-
@obj.to_key.
|
101
|
+
expect(@obj.to_key).to eql([@obj['_id']])
|
102
102
|
end
|
103
103
|
end
|
104
104
|
end
|
@@ -106,14 +106,14 @@ describe "Model Base" do
|
|
106
106
|
describe "#to_param" do
|
107
107
|
context "when the document is new" do
|
108
108
|
it "returns nil" do
|
109
|
-
@obj.to_param.
|
109
|
+
expect(@obj.to_param).to be_nil
|
110
110
|
end
|
111
111
|
end
|
112
112
|
|
113
113
|
context "when the document is not new" do
|
114
114
|
it "returns id" do
|
115
115
|
@obj.save
|
116
|
-
@obj.to_param.
|
116
|
+
expect(@obj.to_param).to eql(@obj['_id'])
|
117
117
|
end
|
118
118
|
end
|
119
119
|
end
|
@@ -121,14 +121,14 @@ describe "Model Base" do
|
|
121
121
|
describe "#persisted?" do
|
122
122
|
context "when the document is new" do
|
123
123
|
it "returns false" do
|
124
|
-
@obj.persisted
|
124
|
+
expect(@obj.persisted?).to be_falsey
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
128
128
|
context "when the document is not new" do
|
129
129
|
it "returns id" do
|
130
130
|
@obj.save
|
131
|
-
@obj.persisted
|
131
|
+
expect(@obj.persisted?).to be_truthy
|
132
132
|
end
|
133
133
|
end
|
134
134
|
|
@@ -136,29 +136,29 @@ describe "Model Base" do
|
|
136
136
|
it "returns false" do
|
137
137
|
@obj.save
|
138
138
|
@obj.destroy
|
139
|
-
@obj.persisted
|
139
|
+
expect(@obj.persisted?).to be_falsey
|
140
140
|
end
|
141
141
|
end
|
142
142
|
end
|
143
143
|
|
144
144
|
describe "#model_name" do
|
145
145
|
it "returns the name of the model" do
|
146
|
-
@obj.class.model_name.
|
147
|
-
WithDefaultValues.model_name.human.
|
146
|
+
expect(@obj.class.model_name).to eql('Basic')
|
147
|
+
expect(WithDefaultValues.model_name.human).to eql("With default values")
|
148
148
|
end
|
149
149
|
end
|
150
150
|
|
151
151
|
describe "#destroyed?" do
|
152
152
|
it "should be present" do
|
153
|
-
@obj.
|
153
|
+
expect(@obj).to respond_to(:destroyed?)
|
154
154
|
end
|
155
155
|
it "should return false with new object" do
|
156
|
-
@obj.destroyed
|
156
|
+
expect(@obj.destroyed?).to be_falsey
|
157
157
|
end
|
158
158
|
it "should return true after destroy" do
|
159
159
|
@obj.save
|
160
160
|
@obj.destroy
|
161
|
-
@obj.destroyed
|
161
|
+
expect(@obj.destroyed?).to be_truthy
|
162
162
|
end
|
163
163
|
end
|
164
164
|
end
|
@@ -168,34 +168,34 @@ describe "Model Base" do
|
|
168
168
|
context "on saved document" do
|
169
169
|
it "should be true on same document" do
|
170
170
|
p = Project.create
|
171
|
-
p.
|
171
|
+
expect(p).to eql(p)
|
172
172
|
end
|
173
173
|
it "should be true after loading" do
|
174
174
|
p = Project.create
|
175
|
-
p.
|
175
|
+
expect(p).to eql(Project.get(p.id))
|
176
176
|
end
|
177
177
|
it "should not be true if databases do not match" do
|
178
178
|
p = Project.create
|
179
179
|
p2 = p.dup
|
180
|
-
p2.
|
181
|
-
p.
|
180
|
+
allow(p2).to receive(:database).and_return('other')
|
181
|
+
expect(p).not_to eql(p2)
|
182
182
|
end
|
183
183
|
it "should always be false if one document not saved" do
|
184
184
|
p = Project.create(:name => 'test')
|
185
185
|
o = Project.new(:name => 'test')
|
186
|
-
p.
|
186
|
+
expect(p).not_to eql(o)
|
187
187
|
end
|
188
188
|
end
|
189
189
|
context "with new documents" do
|
190
190
|
it "should be true when attributes match" do
|
191
191
|
p = Project.new(:name => 'test')
|
192
192
|
o = Project.new(:name => 'test')
|
193
|
-
p.
|
193
|
+
expect(p).to eql(o)
|
194
194
|
end
|
195
195
|
it "should not be true when attributes don't match" do
|
196
196
|
p = Project.new(:name => 'test')
|
197
197
|
o = Project.new(:name => 'testing')
|
198
|
-
p.
|
198
|
+
expect(p).not_to eql(o)
|
199
199
|
end
|
200
200
|
end
|
201
201
|
end
|
@@ -209,37 +209,37 @@ describe "Model Base" do
|
|
209
209
|
@art.save
|
210
210
|
end
|
211
211
|
it "should work for attribute= methods" do
|
212
|
-
@art['title'].
|
213
|
-
@art.
|
214
|
-
@art['title'].
|
212
|
+
expect(@art['title']).to eql("big bad danger")
|
213
|
+
@art.write_attributes('date' => Time.now, :title => "super danger")
|
214
|
+
expect(@art['title']).to eql("super danger")
|
215
215
|
end
|
216
216
|
it "should silently ignore _id" do
|
217
|
-
@art.
|
218
|
-
@art['_id'].
|
217
|
+
@art.write_attributes('_id' => 'foobar')
|
218
|
+
expect(@art['_id']).to_not eql('foobar')
|
219
219
|
end
|
220
220
|
it "should silently ignore _rev" do
|
221
|
-
@art.
|
222
|
-
@art['_rev'].
|
221
|
+
@art.write_attributes('_rev' => 'foobar')
|
222
|
+
expect(@art['_rev']).to_not eql('foobar')
|
223
223
|
end
|
224
224
|
it "should silently ignore created_at" do
|
225
|
-
@art.
|
225
|
+
@art.write_attributes('created_at' => 'foobar')
|
226
226
|
expect(@art['created_at'].to_s).to_not eql('foobar')
|
227
227
|
end
|
228
228
|
it "should silently ignore updated_at" do
|
229
|
-
@art.
|
229
|
+
@art.write_attributes('updated_at' => 'foobar')
|
230
230
|
expect(@art['updated_at']).to_not eql('foobar')
|
231
231
|
end
|
232
232
|
it "should also work using attributes= alias" do
|
233
|
-
@art.respond_to?(:attributes=).
|
233
|
+
expect(@art.respond_to?(:attributes=)).to be_truthy
|
234
234
|
@art.attributes = {'date' => Time.now, :title => "something else"}
|
235
|
-
@art['title'].
|
235
|
+
expect(@art['title']).to eql("something else")
|
236
236
|
end
|
237
237
|
|
238
238
|
it "should not flip out if an attribute= method is missing and ignore it" do
|
239
|
-
|
240
|
-
@art.
|
241
|
-
}.
|
242
|
-
@art.slug.
|
239
|
+
expect {
|
240
|
+
@art.attributes = {'slug' => "new-slug", :title => "super danger"}
|
241
|
+
}.not_to raise_error
|
242
|
+
expect(@art.slug).to eq("big-bad-danger")
|
243
243
|
end
|
244
244
|
|
245
245
|
#it "should not change other attributes if there is an error" do
|
@@ -258,25 +258,25 @@ describe "Model Base" do
|
|
258
258
|
@art.save
|
259
259
|
end
|
260
260
|
it "should save" do
|
261
|
-
@art['title'].
|
261
|
+
expect(@art['title']).to eq("big bad danger")
|
262
262
|
@art.update_attributes('date' => Time.now, :title => "super danger")
|
263
263
|
loaded = Article.get(@art.id)
|
264
|
-
loaded['title'].
|
264
|
+
expect(loaded['title']).to eq("super danger")
|
265
265
|
end
|
266
266
|
end
|
267
267
|
|
268
268
|
describe "with default" do
|
269
269
|
it "should have the default value set at initalization" do
|
270
|
-
@obj.preset.
|
270
|
+
expect(@obj.preset).to eq({:right => 10, :top_align => false})
|
271
271
|
end
|
272
272
|
|
273
273
|
it "should have the default false value explicitly assigned" do
|
274
|
-
@obj.default_false.
|
274
|
+
expect(@obj.default_false).to eq(false)
|
275
275
|
end
|
276
276
|
|
277
277
|
it "should automatically call a proc default at initialization" do
|
278
|
-
@obj.set_by_proc.
|
279
|
-
@obj.set_by_proc.
|
278
|
+
expect(@obj.set_by_proc).to be_an_instance_of(Time)
|
279
|
+
expect(@obj.set_by_proc).to eq(@obj.set_by_proc)
|
280
280
|
expect(@obj.set_by_proc.utc).to be < Time.now.utc
|
281
281
|
end
|
282
282
|
|
@@ -288,31 +288,31 @@ describe "Model Base" do
|
|
288
288
|
it "should keep default values for new instances" do
|
289
289
|
obj = WithDefaultValues.new
|
290
290
|
obj.preset[:alpha] = 123
|
291
|
-
obj.preset.
|
291
|
+
expect(obj.preset).to eq({:right => 10, :top_align => false, :alpha => 123})
|
292
292
|
another = WithDefaultValues.new
|
293
|
-
another.preset.
|
293
|
+
expect(another.preset).to eq({:right => 10, :top_align => false})
|
294
294
|
end
|
295
295
|
|
296
296
|
it "should work with a default empty array" do
|
297
297
|
obj = WithDefaultValues.new(:tags => ['spec'])
|
298
|
-
obj.tags.
|
298
|
+
expect(obj.tags).to eq(['spec'])
|
299
299
|
end
|
300
300
|
|
301
301
|
it "should set default value of read-only property" do
|
302
302
|
obj = WithDefaultValues.new
|
303
|
-
obj.read_only_with_default.
|
303
|
+
expect(obj.read_only_with_default).to eq('generic')
|
304
304
|
end
|
305
305
|
end
|
306
306
|
|
307
307
|
describe "simplified way of setting property types" do
|
308
308
|
it "should set defaults" do
|
309
309
|
obj = WithSimplePropertyType.new
|
310
|
-
obj.preset.
|
310
|
+
expect(obj.preset).to eql('none')
|
311
311
|
end
|
312
312
|
|
313
313
|
it "should handle arrays" do
|
314
314
|
obj = WithSimplePropertyType.new(:tags => ['spec'])
|
315
|
-
obj.tags.
|
315
|
+
expect(obj.tags).to eq(['spec'])
|
316
316
|
end
|
317
317
|
end
|
318
318
|
|
@@ -324,16 +324,16 @@ describe "Model Base" do
|
|
324
324
|
@tmpl2 = WithTemplateAndUniqueID.new(:preset => 'not_value', 'slug' => '1')
|
325
325
|
end
|
326
326
|
it "should have fields set when new" do
|
327
|
-
@tmpl.preset.
|
327
|
+
expect(@tmpl.preset).to eq('value')
|
328
328
|
end
|
329
329
|
it "shouldn't override explicitly set values" do
|
330
|
-
@tmpl2.preset.
|
330
|
+
expect(@tmpl2.preset).to eq('not_value')
|
331
331
|
end
|
332
332
|
it "shouldn't override existing documents" do
|
333
333
|
@tmpl2.save
|
334
334
|
tmpl2_reloaded = WithTemplateAndUniqueID.get(@tmpl2.id)
|
335
|
-
@tmpl2.preset.
|
336
|
-
tmpl2_reloaded.preset.
|
335
|
+
expect(@tmpl2.preset).to eq('not_value')
|
336
|
+
expect(tmpl2_reloaded.preset).to eq('not_value')
|
337
337
|
end
|
338
338
|
end
|
339
339
|
|
@@ -349,7 +349,7 @@ describe "Model Base" do
|
|
349
349
|
end
|
350
350
|
it "should find all" do
|
351
351
|
rs = WithTemplateAndUniqueID.all
|
352
|
-
rs.length.
|
352
|
+
expect(rs.length).to eq(4)
|
353
353
|
end
|
354
354
|
end
|
355
355
|
|
@@ -359,14 +359,14 @@ describe "Model Base" do
|
|
359
359
|
end
|
360
360
|
|
361
361
|
it ".count should return 0 if there are no docuemtns" do
|
362
|
-
WithTemplateAndUniqueID.count.
|
362
|
+
expect(WithTemplateAndUniqueID.count).to eq(0)
|
363
363
|
end
|
364
364
|
|
365
365
|
it ".count should return the number of documents" do
|
366
366
|
WithTemplateAndUniqueID.new('slug' => '1').save
|
367
367
|
WithTemplateAndUniqueID.new('slug' => '2').save
|
368
368
|
WithTemplateAndUniqueID.new('slug' => '3').save
|
369
|
-
WithTemplateAndUniqueID.count.
|
369
|
+
expect(WithTemplateAndUniqueID.count).to eq(3)
|
370
370
|
end
|
371
371
|
end
|
372
372
|
|
@@ -380,11 +380,11 @@ describe "Model Base" do
|
|
380
380
|
end
|
381
381
|
it "should find first" do
|
382
382
|
rs = WithTemplateAndUniqueID.first
|
383
|
-
rs['slug'].
|
383
|
+
expect(rs['slug']).to eq("1")
|
384
384
|
end
|
385
385
|
it "should return nil if no instances are found" do
|
386
386
|
WithTemplateAndUniqueID.all.each {|obj| obj.destroy }
|
387
|
-
WithTemplateAndUniqueID.first.
|
387
|
+
expect(WithTemplateAndUniqueID.first).to be_nil
|
388
388
|
end
|
389
389
|
end
|
390
390
|
|
@@ -402,13 +402,13 @@ describe "Model Base" do
|
|
402
402
|
@course = Course.get r['id']
|
403
403
|
end
|
404
404
|
it "should load the course" do
|
405
|
-
@course["professor"]["name"][1].
|
405
|
+
expect(@course["professor"]["name"][1]).to eq("Hinchliff")
|
406
406
|
end
|
407
407
|
it "should instantiate the professor as a person" do
|
408
|
-
@course['professor'].last_name.
|
408
|
+
expect(@course['professor'].last_name).to eq("Hinchliff")
|
409
409
|
end
|
410
410
|
it "should instantiate the ends_at as a Time" do
|
411
|
-
@course['ends_at'].
|
411
|
+
expect(@course['ends_at']).to eq(Time.parse("2008/12/19 13:00:00 +0800"))
|
412
412
|
end
|
413
413
|
end
|
414
414
|
|
@@ -424,39 +424,39 @@ describe "Model Base" do
|
|
424
424
|
@obj.save
|
425
425
|
json = @obj.to_json
|
426
426
|
obj = WithDefaultValues.get(@obj.id)
|
427
|
-
obj.
|
428
|
-
obj.created_at.
|
429
|
-
obj.updated_at.
|
430
|
-
obj.created_at.to_s.
|
427
|
+
expect(obj).to be_an_instance_of(WithDefaultValues)
|
428
|
+
expect(obj.created_at).to be_an_instance_of(Time)
|
429
|
+
expect(obj.updated_at).to be_an_instance_of(Time)
|
430
|
+
expect(obj.created_at.to_s).to eq(@obj.updated_at.to_s)
|
431
431
|
end
|
432
432
|
|
433
433
|
it "should not change created_at on update" do
|
434
434
|
2.times do
|
435
|
-
|
435
|
+
expect do
|
436
436
|
@art.save
|
437
|
-
end.
|
437
|
+
end.not_to change(@art, :created_at)
|
438
438
|
end
|
439
439
|
end
|
440
440
|
|
441
441
|
it "should set the time on create" do
|
442
|
-
(Time.now - @art.created_at).
|
442
|
+
expect(Time.now - @art.created_at).to be < 2
|
443
443
|
foundart = Article.get @art.id
|
444
444
|
# Use string for comparison to cope with microsecond differences
|
445
|
-
foundart.created_at.to_s.
|
445
|
+
expect(foundart.created_at.to_s).to eq(foundart.updated_at.to_s)
|
446
446
|
end
|
447
447
|
it "should set the time on update" do
|
448
448
|
@art.title = "new title" # only saved if @art.changed? == true
|
449
449
|
@art.save
|
450
|
-
@art.created_at.
|
450
|
+
expect(@art.created_at).to be < @art.updated_at
|
451
451
|
end
|
452
452
|
end
|
453
453
|
|
454
454
|
describe "getter and setter methods" do
|
455
455
|
it "should try to call the arg= method before setting :arg in the hash" do
|
456
456
|
@doc = WithGetterAndSetterMethods.new(:arg => "foo")
|
457
|
-
@doc['arg'].
|
458
|
-
@doc[:arg].
|
459
|
-
@doc.other_arg.
|
457
|
+
expect(@doc['arg']).to be_nil
|
458
|
+
expect(@doc[:arg]).to be_nil
|
459
|
+
expect(@doc.other_arg).to eq("foo-foo")
|
460
460
|
end
|
461
461
|
end
|
462
462
|
|
@@ -468,30 +468,30 @@ describe "Model Base" do
|
|
468
468
|
|
469
469
|
it "should not save if a nested casted model is invalid" do
|
470
470
|
@cat.favorite_toy = CatToy.new
|
471
|
-
@cat.
|
472
|
-
@cat.save.
|
473
|
-
|
471
|
+
expect(@cat).not_to be_valid
|
472
|
+
expect(@cat.save).to be_falsey
|
473
|
+
expect{@cat.save!}.to raise_error(/Validation Failed/)
|
474
474
|
end
|
475
475
|
|
476
476
|
it "should save when nested casted model is valid" do
|
477
477
|
@cat.favorite_toy = CatToy.new(:name => 'Squeaky')
|
478
|
-
@cat.
|
479
|
-
@cat.save.
|
480
|
-
|
478
|
+
expect(@cat).to be_valid
|
479
|
+
expect(@cat.save).to be_truthy
|
480
|
+
expect{@cat.save!}.not_to raise_error
|
481
481
|
end
|
482
482
|
|
483
483
|
it "should not save when nested collection contains an invalid casted model" do
|
484
484
|
@cat.toys = [CatToy.new(:name => 'Feather'), CatToy.new]
|
485
|
-
@cat.
|
486
|
-
@cat.save.
|
487
|
-
|
485
|
+
expect(@cat).not_to be_valid
|
486
|
+
expect(@cat.save).to be_falsey
|
487
|
+
expect{@cat.save!}.to raise_error(/Validation Failed/)
|
488
488
|
end
|
489
489
|
|
490
490
|
it "should save when nested collection contains valid casted models" do
|
491
491
|
@cat.toys = [CatToy.new(:name => 'feather'), CatToy.new(:name => 'ball-o-twine')]
|
492
|
-
@cat.
|
493
|
-
@cat.save.
|
494
|
-
|
492
|
+
expect(@cat).to be_valid
|
493
|
+
expect(@cat.save).to be_truthy
|
494
|
+
expect{@cat.save!}.not_to raise_error
|
495
495
|
end
|
496
496
|
|
497
497
|
it "should not fail if the nested casted model doesn't have validation" do
|
@@ -499,8 +499,8 @@ describe "Model Base" do
|
|
499
499
|
Cat.validates_presence_of :name
|
500
500
|
cat = Cat.new(:name => 'Mr Bigglesworth')
|
501
501
|
cat.trainer = Person.new
|
502
|
-
cat.
|
503
|
-
cat.save.
|
502
|
+
expect(cat).to be_valid
|
503
|
+
expect(cat.save).to be_truthy
|
504
504
|
end
|
505
505
|
end
|
506
506
|
|