From f1495552e41f3a3ea4754ba17d6b0a3c888182e7 Mon Sep 17 00:00:00 2001 From: Peter Jaros Date: Tue, 22 Oct 2013 18:04:33 -0400 Subject: [PATCH] Demonstrate bug: scope_for_create with polymorphic In a #where specifying a value for a polymorphic association, the _type is not set in the #scope_for_create attributes. In vanilla AR4, _type and _id are both set. --- .../active_record/relation_extensions_spec.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/spec/squeel/adapters/active_record/relation_extensions_spec.rb b/spec/squeel/adapters/active_record/relation_extensions_spec.rb index 2754316..e5df0d2 100644 --- a/spec/squeel/adapters/active_record/relation_extensions_spec.rb +++ b/spec/squeel/adapters/active_record/relation_extensions_spec.rb @@ -800,6 +800,17 @@ module ActiveRecord end end + it 'creates new records with values from a polymorphic association' do + if activerecord_version_at_least '4.0.0' + article = Article.first + note = Note.where(notable: article).new + note.notable_id.should eq article.id + note.notable_type.should eq 'Article' + else + pending 'Not required pre-4.0' + end + end + end describe '#as' do