Skip to content

Commit

Permalink
Add test to not use top-level wrapper. Closes #359
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafael Mendonça França committed Nov 9, 2011
1 parent 8128143 commit b1708e2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/simple_form.rb
Expand Up @@ -142,7 +142,7 @@ def self.wrappers(*args, &block)

# Builds a new wrapper using SimpleForm::Wrappers::Builder.
def self.build(options={})
options[:tag] = :div if !options.empty? && options[:tag].nil?
options[:tag] = :div if options[:tag].nil?
builder = SimpleForm::Wrappers::Builder.new
yield builder
SimpleForm::Wrappers::Root.new(builder.to_a, options)
Expand Down
6 changes: 6 additions & 0 deletions test/form_builder/wrapper_test.rb
Expand Up @@ -32,6 +32,12 @@ class WrapperTest < ActionView::TestCase
assert_select 'form > input#user_name.string'
end

test 'wrapper should support no wrapping when wrapper tag is false' do
with_form_for @user, :name, :wrapper => custom_wrapper_without_top_level
assert_select 'form > label[for=user_name]'
assert_select 'form > input#user_name.string'
end

test 'wrapper should wrapping tag adds required/optional css classes' do
with_form_for @user, :name
assert_select 'form div.input.required.string'
Expand Down
8 changes: 8 additions & 0 deletions test/support/misc_helpers.rb
Expand Up @@ -46,6 +46,14 @@ def custom_wrapper
end
end

def custom_wrapper_without_top_level
SimpleForm.build :tag => false, :class => 'custom_wrapper_without_top_level' do |b|
b.use :label_input
b.use :hint, :tag => :span, :class => :hint
b.use :error, :tag => :span, :class => :error
end
end

def custom_form_for(object, *args, &block)
simple_form_for(object, *(args << { :builder => CustomFormBuilder }), &block)
end
Expand Down

0 comments on commit b1708e2

Please sign in to comment.