From 72b331e047b4b05c3e2b6ba44a814499ea65e890 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Wed, 9 Dec 2009 14:03:08 -0200 Subject: [PATCH] Experimental boolean select option --- lib/simple_form/input.rb | 3 +++ test/input_test.rb | 11 ++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/simple_form/input.rb b/lib/simple_form/input.rb index 47f010e6..7efcf409 100644 --- a/lib/simple_form/input.rb +++ b/lib/simple_form/input.rb @@ -30,6 +30,9 @@ module SimpleForm result << radio_button(@attribute, value, html_options) << label("#{@attribute}_#{value}", text, :class => default_css_classes) end + elsif @input_type == :select + return select(@attribute, boolean_collection, + @options[:options], html_options) end mapping = MAPPINGS[@input_type] diff --git a/test/input_test.rb b/test/input_test.rb index d7c6ad9a..a5dc3e7e 100644 --- a/test/input_test.rb +++ b/test/input_test.rb @@ -135,7 +135,7 @@ class InputTest < ActionView::TestCase assert_select 'form input.string#user_born_at' end - test 'input should allow boolean fields as radio buttons' do + test 'input should allow boolean attributes as radio buttons' do simple_form_for @user do |f| concat f.input :active, :as => :radio end @@ -151,6 +151,15 @@ class InputTest < ActionView::TestCase assert_select 'form label.radio[for=user_active_false]', 'No' end + test 'input should allow boolean attributes as a select with options' do + simple_form_for @user do |f| + concat f.input :active, :as => :select + end + assert_select 'form select.select#user_active' + assert_select 'form select option[value=true]', 'Yes' + assert_select 'form select option[value=false]', 'No' + end + test 'input should generate a password field for password attributes' do simple_form_for @user do |f| concat f.input :password