Raise more describprive error when can't reflect on association

This commit is contained in:
Dmytrii Nagirniak 2012-09-24 17:47:47 +10:00
parent 7baae8f8c3
commit a581d0a3ec
2 changed files with 5 additions and 0 deletions

View File

@ -92,6 +92,7 @@ module Cocoon
def create_object(f, association)
assoc = f.object.class.reflect_on_association(association)
raise "Association #{association} doesn't exist on #{f.object.class}" unless assoc
if assoc.class.name == "Mongoid::Relations::Metadata"
conditions = assoc.respond_to?(:conditions) ? assoc.conditions.flatten : []
assoc.klass.new(*conditions)

View File

@ -191,6 +191,10 @@ describe Cocoon do
result = @tester.create_object(stub(:object => Comment.new), :post)
result.should be_a Post
end
it "should raise error if cannot reflect on association" do
expect { @tester.create_object(stub(:object => Comment.new), :not_existing) }.to raise_error /exist/
end
end
context "get_partial_path" do