Raise error when fails to find a given wrapper.
This commit is contained in:
parent
c30d832914
commit
f8095800ec
|
@ -117,7 +117,15 @@ module SimpleForm
|
|||
|
||||
# Retrieves a given wrapper
|
||||
def self.wrapper(name)
|
||||
@@wrappers[name]
|
||||
if wrapper = @@wrappers[name]
|
||||
wrapper
|
||||
else
|
||||
raise WrapperNotFound, "Couldn't find wrapper with name #{name}"
|
||||
end
|
||||
end
|
||||
|
||||
# Raised when fails to find a given wrapper name
|
||||
class WrapperNotFound < StandardError
|
||||
end
|
||||
|
||||
# Define a new wrapper using SimpleForm::Wrappers::Builder
|
||||
|
@ -166,4 +174,4 @@ module SimpleForm
|
|||
"Updating to the new API is easy and fast. Check for more info here: https://github.com/plataformatec/simple_form/wiki/Upgrading-to-Simple-Form-2.0"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -93,7 +93,7 @@ module SimpleForm
|
|||
def input(attribute_name, options={}, &block)
|
||||
chosen =
|
||||
if name = options[:wrapper]
|
||||
name.is_a?(Symbol) ? SimpleForm.wrapper(name) : name
|
||||
name.respond_to?(:render) ? name : SimpleForm.wrapper(name)
|
||||
else
|
||||
wrapper
|
||||
end
|
||||
|
|
|
@ -112,4 +112,10 @@ class WrapperTest < ActionView::TestCase
|
|||
assert_select "section.custom_wrapper div.another_wrapper label"
|
||||
assert_select "section.custom_wrapper div.another_wrapper input.string"
|
||||
end
|
||||
|
||||
test 'raise error when wrapper not found' do
|
||||
assert_raise SimpleForm::WrapperNotFound do
|
||||
with_form_for @user, :name, :wrapper => :not_found
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue