couchrest_model 2.1.0.rc1 → 2.2.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- 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/proxyable_spec.rb
CHANGED
@@ -23,17 +23,43 @@ describe CouchRest::Model::Proxyable do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should respond to method" do
|
26
|
-
@obj.
|
26
|
+
expect(@obj).to respond_to(:proxy_database)
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should provide proxy database from method" do
|
30
30
|
expect(@class).to receive(:proxy_database_method).at_least(:twice).and_return(:slug)
|
31
|
-
expect(@obj.proxy_database).to be_a(CouchRest::Database)
|
32
|
-
expect(@obj.proxy_database.name).to eql('couchrest_proxy')
|
31
|
+
expect(@obj.proxy_database(:assoc)).to be_a(CouchRest::Database)
|
32
|
+
expect(@obj.proxy_database(:assoc).name).to eql('couchrest_proxy')
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should raise an error if called and no proxy_database_method set" do
|
36
|
-
|
36
|
+
expect { @obj.proxy_database(:assoc) }.to raise_error(StandardError, /Please set/)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should support passing a suffix" do
|
40
|
+
allow(@class).to receive(:proxy_database_method).and_return(:slug)
|
41
|
+
allow(@class).to receive(:proxy_database_suffixes).and_return({ assoc: 'suffix' })
|
42
|
+
expect { @obj.proxy_database(:assoc) }.not_to raise_error
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should join the suffix to the database name" do
|
46
|
+
allow(@class).to receive(:proxy_database_method).and_return(:slug)
|
47
|
+
allow(@class).to receive(:proxy_database_suffixes).and_return({ assoc: 'suffix' })
|
48
|
+
expect(@obj.proxy_database(:assoc).name).to eql('couchrest_proxy_suffix')
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should support multiple databases" do
|
52
|
+
allow(@class).to receive(:proxy_database_method).and_return(:slug)
|
53
|
+
allow(@class).to receive(:proxy_database_suffixes).and_return({ assoc: 'suffix', another_assoc: "another_suffix" })
|
54
|
+
expect(@obj.proxy_database(:assoc).name).to eql('couchrest_proxy_suffix')
|
55
|
+
expect(@obj.proxy_database(:another_assoc).name).to eql('couchrest_proxy_another_suffix')
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should use the configuration's join character to add the suffix" do
|
59
|
+
@class.connection.update(:join => '-')
|
60
|
+
allow(@class).to receive(:proxy_database_method).and_return(:slug)
|
61
|
+
allow(@class).to receive(:proxy_database_suffixes).and_return({ assoc: 'suffix' })
|
62
|
+
expect(@obj.proxy_database(:assoc).name).to eql('couchrest-proxy-suffix')
|
37
63
|
end
|
38
64
|
end
|
39
65
|
|
@@ -45,12 +71,12 @@ describe CouchRest::Model::Proxyable do
|
|
45
71
|
@class = DummyProxyable.clone
|
46
72
|
end
|
47
73
|
it "should provide proxy_owner_method accessors" do
|
48
|
-
@class.
|
49
|
-
@class.
|
74
|
+
expect(@class).to respond_to(:proxy_owner_method)
|
75
|
+
expect(@class).to respond_to(:proxy_owner_method=)
|
50
76
|
end
|
51
77
|
it "should work as expected" do
|
52
78
|
@class.proxy_owner_method = "foo"
|
53
|
-
@class.proxy_owner_method.
|
79
|
+
expect(@class.proxy_owner_method).to eql("foo")
|
54
80
|
end
|
55
81
|
end
|
56
82
|
|
@@ -60,7 +86,7 @@ describe CouchRest::Model::Proxyable do
|
|
60
86
|
end
|
61
87
|
it "should be possible to set the proxy database method" do
|
62
88
|
@class.proxy_database_method :db
|
63
|
-
@class.proxy_database_method.
|
89
|
+
expect(@class.proxy_database_method).to eql(:db)
|
64
90
|
end
|
65
91
|
end
|
66
92
|
|
@@ -70,31 +96,54 @@ describe CouchRest::Model::Proxyable do
|
|
70
96
|
end
|
71
97
|
|
72
98
|
it "should be provided" do
|
73
|
-
@class.
|
99
|
+
expect(@class).to respond_to(:proxy_for)
|
74
100
|
end
|
75
101
|
|
76
102
|
it "should add model name to proxied model name array" do
|
77
103
|
@class.proxy_for(:cats)
|
78
|
-
@class.proxied_model_names.
|
104
|
+
expect(@class.proxied_model_names).to eql(['Cat'])
|
79
105
|
end
|
80
106
|
|
81
107
|
it "should add method names to proxied method name array" do
|
82
108
|
@class.proxy_for(:cats)
|
83
|
-
@class.proxy_method_names.
|
109
|
+
expect(@class.proxy_method_names).to eql([:cats])
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should accept a class_name override" do
|
113
|
+
@class.proxy_for(:felines, class_name: "Cat")
|
114
|
+
expect(@class.proxy_method_names).to eql([:felines])
|
115
|
+
expect(@class.proxied_model_names).to eql(['Cat'])
|
116
|
+
end
|
117
|
+
|
118
|
+
describe "proxy database suffix" do
|
119
|
+
it "should support not passing a suffix" do
|
120
|
+
@class.proxy_for(:cats)
|
121
|
+
expect(@class.proxy_database_suffixes).to eql({ cats: nil })
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should set the database suffix if provided" do
|
125
|
+
@class.proxy_for(:cats, use_suffix: true)
|
126
|
+
expect(@class.proxy_database_suffixes).to eql({ cats: 'cats' })
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should accept a database suffix override" do
|
130
|
+
@class.proxy_for(:cats, database_suffix: 'felines')
|
131
|
+
expect(@class.proxy_database_suffixes).to eql({ cats: 'felines' })
|
132
|
+
end
|
84
133
|
end
|
85
134
|
|
86
135
|
it "should create a new method" do
|
87
|
-
DummyProxyable.
|
136
|
+
allow(DummyProxyable).to receive(:method_defined?).and_return(true)
|
88
137
|
DummyProxyable.proxy_for(:cats)
|
89
|
-
DummyProxyable.new.
|
138
|
+
expect(DummyProxyable.new).to respond_to(:cats)
|
90
139
|
end
|
91
140
|
|
92
141
|
describe "generated method" do
|
93
142
|
it "should call ModelProxy" do
|
94
143
|
DummyProxyable.proxy_for(:cats)
|
95
144
|
@obj = DummyProxyable.new
|
96
|
-
CouchRest::Model::Proxyable::ModelProxy.
|
97
|
-
@obj.
|
145
|
+
expect(CouchRest::Model::Proxyable::ModelProxy).to receive(:new).with(Cat, @obj, 'dummy_proxyable', 'db').and_return(true)
|
146
|
+
expect(@obj).to receive(:proxy_database).and_return('db')
|
98
147
|
@obj.cats
|
99
148
|
end
|
100
149
|
|
@@ -104,8 +153,8 @@ describe CouchRest::Model::Proxyable do
|
|
104
153
|
end
|
105
154
|
DummyProxyable.proxy_for(:documents)
|
106
155
|
@obj = DummyProxyable.new
|
107
|
-
CouchRest::Model::Proxyable::ModelProxy.
|
108
|
-
@obj.
|
156
|
+
expect(CouchRest::Model::Proxyable::ModelProxy).to receive(:new).with(::Document, @obj, 'dummy_proxyable', 'db').and_return(true)
|
157
|
+
expect(@obj).to receive('proxy_database').and_return('db')
|
109
158
|
@obj.documents
|
110
159
|
end
|
111
160
|
end
|
@@ -117,36 +166,36 @@ describe CouchRest::Model::Proxyable do
|
|
117
166
|
end
|
118
167
|
|
119
168
|
it "should be provided" do
|
120
|
-
@class.
|
169
|
+
expect(@class).to respond_to(:proxied_by)
|
121
170
|
end
|
122
171
|
|
123
172
|
it "should add an attribute accessor" do
|
124
173
|
@class.proxied_by(:foobar)
|
125
|
-
@class.new.
|
174
|
+
expect(@class.new).to respond_to(:foobar)
|
126
175
|
end
|
127
176
|
|
128
177
|
it "should provide #model_proxy method" do
|
129
178
|
@class.proxied_by(:foobar)
|
130
|
-
@class.new.
|
179
|
+
expect(@class.new).to respond_to(:model_proxy)
|
131
180
|
end
|
132
181
|
|
133
182
|
it "should set the proxy_owner_method" do
|
134
183
|
@class.proxied_by(:foobar)
|
135
|
-
@class.proxy_owner_method.
|
184
|
+
expect(@class.proxy_owner_method).to eql(:foobar)
|
136
185
|
end
|
137
186
|
|
138
187
|
it "should raise an error if model name pre-defined" do
|
139
|
-
|
188
|
+
expect { @class.proxied_by(:object_id) }.to raise_error(/Model can only be proxied once/)
|
140
189
|
end
|
141
190
|
|
142
191
|
it "should raise an error if object already has a proxy" do
|
143
192
|
@class.proxied_by(:department)
|
144
|
-
|
193
|
+
expect { @class.proxied_by(:company) }.to raise_error(/Model can only be proxied once/)
|
145
194
|
end
|
146
195
|
|
147
196
|
it "should overwrite the database method to provide an error" do
|
148
197
|
@class.proxied_by(:company)
|
149
|
-
|
198
|
+
expect { @class.database }.to raise_error(StandardError, /database must be accessed via/)
|
150
199
|
end
|
151
200
|
end
|
152
201
|
|
@@ -156,16 +205,16 @@ describe CouchRest::Model::Proxyable do
|
|
156
205
|
end
|
157
206
|
|
158
207
|
it "should respond to proxied_model_names" do
|
159
|
-
@class.
|
208
|
+
expect(@class).to respond_to(:proxied_model_names)
|
160
209
|
end
|
161
210
|
|
162
211
|
it "should provide an empty array" do
|
163
|
-
@class.proxied_model_names.
|
212
|
+
expect(@class.proxied_model_names).to be_empty
|
164
213
|
end
|
165
214
|
|
166
215
|
it "should accept new entries" do
|
167
216
|
@class.proxied_model_names << 'Cat'
|
168
|
-
@class.proxied_model_names.first.
|
217
|
+
expect(@class.proxied_model_names.first).to eql('Cat')
|
169
218
|
end
|
170
219
|
end
|
171
220
|
|
@@ -179,139 +228,148 @@ describe CouchRest::Model::Proxyable do
|
|
179
228
|
|
180
229
|
before :each do
|
181
230
|
@design_doc = double('Design')
|
182
|
-
@design_doc.
|
231
|
+
allow(@design_doc).to receive(:view_names).and_return(['all', 'by_name'])
|
183
232
|
@model = double('Cat')
|
184
|
-
@model.
|
233
|
+
allow(@model).to receive(:design_docs).and_return([@design_doc])
|
185
234
|
@obj = @klass.new(@model, 'owner', 'owner_name', 'database')
|
186
235
|
end
|
187
236
|
|
188
237
|
describe "initialization" do
|
189
238
|
|
190
239
|
it "should set base attributes" do
|
191
|
-
@obj.model.
|
192
|
-
@obj.owner.
|
193
|
-
@obj.owner_name.
|
194
|
-
@obj.database.
|
240
|
+
expect(@obj.model).to eql(@model)
|
241
|
+
expect(@obj.owner).to eql('owner')
|
242
|
+
expect(@obj.owner_name).to eql('owner_name')
|
243
|
+
expect(@obj.database).to eql('database')
|
195
244
|
end
|
196
245
|
|
197
246
|
it "should create view methods" do
|
198
|
-
@obj.
|
199
|
-
@obj.
|
200
|
-
@obj.
|
201
|
-
@obj.
|
202
|
-
@obj.
|
247
|
+
expect(@obj).to respond_to('all')
|
248
|
+
expect(@obj).to respond_to('by_name')
|
249
|
+
expect(@obj).to respond_to('find_all')
|
250
|
+
expect(@obj).to respond_to('find_by_name')
|
251
|
+
expect(@obj).to respond_to('find_by_name!')
|
203
252
|
end
|
204
253
|
|
205
254
|
it "should create 'all' view method that forward to model's view with proxy" do
|
206
|
-
@model.
|
255
|
+
expect(@model).to receive(:all).with(:proxy => @obj).and_return(nil)
|
207
256
|
@obj.all
|
208
257
|
end
|
209
258
|
|
210
259
|
it "should create 'by_name' view method that forward to model's view with proxy" do
|
211
|
-
@model.
|
260
|
+
expect(@model).to receive(:by_name).with(:proxy => @obj).and_return(nil)
|
212
261
|
@obj.by_name
|
213
262
|
end
|
214
263
|
|
215
264
|
it "should create 'find_by_name' view that forwards to normal view" do
|
216
265
|
view = double('view')
|
217
|
-
view.
|
218
|
-
view.
|
219
|
-
@obj.
|
266
|
+
expect(view).to receive('key').with('name').and_return(view)
|
267
|
+
expect(view).to receive('first').and_return(nil)
|
268
|
+
expect(@obj).to receive(:by_name).and_return(view)
|
220
269
|
@obj.find_by_name('name')
|
221
270
|
end
|
222
271
|
|
223
272
|
it "should create 'find_by_name!' that raises error when there are no results" do
|
224
273
|
view = double('view')
|
225
|
-
view.
|
226
|
-
view.
|
227
|
-
@obj.
|
228
|
-
|
274
|
+
expect(view).to receive('key').with('name').and_return(view)
|
275
|
+
expect(view).to receive('first').and_return(nil)
|
276
|
+
expect(@obj).to receive(:by_name).and_return(view)
|
277
|
+
expect { @obj.find_by_name!('name') }.to raise_error(CouchRest::Model::DocumentNotFound)
|
229
278
|
end
|
230
|
-
|
231
279
|
end
|
232
280
|
|
233
281
|
describe "instance" do
|
234
282
|
|
235
283
|
it "should proxy new call" do
|
236
|
-
@obj.
|
284
|
+
expect(@obj).to receive(:proxy_block_update).with(:new, 'attrs', 'opts')
|
237
285
|
@obj.new('attrs', 'opts')
|
238
286
|
end
|
239
287
|
|
240
288
|
it "should proxy build_from_database" do
|
241
|
-
@obj.
|
289
|
+
expect(@obj).to receive(:proxy_block_update).with(:build_from_database, 'attrs', 'opts')
|
242
290
|
@obj.build_from_database('attrs', 'opts')
|
243
291
|
end
|
244
292
|
|
245
293
|
it "should proxy #count" do
|
246
294
|
view = double('View')
|
247
|
-
view.
|
248
|
-
@model.
|
295
|
+
expect(view).to receive(:count).and_return(nil)
|
296
|
+
expect(@model).to receive(:all).and_return(view)
|
249
297
|
@obj.count
|
250
298
|
end
|
251
299
|
|
252
300
|
it "should proxy #first" do
|
253
301
|
view = double('View')
|
254
|
-
view.
|
255
|
-
@model.
|
302
|
+
expect(view).to receive(:first).and_return(nil)
|
303
|
+
expect(@model).to receive(:all).and_return(view)
|
256
304
|
@obj.first
|
257
305
|
end
|
258
306
|
|
259
307
|
it "should proxy #last" do
|
260
308
|
view = double('View')
|
261
|
-
view.
|
262
|
-
@model.
|
309
|
+
expect(view).to receive(:last).and_return(nil)
|
310
|
+
expect(@model).to receive(:all).and_return(view)
|
263
311
|
@obj.last
|
264
312
|
end
|
265
313
|
|
266
314
|
it "should proxy #get" do
|
267
|
-
@model.
|
268
|
-
@obj.
|
315
|
+
expect(@model).to receive(:get).with(32, 'database')
|
316
|
+
expect(@obj).to receive(:proxy_update)
|
269
317
|
@obj.get(32)
|
270
318
|
end
|
319
|
+
|
271
320
|
it "should proxy #find" do
|
272
|
-
@model.
|
273
|
-
@obj.
|
321
|
+
expect(@model).to receive(:get).with(32, 'database')
|
322
|
+
expect(@obj).to receive(:proxy_update)
|
274
323
|
@obj.find(32)
|
275
324
|
end
|
276
325
|
|
326
|
+
it "should proxy factory methods" do
|
327
|
+
expect(@model).to receive(:factory_method).with(@obj, "arg_1", "arg_2")
|
328
|
+
@obj.factory_method("arg_1", "arg_2")
|
329
|
+
end
|
330
|
+
|
331
|
+
it "shouldn't forward undefined model methods" do
|
332
|
+
expect { @obj.undefined_factory_method("arg_1", "arg_2") }.to raise_error(NoMethodError, /CouchRest::Model::Proxy/)
|
333
|
+
end
|
334
|
+
|
277
335
|
|
278
336
|
### Updating methods
|
279
337
|
|
280
338
|
describe "#proxy_update" do
|
281
339
|
it "should set returned doc fields" do
|
282
340
|
doc = double(:Document)
|
283
|
-
doc.
|
284
|
-
doc.
|
285
|
-
doc.
|
286
|
-
doc.
|
287
|
-
@obj.send(:proxy_update, doc).
|
341
|
+
expect(doc).to receive(:is_a?).with(@model).and_return(true)
|
342
|
+
expect(doc).to receive(:database=).with('database')
|
343
|
+
expect(doc).to receive(:model_proxy=).with(@obj)
|
344
|
+
expect(doc).to receive(:send).with('owner_name=', 'owner')
|
345
|
+
expect(@obj.send(:proxy_update, doc)).to eql(doc)
|
288
346
|
end
|
289
347
|
|
290
348
|
it "should not set anything if matching document not provided" do
|
291
349
|
doc = double(:DocumentFoo)
|
292
|
-
doc.
|
293
|
-
doc.
|
294
|
-
doc.
|
295
|
-
doc.
|
296
|
-
@obj.send(:proxy_update, doc).
|
350
|
+
expect(doc).to receive(:is_a?).with(@model).and_return(false)
|
351
|
+
expect(doc).not_to receive(:database=)
|
352
|
+
expect(doc).not_to receive(:model_proxy=)
|
353
|
+
expect(doc).not_to receive(:owner_name=)
|
354
|
+
expect(@obj.send(:proxy_update, doc)).to eql(doc)
|
297
355
|
end
|
298
356
|
|
299
357
|
it "should pass nil straight through without errors" do
|
300
|
-
|
358
|
+
expect { expect(@obj.send(:proxy_update, nil)).to eql(nil) }.not_to raise_error
|
301
359
|
end
|
302
360
|
end
|
303
361
|
|
304
362
|
it "#proxy_update_all should update array of docs" do
|
305
363
|
docs = [{}, {}]
|
306
|
-
@obj.
|
364
|
+
expect(@obj).to receive(:proxy_update).twice.with({})
|
307
365
|
@obj.send(:proxy_update_all, docs)
|
308
366
|
end
|
309
367
|
|
310
368
|
describe "#proxy_block_update" do
|
311
369
|
it "should proxy block updates" do
|
312
370
|
doc = { }
|
313
|
-
@obj.model.
|
314
|
-
@obj.
|
371
|
+
expect(@obj.model).to receive(:new).and_yield(doc)
|
372
|
+
expect(@obj).to receive(:proxy_update).with(doc)
|
315
373
|
@obj.send(:proxy_block_update, :new)
|
316
374
|
end
|
317
375
|
end
|
@@ -327,7 +385,7 @@ describe CouchRest::Model::Proxyable do
|
|
327
385
|
use_database DB
|
328
386
|
property :slug
|
329
387
|
proxy_for :proxyable_invoices
|
330
|
-
def proxy_database
|
388
|
+
def proxy_database(assoc)
|
331
389
|
@db ||= TEST_SERVER.database!(TESTDB + "-#{slug}")
|
332
390
|
end
|
333
391
|
end
|
@@ -346,26 +404,26 @@ describe CouchRest::Model::Proxyable do
|
|
346
404
|
|
347
405
|
it "should create the new database" do
|
348
406
|
view = @company.proxyable_invoices.all
|
349
|
-
view.
|
350
|
-
TEST_SERVER.databases.find{|db| db =~ /#{TESTDB}-samco/}.
|
407
|
+
expect(view).to be_empty
|
408
|
+
expect(TEST_SERVER.databases.find{|db| db =~ /#{TESTDB}-samco/}).not_to be_nil
|
351
409
|
end
|
352
410
|
|
353
411
|
it "should allow creation of new entries" do
|
354
412
|
inv = @company.proxyable_invoices.new(:client => "Lorena", :total => 35)
|
355
413
|
# inv.database.should_not be_nil
|
356
|
-
inv.save.
|
357
|
-
@company.proxyable_invoices.count.
|
358
|
-
@company.proxyable_invoices.first.client.
|
414
|
+
expect(inv.save).to be_truthy
|
415
|
+
expect(@company.proxyable_invoices.count).to eql(1)
|
416
|
+
expect(@company.proxyable_invoices.first.client).to eql("Lorena")
|
359
417
|
end
|
360
418
|
|
361
419
|
it "should validate uniqueness" do
|
362
420
|
inv = @company.proxyable_invoices.new(:client => "Lorena", :total => 40)
|
363
|
-
inv.save.
|
421
|
+
expect(inv.save).to be_falsey
|
364
422
|
end
|
365
423
|
|
366
424
|
it "should allow design views" do
|
367
425
|
item = @company.proxyable_invoices.by_total.key(35).first
|
368
|
-
item.client.
|
426
|
+
expect(item.client).to eql('Lorena')
|
369
427
|
end
|
370
428
|
|
371
429
|
end
|
data/spec/unit/subclass_spec.rb
CHANGED
@@ -39,55 +39,55 @@ describe "Subclassing a Model" do
|
|
39
39
|
end
|
40
40
|
|
41
41
|
it "shouldn't messup the parent's properties" do
|
42
|
-
Card.properties.
|
42
|
+
expect(Card.properties).not_to eq(BusinessCard.properties)
|
43
43
|
end
|
44
44
|
|
45
45
|
it "should share the same db default" do
|
46
|
-
@card.database.uri.
|
46
|
+
expect(@card.database.uri).to eq(Card.database.uri)
|
47
47
|
end
|
48
48
|
|
49
49
|
it "should have kept the validation details" do
|
50
|
-
@card.
|
50
|
+
expect(@card).not_to be_valid
|
51
51
|
end
|
52
52
|
|
53
53
|
it "should have added the new validation details" do
|
54
54
|
validated_fields = @card.class.validators.map{|v| v.attributes}.flatten
|
55
|
-
validated_fields.
|
56
|
-
validated_fields.
|
55
|
+
expect(validated_fields).to include(:extension_code)
|
56
|
+
expect(validated_fields).to include(:job_title)
|
57
57
|
end
|
58
58
|
|
59
59
|
it "should not add to the parent's validations" do
|
60
60
|
validated_fields = Card.validators.map{|v| v.attributes}.flatten
|
61
|
-
validated_fields.
|
62
|
-
validated_fields.
|
61
|
+
expect(validated_fields).not_to include(:extension_code)
|
62
|
+
expect(validated_fields).not_to include(:job_title)
|
63
63
|
end
|
64
64
|
|
65
65
|
it "should inherit default property values" do
|
66
|
-
@card.bg_color.
|
66
|
+
expect(@card.bg_color).to eq('#ccc')
|
67
67
|
end
|
68
68
|
|
69
69
|
it "should be able to overwrite a default property" do
|
70
|
-
DesignBusinessCard.new.bg_color.
|
70
|
+
expect(DesignBusinessCard.new.bg_color).to eq('#eee')
|
71
71
|
end
|
72
72
|
|
73
73
|
it "should have a design doc slug based on the subclass name" do
|
74
|
-
OnlineCourse.design_doc['_id'].
|
74
|
+
expect(OnlineCourse.design_doc['_id']).to match(/OnlineCourse$/)
|
75
75
|
end
|
76
76
|
|
77
77
|
it "should not add views to the parent's design_doc" do
|
78
|
-
Course.design_doc['views'].keys.
|
78
|
+
expect(Course.design_doc['views'].keys).not_to include('by_url')
|
79
79
|
end
|
80
80
|
|
81
81
|
it "should add the parent's views to its design doc" do
|
82
|
-
OnlineCourse.design_doc['views'].keys.
|
82
|
+
expect(OnlineCourse.design_doc['views'].keys).to include('by_title')
|
83
83
|
end
|
84
84
|
|
85
85
|
it "should add the parent's views but alter the model names in map function" do
|
86
|
-
OnlineCourse.design_doc['views']['by_title']['map'].
|
86
|
+
expect(OnlineCourse.design_doc['views']['by_title']['map']).to match(/doc\['#{OnlineCourse.model_type_key}'\] == 'OnlineCourse'/)
|
87
87
|
end
|
88
88
|
|
89
89
|
it "should have an all view with a guard clause for model == subclass name in the map function" do
|
90
|
-
OnlineCourse.design_doc['views']['all']['map'].
|
90
|
+
expect(OnlineCourse.design_doc['views']['all']['map']).to match(/if \(doc\['#{OnlineCourse.model_type_key}'\] == 'OnlineCourse'\)/)
|
91
91
|
end
|
92
92
|
|
93
93
|
end
|