mattetti-couchrest 0.2.1.0 → 0.13
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +6 -31
- data/Rakefile +1 -1
- data/examples/model/example.rb +13 -19
- data/lib/couchrest/core/database.rb +4 -3
- data/lib/couchrest/core/model.rb +615 -0
- data/lib/couchrest/core/response.rb +4 -5
- data/lib/couchrest/core/server.rb +1 -1
- data/lib/couchrest/mixins/callbacks.rb +33 -74
- data/lib/couchrest/mixins/design_doc.rb +1 -2
- data/lib/couchrest/mixins/document_queries.rb +1 -1
- data/lib/couchrest/mixins/extended_document_mixins.rb +1 -2
- data/lib/couchrest/mixins/properties.rb +3 -8
- data/lib/couchrest/mixins/validation.rb +1 -2
- data/lib/couchrest/mixins/views.rb +5 -5
- data/lib/couchrest/monkeypatches.rb +48 -65
- data/lib/couchrest/more/extended_document.rb +8 -75
- data/lib/couchrest/more/property.rb +1 -12
- data/lib/couchrest/support/class.rb +132 -148
- data/lib/couchrest.rb +8 -33
- data/spec/couchrest/core/database_spec.rb +23 -28
- data/spec/couchrest/core/model_spec.rb +856 -0
- data/spec/couchrest/more/casted_model_spec.rb +0 -14
- data/spec/couchrest/more/extended_doc_spec.rb +4 -450
- data/spec/couchrest/more/property_spec.rb +5 -16
- data/spec/spec_helper.rb +0 -4
- metadata +3 -16
- data/lib/couchrest/mixins/extended_attachments.rb +0 -68
- data/lib/couchrest/validation/validators/confirmation_validator.rb +0 -99
- data/spec/couchrest/more/casted_extended_doc_spec.rb +0 -40
- data/spec/couchrest/more/extended_doc_attachment_spec.rb +0 -129
- data/spec/couchrest/more/extended_doc_view_spec.rb +0 -206
- data/spec/couchrest/support/class_spec.rb +0 -59
- data/spec/fixtures/more/article.rb +0 -34
- data/spec/fixtures/more/course.rb +0 -14
- data/spec/fixtures/more/event.rb +0 -6
- data/spec/fixtures/more/person.rb +0 -8
- data/spec/fixtures/more/question.rb +0 -6
@@ -10,7 +10,6 @@ class DummyModel < CouchRest::ExtendedDocument
|
|
10
10
|
use_database TEST_SERVER.default_database
|
11
11
|
raise "Default DB not set" if TEST_SERVER.default_database.nil?
|
12
12
|
property :casted_attribute, :cast_as => 'WithCastedModelMixin'
|
13
|
-
property :keywords, :cast_as => ["String"]
|
14
13
|
end
|
15
14
|
|
16
15
|
describe CouchRest::CastedModel do
|
@@ -56,23 +55,10 @@ describe CouchRest::CastedModel do
|
|
56
55
|
end
|
57
56
|
end
|
58
57
|
|
59
|
-
describe "casted as an array of a different type" do
|
60
|
-
before(:each) do
|
61
|
-
@obj = DummyModel.new(:keywords => ['couch', 'sofa', 'relax', 'canapé'])
|
62
|
-
end
|
63
|
-
|
64
|
-
it "should cast the array propery" do
|
65
|
-
@obj.keywords.should be_an_instance_of(Array)
|
66
|
-
@obj.keywords.first.should == 'couch'
|
67
|
-
end
|
68
|
-
|
69
|
-
end
|
70
|
-
|
71
58
|
describe "saved document with casted models" do
|
72
59
|
before(:each) do
|
73
60
|
@obj = DummyModel.new(:casted_attribute => {:name => 'whatever'})
|
74
61
|
@obj.save.should be_true
|
75
|
-
@obj = DummyModel.get(@obj.id)
|
76
62
|
end
|
77
63
|
|
78
64
|
it "should be able to load with the casted models" do
|
@@ -1,7 +1,4 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
-
require File.join(FIXTURE_PATH, 'more', 'article')
|
3
|
-
require File.join(FIXTURE_PATH, 'more', 'course')
|
4
|
-
|
5
2
|
|
6
3
|
describe "ExtendedDocument" do
|
7
4
|
|
@@ -9,122 +6,16 @@ describe "ExtendedDocument" do
|
|
9
6
|
use_database TEST_SERVER.default_database
|
10
7
|
property :preset, :default => {:right => 10, :top_align => false}
|
11
8
|
property :set_by_proc, :default => Proc.new{Time.now}, :cast_as => 'Time'
|
12
|
-
property :tags, :default => []
|
13
9
|
property :name
|
14
10
|
timestamps!
|
15
11
|
end
|
16
12
|
|
17
|
-
class WithCallBacks < CouchRest::ExtendedDocument
|
18
|
-
use_database TEST_SERVER.default_database
|
19
|
-
property :name
|
20
|
-
property :run_before_save
|
21
|
-
property :run_after_save
|
22
|
-
property :run_before_create
|
23
|
-
property :run_after_create
|
24
|
-
property :run_before_update
|
25
|
-
property :run_after_update
|
26
|
-
|
27
|
-
save_callback :before do |object|
|
28
|
-
object.run_before_save = true
|
29
|
-
end
|
30
|
-
save_callback :after do |object|
|
31
|
-
object.run_after_save = true
|
32
|
-
end
|
33
|
-
create_callback :before do |object|
|
34
|
-
object.run_before_create = true
|
35
|
-
end
|
36
|
-
create_callback :after do |object|
|
37
|
-
object.run_after_create = true
|
38
|
-
end
|
39
|
-
update_callback :before do |object|
|
40
|
-
object.run_before_update = true
|
41
|
-
end
|
42
|
-
update_callback :after do |object|
|
43
|
-
object.run_after_update = true
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
class WithTemplateAndUniqueID < CouchRest::ExtendedDocument
|
48
|
-
use_database TEST_SERVER.default_database
|
49
|
-
unique_id do |model|
|
50
|
-
model['important-field']
|
51
|
-
end
|
52
|
-
property :preset, :default => 'value'
|
53
|
-
property :has_no_default
|
54
|
-
end
|
55
|
-
|
56
13
|
before(:each) do
|
57
14
|
@obj = WithDefaultValues.new
|
58
15
|
end
|
59
16
|
|
60
|
-
describe "instance database connection" do
|
61
|
-
it "should use the default database" do
|
62
|
-
@obj.database.name.should == 'couchrest-test'
|
63
|
-
end
|
64
|
-
|
65
|
-
it "should override the default db" do
|
66
|
-
@obj.database = TEST_SERVER.database!('couchrest-extendedmodel-test')
|
67
|
-
@obj.database.name.should == 'couchrest-extendedmodel-test'
|
68
|
-
@obj.database.delete!
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
describe "a new model" do
|
73
|
-
it "should be a new_record" do
|
74
|
-
@obj = Basic.new
|
75
|
-
@obj.rev.should be_nil
|
76
|
-
@obj.should be_a_new_record
|
77
|
-
end
|
78
|
-
it "should be a new_document" do
|
79
|
-
@obj = Basic.new
|
80
|
-
@obj.rev.should be_nil
|
81
|
-
@obj.should be_a_new_document
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
describe "update attributes without saving" do
|
86
|
-
before(:each) do
|
87
|
-
a = Article.get "big-bad-danger" rescue nil
|
88
|
-
a.destroy if a
|
89
|
-
@art = Article.new(:title => "big bad danger")
|
90
|
-
@art.save
|
91
|
-
end
|
92
|
-
it "should work for attribute= methods" do
|
93
|
-
@art['title'].should == "big bad danger"
|
94
|
-
@art.update_attributes_without_saving('date' => Time.now, :title => "super danger")
|
95
|
-
@art['title'].should == "super danger"
|
96
|
-
end
|
97
|
-
|
98
|
-
it "should flip out if an attribute= method is missing" do
|
99
|
-
lambda {
|
100
|
-
@art.update_attributes_without_saving('slug' => "new-slug", :title => "super danger")
|
101
|
-
}.should raise_error
|
102
|
-
end
|
103
|
-
|
104
|
-
it "should not change other attributes if there is an error" do
|
105
|
-
lambda {
|
106
|
-
@art.update_attributes_without_saving('slug' => "new-slug", :title => "super danger")
|
107
|
-
}.should raise_error
|
108
|
-
@art['title'].should == "big bad danger"
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
describe "update attributes" do
|
113
|
-
before(:each) do
|
114
|
-
a = Article.get "big-bad-danger" rescue nil
|
115
|
-
a.destroy if a
|
116
|
-
@art = Article.new(:title => "big bad danger")
|
117
|
-
@art.save
|
118
|
-
end
|
119
|
-
it "should save" do
|
120
|
-
@art['title'].should == "big bad danger"
|
121
|
-
@art.update_attributes('date' => Time.now, :title => "super danger")
|
122
|
-
loaded = Article.get(@art.id)
|
123
|
-
loaded['title'].should == "super danger"
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
17
|
describe "with default" do
|
18
|
+
|
128
19
|
it "should have the default value set at initalization" do
|
129
20
|
@obj.preset.should == {:right => 10, :top_align => false}
|
130
21
|
end
|
@@ -134,148 +25,9 @@ describe "ExtendedDocument" do
|
|
134
25
|
@obj.set_by_proc.should == @obj.set_by_proc
|
135
26
|
@obj.set_by_proc.should < Time.now
|
136
27
|
end
|
137
|
-
|
138
|
-
it "should let you overwrite the default values" do
|
139
|
-
obj = WithDefaultValues.new(:preset => 'test')
|
140
|
-
obj.preset = 'test'
|
141
|
-
end
|
142
|
-
|
143
|
-
it "should work with a default empty array" do
|
144
|
-
obj = WithDefaultValues.new(:tags => ['spec'])
|
145
|
-
obj.tags.should == ['spec']
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
describe "a doc with template values (CR::Model spec)" do
|
150
|
-
before(:all) do
|
151
|
-
WithTemplateAndUniqueID.all.map{|o| o.destroy(true)}
|
152
|
-
WithTemplateAndUniqueID.database.bulk_delete
|
153
|
-
@tmpl = WithTemplateAndUniqueID.new
|
154
|
-
@tmpl2 = WithTemplateAndUniqueID.new(:preset => 'not_value', 'important-field' => '1')
|
155
|
-
end
|
156
|
-
it "should have fields set when new" do
|
157
|
-
@tmpl.preset.should == 'value'
|
158
|
-
end
|
159
|
-
it "shouldn't override explicitly set values" do
|
160
|
-
@tmpl2.preset.should == 'not_value'
|
161
|
-
end
|
162
|
-
it "shouldn't override existing documents" do
|
163
|
-
@tmpl2.save
|
164
|
-
tmpl2_reloaded = WithTemplateAndUniqueID.get(@tmpl2.id)
|
165
|
-
@tmpl2.preset.should == 'not_value'
|
166
|
-
tmpl2_reloaded.preset.should == 'not_value'
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
describe "getting a model" do
|
171
|
-
before(:all) do
|
172
|
-
@art = Article.new(:title => 'All About Getting')
|
173
|
-
@art.save
|
174
|
-
end
|
175
|
-
it "should load and instantiate it" do
|
176
|
-
foundart = Article.get @art.id
|
177
|
-
foundart.title.should == "All About Getting"
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
describe "getting a model with a subobjects array" do
|
182
|
-
before(:all) do
|
183
|
-
course_doc = {
|
184
|
-
"title" => "Metaphysics 200",
|
185
|
-
"questions" => [
|
186
|
-
{
|
187
|
-
"q" => "Carve the ___ of reality at the ___.",
|
188
|
-
"a" => ["beast","joints"]
|
189
|
-
},{
|
190
|
-
"q" => "Who layed the smack down on Leibniz's Law?",
|
191
|
-
"a" => "Willard Van Orman Quine"
|
192
|
-
}
|
193
|
-
]
|
194
|
-
}
|
195
|
-
r = Course.database.save_doc course_doc
|
196
|
-
@course = Course.get r['id']
|
197
|
-
end
|
198
|
-
it "should load the course" do
|
199
|
-
@course.title.should == "Metaphysics 200"
|
200
|
-
end
|
201
|
-
it "should instantiate them as such" do
|
202
|
-
@course["questions"][0].a[0].should == "beast"
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
|
-
describe "finding all instances of a model" do
|
207
|
-
before(:all) do
|
208
|
-
WithTemplateAndUniqueID.all.map{|o| o.destroy(true)}
|
209
|
-
WithTemplateAndUniqueID.database.bulk_delete
|
210
|
-
WithTemplateAndUniqueID.new('important-field' => '1').save
|
211
|
-
WithTemplateAndUniqueID.new('important-field' => '2').save
|
212
|
-
WithTemplateAndUniqueID.new('important-field' => '3').save
|
213
|
-
WithTemplateAndUniqueID.new('important-field' => '4').save
|
214
|
-
end
|
215
|
-
it "should make the design doc" do
|
216
|
-
WithTemplateAndUniqueID.all
|
217
|
-
d = WithTemplateAndUniqueID.design_doc
|
218
|
-
d['views']['all']['map'].should include('WithTemplateAndUniqueID')
|
219
|
-
end
|
220
|
-
it "should find all" do
|
221
|
-
rs = WithTemplateAndUniqueID.all
|
222
|
-
rs.length.should == 4
|
223
|
-
end
|
224
|
-
end
|
225
|
-
|
226
|
-
describe "finding the first instance of a model" do
|
227
|
-
before(:each) do
|
228
|
-
@db = reset_test_db!
|
229
|
-
WithTemplateAndUniqueID.new('important-field' => '1').save
|
230
|
-
WithTemplateAndUniqueID.new('important-field' => '2').save
|
231
|
-
WithTemplateAndUniqueID.new('important-field' => '3').save
|
232
|
-
WithTemplateAndUniqueID.new('important-field' => '4').save
|
233
|
-
end
|
234
|
-
it "should make the design doc" do
|
235
|
-
WithTemplateAndUniqueID.all
|
236
|
-
d = WithTemplateAndUniqueID.design_doc
|
237
|
-
d['views']['all']['map'].should include('WithTemplateAndUniqueID')
|
238
|
-
end
|
239
|
-
it "should find first" do
|
240
|
-
rs = WithTemplateAndUniqueID.first
|
241
|
-
rs['important-field'].should == "1"
|
242
|
-
end
|
243
|
-
it "should return nil if no instances are found" do
|
244
|
-
WithTemplateAndUniqueID.all.each {|obj| obj.destroy }
|
245
|
-
WithTemplateAndUniqueID.first.should be_nil
|
246
|
-
end
|
247
|
-
end
|
248
|
-
|
249
|
-
describe "getting a model with a subobject field" do
|
250
|
-
before(:all) do
|
251
|
-
course_doc = {
|
252
|
-
"title" => "Metaphysics 410",
|
253
|
-
"professor" => {
|
254
|
-
"name" => ["Mark", "Hinchliff"]
|
255
|
-
},
|
256
|
-
"final_test_at" => "2008/12/19 13:00:00 +0800"
|
257
|
-
}
|
258
|
-
r = Course.database.save_doc course_doc
|
259
|
-
@course = Course.get r['id']
|
260
|
-
end
|
261
|
-
it "should load the course" do
|
262
|
-
@course["professor"]["name"][1].should == "Hinchliff"
|
263
|
-
end
|
264
|
-
it "should instantiate the professor as a person" do
|
265
|
-
@course['professor'].last_name.should == "Hinchliff"
|
266
|
-
end
|
267
|
-
it "should instantiate the final_test_at as a Time" do
|
268
|
-
@course['final_test_at'].should == Time.parse("2008/12/19 13:00:00 +0800")
|
269
|
-
end
|
270
28
|
end
|
271
29
|
|
272
30
|
describe "timestamping" do
|
273
|
-
before(:each) do
|
274
|
-
oldart = Article.get "saving-this" rescue nil
|
275
|
-
oldart.destroy if oldart
|
276
|
-
@art = Article.new(:title => "Saving this")
|
277
|
-
@art.save
|
278
|
-
end
|
279
31
|
|
280
32
|
it "should define the updated_at and created_at getters and set the values" do
|
281
33
|
@obj.save
|
@@ -284,19 +36,12 @@ describe "ExtendedDocument" do
|
|
284
36
|
obj.created_at.should be_an_instance_of(Time)
|
285
37
|
obj.updated_at.should be_an_instance_of(Time)
|
286
38
|
obj.created_at.to_s.should == @obj.updated_at.to_s
|
287
|
-
end
|
288
|
-
it "should set the time on create" do
|
289
|
-
(Time.now - @art.created_at).should < 2
|
290
|
-
foundart = Article.get @art.id
|
291
|
-
foundart.created_at.should == foundart.updated_at
|
292
|
-
end
|
293
|
-
it "should set the time on update" do
|
294
|
-
@art.save
|
295
|
-
@art.created_at.should < @art.updated_at
|
296
39
|
end
|
40
|
+
|
297
41
|
end
|
298
42
|
|
299
|
-
describe "
|
43
|
+
describe "saving and retrieving" do
|
44
|
+
|
300
45
|
it "should work fine" do
|
301
46
|
@obj.name = "should be easily saved and retrieved"
|
302
47
|
@obj.save
|
@@ -312,198 +57,7 @@ describe "ExtendedDocument" do
|
|
312
57
|
saved_obj = WithDefaultValues.get(@obj.id)
|
313
58
|
saved_obj.set_by_proc.should be_an_instance_of(Time)
|
314
59
|
end
|
315
|
-
end
|
316
|
-
|
317
|
-
describe "saving a model" do
|
318
|
-
before(:all) do
|
319
|
-
@sobj = Basic.new
|
320
|
-
@sobj.save.should == true
|
321
|
-
end
|
322
60
|
|
323
|
-
it "should save the doc" do
|
324
|
-
doc = Basic.get(@sobj.id)
|
325
|
-
doc['_id'].should == @sobj.id
|
326
|
-
end
|
327
|
-
|
328
|
-
it "should be set for resaving" do
|
329
|
-
rev = @obj.rev
|
330
|
-
@sobj['another-key'] = "some value"
|
331
|
-
@sobj.save
|
332
|
-
@sobj.rev.should_not == rev
|
333
|
-
end
|
334
|
-
|
335
|
-
it "should set the id" do
|
336
|
-
@sobj.id.should be_an_instance_of(String)
|
337
|
-
end
|
338
|
-
|
339
|
-
it "should set the type" do
|
340
|
-
@sobj['couchrest-type'].should == 'Basic'
|
341
|
-
end
|
342
61
|
end
|
343
62
|
|
344
|
-
describe "saving a model with a unique_id configured" do
|
345
|
-
before(:each) do
|
346
|
-
@art = Article.new
|
347
|
-
@old = Article.database.get('this-is-the-title') rescue nil
|
348
|
-
Article.database.delete_doc(@old) if @old
|
349
|
-
end
|
350
|
-
|
351
|
-
it "should be a new document" do
|
352
|
-
@art.should be_a_new_document
|
353
|
-
@art.title.should be_nil
|
354
|
-
end
|
355
|
-
|
356
|
-
it "should require the title" do
|
357
|
-
lambda{@art.save}.should raise_error
|
358
|
-
@art.title = 'This is the title'
|
359
|
-
@art.save.should == true
|
360
|
-
end
|
361
|
-
|
362
|
-
it "should not change the slug on update" do
|
363
|
-
@art.title = 'This is the title'
|
364
|
-
@art.save.should == true
|
365
|
-
@art.title = 'new title'
|
366
|
-
@art.save.should == true
|
367
|
-
@art.slug.should == 'this-is-the-title'
|
368
|
-
end
|
369
|
-
|
370
|
-
it "should raise an error when the slug is taken" do
|
371
|
-
@art.title = 'This is the title'
|
372
|
-
@art.save.should == true
|
373
|
-
@art2 = Article.new(:title => 'This is the title!')
|
374
|
-
lambda{@art2.save}.should raise_error
|
375
|
-
end
|
376
|
-
|
377
|
-
it "should set the slug" do
|
378
|
-
@art.title = 'This is the title'
|
379
|
-
@art.save.should == true
|
380
|
-
@art.slug.should == 'this-is-the-title'
|
381
|
-
end
|
382
|
-
|
383
|
-
it "should set the id" do
|
384
|
-
@art.title = 'This is the title'
|
385
|
-
@art.save.should == true
|
386
|
-
@art.id.should == 'this-is-the-title'
|
387
|
-
end
|
388
|
-
end
|
389
|
-
|
390
|
-
describe "saving a model with a unique_id lambda" do
|
391
|
-
before(:each) do
|
392
|
-
@templated = WithTemplateAndUniqueID.new
|
393
|
-
@old = WithTemplateAndUniqueID.get('very-important') rescue nil
|
394
|
-
@old.destroy if @old
|
395
|
-
end
|
396
|
-
|
397
|
-
it "should require the field" do
|
398
|
-
lambda{@templated.save}.should raise_error
|
399
|
-
@templated['important-field'] = 'very-important'
|
400
|
-
@templated.save.should == true
|
401
|
-
end
|
402
|
-
|
403
|
-
it "should save with the id" do
|
404
|
-
@templated['important-field'] = 'very-important'
|
405
|
-
@templated.save.should == true
|
406
|
-
t = WithTemplateAndUniqueID.get('very-important')
|
407
|
-
t.should == @templated
|
408
|
-
end
|
409
|
-
|
410
|
-
it "should not change the id on update" do
|
411
|
-
@templated['important-field'] = 'very-important'
|
412
|
-
@templated.save.should == true
|
413
|
-
@templated['important-field'] = 'not-important'
|
414
|
-
@templated.save.should == true
|
415
|
-
t = WithTemplateAndUniqueID.get('very-important')
|
416
|
-
t.should == @templated
|
417
|
-
end
|
418
|
-
|
419
|
-
it "should raise an error when the id is taken" do
|
420
|
-
@templated['important-field'] = 'very-important'
|
421
|
-
@templated.save.should == true
|
422
|
-
lambda{WithTemplateAndUniqueID.new('important-field' => 'very-important').save}.should raise_error
|
423
|
-
end
|
424
|
-
|
425
|
-
it "should set the id" do
|
426
|
-
@templated['important-field'] = 'very-important'
|
427
|
-
@templated.save.should == true
|
428
|
-
@templated.id.should == 'very-important'
|
429
|
-
end
|
430
|
-
end
|
431
|
-
|
432
|
-
describe "destroying an instance" do
|
433
|
-
before(:each) do
|
434
|
-
@dobj = Basic.new
|
435
|
-
@dobj.save.should == true
|
436
|
-
end
|
437
|
-
it "should return true" do
|
438
|
-
result = @dobj.destroy
|
439
|
-
result.should == true
|
440
|
-
end
|
441
|
-
it "should be resavable" do
|
442
|
-
@dobj.destroy
|
443
|
-
@dobj.rev.should be_nil
|
444
|
-
@dobj.id.should be_nil
|
445
|
-
@dobj.save.should == true
|
446
|
-
end
|
447
|
-
it "should make it go away" do
|
448
|
-
@dobj.destroy
|
449
|
-
lambda{Basic.get(@dobj.id)}.should raise_error
|
450
|
-
end
|
451
|
-
end
|
452
|
-
|
453
|
-
|
454
|
-
describe "callbacks" do
|
455
|
-
|
456
|
-
before(:each) do
|
457
|
-
@doc = WithCallBacks.new
|
458
|
-
end
|
459
|
-
|
460
|
-
describe "save" do
|
461
|
-
it "should run the after filter after saving" do
|
462
|
-
@doc.run_after_save.should be_nil
|
463
|
-
@doc.save.should be_true
|
464
|
-
@doc.run_after_save.should be_true
|
465
|
-
end
|
466
|
-
end
|
467
|
-
describe "create" do
|
468
|
-
it "should run the before save filter when creating" do
|
469
|
-
@doc.run_before_save.should be_nil
|
470
|
-
@doc.create.should_not be_nil
|
471
|
-
@doc.run_before_save.should be_true
|
472
|
-
end
|
473
|
-
it "should run the before create filter" do
|
474
|
-
@doc.run_before_create.should be_nil
|
475
|
-
@doc.create.should_not be_nil
|
476
|
-
@doc.create
|
477
|
-
@doc.run_before_create.should be_true
|
478
|
-
end
|
479
|
-
it "should run the after create filter" do
|
480
|
-
@doc.run_after_create.should be_nil
|
481
|
-
@doc.create.should_not be_nil
|
482
|
-
@doc.create
|
483
|
-
@doc.run_after_create.should be_true
|
484
|
-
end
|
485
|
-
end
|
486
|
-
describe "update" do
|
487
|
-
|
488
|
-
before(:each) do
|
489
|
-
@doc.save
|
490
|
-
end
|
491
|
-
it "should run the before update filter when updating an existing document" do
|
492
|
-
@doc.run_before_update.should be_nil
|
493
|
-
@doc.update
|
494
|
-
@doc.run_before_update.should be_true
|
495
|
-
end
|
496
|
-
it "should run the after update filter when updating an existing document" do
|
497
|
-
@doc.run_after_update.should be_nil
|
498
|
-
@doc.update
|
499
|
-
@doc.run_after_update.should be_true
|
500
|
-
end
|
501
|
-
it "should run the before update filter when saving an existing document" do
|
502
|
-
@doc.run_before_update.should be_nil
|
503
|
-
@doc.save
|
504
|
-
@doc.run_before_update.should be_true
|
505
|
-
end
|
506
|
-
|
507
|
-
end
|
508
|
-
end
|
509
63
|
end
|
@@ -1,8 +1,7 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
|
2
2
|
require File.join(FIXTURE_PATH, 'more', 'card')
|
3
3
|
require File.join(FIXTURE_PATH, 'more', 'invoice')
|
4
|
-
require File.join(FIXTURE_PATH, 'more', 'service')
|
5
|
-
require File.join(FIXTURE_PATH, 'more', 'event')
|
4
|
+
require File.join(FIXTURE_PATH, 'more', 'service.rb')
|
6
5
|
|
7
6
|
|
8
7
|
describe "ExtendedDocument properties" do
|
@@ -44,6 +43,7 @@ describe "ExtendedDocument properties" do
|
|
44
43
|
end
|
45
44
|
|
46
45
|
describe "validation" do
|
46
|
+
|
47
47
|
before(:each) do
|
48
48
|
@invoice = Invoice.new(:client_name => "matt", :employee_name => "Chris", :location => "San Diego, CA")
|
49
49
|
end
|
@@ -79,9 +79,11 @@ describe "ExtendedDocument properties" do
|
|
79
79
|
@invoice.save.should be_false
|
80
80
|
@invoice.should be_new_document
|
81
81
|
end
|
82
|
+
|
82
83
|
end
|
83
84
|
|
84
85
|
describe "autovalidation" do
|
86
|
+
|
85
87
|
before(:each) do
|
86
88
|
@service = Service.new(:name => "Coumpound analysis", :price => 3_000)
|
87
89
|
end
|
@@ -110,20 +112,7 @@ describe "ExtendedDocument properties" do
|
|
110
112
|
@service.errors.on(:name).first.should == "Name must be between 4 and 19 characters long"
|
111
113
|
end
|
112
114
|
end
|
113
|
-
|
114
|
-
|
115
|
-
describe "casting" do
|
116
|
-
describe "cast keys to any type" do
|
117
|
-
before(:all) do
|
118
|
-
event_doc = { :subject => "Some event", :occurs_at => Time.now }
|
119
|
-
e = Event.database.save_doc event_doc
|
120
|
-
|
121
|
-
@event = Event.get e['id']
|
122
|
-
end
|
123
|
-
it "should cast created_at to Time" do
|
124
|
-
@event['occurs_at'].should be_an_instance_of(Time)
|
125
|
-
end
|
126
|
-
end
|
115
|
+
|
127
116
|
end
|
128
117
|
|
129
118
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mattetti-couchrest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: "0.13"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- J. Chris Anderson
|
@@ -15,7 +15,6 @@ default_executable:
|
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: json
|
18
|
-
type: :runtime
|
19
18
|
version_requirement:
|
20
19
|
version_requirements: !ruby/object:Gem::Requirement
|
21
20
|
requirements:
|
@@ -25,7 +24,6 @@ dependencies:
|
|
25
24
|
version:
|
26
25
|
- !ruby/object:Gem::Dependency
|
27
26
|
name: rest-client
|
28
|
-
type: :runtime
|
29
27
|
version_requirement:
|
30
28
|
version_requirements: !ruby/object:Gem::Requirement
|
31
29
|
requirements:
|
@@ -35,7 +33,6 @@ dependencies:
|
|
35
33
|
version:
|
36
34
|
- !ruby/object:Gem::Dependency
|
37
35
|
name: mime-types
|
38
|
-
type: :runtime
|
39
36
|
version_requirement:
|
40
37
|
version_requirements: !ruby/object:Gem::Requirement
|
41
38
|
requirements:
|
@@ -83,6 +80,7 @@ files:
|
|
83
80
|
- lib/couchrest/core/database.rb
|
84
81
|
- lib/couchrest/core/design.rb
|
85
82
|
- lib/couchrest/core/document.rb
|
83
|
+
- lib/couchrest/core/model.rb
|
86
84
|
- lib/couchrest/core/response.rb
|
87
85
|
- lib/couchrest/core/server.rb
|
88
86
|
- lib/couchrest/core/view.rb
|
@@ -94,7 +92,6 @@ files:
|
|
94
92
|
- lib/couchrest/mixins/callbacks.rb
|
95
93
|
- lib/couchrest/mixins/design_doc.rb
|
96
94
|
- lib/couchrest/mixins/document_queries.rb
|
97
|
-
- lib/couchrest/mixins/extended_attachments.rb
|
98
95
|
- lib/couchrest/mixins/extended_document_mixins.rb
|
99
96
|
- lib/couchrest/mixins/properties.rb
|
100
97
|
- lib/couchrest/mixins/validation.rb
|
@@ -114,7 +111,6 @@ files:
|
|
114
111
|
- lib/couchrest/validation/validation_errors.rb
|
115
112
|
- lib/couchrest/validation/validators
|
116
113
|
- lib/couchrest/validation/validators/absent_field_validator.rb
|
117
|
-
- lib/couchrest/validation/validators/confirmation_validator.rb
|
118
114
|
- lib/couchrest/validation/validators/format_validator.rb
|
119
115
|
- lib/couchrest/validation/validators/formats
|
120
116
|
- lib/couchrest/validation/validators/formats/email.rb
|
@@ -131,19 +127,15 @@ files:
|
|
131
127
|
- spec/couchrest/core/database_spec.rb
|
132
128
|
- spec/couchrest/core/design_spec.rb
|
133
129
|
- spec/couchrest/core/document_spec.rb
|
130
|
+
- spec/couchrest/core/model_spec.rb
|
134
131
|
- spec/couchrest/core/server_spec.rb
|
135
132
|
- spec/couchrest/helpers
|
136
133
|
- spec/couchrest/helpers/pager_spec.rb
|
137
134
|
- spec/couchrest/helpers/streamer_spec.rb
|
138
135
|
- spec/couchrest/more
|
139
|
-
- spec/couchrest/more/casted_extended_doc_spec.rb
|
140
136
|
- spec/couchrest/more/casted_model_spec.rb
|
141
|
-
- spec/couchrest/more/extended_doc_attachment_spec.rb
|
142
137
|
- spec/couchrest/more/extended_doc_spec.rb
|
143
|
-
- spec/couchrest/more/extended_doc_view_spec.rb
|
144
138
|
- spec/couchrest/more/property_spec.rb
|
145
|
-
- spec/couchrest/support
|
146
|
-
- spec/couchrest/support/class_spec.rb
|
147
139
|
- spec/fixtures
|
148
140
|
- spec/fixtures/attachments
|
149
141
|
- spec/fixtures/attachments/couchdb.png
|
@@ -170,13 +162,8 @@ files:
|
|
170
162
|
- spec/fixtures/couchapp-test/my-app/views/example-map.js
|
171
163
|
- spec/fixtures/couchapp-test/my-app/views/example-reduce.js
|
172
164
|
- spec/fixtures/more
|
173
|
-
- spec/fixtures/more/article.rb
|
174
165
|
- spec/fixtures/more/card.rb
|
175
|
-
- spec/fixtures/more/course.rb
|
176
|
-
- spec/fixtures/more/event.rb
|
177
166
|
- spec/fixtures/more/invoice.rb
|
178
|
-
- spec/fixtures/more/person.rb
|
179
|
-
- spec/fixtures/more/question.rb
|
180
167
|
- spec/fixtures/more/service.rb
|
181
168
|
- spec/fixtures/views
|
182
169
|
- spec/fixtures/views/lib.js
|