association creates blank select if collection is nil

closes #595
This commit is contained in:
Vasiliy Ermolovich 2012-06-23 00:23:55 +03:00
parent 840d115d57
commit 1cf06d3a7e
2 changed files with 9 additions and 1 deletions

View File

@ -174,7 +174,9 @@ module SimpleForm
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 File

@ -79,6 +79,12 @@ class AssociationTest < ActionView::TestCase
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'