Permalink
Browse files

Merge pull request #598 from nashby/fix-595

association creates blank select if collection is nil
  • Loading branch information...
2 parents 840d115 + 1cf06d3 commit 2db82867b569824968e2131210981e868b834e62 @rafaelfranca rafaelfranca committed Jun 22, 2012
Showing with 9 additions and 1 deletion.
  1. +3 −1 lib/simple_form/form_builder.rb
  2. +6 −0 test/form_builder/association_test.rb
View
4 lib/simple_form/form_builder.rb
@@ -174,7 +174,9 @@ def association(association, options={}, &block)
raise "Association #{association.inspect} not found" unless reflection
options[:as] ||= :select
- options[:collection] ||= reflection.klass.all(reflection.options.slice(:conditions, :order))
+ options[:collection] ||= options.fetch(:collection) {
+ reflection.klass.all(reflection.options.slice(:conditions, :order))
+ }
attribute = case reflection.macro
when :belongs_to
View
6 test/form_builder/association_test.rb
@@ -79,6 +79,12 @@ def with_association_for(object, *args)
assert_select 'form select option[value=3]', 'Company 3'
end
+ test 'builder creates blank select if collection is nil' do
+ with_association_for @user, :company, :collection => nil
+ assert_select 'form select.select#user_company_id'
+ assert_no_select 'form select option[value=1]', 'Company 1'
+ end
+
test 'builder allows collection radio for belongs_to associations' do
with_association_for @user, :company, :as => :radio_buttons
assert_select 'form input.radio_buttons#user_company_id_1'

0 comments on commit 2db8286

Please sign in to comment.