Add tests for custom wrappers.
This commit is contained in:
parent
cc72315703
commit
f93a6be226
|
@ -5,8 +5,6 @@ module SimpleForm
|
|||
autoload :Root, 'simple_form/wrappers/root'
|
||||
autoload :Single, 'simple_form/wrappers/single'
|
||||
|
||||
# TODO: Test the many case
|
||||
# TODO: Test nested wrappers
|
||||
def self.find(name)
|
||||
SimpleForm.wrapper.find(name) || SingleForm::Wrappers::Many.new(name, [name])
|
||||
end
|
||||
|
|
|
@ -75,18 +75,27 @@ class ErrorTest < ActionView::TestCase
|
|||
|
||||
# FULL ERRORS
|
||||
|
||||
test 'builder should generate an full error tag for the attribute' do
|
||||
test 'full error should generate an full error tag for the attribute' do
|
||||
with_full_error_for @user, :name
|
||||
assert_select 'span.error', "Super User Name! can't be blank"
|
||||
end
|
||||
|
||||
test 'builder should generate an full error tag with a clean HTML' do
|
||||
test 'full error should generate an full error tag with a clean HTML' do
|
||||
with_full_error_for @user, :name
|
||||
assert_no_select 'span.error[error_html]'
|
||||
end
|
||||
|
||||
test 'builder should allow passing options to full error tag' do
|
||||
test 'full error should allow passing options to full error tag' do
|
||||
with_full_error_for @user, :name, :id => 'name_error', :error_prefix => "Your name"
|
||||
assert_select 'span.error#name_error', "Your name can't be blank"
|
||||
end
|
||||
|
||||
# CUSTOM WRAPPERS
|
||||
|
||||
test 'error with custom wrappers works' do
|
||||
swap SimpleForm, :wrapper => custom_wrapper do
|
||||
with_error_for @user, :name
|
||||
assert_select 'span.omg_error', "can't be blank"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,12 +2,6 @@
|
|||
require 'test_helper'
|
||||
|
||||
class FormBuilderTest < ActionView::TestCase
|
||||
def with_form_for(object, *args, &block)
|
||||
with_concat_form_for(object) do |f|
|
||||
f.input(*args, &block)
|
||||
end
|
||||
end
|
||||
|
||||
def with_custom_form_for(object, *args, &block)
|
||||
with_concat_custom_form_for(object) do |f|
|
||||
f.input(*args, &block)
|
||||
|
|
|
@ -103,4 +103,13 @@ class HintTest < ActionView::TestCase
|
|||
with_hint_for :project, :name, :hint => 'Test without object'
|
||||
assert_select 'span.hint', 'Test without object'
|
||||
end
|
||||
|
||||
# Custom wrappers
|
||||
|
||||
test 'hint with custom wrappers works' do
|
||||
swap SimpleForm, :wrapper => custom_wrapper do
|
||||
with_hint_for @user, :name, :hint => "can't be blank"
|
||||
assert_select 'span.omg_hint', "can't be blank"
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,12 +1,6 @@
|
|||
require 'test_helper'
|
||||
|
||||
class WrapperTest < ActionView::TestCase
|
||||
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_form_for @user, :active
|
||||
assert_no_select 'div.field_with_errors'
|
||||
|
@ -86,4 +80,26 @@ class WrapperTest < ActionView::TestCase
|
|||
with_form_for @user, :name, :wrapper_class => :wrapper
|
||||
assert_select 'form div.wrapper.required.string'
|
||||
end
|
||||
|
||||
# Custom wrapper test
|
||||
|
||||
test 'custom wrappers works' do
|
||||
swap SimpleForm, :wrapper => custom_wrapper do
|
||||
with_form_for @user, :name, :hint => "cool"
|
||||
assert_select "section.custom_wrapper div.another_wrapper label"
|
||||
assert_select "section.custom_wrapper div.another_wrapper input.string"
|
||||
assert_no_select "section.custom_wrapper div.another_wrapper span.omg_error"
|
||||
assert_select "section.custom_wrapper div.error_wrapper span.omg_error"
|
||||
assert_select "section.custom_wrapper > span.omg_hint", "cool"
|
||||
end
|
||||
end
|
||||
|
||||
test 'custom wrappers can be turned off' do
|
||||
swap SimpleForm, :wrapper => custom_wrapper do
|
||||
with_form_for @user, :name, :another => false
|
||||
assert_no_select "section.custom_wrapper div.another_wrapper label"
|
||||
assert_no_select "section.custom_wrapper div.another_wrapper input.string"
|
||||
assert_select "section.custom_wrapper div.error_wrapper span.omg_error"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
require 'test_helper'
|
||||
|
||||
class RequiredTest < ActionView::TestCase
|
||||
def with_form_for(object, *args, &block)
|
||||
with_concat_form_for(object) do |f|
|
||||
f.input(*args, &block)
|
||||
end
|
||||
end
|
||||
|
||||
# REQUIRED AND PRESENCE VALIDATION
|
||||
test 'builder input should obtain required from ActiveModel::Validations when it is included' do
|
||||
with_form_for @validating_user, :name
|
||||
|
|
|
@ -25,7 +25,21 @@ module MiscHelpers
|
|||
end
|
||||
end
|
||||
|
||||
def custom_wrapper
|
||||
SimpleForm.build :tag => :section, :class => "custom_wrapper" do |b|
|
||||
b.use :another, :tag => :div, :class => "another_wrapper" do |ba|
|
||||
ba.use :label
|
||||
ba.use :input
|
||||
end
|
||||
b.use :error_wrapper, :tag => :div, :class => "error_wrapper" do |be|
|
||||
be.use :error, :tag => :span, :class => "omg_error"
|
||||
end
|
||||
b.use :hint, :tag => :span, :class => "omg_hint"
|
||||
end
|
||||
end
|
||||
|
||||
# Temporary hack to deal with components.
|
||||
# TODO: Remove this and tests that uses this once we remove components
|
||||
def swap!(*args)
|
||||
swap(*args) do
|
||||
SimpleForm.deprecated_components = [ :placeholder, :label_input, :hint, :error ]
|
||||
|
|
Loading…
Reference in New Issue