Narrow the rescued exception to avoid catching class evaluation errors that has nothing to to with the association.
Example: /Users/weppos/.rvm/gems/ruby-1.8.7-p330/gems/couchrest_model-1.0.0/lib/couchrest/model/associations.rb:29:in `belongs_to': Unable to convert class name into Constant for Document#dossier (RuntimeError) although the real error is /Users/weppos/Projects/working/.../app/models/user.rb:56: undefined method `validates_uniqueness_of' for User:Class (NoMethodError)
This commit is contained in:
parent
c6be3fdf64
commit
f76517d0fa
|
@ -25,8 +25,8 @@ module CouchRest
|
||||||
|
|
||||||
begin
|
begin
|
||||||
opts[:class] = opts[:class_name].constantize
|
opts[:class] = opts[:class_name].constantize
|
||||||
rescue
|
rescue NameError
|
||||||
raise "Unable to convert class name into Constant for #{self.name}##{attrib}"
|
raise NameError, "Unable to convert class name into Constant for #{self.name}##{attrib}"
|
||||||
end
|
end
|
||||||
|
|
||||||
prop = property(opts[:foreign_key], opts)
|
prop = property(opts[:foreign_key], opts)
|
||||||
|
|
|
@ -44,11 +44,11 @@ describe "Assocations" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should raise error if class name does not exist" do
|
it "should raise error if class name does not exist" do
|
||||||
lambda {
|
lambda do
|
||||||
class TestBadAssoc < CouchRest::Model::Base
|
class TestBadAssoc < CouchRest::Model::Base
|
||||||
belongs_to :test_bad_item
|
belongs_to :test_bad_item
|
||||||
end
|
end
|
||||||
}.should raise_error
|
end.should raise_error(NameError, /TestBadAssoc#test_bad_item/)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should allow override of foreign key" do
|
it "should allow override of foreign key" do
|
||||||
|
|
Loading…
Reference in a new issue