couchrest_model 1.1.0.beta2 → 1.1.0.beta3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -1
- data/README.md +50 -3
- data/VERSION +1 -1
- data/benchmarks/dirty.rb +118 -0
- data/couchrest_model.gemspec +1 -0
- data/history.txt +12 -0
- data/lib/couchrest/model/base.rb +15 -23
- data/lib/couchrest/model/casted_array.rb +26 -1
- data/lib/couchrest/model/casted_by.rb +23 -0
- data/lib/couchrest/model/casted_hash.rb +76 -0
- data/lib/couchrest/model/casted_model.rb +9 -6
- data/lib/couchrest/model/collection.rb +10 -1
- data/lib/couchrest/model/configuration.rb +4 -4
- data/lib/couchrest/model/design_doc.rb +65 -71
- data/lib/couchrest/model/designs/view.rb +26 -19
- data/lib/couchrest/model/designs.rb +0 -2
- data/lib/couchrest/model/dirty.rb +49 -0
- data/lib/couchrest/model/extended_attachments.rb +7 -1
- data/lib/couchrest/model/persistence.rb +15 -4
- data/lib/couchrest/model/properties.rb +50 -9
- data/lib/couchrest/model/property.rb +6 -2
- data/lib/couchrest/model/proxyable.rb +13 -19
- data/lib/couchrest/model/support/couchrest_design.rb +33 -0
- data/lib/couchrest/model/views.rb +4 -18
- data/lib/couchrest_model.rb +8 -3
- data/spec/couchrest/base_spec.rb +1 -28
- data/spec/couchrest/casted_model_spec.rb +1 -1
- data/spec/couchrest/collection_spec.rb +0 -1
- data/spec/couchrest/design_doc_spec.rb +211 -0
- data/spec/couchrest/designs/view_spec.rb +41 -17
- data/spec/couchrest/designs_spec.rb +0 -5
- data/spec/couchrest/dirty_spec.rb +355 -0
- data/spec/couchrest/property_spec.rb +5 -2
- data/spec/couchrest/proxyable_spec.rb +0 -11
- data/spec/couchrest/subclass_spec.rb +6 -16
- data/spec/couchrest/view_spec.rb +6 -50
- data/spec/fixtures/base.rb +1 -1
- data/spec/fixtures/more/card.rb +2 -2
- data/spec/spec_helper.rb +2 -0
- metadata +9 -4
- data/Gemfile.lock +0 -76
- data/lib/couchrest/model/support/couchrest.rb +0 -19
@@ -0,0 +1,355 @@
|
|
1
|
+
require File.expand_path("../../spec_helper", __FILE__)
|
2
|
+
|
3
|
+
require File.join(FIXTURE_PATH, 'more', 'cat')
|
4
|
+
require File.join(FIXTURE_PATH, 'more', 'article')
|
5
|
+
require File.join(FIXTURE_PATH, 'more', 'course')
|
6
|
+
require File.join(FIXTURE_PATH, 'more', 'card')
|
7
|
+
require File.join(FIXTURE_PATH, 'base')
|
8
|
+
|
9
|
+
class WithCastedModelMixin < Hash
|
10
|
+
include CouchRest::Model::CastedModel
|
11
|
+
property :name
|
12
|
+
property :details, Object, :default => {}
|
13
|
+
property :casted_attribute, WithCastedModelMixin
|
14
|
+
end
|
15
|
+
|
16
|
+
class DummyModel < CouchRest::Model::Base
|
17
|
+
use_database DB
|
18
|
+
|
19
|
+
property :casted_attribute, WithCastedModelMixin
|
20
|
+
property :title, :default => 'Sample Title'
|
21
|
+
property :details, Object, :default => { 'color' => 'blue' }
|
22
|
+
property :keywords, [String], :default => ['default-keyword']
|
23
|
+
property :sub_models do
|
24
|
+
property :title
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "Dirty" do
|
29
|
+
|
30
|
+
describe "changes" do
|
31
|
+
|
32
|
+
it "should return changes on an attribute" do
|
33
|
+
@card = Card.new(:first_name => "matt")
|
34
|
+
@card.first_name = "andrew"
|
35
|
+
@card.first_name_changed?.should be_true
|
36
|
+
@card.changes.should == { "first_name" => ["matt", "andrew"] }
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "save" do
|
42
|
+
|
43
|
+
it "should not save unchanged records" do
|
44
|
+
card_id = Card.create!(:first_name => "matt").id
|
45
|
+
@card = Card.find(card_id)
|
46
|
+
@card.database.should_not_receive(:save_doc)
|
47
|
+
@card.save
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should save changed records" do
|
51
|
+
card_id = Card.create!(:first_name => "matt").id
|
52
|
+
@card = Card.find(card_id)
|
53
|
+
@card.first_name = "andrew"
|
54
|
+
@card.database.should_receive(:save_doc).and_return({"ok" => true})
|
55
|
+
@card.save
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "changed?" do
|
61
|
+
|
62
|
+
# match activerecord behaviour
|
63
|
+
it "should report no changes on a new object with no attributes set" do
|
64
|
+
@card = Card.new
|
65
|
+
@card.changed?.should be_false
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should report no changes on a hash property with a default value" do
|
69
|
+
@obj = DummyModel.new
|
70
|
+
@obj.details.changed?.should be_false
|
71
|
+
end
|
72
|
+
|
73
|
+
=begin
|
74
|
+
# match activerecord behaviour
|
75
|
+
# not currently working - not too important
|
76
|
+
it "should report changes on a new object with attributes set" do
|
77
|
+
@card = Card.new(:first_name => "matt")
|
78
|
+
@card.changed?.should be_true
|
79
|
+
end
|
80
|
+
=end
|
81
|
+
|
82
|
+
it "should report no changes on objects fetched from the database" do
|
83
|
+
card_id = Card.create!(:first_name => "matt").id
|
84
|
+
@card = Card.find(card_id)
|
85
|
+
@card.changed?.should be_false
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should report changes if the record is modified" do
|
89
|
+
@card = Card.new
|
90
|
+
@card.first_name = "andrew"
|
91
|
+
@card.changed?.should be_true
|
92
|
+
@card.first_name_changed?.should be_true
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should report no changes for unmodified records" do
|
96
|
+
card_id = Card.create!(:first_name => "matt").id
|
97
|
+
@card = Card.find(card_id)
|
98
|
+
@card.first_name = "matt"
|
99
|
+
@card.changed?.should be_false
|
100
|
+
@card.first_name_changed?.should be_false
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should report no changes after a new record has been saved" do
|
104
|
+
@card = Card.new(:first_name => "matt")
|
105
|
+
@card.save!
|
106
|
+
@card.changed?.should be_false
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should report no changes after a record has been saved" do
|
110
|
+
card_id = Card.create!(:first_name => "matt").id
|
111
|
+
@card = Card.find(card_id)
|
112
|
+
@card.first_name = "andrew"
|
113
|
+
@card.save!
|
114
|
+
@card.changed?.should be_false
|
115
|
+
end
|
116
|
+
|
117
|
+
# test changing list properties
|
118
|
+
|
119
|
+
it "should report changes if a list property is modified" do
|
120
|
+
cat_id = Cat.create!(:name => "Felix", :toys => [{:name => "Mouse"}]).id
|
121
|
+
@cat = Cat.find(cat_id)
|
122
|
+
@cat.toys = [{:name => "Feather"}]
|
123
|
+
@cat.changed?.should be_true
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should report no changes if a list property is unmodified" do
|
127
|
+
cat_id = Cat.create!(:name => "Felix", :toys => [{:name => "Mouse"}]).id
|
128
|
+
@cat = Cat.find(cat_id)
|
129
|
+
@cat.toys = [{:name => "Mouse"}] # same as original list
|
130
|
+
@cat.changed?.should be_false
|
131
|
+
end
|
132
|
+
|
133
|
+
# attachments
|
134
|
+
|
135
|
+
it "should report changes if an attachment is added" do
|
136
|
+
cat_id = Cat.create!(:name => "Felix", :toys => [{:name => "Mouse"}]).id
|
137
|
+
@file = File.open(FIXTURE_PATH + '/attachments/test.html')
|
138
|
+
@cat = Cat.find(cat_id)
|
139
|
+
@cat.create_attachment(:file => @file, :name => "my_attachment")
|
140
|
+
@cat.changed?.should be_true
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should report changes if an attachment is deleted" do
|
144
|
+
@cat = Cat.create!(:name => "Felix", :toys => [{:name => "Mouse"}])
|
145
|
+
@file = File.open(FIXTURE_PATH + '/attachments/test.html')
|
146
|
+
@attachment_name = "my_attachment"
|
147
|
+
@cat.create_attachment(:file => @file, :name => @attachment_name)
|
148
|
+
@cat.save
|
149
|
+
@cat = Cat.find(@cat.id)
|
150
|
+
@cat.delete_attachment(@attachment_name)
|
151
|
+
@cat.changed?.should be_true
|
152
|
+
end
|
153
|
+
|
154
|
+
# casted models
|
155
|
+
|
156
|
+
it "should report changes to casted models" do
|
157
|
+
@cat = Cat.create!(:name => "Felix", :favorite_toy => { :name => "Mouse" })
|
158
|
+
@cat = Cat.find(@cat.id)
|
159
|
+
@cat.favorite_toy['name'] = 'Feather'
|
160
|
+
@cat.changed?.should be_true
|
161
|
+
end
|
162
|
+
|
163
|
+
# casted arrays
|
164
|
+
|
165
|
+
def test_casted_array(change_expected)
|
166
|
+
obj = DummyModel.create!
|
167
|
+
obj = DummyModel.get(obj.id)
|
168
|
+
array = obj.keywords
|
169
|
+
yield array, obj
|
170
|
+
if change_expected
|
171
|
+
obj.changed?.should be_true
|
172
|
+
else
|
173
|
+
obj.changed?.should be_false
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
def should_change_array
|
178
|
+
test_casted_array(true) { |a,b| yield a,b }
|
179
|
+
end
|
180
|
+
|
181
|
+
def should_not_change_array
|
182
|
+
test_casted_array(false) { |a,b| yield a,b }
|
183
|
+
end
|
184
|
+
|
185
|
+
it "should report changes if an array index is modified" do
|
186
|
+
should_change_array do |array, obj|
|
187
|
+
array[0] = "keyword"
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
it "should report no changes if an array index is unmodified" do
|
192
|
+
should_not_change_array do |array, obj|
|
193
|
+
array[0] = array[0]
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
it "should report changes if an array is appended with <<" do
|
198
|
+
should_change_array do |array, obj|
|
199
|
+
array << 'keyword'
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
it "should report changes if an array is popped" do
|
204
|
+
should_change_array do |array, obj|
|
205
|
+
array.pop
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
it "should report no changes if an empty array is popped" do
|
210
|
+
should_not_change_array do |array, obj|
|
211
|
+
array.clear
|
212
|
+
obj.save! # clears changes
|
213
|
+
array.pop
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
it "should report changes if an array is pushed" do
|
218
|
+
should_change_array do |array, obj|
|
219
|
+
array.push("keyword")
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
it "should report changes if an array is shifted" do
|
224
|
+
should_change_array do |array, obj|
|
225
|
+
array.shift
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
it "should report no changes if an empty array is shifted" do
|
230
|
+
should_not_change_array do |array, obj|
|
231
|
+
array.clear
|
232
|
+
obj.save! # clears changes
|
233
|
+
array.shift
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
it "should report changes if an array is unshifted" do
|
238
|
+
should_change_array do |array, obj|
|
239
|
+
array.unshift("keyword")
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
it "should report changes if an array is cleared" do
|
244
|
+
should_change_array do |array, obj|
|
245
|
+
array.clear
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
# Object, {} (casted hash)
|
250
|
+
|
251
|
+
def test_casted_hash(change_expected)
|
252
|
+
obj = DummyModel.create!
|
253
|
+
obj = DummyModel.get(obj.id)
|
254
|
+
hash = obj.details
|
255
|
+
yield hash, obj
|
256
|
+
if change_expected
|
257
|
+
obj.changed?.should be_true
|
258
|
+
else
|
259
|
+
obj.changed?.should be_false
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
def should_change_hash
|
264
|
+
test_casted_hash(true) { |a,b| yield a,b }
|
265
|
+
end
|
266
|
+
|
267
|
+
def should_not_change_hash
|
268
|
+
test_casted_hash(false) { |a,b| yield a,b }
|
269
|
+
end
|
270
|
+
|
271
|
+
it "should report changes if a hash is modified" do
|
272
|
+
should_change_hash do |hash, obj|
|
273
|
+
hash['color'] = 'orange'
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
it "should report no changes if a hash is unmodified" do
|
278
|
+
should_not_change_hash do |hash, obj|
|
279
|
+
hash['color'] = hash['color']
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
it "should report changes when deleting from a hash" do
|
284
|
+
should_change_hash do |hash, obj|
|
285
|
+
hash.delete('color')
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
it "should report no changes when deleting a non existent key from a hash" do
|
290
|
+
should_not_change_hash do |hash, obj|
|
291
|
+
hash.delete('non-existent-key')
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
295
|
+
it "should report changes when clearing a hash" do
|
296
|
+
should_change_hash do |hash, obj|
|
297
|
+
hash.clear
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
it "should report changes when merging changes to a hash" do
|
302
|
+
should_change_hash do |hash, obj|
|
303
|
+
hash.merge!('foo' => 'bar')
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
it "should report no changes when merging no changes to a hash" do
|
308
|
+
should_not_change_hash do |hash, obj|
|
309
|
+
hash.merge!('color' => hash['color'])
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
it "should report changes when replacing hash content" do
|
314
|
+
should_change_hash do |hash, obj|
|
315
|
+
hash.replace('foo' => 'bar')
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
it "should report no changes when replacing hash content with same content" do
|
320
|
+
should_not_change_hash do |hash, obj|
|
321
|
+
hash.replace(hash)
|
322
|
+
end
|
323
|
+
end
|
324
|
+
|
325
|
+
it "should report changes when removing records with delete_if" do
|
326
|
+
should_change_hash do |hash, obj|
|
327
|
+
hash.delete_if { true }
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
331
|
+
it "should report no changes when removing no records with delete_if" do
|
332
|
+
should_not_change_hash do |hash, obj|
|
333
|
+
hash.delete_if { false }
|
334
|
+
end
|
335
|
+
end
|
336
|
+
|
337
|
+
if {}.respond_to?(:keep_if)
|
338
|
+
|
339
|
+
it "should report changes when removing records with keep_if" do
|
340
|
+
should_change_hash do |hash, obj|
|
341
|
+
hash.keep_if { false }
|
342
|
+
end
|
343
|
+
end
|
344
|
+
|
345
|
+
it "should report no changes when removing no records with keep_if" do
|
346
|
+
should_not_change_hash do |hash, obj|
|
347
|
+
hash.keep_if { true }
|
348
|
+
end
|
349
|
+
end
|
350
|
+
|
351
|
+
end
|
352
|
+
|
353
|
+
end
|
354
|
+
|
355
|
+
end
|
@@ -55,6 +55,9 @@ describe "Model properties" do
|
|
55
55
|
card.calias.name.should == ["Aimonetti"]
|
56
56
|
end
|
57
57
|
|
58
|
+
it "should raise error if property name coincides with model type key" do
|
59
|
+
lambda { Person.property(Person.model_type_key) }.should raise_error(/already used/)
|
60
|
+
end
|
58
61
|
|
59
62
|
it "should be auto timestamped" do
|
60
63
|
@card.created_at.should be_nil
|
@@ -354,10 +357,10 @@ describe "Property Class" do
|
|
354
357
|
property.cast(parent, ["2010-06-01", "2010-06-02"]).class.should eql(CouchRest::Model::CastedArray)
|
355
358
|
end
|
356
359
|
|
357
|
-
it "should
|
360
|
+
it "should set a CastedArray on array of Strings" do
|
358
361
|
property = CouchRest::Model::Property.new(:test, [String])
|
359
362
|
parent = mock("FooObject")
|
360
|
-
property.cast(parent, ["2010-06-01", "2010-06-02"]).class.
|
363
|
+
property.cast(parent, ["2010-06-01", "2010-06-02"]).class.should eql(CouchRest::Model::CastedArray)
|
361
364
|
end
|
362
365
|
|
363
366
|
it "should raise and error if value is array when type is not" do
|
@@ -233,17 +233,6 @@ describe "Proxyable" do
|
|
233
233
|
@obj.design_doc
|
234
234
|
end
|
235
235
|
|
236
|
-
describe "#refresh_design_doc" do
|
237
|
-
it "should be proxied without database arg" do
|
238
|
-
Cat.should_receive(:refresh_design_doc).with('database')
|
239
|
-
@obj.refresh_design_doc
|
240
|
-
end
|
241
|
-
it "should be proxied with database arg" do
|
242
|
-
Cat.should_receive(:refresh_design_doc).with('db')
|
243
|
-
@obj.refresh_design_doc('db')
|
244
|
-
end
|
245
|
-
end
|
246
|
-
|
247
236
|
describe "#save_design_doc" do
|
248
237
|
it "should be proxied without args" do
|
249
238
|
Cat.should_receive(:save_design_doc).with('database')
|
@@ -61,37 +61,27 @@ describe "Subclassing a Model" do
|
|
61
61
|
validated_fields.should_not include(:extension_code)
|
62
62
|
validated_fields.should_not include(:job_title)
|
63
63
|
end
|
64
|
-
|
64
|
+
|
65
65
|
it "should inherit default property values" do
|
66
66
|
@card.bg_color.should == '#ccc'
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
it "should be able to overwrite a default property" do
|
70
70
|
DesignBusinessCard.new.bg_color.should == '#eee'
|
71
71
|
end
|
72
|
-
|
72
|
+
|
73
73
|
it "should have a design doc slug based on the subclass name" do
|
74
|
-
Course.refresh_design_doc
|
75
74
|
OnlineCourse.design_doc_slug.should =~ /^OnlineCourse/
|
76
75
|
end
|
77
|
-
|
78
|
-
it "should have its own design_doc_fresh" do
|
79
|
-
Animal.refresh_design_doc
|
80
|
-
Dog.send(:design_doc_fresh, Dog.database).should_not == true
|
81
|
-
Dog.refresh_design_doc
|
82
|
-
Dog.send(:design_doc_fresh, Dog.database).should == true
|
83
|
-
end
|
84
|
-
|
76
|
+
|
85
77
|
it "should not add views to the parent's design_doc" do
|
86
78
|
Course.design_doc['views'].keys.should_not include('by_url')
|
87
79
|
end
|
88
|
-
|
80
|
+
|
89
81
|
it "should not add the parent's views to its design doc" do
|
90
|
-
Course.refresh_design_doc
|
91
|
-
OnlineCourse.refresh_design_doc
|
92
82
|
OnlineCourse.design_doc['views'].keys.should_not include('by_title')
|
93
83
|
end
|
94
|
-
|
84
|
+
|
95
85
|
it "should have an all view with a guard clause for model == subclass name in the map function" do
|
96
86
|
OnlineCourse.design_doc['views']['all']['map'].should =~ /if \(doc\['#{OnlineCourse.model_type_key}'\] == 'OnlineCourse'\)/
|
97
87
|
end
|
data/spec/couchrest/view_spec.rb
CHANGED
@@ -19,11 +19,11 @@ describe "Model views" do
|
|
19
19
|
# NOTE! Add more unit tests!
|
20
20
|
|
21
21
|
describe "#view" do
|
22
|
-
|
22
|
+
|
23
23
|
it "should not alter original query" do
|
24
24
|
options = { :database => DB }
|
25
25
|
view = Article.view('by_date', options)
|
26
|
-
options[:database].
|
26
|
+
options[:database].should eql(DB)
|
27
27
|
end
|
28
28
|
|
29
29
|
end
|
@@ -56,35 +56,6 @@ describe "Model views" do
|
|
56
56
|
written_at += 24 * 3600
|
57
57
|
end
|
58
58
|
end
|
59
|
-
it "should have a design doc" do
|
60
|
-
Article.design_doc["views"]["by_date"].should_not be_nil
|
61
|
-
end
|
62
|
-
it "should save the design doc" do
|
63
|
-
Article.by_date #rescue nil
|
64
|
-
doc = Article.database.get Article.design_doc.id
|
65
|
-
doc['views']['by_date'].should_not be_nil
|
66
|
-
end
|
67
|
-
it "should save design doc if a view changed" do
|
68
|
-
Article.by_date
|
69
|
-
orig = Article.stored_design_doc
|
70
|
-
orig['views']['by_date']['map'] = "function() { }"
|
71
|
-
Article.database.save_doc(orig)
|
72
|
-
rev = Article.stored_design_doc['_rev']
|
73
|
-
Article.req_design_doc_refresh # prepare for re-load
|
74
|
-
Article.by_date
|
75
|
-
orig = Article.stored_design_doc
|
76
|
-
orig['views']['by_date']['map'].should eql(Article.design_doc['views']['by_date']['map'])
|
77
|
-
orig['_rev'].should_not eql(rev)
|
78
|
-
end
|
79
|
-
it "should not save design doc if not changed" do
|
80
|
-
Article.by_date
|
81
|
-
orig = Article.stored_design_doc['_rev']
|
82
|
-
Article.req_design_doc_refresh
|
83
|
-
Article.by_date
|
84
|
-
Article.stored_design_doc['_rev'].should eql(orig)
|
85
|
-
end
|
86
|
-
|
87
|
-
|
88
59
|
it "should return the matching raw view result" do
|
89
60
|
view = Article.by_date :raw => true
|
90
61
|
view['rows'].length.should == 4
|
@@ -107,9 +78,8 @@ describe "Model views" do
|
|
107
78
|
Article.view_by :title
|
108
79
|
lambda{Article.by_title}.should_not raise_error
|
109
80
|
end
|
110
|
-
|
111
81
|
end
|
112
|
-
|
82
|
+
|
113
83
|
describe "another model with a simple view" do
|
114
84
|
before(:all) do
|
115
85
|
reset_test_db!
|
@@ -240,7 +210,6 @@ describe "Model views" do
|
|
240
210
|
lambda{Unattached.all}.should raise_error
|
241
211
|
end
|
242
212
|
it "should query all" do
|
243
|
-
# Unattached.cleanup_design_docs!(@db)
|
244
213
|
rs = Unattached.all :database => @db
|
245
214
|
rs.length.should == 4
|
246
215
|
end
|
@@ -297,19 +266,7 @@ describe "Model views" do
|
|
297
266
|
u = Unattached.last :database=>@db
|
298
267
|
u.title.should == "aaa"
|
299
268
|
end
|
300
|
-
|
301
|
-
it "should barf on all_design_doc_versions if no database given" do
|
302
|
-
lambda{Unattached.all_design_doc_versions}.should raise_error
|
303
|
-
end
|
304
|
-
it "should be able to cleanup the db/bump the revision number" do
|
305
|
-
# if the previous specs were not run, the model_design_doc will be blank
|
306
|
-
Unattached.use_database DB
|
307
|
-
Unattached.view_by :questions
|
308
|
-
Unattached.by_questions(:database => @db)
|
309
|
-
original_revision = Unattached.model_design_doc(@db)['_rev']
|
310
|
-
Unattached.save_design_doc!(@db)
|
311
|
-
Unattached.model_design_doc(@db)['_rev'].should_not == original_revision
|
312
|
-
end
|
269
|
+
|
313
270
|
end
|
314
271
|
|
315
272
|
describe "a model with a compound key view" do
|
@@ -377,7 +334,7 @@ describe "Model views" do
|
|
377
334
|
before(:each) do
|
378
335
|
reset_test_db!
|
379
336
|
Article.by_date
|
380
|
-
@original_doc_rev = Article.
|
337
|
+
@original_doc_rev = Article.stored_design_doc['_rev']
|
381
338
|
@design_docs = Article.database.documents :startkey => "_design/", :endkey => "_design/\u9999"
|
382
339
|
end
|
383
340
|
it "should not create a design doc on view definition" do
|
@@ -386,10 +343,9 @@ describe "Model views" do
|
|
386
343
|
newdocs["rows"].length.should == @design_docs["rows"].length
|
387
344
|
end
|
388
345
|
it "should create a new version of the design document on view access" do
|
389
|
-
ddocs = Article.all_design_doc_versions["rows"].length
|
390
346
|
Article.view_by :updated_at
|
391
347
|
Article.by_updated_at
|
392
|
-
@original_doc_rev.should_not == Article.
|
348
|
+
@original_doc_rev.should_not == Article.stored_design_doc['_rev']
|
393
349
|
Article.design_doc["views"].keys.should include("by_updated_at")
|
394
350
|
end
|
395
351
|
end
|
data/spec/fixtures/base.rb
CHANGED
data/spec/fixtures/more/card.rb
CHANGED
@@ -7,10 +7,10 @@ class Card < CouchRest::Model::Base
|
|
7
7
|
property :last_name, :alias => :family_name
|
8
8
|
property :read_only_value, :read_only => true
|
9
9
|
property :cast_alias, Person, :alias => :calias
|
10
|
+
property :fg_color, :default => '#000'
|
10
11
|
|
11
|
-
|
12
12
|
timestamps!
|
13
|
-
|
13
|
+
|
14
14
|
# Validation
|
15
15
|
validates_presence_of :first_name
|
16
16
|
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
|
|
6
6
|
- 1
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.1.0.
|
9
|
+
- beta3
|
10
|
+
version: 1.1.0.beta3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- J. Chris Anderson
|
@@ -141,12 +141,12 @@ files:
|
|
141
141
|
- .gitignore
|
142
142
|
- .rspec
|
143
143
|
- Gemfile
|
144
|
-
- Gemfile.lock
|
145
144
|
- LICENSE
|
146
145
|
- README.md
|
147
146
|
- Rakefile
|
148
147
|
- THANKS.md
|
149
148
|
- VERSION
|
149
|
+
- benchmarks/dirty.rb
|
150
150
|
- couchrest_model.gemspec
|
151
151
|
- history.txt
|
152
152
|
- init.rb
|
@@ -155,6 +155,8 @@ files:
|
|
155
155
|
- lib/couchrest/model/base.rb
|
156
156
|
- lib/couchrest/model/callbacks.rb
|
157
157
|
- lib/couchrest/model/casted_array.rb
|
158
|
+
- lib/couchrest/model/casted_by.rb
|
159
|
+
- lib/couchrest/model/casted_hash.rb
|
158
160
|
- lib/couchrest/model/casted_model.rb
|
159
161
|
- lib/couchrest/model/class_proxy.rb
|
160
162
|
- lib/couchrest/model/collection.rb
|
@@ -164,6 +166,7 @@ files:
|
|
164
166
|
- lib/couchrest/model/design_doc.rb
|
165
167
|
- lib/couchrest/model/designs.rb
|
166
168
|
- lib/couchrest/model/designs/view.rb
|
169
|
+
- lib/couchrest/model/dirty.rb
|
167
170
|
- lib/couchrest/model/document_queries.rb
|
168
171
|
- lib/couchrest/model/errors.rb
|
169
172
|
- lib/couchrest/model/extended_attachments.rb
|
@@ -172,7 +175,7 @@ files:
|
|
172
175
|
- lib/couchrest/model/property.rb
|
173
176
|
- lib/couchrest/model/property_protection.rb
|
174
177
|
- lib/couchrest/model/proxyable.rb
|
175
|
-
- lib/couchrest/model/support/
|
178
|
+
- lib/couchrest/model/support/couchrest_design.rb
|
176
179
|
- lib/couchrest/model/typecast.rb
|
177
180
|
- lib/couchrest/model/validations.rb
|
178
181
|
- lib/couchrest/model/validations/casted_model.rb
|
@@ -194,8 +197,10 @@ files:
|
|
194
197
|
- spec/couchrest/collection_spec.rb
|
195
198
|
- spec/couchrest/configuration_spec.rb
|
196
199
|
- spec/couchrest/core_extensions/time_parsing.rb
|
200
|
+
- spec/couchrest/design_doc_spec.rb
|
197
201
|
- spec/couchrest/designs/view_spec.rb
|
198
202
|
- spec/couchrest/designs_spec.rb
|
203
|
+
- spec/couchrest/dirty_spec.rb
|
199
204
|
- spec/couchrest/inherited_spec.rb
|
200
205
|
- spec/couchrest/persistence_spec.rb
|
201
206
|
- spec/couchrest/property_protection_spec.rb
|