From a581d0a3ec7369db7af7024f759fda926ed55bec Mon Sep 17 00:00:00 2001 From: Dmytrii Nagirniak Date: Mon, 24 Sep 2012 17:47:47 +1000 Subject: [PATCH] Raise more describprive error when can't reflect on association --- lib/cocoon/view_helpers.rb | 1 + spec/cocoon_spec.rb | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/lib/cocoon/view_helpers.rb b/lib/cocoon/view_helpers.rb index 7b66e7c..2321894 100644 --- a/lib/cocoon/view_helpers.rb +++ b/lib/cocoon/view_helpers.rb @@ -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) diff --git a/spec/cocoon_spec.rb b/spec/cocoon_spec.rb index 355d650..cc1a61a 100644 --- a/spec/cocoon_spec.rb +++ b/spec/cocoon_spec.rb @@ -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