add optional :components key to control component rendering

- don't freeze SimpleForm::VERSION, otherwise rake test will bomb out with error "can't modify frozen string"
This commit is contained in:
Khoa Nguyen 2010-09-27 17:56:37 +08:00 committed by Carlos Antonio da Silva
parent 583bdaf2b7
commit 7125fa4fdb
3 changed files with 28 additions and 2 deletions

View File

@ -51,7 +51,7 @@ module SimpleForm
protected
def components_list
SimpleForm.components
options[:components] || SimpleForm.components
end
def attribute_required?

View File

@ -1,3 +1,3 @@
module SimpleForm
VERSION = "1.2.2".freeze
VERSION = "1.2.2"#.freeze
end

View File

@ -27,6 +27,32 @@ class InputTest < ActionView::TestCase
assert_select 'select.datetime'
end
test 'input should render components according to an optional :components option' do
with_input_for @user, :name, :string, :components => [:input, :label]
assert_select 'input + label'
with_input_for @user, :age, :integer, :components => [:input, :label]
assert_select 'input + label'
with_input_for @user, :active, :boolean, :components => [:label, :input]
assert_select 'label + input'
with_input_for @user, :description, :text, :components => [:input, :label]
assert_select 'textarea + label'
with_input_for @user, :password, :password, :components => [:input, :label]
assert_select 'input + label'
with_input_for @user, :name, :file, :components => [:input, :label]
assert_select 'input + label'
with_input_for @user, :country, :country, :components => [:input, :label]
assert_select 'select + label'
with_input_for @user, :time_zone, :time_zone, :components => [:input, :label]
assert_select 'select + label'
end
# StringInput
test 'input should map text field to string attribute' do
with_input_for @user, :name, :string