fixing proxy setting proxied_by accessor

This commit is contained in:
Sam Lown 2011-02-13 17:45:59 +01:00
parent e8959883a9
commit 6a896c27b3
3 changed files with 28 additions and 13 deletions

View file

@ -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)

View file

@ -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

View file

@ -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