More concat cleanup on tests
This commit is contained in:
parent
146d18e6f8
commit
f570602c09
|
@ -1,29 +1,34 @@
|
|||
require 'test_helper'
|
||||
|
||||
class BuilderTest < ActionView::TestCase
|
||||
|
||||
def with_concat_form_for(object, &block)
|
||||
concat form_for(object, &block)
|
||||
end
|
||||
|
||||
# COLLECTION RADIO
|
||||
test 'collection radio accepts a collection and generate inputs from value method' do
|
||||
concat(form_for(@user) do |f|
|
||||
with_concat_form_for(@user) do |f|
|
||||
f.collection_radio :active, [true, false], :to_s, :to_s
|
||||
end)
|
||||
end
|
||||
|
||||
assert_select 'form input[type=radio][value=true]#user_active_true'
|
||||
assert_select 'form input[type=radio][value=false]#user_active_false'
|
||||
end
|
||||
|
||||
test 'collection radio accepts a collection and generate inputs from label method' do
|
||||
concat(form_for(@user) do |f|
|
||||
with_concat_form_for(@user) do |f|
|
||||
f.collection_radio :active, [true, false], :to_s, :to_s
|
||||
end)
|
||||
end
|
||||
|
||||
assert_select 'form label.collection_radio[for=user_active_true]', 'true'
|
||||
assert_select 'form label.collection_radio[for=user_active_false]', 'false'
|
||||
end
|
||||
|
||||
test 'collection radio accepts checked item' do
|
||||
concat(form_for(@user) do |f|
|
||||
with_concat_form_for(@user) do |f|
|
||||
f.collection_radio :active, [[1, true], [0, false]], :last, :first, :checked => true
|
||||
end)
|
||||
end
|
||||
|
||||
assert_select 'form input[type=radio][value=true][checked=checked]'
|
||||
assert_no_select 'form input[type=radio][value=false][checked=checked]'
|
||||
|
@ -31,9 +36,9 @@ class BuilderTest < ActionView::TestCase
|
|||
|
||||
test 'collection radio accepts multiple disabled items' do
|
||||
collection = [[1, true], [0, false], [2, 'other']]
|
||||
concat(form_for(@user) do |f|
|
||||
with_concat_form_for(@user) do |f|
|
||||
f.collection_radio :active, collection, :last, :first, :disabled => [true, false]
|
||||
end)
|
||||
end
|
||||
|
||||
assert_select 'form input[type=radio][value=true][disabled=disabled]'
|
||||
assert_select 'form input[type=radio][value=false][disabled=disabled]'
|
||||
|
@ -42,18 +47,18 @@ class BuilderTest < ActionView::TestCase
|
|||
|
||||
test 'collection radio accepts single disable item' do
|
||||
collection = [[1, true], [0, false]]
|
||||
concat(form_for(@user) do |f|
|
||||
with_concat_form_for(@user) do |f|
|
||||
f.collection_radio :active, collection, :last, :first, :disabled => true
|
||||
end)
|
||||
end
|
||||
|
||||
assert_select 'form input[type=radio][value=true][disabled=disabled]'
|
||||
assert_no_select 'form input[type=radio][value=false][disabled=disabled]'
|
||||
end
|
||||
|
||||
test 'collection radio accepts html options as input' do
|
||||
concat(form_for(@user) do |f|
|
||||
with_concat_form_for(@user) do |f|
|
||||
f.collection_radio :active, [[1, true], [0, false]], :last, :first, {}, :class => 'radio'
|
||||
end)
|
||||
end
|
||||
|
||||
assert_select 'form input[type=radio][value=true].radio#user_active_true'
|
||||
assert_select 'form input[type=radio][value=false].radio#user_active_false'
|
||||
|
@ -62,9 +67,9 @@ class BuilderTest < ActionView::TestCase
|
|||
# COLLECTION CHECK BOX
|
||||
test 'collection check box accepts a collection and generate a serie of checkboxes for value method' do
|
||||
collection = [Tag.new(1, 'Tag 1'), Tag.new(2, 'Tag 2')]
|
||||
concat(form_for(@user) do |f|
|
||||
with_concat_form_for(@user) do |f|
|
||||
f.collection_check_boxes :tag_ids, collection, :id, :name
|
||||
end)
|
||||
end
|
||||
|
||||
assert_select "form input[type=hidden][name='user[tag_ids][]'][value=]"
|
||||
assert_select 'form input#user_tag_ids_1[type=checkbox][value=1]'
|
||||
|
@ -73,9 +78,9 @@ class BuilderTest < ActionView::TestCase
|
|||
|
||||
test 'collection check box accepts a collection and generate a serie of checkboxes with labels for label method' do
|
||||
collection = [Tag.new(1, 'Tag 1'), Tag.new(2, 'Tag 2')]
|
||||
concat(form_for(@user) do |f|
|
||||
with_concat_form_for(@user) do |f|
|
||||
f.collection_check_boxes :tag_ids, collection, :id, :name
|
||||
end)
|
||||
end
|
||||
|
||||
assert_select 'form label.collection_check_boxes[for=user_tag_ids_1]', 'Tag 1'
|
||||
assert_select 'form label.collection_check_boxes[for=user_tag_ids_2]', 'Tag 2'
|
||||
|
@ -83,9 +88,9 @@ class BuilderTest < ActionView::TestCase
|
|||
|
||||
test 'collection check box accepts selected values as :checked option' do
|
||||
collection = (1..3).map{|i| [i, "Tag #{i}"] }
|
||||
concat(form_for(@user) do |f|
|
||||
with_concat_form_for(@user) do |f|
|
||||
f.collection_check_boxes :tag_ids, collection, :first, :last, :checked => [1, 3]
|
||||
end)
|
||||
end
|
||||
|
||||
assert_select 'form input[type=checkbox][value=1][checked=checked]'
|
||||
assert_select 'form input[type=checkbox][value=3][checked=checked]'
|
||||
|
@ -94,9 +99,9 @@ class BuilderTest < ActionView::TestCase
|
|||
|
||||
test 'collection check box accepts a single checked value' do
|
||||
collection = (1..3).map{|i| [i, "Tag #{i}"] }
|
||||
concat(form_for(@user) do |f|
|
||||
with_concat_form_for(@user) do |f|
|
||||
f.collection_check_boxes :tag_ids, collection, :first, :last, :checked => 3
|
||||
end)
|
||||
end
|
||||
|
||||
assert_select 'form input[type=checkbox][value=3][checked=checked]'
|
||||
assert_no_select 'form input[type=checkbox][value=1][checked=checked]'
|
||||
|
@ -105,9 +110,9 @@ class BuilderTest < ActionView::TestCase
|
|||
|
||||
test 'collection check box accepts multiple disabled items' do
|
||||
collection = (1..3).map{|i| [i, "Tag #{i}"] }
|
||||
concat(form_for(@user) do |f|
|
||||
with_concat_form_for(@user) do |f|
|
||||
f.collection_check_boxes :tag_ids, collection, :first, :last, :disabled => [1, 3]
|
||||
end)
|
||||
end
|
||||
|
||||
assert_select 'form input[type=checkbox][value=1][disabled=disabled]'
|
||||
assert_select 'form input[type=checkbox][value=3][disabled=disabled]'
|
||||
|
@ -116,9 +121,9 @@ class BuilderTest < ActionView::TestCase
|
|||
|
||||
test 'collection check box accepts single disable item' do
|
||||
collection = (1..3).map{|i| [i, "Tag #{i}"] }
|
||||
concat(form_for(@user) do |f|
|
||||
with_concat_form_for(@user) do |f|
|
||||
f.collection_check_boxes :tag_ids, collection, :first, :last, :disabled => 1
|
||||
end)
|
||||
end
|
||||
|
||||
assert_select 'form input[type=checkbox][value=1][disabled=disabled]'
|
||||
assert_no_select 'form input[type=checkbox][value=3][disabled=disabled]'
|
||||
|
@ -127,9 +132,9 @@ class BuilderTest < ActionView::TestCase
|
|||
|
||||
test 'collection check box accepts a proc to disabled items' do
|
||||
collection = (1..3).map{|i| [i, "Tag #{i}"] }
|
||||
concat(form_for(@user) do |f|
|
||||
with_concat_form_for(@user) do |f|
|
||||
f.collection_check_boxes :tag_ids, collection, :first, :last, :disabled => proc { |i| i.first == 1 }
|
||||
end)
|
||||
end
|
||||
|
||||
assert_select 'form input[type=checkbox][value=1][disabled=disabled]'
|
||||
assert_no_select 'form input[type=checkbox][value=3][disabled=disabled]'
|
||||
|
@ -138,9 +143,9 @@ class BuilderTest < ActionView::TestCase
|
|||
|
||||
test 'collection check box accepts html options' do
|
||||
collection = [[1, 'Tag 1'], [2, 'Tag 2']]
|
||||
concat(form_for(@user) do |f|
|
||||
with_concat_form_for(@user) do |f|
|
||||
f.collection_check_boxes :tag_ids, collection, :first, :last, {}, :class => 'check'
|
||||
end)
|
||||
end
|
||||
|
||||
assert_select 'form input.check[type=checkbox][value=1]'
|
||||
assert_select 'form input.check[type=checkbox][value=2]'
|
||||
|
@ -148,11 +153,11 @@ class BuilderTest < ActionView::TestCase
|
|||
|
||||
test 'collection check box with fields for' do
|
||||
collection = [Tag.new(1, 'Tag 1'), Tag.new(2, 'Tag 2')]
|
||||
concat(form_for(@user) do |f|
|
||||
with_concat_form_for(@user) do |f|
|
||||
f.fields_for(:post) do |p|
|
||||
p.collection_check_boxes :tag_ids, collection, :id, :name
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
assert_select 'form input#user_post_tag_ids_1[type=checkbox][value=1]'
|
||||
assert_select 'form input#user_post_tag_ids_2[type=checkbox][value=2]'
|
||||
|
@ -163,10 +168,10 @@ class BuilderTest < ActionView::TestCase
|
|||
|
||||
# SIMPLE FIELDS
|
||||
test 'simple fields for is available and yields an instance of FormBuilder' do
|
||||
concat(form_for(@user) do |f|
|
||||
with_concat_form_for(@user) do |f|
|
||||
f.simple_fields_for(:posts) do |posts_form|
|
||||
assert posts_form.instance_of?(SimpleForm::FormBuilder)
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,14 +3,14 @@ require 'test_helper'
|
|||
class ErrorTest < ActionView::TestCase
|
||||
|
||||
def with_error_for(object, attribute_name, type, options={}, &block)
|
||||
concat(simple_form_for(object) do |f|
|
||||
with_concat_form_for(object) do |f|
|
||||
f.attribute_name = attribute_name
|
||||
f.reflection = Association.new(Company, :company, {}) if options.delete(:setup_association)
|
||||
f.input_type = type
|
||||
f.options = options
|
||||
|
||||
SimpleForm::Inputs::Base.new(f).error.to_s
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
test 'error should not generate content for attribute without errors' do
|
||||
|
|
|
@ -3,14 +3,14 @@ require 'test_helper'
|
|||
class HintTest < ActionView::TestCase
|
||||
|
||||
def with_hint_for(object, attribute_name, type, options={}, &block)
|
||||
concat(simple_form_for(object) do |f|
|
||||
with_concat_form_for(object) do |f|
|
||||
f.attribute_name = attribute_name
|
||||
f.reflection = Association.new(Company, :company, {}) if options.delete(:setup_association)
|
||||
f.input_type = type
|
||||
f.options = options
|
||||
|
||||
SimpleForm::Inputs::Base.new(f).hint.to_s
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
test 'hint should not be generated by default' do
|
||||
|
|
|
@ -8,14 +8,14 @@ class LabelTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
def with_label_for(object, attribute_name, type, options={})
|
||||
concat(simple_form_for(object) do |f|
|
||||
with_concat_form_for(object) do |f|
|
||||
f.attribute_name = attribute_name
|
||||
f.reflection = Association.new(Company, :company, {}) if options.delete(:setup_association)
|
||||
f.input_type = type
|
||||
f.options = options
|
||||
|
||||
SimpleForm::Inputs::Base.new(f).label
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
test 'label should generate a default humanized description' do
|
||||
|
|
|
@ -2,15 +2,15 @@ require 'test_helper'
|
|||
|
||||
class WrapperTest < ActionView::TestCase
|
||||
def with_error_for(object, attribute_name, &block)
|
||||
concat(simple_form_for(object) do |f|
|
||||
with_concat_form_for(object) do |f|
|
||||
f.input attribute_name
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
def with_form_for(object, *args, &block)
|
||||
concat(simple_form_for(object) do |f|
|
||||
with_concat_form_for(object) do |f|
|
||||
f.input(*args, &block)
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
test 'wrapper should not have error class for attribute without errors' do
|
||||
|
|
|
@ -3,9 +3,9 @@ require 'test_helper'
|
|||
class ErrorNotificationTest < ActionView::TestCase
|
||||
|
||||
def with_error_notification_for(object, options={}, &block)
|
||||
concat(simple_form_for(object) do |f|
|
||||
with_concat_form_for(object) do |f|
|
||||
f.error_notification(options)
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
test 'error notification is not generated when the object has no error' do
|
||||
|
|
|
@ -4,39 +4,39 @@ require 'test_helper'
|
|||
class FormBuilderTest < ActionView::TestCase
|
||||
|
||||
def with_form_for(object, *args, &block)
|
||||
concat(simple_form_for(object) do |f|
|
||||
with_concat_form_for(object) do |f|
|
||||
f.input(*args, &block)
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
def with_button_for(object, *args)
|
||||
concat(simple_form_for(object) do |f|
|
||||
with_concat_form_for(object) do |f|
|
||||
f.button(*args)
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
def with_error_for(object, *args)
|
||||
concat(simple_form_for(object) do |f|
|
||||
with_concat_form_for(object) do |f|
|
||||
f.error(*args)
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
def with_hint_for(object, *args)
|
||||
concat(simple_form_for(object) do |f|
|
||||
with_concat_form_for(object) do |f|
|
||||
f.hint(*args)
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
def with_label_for(object, *args)
|
||||
concat(simple_form_for(object) do |f|
|
||||
with_concat_form_for(object) do |f|
|
||||
f.label(*args)
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
def with_association_for(object, *args)
|
||||
concat(simple_form_for(object) do |f|
|
||||
with_concat_form_for(object) do |f|
|
||||
f.association(*args)
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
# All
|
||||
|
@ -299,16 +299,16 @@ class FormBuilderTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
test 'builder allows wrapper tag to be given on demand' do
|
||||
concat(simple_form_for(@user) do |f|
|
||||
with_concat_form_for(@user) do |f|
|
||||
f.input :name, :wrapper_tag => :b
|
||||
end)
|
||||
end
|
||||
assert_select 'form b.required.string'
|
||||
end
|
||||
|
||||
test 'builder allows wrapper class to be given on demand' do
|
||||
concat(simple_form_for(@user) do |f|
|
||||
with_concat_form_for(@user) do |f|
|
||||
f.input :name, :wrapper_class => :wrapper
|
||||
end)
|
||||
end
|
||||
assert_select 'form div.wrapper.required.string'
|
||||
end
|
||||
|
||||
|
|
|
@ -8,9 +8,9 @@ class InputTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
def with_input_for(object, attribute_name, type, options={})
|
||||
concat(simple_form_for(object) do |f|
|
||||
with_concat_form_for(object) do |f|
|
||||
f.input(attribute_name, options.merge(:as => type))
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
# ALL
|
||||
|
|
|
@ -24,4 +24,8 @@ module MiscHelpers
|
|||
object.send :"#{key}=", value
|
||||
end
|
||||
end
|
||||
|
||||
def with_concat_form_for(object, &block)
|
||||
concat simple_form_for(object, &block)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue