Checking for block given and ensuring proyxable finds classes in root namespace

This commit is contained in:
Sam Lown 2011-03-13 13:39:26 +01:00
parent f58482553c
commit d1baf99324
5 changed files with 24 additions and 2 deletions

View file

@ -66,6 +66,11 @@ PLATFORMS
ruby ruby
DEPENDENCIES DEPENDENCIES
activemodel (~> 3.0.0)
couchrest (~> 1.0.1)
couchrest_model! couchrest_model!
mime-types (~> 1.15)
rack-test (>= 0.5.7) rack-test (>= 0.5.7)
railties (~> 3.0.0)
rspec (>= 2.0.0) rspec (>= 2.0.0)
tzinfo (~> 0.3.22)

View file

@ -27,7 +27,7 @@ module CouchRest
mapper = DesignMapper.new(self) mapper = DesignMapper.new(self)
mapper.create_view_method(:all) mapper.create_view_method(:all)
mapper.instance_eval(&block) mapper.instance_eval(&block) if block_given?
req_design_doc_refresh req_design_doc_refresh
end end

View file

@ -20,7 +20,7 @@ module CouchRest
unless respond_to?('#{db_method}') unless respond_to?('#{db_method}')
raise "Missing ##{db_method} method for proxy" raise "Missing ##{db_method} method for proxy"
end end
@#{model_name} ||= CouchRest::Model::Proxyable::ModelProxy.new(#{options[:class_name]}, self, self.class.to_s.underscore, #{db_method}) @#{model_name} ||= CouchRest::Model::Proxyable::ModelProxy.new(::#{options[:class_name]}, self, self.class.to_s.underscore, #{db_method})
end end
EOS EOS
end end

View file

@ -36,6 +36,10 @@ describe "Design" do
DesignModel.design() { } DesignModel.design() { }
end end
it "should work even if a block is not provided" do
lambda { DesignModel.design }.should_not raise_error
end
end end
describe "default_per_page" do describe "default_per_page" do

View file

@ -41,6 +41,18 @@ describe "Proxyable" do
@obj.cats @obj.cats
end end
it "should call class on root namespace" do
class ::Document < CouchRest::Model::Base
def self.foo; puts 'bar'; end
end
DummyProxyable.proxy_for(:documents)
@obj = DummyProxyable.new
CouchRest::Model::Proxyable::ModelProxy.should_receive(:new).with(::Document, @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.documents
end
it "should raise an error if the database method is missing" do it "should raise an error if the database method is missing" do
DummyProxyable.proxy_for(:cats) DummyProxyable.proxy_for(:cats)
@obj = DummyProxyable.new @obj = DummyProxyable.new
@ -54,6 +66,7 @@ describe "Proxyable" do
lambda { @obj.proxy_kittens }.should raise_error(StandardError, "Missing #foobardom method for proxy") lambda { @obj.proxy_kittens }.should raise_error(StandardError, "Missing #foobardom method for proxy")
end end
end end
end end