couchrest query params passed through by_xxxx views
This commit is contained in:
parent
f408dfceb6
commit
4a1de8c1ba
|
@ -148,18 +148,18 @@ module CouchRest
|
||||||
@@design_doc_fresh = false
|
@@design_doc_fresh = false
|
||||||
|
|
||||||
self.meta_class.instance_eval do
|
self.meta_class.instance_eval do
|
||||||
define_method method_name do |args|
|
define_method method_name do |*args|
|
||||||
args ||= {}
|
opts = args[0] || {}
|
||||||
unless @@design_doc_fresh
|
unless @@design_doc_fresh
|
||||||
refresh_design_doc
|
refresh_design_doc
|
||||||
end
|
end
|
||||||
raw = args.delete(:raw)
|
raw = opts.delete(:raw)
|
||||||
view_name = "#{type}/#{method_name}"
|
view_name = "#{type}/#{method_name}"
|
||||||
|
|
||||||
if raw
|
if raw
|
||||||
fetch_view(view_name)
|
fetch_view(view_name, opts)
|
||||||
else
|
else
|
||||||
view = fetch_view(view_name)
|
view = fetch_view(view_name, opts)
|
||||||
# TODO this can be optimized once the include-docs patch is applied
|
# TODO this can be optimized once the include-docs patch is applied
|
||||||
view['rows'].collect{|r|new(database.get(r['id']))}
|
view['rows'].collect{|r|new(database.get(r['id']))}
|
||||||
end
|
end
|
||||||
|
@ -169,10 +169,10 @@ module CouchRest
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def fetch_view view_name
|
def fetch_view view_name, opts
|
||||||
retryable = true
|
retryable = true
|
||||||
begin
|
begin
|
||||||
database.view(view_name)
|
database.view(view_name, opts)
|
||||||
# the design doc could have been deleted by a rouge process
|
# the design doc could have been deleted by a rouge process
|
||||||
rescue RestClient::ResourceNotFound => e
|
rescue RestClient::ResourceNotFound => e
|
||||||
if retryable
|
if retryable
|
||||||
|
|
|
@ -236,7 +236,13 @@ describe CouchRest::Model do
|
||||||
end
|
end
|
||||||
it "should sort correctly" do
|
it "should sort correctly" do
|
||||||
articles = Article.by_user_id_and_date
|
articles = Article.by_user_id_and_date
|
||||||
# articles.should == 'x'
|
articles.collect{|a|a.doc['user_id']}.should == ['aaron', 'aaron', 'quentin', 'quentin']
|
||||||
|
articles[1].title.should == 'not junk'
|
||||||
|
end
|
||||||
|
it "should be queryable with couchrest options" do
|
||||||
|
articles = Article.by_user_id_and_date :count => 1, :startkey => 'quentin'
|
||||||
|
articles.length.should == 1
|
||||||
|
articles[0].title.should == "even more interesting"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
Loading…
Reference in a new issue