diff --git a/Gemfile.lock b/Gemfile.lock index 0f7d5b3..234bcf3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - couchrest_model (1.0.0) + couchrest_model (1.1.0.beta) activemodel (~> 3.0.0) couchrest (~> 1.0.1) mime-types (~> 1.15) diff --git a/lib/couchrest/model/proxyable.rb b/lib/couchrest/model/proxyable.rb index d7fec3d..e35656e 100644 --- a/lib/couchrest/model/proxyable.rb +++ b/lib/couchrest/model/proxyable.rb @@ -20,7 +20,7 @@ module CouchRest unless respond_to?('#{db_method}') raise "Missing ##{db_method} method for proxy" end - @#{model_name} ||= CouchRest::Model::Proxyable::ModelProxy.new(#{options[:class_name]}, self, '#{model_name}', #{db_method}) + @#{model_name} ||= CouchRest::Model::Proxyable::ModelProxy.new(#{options[:class_name]}, self, self.class.to_s.underscore, #{db_method}) end EOS end @@ -118,12 +118,12 @@ module CouchRest @model.design_doc end - def refresh_design_doc - @model.refresh_design_doc(@database) + def refresh_design_doc(db = nil) + @model.refresh_design_doc(db || @database) end - def save_design_doc - @model.save_design_doc(@database) + def save_design_doc(db = nil) + @model.save_design_doc(db || @database) end diff --git a/spec/couchrest/proxyable_spec.rb b/spec/couchrest/proxyable_spec.rb index de2911b..13098b7 100644 --- a/spec/couchrest/proxyable_spec.rb +++ b/spec/couchrest/proxyable_spec.rb @@ -35,7 +35,7 @@ describe "Proxyable" do it "should call ModelProxy" do DummyProxyable.proxy_for(:cats) @obj = DummyProxyable.new - CouchRest::Model::Proxyable::ModelProxy.should_receive(:new).with(Cat, @obj, 'cats', 'db').and_return(true) + CouchRest::Model::Proxyable::ModelProxy.should_receive(:new).with(Cat, @obj, 'dummy_proxyable', 'db').and_return(true) @obj.should_receive('proxy_database').and_return('db') @obj.should_receive(:respond_to?).with('proxy_database').and_return(true) @obj.cats @@ -198,16 +198,31 @@ describe "Proxyable" do @obj.design_doc end - it "should proxy refresh_design_doc" do - Cat.should_receive(:refresh_design_doc).with('database') - @obj.refresh_design_doc + describe "#refresh_design_doc" do + it "should be proxied without database arg" do + Cat.should_receive(:refresh_design_doc).with('database') + @obj.refresh_design_doc + end + it "should be proxied with database arg" do + Cat.should_receive(:refresh_design_doc).with('db') + @obj.refresh_design_doc('db') + end end - it "should proxy save_design_doc" do - Cat.should_receive(:save_design_doc).with('database') - @obj.save_design_doc + describe "#save_design_doc" do + it "should be proxied without args" do + Cat.should_receive(:save_design_doc).with('database') + @obj.save_design_doc + end + + it "should be proxied with database arg" do + Cat.should_receive(:save_design_doc).with('db') + @obj.save_design_doc('db') + end end + + ### Updating methods describe "#proxy_update" do