mattetti-couchrest 0.25 → 0.26
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/lib/couchrest.rb +1 -1
- data/lib/couchrest/mixins/class_proxy.rb +4 -0
- data/lib/couchrest/mixins/design_doc.rb +1 -2
- data/lib/couchrest/mixins/properties.rb +2 -2
- data/lib/couchrest/mixins/views.rb +22 -14
- data/spec/couchrest/more/extended_doc_spec.rb +4 -4
- data/spec/couchrest/more/extended_doc_view_spec.rb +10 -27
- metadata +1 -1
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# CouchRest: CouchDB, close to the metal
|
2
2
|
|
3
3
|
CouchRest is based on [CouchDB's couch.js test
|
4
|
-
library](http://svn.apache.org/repos/asf/
|
4
|
+
library](http://svn.apache.org/repos/asf/couchdb/trunk/share/www/script/couch.js),
|
5
5
|
which I find to be concise, clear, and well designed. CouchRest lightly wraps
|
6
6
|
CouchDB's HTTP API, managing JSON serialization, and remembering the URI-paths
|
7
7
|
to CouchDB's API endpoints so you don't have to.
|
data/lib/couchrest.rb
CHANGED
@@ -30,7 +30,7 @@ require 'couchrest/monkeypatches'
|
|
30
30
|
|
31
31
|
# = CouchDB, close to the metal
|
32
32
|
module CouchRest
|
33
|
-
VERSION = '0.
|
33
|
+
VERSION = '0.26' unless self.const_defined?("VERSION")
|
34
34
|
|
35
35
|
autoload :Server, 'couchrest/core/server'
|
36
36
|
autoload :Database, 'couchrest/core/database'
|
@@ -25,8 +25,7 @@ module CouchRest
|
|
25
25
|
design_doc['views'].each do |name, view|
|
26
26
|
funcs << "#{name}/#{view['map']}#{view['reduce']}"
|
27
27
|
end
|
28
|
-
|
29
|
-
self.design_doc_slug_cache = "#{self.to_s}-#{md5}"
|
28
|
+
self.design_doc_slug_cache = self.to_s
|
30
29
|
end
|
31
30
|
|
32
31
|
def default_design_doc
|
@@ -23,8 +23,8 @@ module CouchRest
|
|
23
23
|
# TODO: cache the default object
|
24
24
|
self.class.properties.each do |property|
|
25
25
|
key = property.name.to_s
|
26
|
-
# let's make sure we have a default
|
27
|
-
if
|
26
|
+
# let's make sure we have a default
|
27
|
+
if property.default
|
28
28
|
if property.default.class == Proc
|
29
29
|
self[key] = property.default.call
|
30
30
|
else
|
@@ -104,26 +104,34 @@ module CouchRest
|
|
104
104
|
fetch_view_with_docs(db, name, query, raw, &block)
|
105
105
|
end
|
106
106
|
|
107
|
+
# DEPRECATED
|
108
|
+
# user model_design_doc to retrieve the current design doc
|
107
109
|
def all_design_doc_versions(db = database)
|
108
|
-
db.documents :startkey => "_design/#{self.to_s}
|
110
|
+
db.documents :startkey => "_design/#{self.to_s}",
|
109
111
|
:endkey => "_design/#{self.to_s}-\u9999"
|
110
112
|
end
|
113
|
+
|
114
|
+
def model_design_doc(db = database)
|
115
|
+
begin
|
116
|
+
@model_design_doc = db.get("_design/#{self.to_s}")
|
117
|
+
rescue
|
118
|
+
nil
|
119
|
+
end
|
120
|
+
end
|
111
121
|
|
112
|
-
# Deletes
|
113
|
-
# Running
|
114
|
-
# and consistently using the latest code, is the way to clear out old design
|
115
|
-
# docs. Running it to early could mean that live code has to regenerate
|
122
|
+
# Deletes the current design doc for the current class.
|
123
|
+
# Running it to early could mean that live code has to regenerate
|
116
124
|
# potentially large indexes.
|
117
125
|
def cleanup_design_docs!(db = database)
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
end
|
126
|
+
save_design_doc_on(db)
|
127
|
+
# db.refresh_design_doc
|
128
|
+
# db.save_design_doc
|
129
|
+
# design_doc = model_design_doc(db)
|
130
|
+
# if design_doc
|
131
|
+
# db.delete_doc(design_doc)
|
132
|
+
# else
|
133
|
+
# false
|
134
|
+
# end
|
127
135
|
end
|
128
136
|
|
129
137
|
private
|
@@ -10,7 +10,7 @@ describe "ExtendedDocument" do
|
|
10
10
|
property :preset, :default => {:right => 10, :top_align => false}
|
11
11
|
property :set_by_proc, :default => Proc.new{Time.now}, :cast_as => 'Time'
|
12
12
|
property :tags, :default => []
|
13
|
-
property :
|
13
|
+
property :read_only_with_default, :default => 'generic', :read_only => true
|
14
14
|
property :name
|
15
15
|
timestamps!
|
16
16
|
end
|
@@ -158,10 +158,10 @@ describe "ExtendedDocument" do
|
|
158
158
|
obj = WithDefaultValues.new(:tags => ['spec'])
|
159
159
|
obj.tags.should == ['spec']
|
160
160
|
end
|
161
|
-
|
162
|
-
it "should
|
161
|
+
|
162
|
+
it "should set default value of read-only property" do
|
163
163
|
obj = WithDefaultValues.new
|
164
|
-
obj.
|
164
|
+
obj.read_only_with_default.should == 'generic'
|
165
165
|
end
|
166
166
|
end
|
167
167
|
|
@@ -183,14 +183,13 @@ describe "ExtendedDocument views" do
|
|
183
183
|
it "should barf on all_design_doc_versions if no database given" do
|
184
184
|
lambda{Unattached.all_design_doc_versions}.should raise_error
|
185
185
|
end
|
186
|
-
it "should
|
187
|
-
|
188
|
-
Unattached.all_design_doc_versions(@db)["rows"].length.should == 1
|
186
|
+
it "should be able to cleanup the db/bump the revision number" do
|
187
|
+
# if the previous specs were not run, the model_design_doc will be blank
|
189
188
|
Unattached.view_by :questions
|
190
|
-
Unattached.by_questions
|
191
|
-
Unattached.
|
189
|
+
Unattached.by_questions(:database => @db)
|
190
|
+
original_revision = Unattached.model_design_doc(@db)['_rev']
|
192
191
|
Unattached.cleanup_design_docs!(@db)
|
193
|
-
Unattached.
|
192
|
+
Unattached.model_design_doc(@db)['_rev'].should_not == original_revision
|
194
193
|
end
|
195
194
|
end
|
196
195
|
|
@@ -246,12 +245,10 @@ describe "ExtendedDocument views" do
|
|
246
245
|
end
|
247
246
|
it "should clean up design docs left around on specific database" do
|
248
247
|
@us.by_title
|
249
|
-
@us.
|
248
|
+
original_id = @us.model_design_doc['_rev']
|
250
249
|
Unattached.view_by :professor
|
251
250
|
@us.by_professor
|
252
|
-
@us.
|
253
|
-
@us.cleanup_design_docs!
|
254
|
-
@us.all_design_doc_versions["rows"].length.should == 1
|
251
|
+
@us.model_design_doc['_rev'].should_not == original_id
|
255
252
|
end
|
256
253
|
end
|
257
254
|
|
@@ -321,6 +318,7 @@ describe "ExtendedDocument views" do
|
|
321
318
|
before(:each) do
|
322
319
|
reset_test_db!
|
323
320
|
Article.by_date
|
321
|
+
@original_doc_rev = Article.model_design_doc['_rev']
|
324
322
|
@design_docs = Article.database.documents :startkey => "_design/", :endkey => "_design/\u9999"
|
325
323
|
end
|
326
324
|
it "should not create a design doc on view definition" do
|
@@ -332,24 +330,9 @@ describe "ExtendedDocument views" do
|
|
332
330
|
ddocs = Article.all_design_doc_versions["rows"].length
|
333
331
|
Article.view_by :updated_at
|
334
332
|
Article.by_updated_at
|
335
|
-
Article.
|
333
|
+
@original_doc_rev.should_not == Article.model_design_doc['_rev']
|
336
334
|
Article.design_doc["views"].keys.should include("by_updated_at")
|
337
335
|
end
|
338
336
|
end
|
339
|
-
|
340
|
-
describe "with a lot of designs left around" do
|
341
|
-
before(:each) do
|
342
|
-
reset_test_db!
|
343
|
-
Article.by_date
|
344
|
-
Article.view_by :field
|
345
|
-
Article.by_field
|
346
|
-
end
|
347
|
-
it "should clean them up" do
|
348
|
-
Article.view_by :stream
|
349
|
-
Article.by_stream
|
350
|
-
Article.all_design_doc_versions["rows"].length.should > 1
|
351
|
-
Article.cleanup_design_docs!
|
352
|
-
Article.all_design_doc_versions["rows"].length.should == 1
|
353
|
-
end
|
354
|
-
end
|
337
|
+
|
355
338
|
end
|