1
0
Fork 0
mirror of https://github.com/heartcombo/simple_form.git synced 2022-11-09 12:19:26 -05:00
heartcombo--simple_form/test/components/wrapper_test.rb
2010-09-26 19:39:02 -03:00

53 lines
1.4 KiB
Ruby

require 'test_helper'
class WrapperTest < ActionView::TestCase
def with_error_for(object, attribute_name, &block)
with_concat_form_for(object) do |f|
f.input attribute_name
end
end
def with_form_for(object, *args, &block)
with_concat_form_for(object) do |f|
f.input(*args, &block)
end
end
test 'wrapper should not have error class for attribute without errors' do
with_error_for @user, :active
assert_no_select 'div.field_with_errors'
end
test 'wrapper should not have error class when object is not present' do
with_error_for :project, :name
assert_no_select 'div.field_with_errors'
end
test 'wrapper should add error class for attribute with errors' do
with_error_for @user, :name
assert_select 'div.field_with_errors'
end
test 'wrapper should add chosen error class for attribute with errors' do
swap SimpleForm, :wrapper_error_class => "omgError" do
with_error_for @user, :name
assert_select 'div.omgError'
end
end
test 'wrapper should add chosen wrapper class' do
swap SimpleForm, :wrapper_class => "wrapper" do
with_form_for @user, :active
assert_select 'div.wrapper'
assert_no_select 'div.input'
with_form_for @user, :name
assert_select 'div.wrapper'
assert_no_select 'div.input'
with_form_for :project, :name
assert_select 'div.wrapper'
assert_no_select 'div.input'
end
end
end