From f2c16144b074dc8fef1186bfb8cb3b05a6af995d Mon Sep 17 00:00:00 2001 From: Peter Williams Date: Wed, 16 Nov 2011 15:30:46 -0700 Subject: [PATCH] #view method works when auto_update_design_doc is disabled --- lib/couchrest/model/designs.rb | 7 ++++--- spec/couchrest/designs_spec.rb | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/couchrest/model/designs.rb b/lib/couchrest/model/designs.rb index e17f1bc..3862567 100644 --- a/lib/couchrest/model/designs.rb +++ b/lib/couchrest/model/designs.rb @@ -58,10 +58,11 @@ module CouchRest self.model = model end - # Define a view and generate a method that will provide a new - # View instance when requested. + # Generate a method that will provide a new View instance when + # requested. This will also define the view in CouchDB unless + # auto_update_design_doc is disabled. def view(name, opts = {}) - View.create(model, name, opts) + View.create(model, name, opts) if model.auto_update_design_doc create_view_method(name) end diff --git a/spec/couchrest/designs_spec.rb b/spec/couchrest/designs_spec.rb index 3fa2f6a..3864b69 100644 --- a/spec/couchrest/designs_spec.rb +++ b/spec/couchrest/designs_spec.rb @@ -84,7 +84,23 @@ describe "Design" do @object.should_receive(:create_view_method).with('test') @object.view('test') end + end + context "for model with auto_update_design_doc disabled " do + class ::DesignModelAutoUpdateDesignDocDisabled < ::CouchRest::Model::Base + self.auto_update_design_doc = false + end + + describe "#view" do + before :each do + @object = @klass.new(DesignModelAutoUpdateDesignDocDisabled) + end + + it "does not attempt to create view" do + CouchRest::Model::Designs::View.should_not_receive(:create) + @object.view('test') + end + end end describe "#filter" do