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
Carlos Antonio da Silva ba05460415 Add "disabled" class to wrapper tag when the input is disabled
This helps styling disabled elements inside the wrapper.
2010-11-21 22:07:23 -02:00

63 lines
1.7 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
test 'wrapper should not have disabled class by default' do
with_form_for @user, :active
assert_no_select 'div.disabled'
end
test 'wrapper should add disabled class when the input is disabled' do
with_form_for @user, :active, :disabled => true
assert_select 'div.disabled'
end
end