Fixing support for specifying database in collections

This commit is contained in:
Sam Lown 2010-04-05 22:22:56 +00:00
parent 456946c149
commit 77cb8160c7
3 changed files with 11 additions and 4 deletions

View file

@ -20,7 +20,7 @@ module CouchRest
class_eval <<-END, __FILE__, __LINE__ + 1 class_eval <<-END, __FILE__, __LINE__ + 1
def self.find_all_#{collection_name}(options = {}) def self.find_all_#{collection_name}(options = {})
view_options = #{view_options.inspect} || {} view_options = #{view_options.inspect} || {}
CollectionProxy.new(database, "#{design_doc}", "#{view_name}", view_options.merge(options), Kernel.const_get('#{self}')) CollectionProxy.new(options[:database] || database, "#{design_doc}", "#{view_name}", view_options.merge(options), Kernel.const_get('#{self}'))
end end
END END
end end
@ -63,12 +63,12 @@ module CouchRest
def create_collection_proxy(options) def create_collection_proxy(options)
design_doc, view_name, view_options = parse_view_options(options) design_doc, view_name, view_options = parse_view_options(options)
CollectionProxy.new(database, design_doc, view_name, view_options, self) CollectionProxy.new(options[:database] || database, design_doc, view_name, view_options, self)
end end
def create_search_collection_proxy(options) def create_search_collection_proxy(options)
design_doc, search_name, search_options = parse_search_options(options) design_doc, search_name, search_options = parse_search_options(options)
CollectionProxy.new(@database, design_doc, search_name, search_options, self, :search) CollectionProxy.new(options[:database] || database, design_doc, search_name, search_options, self, :search)
end end
def parse_view_options(options) def parse_view_options(options)

View file

@ -83,7 +83,7 @@ describe "ExtendedDocument" do
self.conditional_two = true self.conditional_two = true
end end
end end
class WithTemplateAndUniqueID < CouchRest::ExtendedDocument class WithTemplateAndUniqueID < CouchRest::ExtendedDocument
use_database TEST_SERVER.default_database use_database TEST_SERVER.default_database
unique_id do |model| unique_id do |model|
@ -641,6 +641,7 @@ describe "ExtendedDocument" do
@doc.run_after_validate.should be_true @doc.run_after_validate.should be_true
end end
end end
describe "save" do describe "save" do
it "should run the after filter after saving" do it "should run the after filter after saving" do
@doc.run_after_save.should be_nil @doc.run_after_save.should be_nil

View file

@ -451,6 +451,12 @@ describe "ExtendedDocument views" do
articles.paginate(:page => 4, :per_page => 3).size.should == 3 articles.paginate(:page => 4, :per_page => 3).size.should == 3
articles.paginate(:page => 5, :per_page => 3).size.should == 1 articles.paginate(:page => 5, :per_page => 3).size.should == 1
end end
it "should pass database parameter to pager" do
proxy = mock(:proxy)
proxy.stub!(:paginate)
::CouchRest::Mixins::Collection::CollectionProxy.should_receive(:new).with('database', anything(), anything(), anything(), anything()).and_return(proxy)
Article.paginate(:design_doc => 'Article', :view_name => 'by_date', :database => 'database')
end
end end
end end