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