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
2 changed files with 4 additions and 4 deletions
|
@ -25,8 +25,8 @@ module CouchRest
|
|||
|
||||
begin
|
||||
opts[:class] = opts[:class_name].constantize
|
||||
rescue
|
||||
raise "Unable to convert class name into Constant for #{self.name}##{attrib}"
|
||||
rescue NameError
|
||||
raise NameError, "Unable to convert class name into Constant for #{self.name}##{attrib}"
|
||||
end
|
||||
|
||||
prop = property(opts[:foreign_key], opts)
|
||||
|
|
|
@ -44,11 +44,11 @@ describe "Assocations" do
|
|||
end
|
||||
|
||||
it "should raise error if class name does not exist" do
|
||||
lambda {
|
||||
lambda do
|
||||
class TestBadAssoc < CouchRest::Model::Base
|
||||
belongs_to :test_bad_item
|
||||
end
|
||||
}.should raise_error
|
||||
end.should raise_error(NameError, /TestBadAssoc#test_bad_item/)
|
||||
end
|
||||
|
||||
it "should allow override of foreign key" do
|
||||
|
|
Loading…
Reference in a new issue