From 226fe3bf38c2f592f0b71e3904685bbb86320ebc Mon Sep 17 00:00:00 2001 From: Sam Lown Date: Mon, 21 Jun 2010 16:43:33 +0200 Subject: [PATCH] Fixing view deleting database option bug --- lib/couchrest/model/views.rb | 1 + spec/couchrest/view_spec.rb | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/couchrest/model/views.rb b/lib/couchrest/model/views.rb index 8e2e0d7..bd5c0bc 100644 --- a/lib/couchrest/model/views.rb +++ b/lib/couchrest/model/views.rb @@ -92,6 +92,7 @@ module CouchRest # Dispatches to any named view. def view(name, query={}, &block) + query = query.dup # Modifications made on copy! db = query.delete(:database) || database refresh_design_doc(db) query[:raw] = true if query[:reduce] diff --git a/spec/couchrest/view_spec.rb b/spec/couchrest/view_spec.rb index 4329caf..5f1ec64 100644 --- a/spec/couchrest/view_spec.rb +++ b/spec/couchrest/view_spec.rb @@ -13,7 +13,22 @@ describe "Model views" do property :professor view_by :title end - + + + describe "ClassMethods" do + # NOTE! Add more unit tests! + + describe "#view" do + + it "should not alter original query" do + options = { :database => DB } + view = Article.view('by_date', options) + options[:database].should_not be_nil + end + + end + end + describe "a model with simple views and a default param" do before(:all) do Article.all.map{|a| a.destroy(true)}