Force wrappers name as symbols.

This commit is contained in:
Fabio Yamate 2011-09-26 23:41:53 -03:00
parent f8095800ec
commit f1b9d2dfc3
2 changed files with 13 additions and 4 deletions

View File

@ -117,7 +117,7 @@ module SimpleForm
# Retrieves a given wrapper # Retrieves a given wrapper
def self.wrapper(name) def self.wrapper(name)
if wrapper = @@wrappers[name] if wrapper = @@wrappers[name.to_sym]
wrapper wrapper
else else
raise WrapperNotFound, "Couldn't find wrapper with name #{name}" raise WrapperNotFound, "Couldn't find wrapper with name #{name}"
@ -132,9 +132,9 @@ module SimpleForm
# and store it in the given name. # and store it in the given name.
def self.wrappers(*args, &block) def self.wrappers(*args, &block)
if block_given? if block_given?
options = args.extract_options! options = args.extract_options!
name = args.first || :default name = args.first || :default
@@wrappers[name] = build(options, &block) @@wrappers[name.to_sym] = build(options, &block)
else else
@@wrappers @@wrappers
end end

View File

@ -113,6 +113,15 @@ class WrapperTest < ActionView::TestCase
assert_select "section.custom_wrapper div.another_wrapper input.string" assert_select "section.custom_wrapper div.another_wrapper input.string"
end end
test 'access wrappers with indifferent access' do
swap_wrapper :another do
with_form_for @user, :name, :wrapper => "another"
assert_select "section.custom_wrapper div.another_wrapper label"
assert_select "section.custom_wrapper div.another_wrapper input.string"
output_buffer.replace ""
end
end
test 'raise error when wrapper not found' do test 'raise error when wrapper not found' do
assert_raise SimpleForm::WrapperNotFound do assert_raise SimpleForm::WrapperNotFound do
with_form_for @user, :name, :wrapper => :not_found with_form_for @user, :name, :wrapper => :not_found