Code cleanup
This commit is contained in:
parent
67381fbe74
commit
928adab801
|
@ -47,7 +47,7 @@ SimpleForm.setup do |config|
|
|||
b.optional :readonly
|
||||
|
||||
b.wrapper :container_wrapper, tag: 'div', class: 'small-offset-3 small-9 columns' do |ba|
|
||||
ba.wrapper :tag => 'label', :class => 'checkbox' do |bb|
|
||||
ba.wrapper tag: 'label', class: 'checkbox' do |bb|
|
||||
bb.use :input
|
||||
bb.use :label_text
|
||||
end
|
||||
|
|
|
@ -60,11 +60,11 @@ See https://github.com/plataformatec/simple_form/pull/997 for more information.
|
|||
|
||||
# Series of attemps to detect a default label method for collection.
|
||||
mattr_accessor :collection_label_methods
|
||||
@@collection_label_methods = [:to_label, :name, :title, :to_s]
|
||||
@@collection_label_methods = %i[to_label name title to_s]
|
||||
|
||||
# Series of attemps to detect a default value method for collection.
|
||||
mattr_accessor :collection_value_methods
|
||||
@@collection_value_methods = [:id, :to_s]
|
||||
@@collection_value_methods = %i[id to_s]
|
||||
|
||||
# You can wrap a collection of radio/check boxes in a pre-defined tag, defaulting to none.
|
||||
mattr_accessor :collection_wrapper_tag
|
||||
|
@ -86,7 +86,7 @@ See https://github.com/plataformatec/simple_form/pull/997 for more information.
|
|||
|
||||
# How the label text should be generated altogether with the required text.
|
||||
mattr_accessor :label_text
|
||||
@@label_text = lambda { |label, required, explicit_label| "#{required} #{label}" }
|
||||
@@label_text = ->(label, required, explicit_label) { "#{required} #{label}" }
|
||||
|
||||
# You can define the class to be used on all labels. Defaults to none.
|
||||
mattr_accessor :label_class
|
||||
|
@ -110,7 +110,7 @@ See https://github.com/plataformatec/simple_form/pull/997 for more information.
|
|||
|
||||
# You can define which elements should obtain additional classes.
|
||||
mattr_accessor :generate_additional_classes_for
|
||||
@@generate_additional_classes_for = [:wrapper, :label, :input]
|
||||
@@generate_additional_classes_for = %i[wrapper label input]
|
||||
|
||||
# Whether attributes are required by default or not.
|
||||
mattr_accessor :required_by_default
|
||||
|
@ -122,7 +122,7 @@ See https://github.com/plataformatec/simple_form/pull/997 for more information.
|
|||
|
||||
# Collection of methods to detect if a file type was given.
|
||||
mattr_accessor :file_methods
|
||||
@@file_methods = [:mounted_as, :file?, :public_filename]
|
||||
@@file_methods = %i[mounted_as file? public_filename]
|
||||
|
||||
# Custom mappings for input types. This should be a hash containing a regexp
|
||||
# to match as key, and the input type that will be used when the field name
|
||||
|
|
|
@ -21,7 +21,7 @@ module SimpleForm
|
|||
def deprecated_component(namespace, wrapper_options)
|
||||
method = method(namespace)
|
||||
|
||||
if method.arity == 0
|
||||
if method.arity.zero?
|
||||
ActiveSupport::Deprecation.warn(SimpleForm::CUSTOM_INPUT_DEPRECATION_WARN % { name: namespace })
|
||||
|
||||
method.call
|
||||
|
|
|
@ -8,7 +8,7 @@ module SimpleForm
|
|||
def translate_required_html
|
||||
i18n_cache :translate_required_html do
|
||||
I18n.t(:"simple_form.required.html", default:
|
||||
%[<abbr title="#{translate_required_text}">#{translate_required_mark}</abbr>]
|
||||
%(<abbr title="#{translate_required_text}">#{translate_required_mark}</abbr>)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,9 +11,9 @@ module SimpleForm
|
|||
ACTIONS = {
|
||||
'create' => 'new',
|
||||
'update' => 'edit'
|
||||
}
|
||||
}.freeze
|
||||
|
||||
ATTRIBUTE_COMPONENTS = [:html5, :min_max, :maxlength, :minlength, :placeholder, :pattern, :readonly]
|
||||
ATTRIBUTE_COMPONENTS = %i[html5 min_max maxlength minlength placeholder pattern readonly].freeze
|
||||
|
||||
extend MapType
|
||||
include SimpleForm::Inputs
|
||||
|
|
|
@ -25,7 +25,7 @@ module SimpleForm
|
|||
end
|
||||
|
||||
def action_validator_match?(validator)
|
||||
return true if !validator.options.include?(:on)
|
||||
return true unless validator.options.include?(:on)
|
||||
|
||||
case validator.options[:on]
|
||||
when :save
|
||||
|
|
|
@ -96,7 +96,7 @@ module SimpleForm
|
|||
end
|
||||
|
||||
def input_class
|
||||
"#{lookup_model_names.join("_")}_#{reflection_or_attribute_name}"
|
||||
"#{lookup_model_names.join('_')}_#{reflection_or_attribute_name}"
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -62,7 +62,7 @@ module SimpleForm
|
|||
def build_hidden_field_for_checkbox
|
||||
return "" if !include_hidden? || !unchecked_value
|
||||
options = { value: unchecked_value, id: nil, disabled: input_html_options[:disabled] }
|
||||
options[:name] = input_html_options[:name] if input_html_options.has_key?(:name)
|
||||
options[:name] = input_html_options[:name] if input_html_options.key?(:name)
|
||||
|
||||
@builder.hidden_field(attribute_name, options)
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
module SimpleForm
|
||||
module Inputs
|
||||
class CollectionInput < Base
|
||||
BASIC_OBJECT_CLASSES = [String, Integer, Float, NilClass, Symbol, TrueClass, FalseClass]
|
||||
BASIC_OBJECT_CLASSES = [String, Integer, Float, NilClass, Symbol, TrueClass, FalseClass].freeze
|
||||
BASIC_OBJECT_CLASSES.push(Fixnum, Bignum) unless 1.class == Integer
|
||||
|
||||
# Default boolean collection for use with selects/radios when no
|
||||
|
@ -46,7 +46,7 @@ module SimpleForm
|
|||
|
||||
# Check if :include_blank must be included by default.
|
||||
def skip_include_blank?
|
||||
(options.keys & [:prompt, :include_blank, :default, :selected]).any? || multiple?
|
||||
(options.keys & %i[prompt include_blank default selected]).any? || multiple?
|
||||
end
|
||||
|
||||
def multiple?
|
||||
|
@ -90,7 +90,7 @@ module SimpleForm
|
|||
end
|
||||
|
||||
def detect_collection_classes(some_collection = collection)
|
||||
some_collection.map { |e| e.class }.uniq
|
||||
some_collection.map(&:class).uniq
|
||||
end
|
||||
|
||||
def collection_includes_basic_objects?(collection_classes)
|
||||
|
|
|
@ -12,7 +12,7 @@ module SimpleForm
|
|||
def render(input)
|
||||
method = input.method(@namespace)
|
||||
|
||||
if method.arity == 0
|
||||
if method.arity.zero?
|
||||
ActiveSupport::Deprecation.warn(SimpleForm::CUSTOM_INPUT_DEPRECATION_WARN % { name: @namespace })
|
||||
|
||||
method.call
|
||||
|
|
|
@ -20,7 +20,7 @@ module SimpleForm
|
|||
private
|
||||
|
||||
def html_options(options)
|
||||
[:label, :input].include?(namespace) ? {} : super
|
||||
%i[label input].include?(namespace) ? {} : super
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -37,7 +37,7 @@ class BuilderTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
test "collection radio handles camelized collection values for labels correctly" do
|
||||
with_collection_radio_buttons @user, :active, ['Yes', 'No'], :to_s, :to_s
|
||||
with_collection_radio_buttons @user, :active, %w[Yes No], :to_s, :to_s
|
||||
|
||||
assert_select 'form label.collection_radio_buttons[for=user_active_yes]', 'Yes'
|
||||
assert_select 'form label.collection_radio_buttons[for=user_active_no]', 'No'
|
||||
|
@ -244,7 +244,7 @@ class BuilderTest < ActionView::TestCase
|
|||
|
||||
test "collection radio with block helpers does not leak the template" do
|
||||
with_concat_form_for(@user) do |f|
|
||||
collection_input = f.collection_radio_buttons :active, [true, false], :to_s, :to_s do |b|
|
||||
collection_input = f.collection_radio_buttons :active, [true, false], :to_s, :to_s do |b|
|
||||
b.label(class: b.object) { b.radio_button + b.text }
|
||||
end
|
||||
concat collection_input
|
||||
|
@ -284,7 +284,7 @@ class BuilderTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
test "collection check box handles camelized collection values for labels correctly" do
|
||||
with_collection_check_boxes @user, :active, ['Yes', 'No'], :to_s, :to_s
|
||||
with_collection_check_boxes @user, :active, %w[Yes No], :to_s, :to_s
|
||||
|
||||
assert_select 'form label.collection_check_boxes[for=user_active_yes]', 'Yes'
|
||||
assert_select 'form label.collection_check_boxes[for=user_active_no]', 'No'
|
||||
|
@ -318,7 +318,7 @@ class BuilderTest < ActionView::TestCase
|
|||
|
||||
test "collection check boxes accepts selected string values as :checked option" do
|
||||
collection = (1..3).map { |i| [i, "Category #{i}"] }
|
||||
with_collection_check_boxes :user, :category_ids, collection, :first, :last, checked: ['1', '3']
|
||||
with_collection_check_boxes :user, :category_ids, collection, :first, :last, checked: %w[1 3]
|
||||
|
||||
assert_select 'input[type=checkbox][value="1"][checked=checked]'
|
||||
assert_select 'input[type=checkbox][value="3"][checked=checked]'
|
||||
|
@ -542,7 +542,7 @@ class BuilderTest < ActionView::TestCase
|
|||
|
||||
test "collection check boxes with block helpers does not leak the template" do
|
||||
with_concat_form_for(@user) do |f|
|
||||
collection_input = f.collection_check_boxes :active, [true, false], :to_s, :to_s do |b|
|
||||
collection_input = f.collection_check_boxes :active, [true, false], :to_s, :to_s do |b|
|
||||
b.label(class: b.object) { b.check_box + b.text }
|
||||
end
|
||||
concat collection_input
|
||||
|
|
|
@ -152,7 +152,7 @@ class FormHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
test 'SimpleForm for swaps default action view field_error_proc' do
|
||||
expected_error_proc = lambda {}
|
||||
expected_error_proc = -> {}
|
||||
swap SimpleForm, field_error_proc: expected_error_proc do
|
||||
simple_form_for :user do |f|
|
||||
assert_equal expected_error_proc, ::ActionView::Base.field_error_proc
|
||||
|
@ -162,7 +162,7 @@ class FormHelperTest < ActionView::TestCase
|
|||
|
||||
private
|
||||
|
||||
def swap_field_error_proc(expected_error_proc = lambda {})
|
||||
def swap_field_error_proc(expected_error_proc = -> {})
|
||||
swap ActionView::Base, field_error_proc: expected_error_proc do
|
||||
yield
|
||||
|
||||
|
|
|
@ -178,7 +178,7 @@ class IsolatedLabelTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
test 'label does not have css class from type when generate_additional_classes_for does not include :label' do
|
||||
swap SimpleForm, generate_additional_classes_for: [:wrapper, :input] do
|
||||
swap SimpleForm, generate_additional_classes_for: %i[wrapper input] do
|
||||
with_label_for @user, :name, :string
|
||||
assert_no_select 'label.string'
|
||||
with_label_for @user, :description, :text
|
||||
|
@ -193,7 +193,7 @@ class IsolatedLabelTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
test 'label does not generate empty css class' do
|
||||
swap SimpleForm, generate_additional_classes_for: [:wrapper, :input] do
|
||||
swap SimpleForm, generate_additional_classes_for: %i[wrapper input] do
|
||||
with_label_for @user, :name, :string
|
||||
assert_no_select 'label[class]'
|
||||
end
|
||||
|
@ -207,7 +207,7 @@ class IsolatedLabelTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
test 'label does not obtain required from ActiveModel::Validations when generate_additional_classes_for does not include :label' do
|
||||
swap SimpleForm, generate_additional_classes_for: [:wrapper, :input] do
|
||||
swap SimpleForm, generate_additional_classes_for: %i[wrapper input] do
|
||||
with_label_for @validating_user, :name, :string
|
||||
assert_no_select 'label.required'
|
||||
with_label_for @validating_user, :status, :string
|
||||
|
@ -290,7 +290,7 @@ class IsolatedLabelTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
test 'label includes for attribute for select collection' do
|
||||
with_label_for @user, :sex, :select, collection: [:male, :female]
|
||||
with_label_for @user, :sex, :select, collection: %i[male female]
|
||||
assert_select 'label[for=user_sex]'
|
||||
end
|
||||
|
||||
|
|
|
@ -235,12 +235,12 @@ class AssociationTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
test 'builder with collection support does not change the options hash' do
|
||||
options = { as: :check_boxes, collection_wrapper_tag: :ul, item_wrapper_tag: :li}
|
||||
options = { as: :check_boxes, collection_wrapper_tag: :ul, item_wrapper_tag: :li }
|
||||
with_association_for @user, :tags, options
|
||||
|
||||
assert_select 'form ul', count: 1
|
||||
assert_select 'form ul li', count: 3
|
||||
assert_equal({ as: :check_boxes, collection_wrapper_tag: :ul, item_wrapper_tag: :li},
|
||||
assert_equal({ as: :check_boxes, collection_wrapper_tag: :ul, item_wrapper_tag: :li },
|
||||
options)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -56,7 +56,7 @@ class FormBuilderTest < ActionView::TestCase
|
|||
test 'builder does not override custom input mappings for custom collection' do
|
||||
swap SimpleForm, input_mappings: { /gender$/ => :check_boxes } do
|
||||
with_concat_form_for @user do |f|
|
||||
f.input :gender, collection: [:male, :female]
|
||||
f.input :gender, collection: %i[male female]
|
||||
end
|
||||
|
||||
assert_no_select 'select option', 'Male'
|
||||
|
@ -65,7 +65,7 @@ class FormBuilderTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
test 'builder allows to skip input_type class' do
|
||||
swap SimpleForm, generate_additional_classes_for: [:label, :wrapper] do
|
||||
swap SimpleForm, generate_additional_classes_for: %i[label wrapper] do
|
||||
with_form_for @user, :post_count
|
||||
assert_no_select "form input#user_post_count.integer"
|
||||
assert_select "form input#user_post_count"
|
||||
|
@ -389,7 +389,7 @@ class FormBuilderTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
# DEFAULT OPTIONS
|
||||
[:input, :input_field].each do |method|
|
||||
%i[input input_field].each do |method|
|
||||
test "builder receives a default argument and pass it to the inputs when calling '#{method}'" do
|
||||
with_concat_form_for @user, defaults: { input_html: { class: 'default_class' } } do |f|
|
||||
f.public_send(method, :name)
|
||||
|
|
|
@ -113,7 +113,7 @@ class InputFieldTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
test 'builder collection input_field generates input tag with a clean HTML' do
|
||||
with_input_field_for @user, :status, collection: ['Open', 'Closed'],
|
||||
with_input_field_for @user, :status, collection: %w[Open Closed],
|
||||
class: 'status', label_method: :to_s, value_method: :to_s
|
||||
|
||||
assert_no_select 'select.status[input_html]'
|
||||
|
|
|
@ -114,21 +114,21 @@ class LabelTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
test 'builder allows custom formatting when label is explicitly specified' do
|
||||
swap SimpleForm, label_text: lambda { |l, r, explicit_label| explicit_label ? l : "#{l.titleize}:" } do
|
||||
swap SimpleForm, label_text: ->(l, r, explicit_label) { explicit_label ? l : "#{l.titleize}:" } do
|
||||
with_label_for @user, :time_zone, 'What is your home time zone?'
|
||||
assert_select 'label[for=user_time_zone]', 'What is your home time zone?'
|
||||
end
|
||||
end
|
||||
|
||||
test 'builder allows custom formatting when label is generated' do
|
||||
swap SimpleForm, label_text: lambda { |l, r, explicit_label| explicit_label ? l : "#{l.titleize}:" } do
|
||||
swap SimpleForm, label_text: ->(l, r, explicit_label) { explicit_label ? l : "#{l.titleize}:" } do
|
||||
with_label_for @user, :time_zone
|
||||
assert_select 'label[for=user_time_zone]', 'Time Zone:'
|
||||
end
|
||||
end
|
||||
|
||||
test 'builder allows label specific `label_text` option' do
|
||||
with_label_for @user, :time_zone, label_text: lambda { |l, _, _| "#{l.titleize}:" }
|
||||
with_label_for @user, :time_zone, label_text: ->(l, _, _) { "#{l.titleize}:" }
|
||||
|
||||
assert_no_select 'label[label_text]'
|
||||
assert_select 'label[for=user_time_zone]', 'Time Zone:'
|
||||
|
|
|
@ -89,7 +89,7 @@ class WrapperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
test 'wrapper skips additional classes when configured' do
|
||||
swap SimpleForm, generate_additional_classes_for: [:input, :label] do
|
||||
swap SimpleForm, generate_additional_classes_for: %i[input label] do
|
||||
with_form_for @user, :name, wrapper_class: :wrapper
|
||||
assert_select 'form div.wrapper'
|
||||
assert_no_select 'div.required'
|
||||
|
@ -99,7 +99,7 @@ class WrapperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
test 'wrapper does not generate empty css class' do
|
||||
swap SimpleForm, generate_additional_classes_for: [:input, :label] do
|
||||
swap SimpleForm, generate_additional_classes_for: %i[input label] do
|
||||
swap_wrapper :default, custom_wrapper_without_class do
|
||||
with_form_for @user, :name
|
||||
assert_no_select 'div#custom_wrapper_without_class[class]'
|
||||
|
|
|
@ -19,7 +19,7 @@ class SimpleFormGeneratorTest < Rails::Generators::TestCase
|
|||
end
|
||||
|
||||
test 'generates the simple_form initializer with the bootstrap wrappers' do
|
||||
run_generator %w(--bootstrap)
|
||||
run_generator %w[--bootstrap]
|
||||
assert_file 'config/initializers/simple_form.rb',
|
||||
/config\.default_wrapper = :default/, /config\.boolean_style = :nested/
|
||||
assert_file 'config/initializers/simple_form_bootstrap.rb', /config\.wrappers :vertical_form/,
|
||||
|
@ -27,14 +27,14 @@ class SimpleFormGeneratorTest < Rails::Generators::TestCase
|
|||
end
|
||||
|
||||
test 'generates the simple_form initializer with the foundation wrappers' do
|
||||
run_generator %w(--foundation)
|
||||
run_generator %w[--foundation]
|
||||
assert_file 'config/initializers/simple_form.rb',
|
||||
/config\.default_wrapper = :default/, /config\.boolean_style = :nested/
|
||||
assert_file 'config/initializers/simple_form_foundation.rb', /config\.wrappers :vertical_form/,
|
||||
/config\.default_wrapper = :vertical_form/, /config\.item_wrapper_tag = :div/
|
||||
end
|
||||
|
||||
%W(erb haml slim).each do |engine|
|
||||
%w[erb haml slim].each do |engine|
|
||||
test "generates the scaffold template when using #{engine}" do
|
||||
run_generator ['-e', engine]
|
||||
assert_file "lib/templates/#{engine}/scaffold/_form.html.#{engine}"
|
||||
|
|
|
@ -8,33 +8,33 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
test 'input check boxes does not include for attribute by default' do
|
||||
with_input_for @user, :gender, :check_boxes, collection: [:male, :female]
|
||||
with_input_for @user, :gender, :check_boxes, collection: %i[male female]
|
||||
assert_select 'label'
|
||||
assert_no_select 'label[for=user_gender]'
|
||||
end
|
||||
|
||||
test 'input check boxes includes for attribute when giving as html option' do
|
||||
with_input_for @user, :gender, :check_boxes, collection: [:male, :female], label_html: { for: 'gender' }
|
||||
with_input_for @user, :gender, :check_boxes, collection: %i[male female], label_html: { for: 'gender' }
|
||||
assert_select 'label[for=gender]'
|
||||
end
|
||||
|
||||
test 'collection input with check_boxes type does not generate required html attribute' do
|
||||
with_input_for @user, :name, :check_boxes, collection: ['Jose', 'Carlos']
|
||||
with_input_for @user, :name, :check_boxes, collection: %w[Jose Carlos]
|
||||
assert_select 'input.required'
|
||||
assert_no_select 'input[required]'
|
||||
end
|
||||
|
||||
test 'collection input with check_boxes type does not generate aria-required html attribute' do
|
||||
with_input_for @user, :name, :check_boxes, collection: ['Jose', 'Carlos']
|
||||
with_input_for @user, :name, :check_boxes, collection: %w[Jose Carlos]
|
||||
assert_select 'input.required'
|
||||
assert_no_select 'input[aria-required]'
|
||||
end
|
||||
|
||||
test 'input does automatic collection translation for check_box types using defaults key' do
|
||||
store_translations(:en, simple_form: { options: { defaults: {
|
||||
gender: { male: 'Male', female: 'Female'}
|
||||
gender: { male: 'Male', female: 'Female' }
|
||||
} } } ) do
|
||||
with_input_for @user, :gender, :check_boxes, collection: [:male, :female]
|
||||
with_input_for @user, :gender, :check_boxes, collection: %i[male female]
|
||||
assert_select 'input[type=checkbox][value=male]'
|
||||
assert_select 'input[type=checkbox][value=female]'
|
||||
assert_select 'label.collection_check_boxes', 'Male'
|
||||
|
@ -44,9 +44,9 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
|
|||
|
||||
test 'input does automatic collection translation for check_box types using specific object key' do
|
||||
store_translations(:en, simple_form: { options: { user: {
|
||||
gender: { male: 'Male', female: 'Female'}
|
||||
gender: { male: 'Male', female: 'Female' }
|
||||
} } } ) do
|
||||
with_input_for @user, :gender, :check_boxes, collection: [:male, :female]
|
||||
with_input_for @user, :gender, :check_boxes, collection: %i[male female]
|
||||
assert_select 'input[type=checkbox][value=male]'
|
||||
assert_select 'input[type=checkbox][value=female]'
|
||||
assert_select 'label.collection_check_boxes', 'Male'
|
||||
|
@ -56,11 +56,11 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
|
|||
|
||||
test 'input that uses automatic collection translation for check_boxes properly sets checked values' do
|
||||
store_translations(:en, simple_form: { options: { defaults: {
|
||||
gender: { male: 'Male', female: 'Female'}
|
||||
gender: { male: 'Male', female: 'Female' }
|
||||
} } } ) do
|
||||
@user.gender = 'male'
|
||||
|
||||
with_input_for @user, :gender, :check_boxes, collection: [:male, :female]
|
||||
with_input_for @user, :gender, :check_boxes, collection: %i[male female]
|
||||
assert_select 'input[type=checkbox][value=male][checked=checked]'
|
||||
assert_select 'input[type=checkbox][value=female]'
|
||||
assert_select 'label.collection_check_boxes', 'Male'
|
||||
|
@ -265,7 +265,7 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
|
|||
|
||||
test 'input check boxes wrapper class are not included when set to falsey' do
|
||||
swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
|
||||
with_input_for @user, :gender, :check_boxes, collection: [:male, :female]
|
||||
with_input_for @user, :gender, :check_boxes, collection: %i[male female]
|
||||
|
||||
assert_no_select 'label.checkbox'
|
||||
end
|
||||
|
@ -273,7 +273,7 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
|
|||
|
||||
test 'input check boxes custom wrapper class is included when include input wrapper class is falsey' do
|
||||
swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
|
||||
with_input_for @user, :gender, :check_boxes, collection: [:male, :female], item_wrapper_class: 'custom'
|
||||
with_input_for @user, :gender, :check_boxes, collection: %i[male female], item_wrapper_class: 'custom'
|
||||
|
||||
assert_no_select 'label.checkbox'
|
||||
assert_select 'span.custom'
|
||||
|
@ -283,7 +283,7 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
|
|||
test 'input check boxes with nested style and namespace uses the right for attribute' do
|
||||
swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
|
||||
with_concat_form_for @user, namespace: :foo do |f|
|
||||
concat f.input :gender, as: :check_boxes, collection: [:male, :female]
|
||||
concat f.input :gender, as: :check_boxes, collection: %i[male female]
|
||||
end
|
||||
|
||||
assert_select 'label[for=foo_user_gender_male]'
|
||||
|
@ -294,7 +294,7 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
|
|||
test 'input check boxes with nested style and index uses the right for attribute' do
|
||||
swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
|
||||
with_concat_form_for @user, index: 1 do |f|
|
||||
concat f.input :gender, as: :check_boxes, collection: [:male, :female]
|
||||
concat f.input :gender, as: :check_boxes, collection: %i[male female]
|
||||
end
|
||||
|
||||
assert_select 'label[for=user_1_gender_male]'
|
||||
|
|
|
@ -44,13 +44,13 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
test 'input radio does not include for attribute by default' do
|
||||
with_input_for @user, :gender, :radio_buttons, collection: [:male, :female]
|
||||
with_input_for @user, :gender, :radio_buttons, collection: %i[male female]
|
||||
assert_select 'label'
|
||||
assert_no_select 'label[for=user_gender]'
|
||||
end
|
||||
|
||||
test 'input radio includes for attribute when giving as html option' do
|
||||
with_input_for @user, :gender, :radio_buttons, collection: [:male, :female], label_html: { for: 'gender' }
|
||||
with_input_for @user, :gender, :radio_buttons, collection: %i[male female], label_html: { for: 'gender' }
|
||||
assert_select 'label[for=gender]'
|
||||
end
|
||||
|
||||
|
@ -62,7 +62,7 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
test 'input allows overriding collection for radio types' do
|
||||
with_input_for @user, :name, :radio_buttons, collection: ['Jose', 'Carlos']
|
||||
with_input_for @user, :name, :radio_buttons, collection: %w[Jose Carlos]
|
||||
assert_select 'input[type=radio][value=Jose]'
|
||||
assert_select 'input[type=radio][value=Carlos]'
|
||||
assert_select 'label.collection_radio_buttons[for=user_name_jose]', 'Jose'
|
||||
|
@ -71,9 +71,9 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|||
|
||||
test 'input does automatic collection translation for radio types using defaults key' do
|
||||
store_translations(:en, simple_form: { options: { defaults: {
|
||||
gender: { male: 'Male', female: 'Female'}
|
||||
gender: { male: 'Male', female: 'Female' }
|
||||
} } } ) do
|
||||
with_input_for @user, :gender, :radio_buttons, collection: [:male, :female]
|
||||
with_input_for @user, :gender, :radio_buttons, collection: %i[male female]
|
||||
assert_select 'input[type=radio][value=male]'
|
||||
assert_select 'input[type=radio][value=female]'
|
||||
assert_select 'label.collection_radio_buttons[for=user_gender_male]', 'Male'
|
||||
|
@ -83,9 +83,9 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|||
|
||||
test 'input does automatic collection translation for radio types using specific object key' do
|
||||
store_translations(:en, simple_form: { options: { user: {
|
||||
gender: { male: 'Male', female: 'Female'}
|
||||
gender: { male: 'Male', female: 'Female' }
|
||||
} } } ) do
|
||||
with_input_for @user, :gender, :radio_buttons, collection: [:male, :female]
|
||||
with_input_for @user, :gender, :radio_buttons, collection: %i[male female]
|
||||
assert_select 'input[type=radio][value=male]'
|
||||
assert_select 'input[type=radio][value=female]'
|
||||
assert_select 'label.collection_radio_buttons[for=user_gender_male]', 'Male'
|
||||
|
@ -98,7 +98,7 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|||
store_translations(:en, simple_form: { options: { user: {
|
||||
gender: { male_html: '<strong>Male</strong>', female_html: '<strong>Female</strong>' }
|
||||
} } } ) do
|
||||
with_input_for @user, :gender, :radio_buttons, collection: [:male, :female]
|
||||
with_input_for @user, :gender, :radio_buttons, collection: %i[male female]
|
||||
assert_select 'input[type=radio][value=male]'
|
||||
assert_select 'input[type=radio][value=female]'
|
||||
assert_select 'label[for=user_gender_male] strong', 'Male'
|
||||
|
@ -112,7 +112,7 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|||
store_translations(:en, simple_form: { options: { user: {
|
||||
gender: { male_html: 'Male', female_html: 'Female' }
|
||||
} } } ) do
|
||||
with_input_for @user, :gender, :radio_buttons, collection: [:male, :female]
|
||||
with_input_for @user, :gender, :radio_buttons, collection: %i[male female]
|
||||
assert_select 'input[type=radio][value=male]'
|
||||
assert_select 'input[type=radio][value=female]'
|
||||
assert_select 'label[for=user_gender_male]', 'Male'
|
||||
|
@ -123,7 +123,7 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|||
|
||||
test 'input marks the current radio value by default' do
|
||||
@user.name = "Carlos"
|
||||
with_input_for @user, :name, :radio_buttons, collection: ['Jose', 'Carlos']
|
||||
with_input_for @user, :name, :radio_buttons, collection: %w[Jose Carlos]
|
||||
assert_select 'input[type=radio][value=Carlos][checked=checked]'
|
||||
end
|
||||
|
||||
|
@ -133,7 +133,7 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
test 'input allows using a collection with text/value arrays' do
|
||||
with_input_for @user, :name, :radio_buttons, collection: [['Jose', 'jose'], ['Carlos', 'carlos']]
|
||||
with_input_for @user, :name, :radio_buttons, collection: [%w[Jose jose], %w[Carlos carlos]]
|
||||
assert_select 'input[type=radio][value=jose]'
|
||||
assert_select 'input[type=radio][value=carlos]'
|
||||
assert_select 'label.collection_radio_buttons', 'Jose'
|
||||
|
@ -141,14 +141,14 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
test 'input allows using a collection with a Proc' do
|
||||
with_input_for @user, :name, :radio_buttons, collection: Proc.new { ['Jose', 'Carlos' ] }
|
||||
with_input_for @user, :name, :radio_buttons, collection: proc { %w[Jose Carlos] }
|
||||
assert_select 'label.collection_radio_buttons', 'Jose'
|
||||
assert_select 'label.collection_radio_buttons', 'Carlos'
|
||||
end
|
||||
|
||||
test 'input allows overriding only label method for collections' do
|
||||
with_input_for @user, :name, :radio_buttons,
|
||||
collection: ['Jose', 'Carlos'],
|
||||
collection: %w[Jose Carlos],
|
||||
label_method: :upcase
|
||||
assert_select 'label.collection_radio_buttons', 'JOSE'
|
||||
assert_select 'label.collection_radio_buttons', 'CARLOS'
|
||||
|
@ -156,7 +156,7 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|||
|
||||
test 'input allows overriding only value method for collections' do
|
||||
with_input_for @user, :name, :radio_buttons,
|
||||
collection: ['Jose', 'Carlos'],
|
||||
collection: %w[Jose Carlos],
|
||||
value_method: :upcase
|
||||
assert_select 'input[type=radio][value=JOSE]'
|
||||
assert_select 'input[type=radio][value=CARLOS]'
|
||||
|
@ -164,7 +164,7 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|||
|
||||
test 'input allows overriding label and value method for collections' do
|
||||
with_input_for @user, :name, :radio_buttons,
|
||||
collection: ['Jose', 'Carlos'],
|
||||
collection: %w[Jose Carlos],
|
||||
label_method: :upcase,
|
||||
value_method: :downcase
|
||||
assert_select 'input[type=radio][value=jose]'
|
||||
|
@ -175,9 +175,9 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|||
|
||||
test 'input allows overriding label and value method using a lambda for collections' do
|
||||
with_input_for @user, :name, :radio_buttons,
|
||||
collection: ['Jose', 'Carlos'],
|
||||
label_method: lambda { |i| i.upcase },
|
||||
value_method: lambda { |i| i.downcase }
|
||||
collection: %w[Jose Carlos],
|
||||
label_method: ->(i) { i.upcase },
|
||||
value_method: ->(i) { i.downcase }
|
||||
assert_select 'input[type=radio][value=jose]'
|
||||
assert_select 'input[type=radio][value=carlos]'
|
||||
assert_select 'label.collection_radio_buttons', 'JOSE'
|
||||
|
@ -185,13 +185,13 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
test 'collection input with radio type generates required html attribute' do
|
||||
with_input_for @user, :name, :radio_buttons, collection: ['Jose', 'Carlos']
|
||||
with_input_for @user, :name, :radio_buttons, collection: %w[Jose Carlos]
|
||||
assert_select 'input[type=radio].required'
|
||||
assert_select 'input[type=radio][required]'
|
||||
end
|
||||
|
||||
test 'collection input with radio type generates aria-required html attribute' do
|
||||
with_input_for @user, :name, :radio_buttons, collection: ['Jose', 'Carlos']
|
||||
with_input_for @user, :name, :radio_buttons, collection: %w[Jose Carlos]
|
||||
assert_select 'input[type=radio].required'
|
||||
assert_select 'input[type=radio][aria-required=true]'
|
||||
end
|
||||
|
@ -388,7 +388,7 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|||
|
||||
test 'input radio wrapper class are not included when set to falsey' do
|
||||
swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
|
||||
with_input_for @user, :gender, :radio_buttons, collection: [:male, :female]
|
||||
with_input_for @user, :gender, :radio_buttons, collection: %i[male female]
|
||||
|
||||
assert_no_select 'label.radio'
|
||||
end
|
||||
|
@ -396,7 +396,7 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|||
|
||||
test 'input radio custom wrapper class is included when include input wrapper class is falsey' do
|
||||
swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
|
||||
with_input_for @user, :gender, :radio_buttons, collection: [:male, :female], item_wrapper_class: 'custom'
|
||||
with_input_for @user, :gender, :radio_buttons, collection: %i[male female], item_wrapper_class: 'custom'
|
||||
|
||||
assert_no_select 'label.radio'
|
||||
assert_select 'span.custom'
|
||||
|
@ -406,7 +406,7 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|||
test 'input radio with nested style and namespace uses the right for attribute' do
|
||||
swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
|
||||
with_concat_form_for @user, namespace: :foo do |f|
|
||||
concat f.input :gender, as: :radio_buttons, collection: [:male, :female]
|
||||
concat f.input :gender, as: :radio_buttons, collection: %i[male female]
|
||||
end
|
||||
|
||||
assert_select 'label[for=foo_user_gender_male]'
|
||||
|
@ -417,7 +417,7 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|||
test 'input radio with nested style and index uses the right for attribute' do
|
||||
swap SimpleForm, include_default_input_wrapper_class: false, boolean_style: :nested do
|
||||
with_concat_form_for @user, index: 1 do |f|
|
||||
concat f.input :gender, as: :radio_buttons, collection: [:male, :female]
|
||||
concat f.input :gender, as: :radio_buttons, collection: %i[male female]
|
||||
end
|
||||
|
||||
assert_select 'label[for=user_1_gender_male]'
|
||||
|
|
|
@ -23,7 +23,7 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
test 'input allows overriding collection for select types' do
|
||||
with_input_for @user, :name, :select, collection: ['Jose', 'Carlos']
|
||||
with_input_for @user, :name, :select, collection: %w[Jose Carlos]
|
||||
assert_select 'select.select#user_name'
|
||||
assert_select 'select option', 'Jose'
|
||||
assert_select 'select option', 'Carlos'
|
||||
|
@ -31,9 +31,9 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|||
|
||||
test 'input does automatic collection translation for select types using defaults key' do
|
||||
store_translations(:en, simple_form: { options: { defaults: {
|
||||
gender: { male: 'Male', female: 'Female'}
|
||||
gender: { male: 'Male', female: 'Female' }
|
||||
} } }) do
|
||||
with_input_for @user, :gender, :select, collection: [:male, :female]
|
||||
with_input_for @user, :gender, :select, collection: %i[male female]
|
||||
assert_select 'select.select#user_gender'
|
||||
assert_select 'select option', 'Male'
|
||||
assert_select 'select option', 'Female'
|
||||
|
@ -42,9 +42,9 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|||
|
||||
test 'input does automatic collection translation for select types using specific object key' do
|
||||
store_translations(:en, simple_form: { options: { user: {
|
||||
gender: { male: 'Male', female: 'Female'}
|
||||
gender: { male: 'Male', female: 'Female' }
|
||||
} } }) do
|
||||
with_input_for @user, :gender, :select, collection: [:male, :female]
|
||||
with_input_for @user, :gender, :select, collection: %i[male female]
|
||||
assert_select 'select.select#user_gender'
|
||||
assert_select 'select option', 'Male'
|
||||
assert_select 'select option', 'Female'
|
||||
|
@ -53,7 +53,7 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|||
|
||||
test 'input marks the selected value by default' do
|
||||
@user.name = "Carlos"
|
||||
with_input_for @user, :name, :select, collection: ['Jose', 'Carlos']
|
||||
with_input_for @user, :name, :select, collection: %w[Jose Carlos]
|
||||
assert_select 'select option[selected=selected]', 'Carlos'
|
||||
end
|
||||
|
||||
|
@ -114,7 +114,7 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|||
|
||||
test 'input translates include blank with a default' do
|
||||
store_translations(:en, simple_form: { include_blanks: { defaults: {
|
||||
age: 'Rather not say',
|
||||
age: 'Rather not say'
|
||||
} } }) do
|
||||
with_input_for @user, :age, :select, collection: 18..30, include_blank: :translate
|
||||
assert_select 'select option[value=""]', 'Rather not say'
|
||||
|
@ -183,7 +183,7 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|||
|
||||
test 'input translates prompt with a default' do
|
||||
store_translations(:en, simple_form: { prompts: { defaults: {
|
||||
age: 'Select age:',
|
||||
age: 'Select age:'
|
||||
} } }) do
|
||||
with_input_for @user, :age, :select, collection: 18..30, prompt: :translate
|
||||
assert_select 'select option[value=""]', 'Select age:'
|
||||
|
@ -225,7 +225,7 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
test 'input disables the anothers components when the option is a object' do
|
||||
with_input_for @user, :description, :select, collection: ["Jose", "Carlos"], disabled: true
|
||||
with_input_for @user, :description, :select, collection: %w[Jose Carlos], disabled: true
|
||||
assert_no_select 'select option[value=Jose][disabled=disabled]', 'Jose'
|
||||
assert_no_select 'select option[value=Carlos][disabled=disabled]', 'Carlos'
|
||||
assert_select 'select[disabled=disabled]'
|
||||
|
@ -233,7 +233,7 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
test 'input does not disable the anothers components when the option is a object' do
|
||||
with_input_for @user, :description, :select, collection: ["Jose", "Carlos"], disabled: 'Jose'
|
||||
with_input_for @user, :description, :select, collection: %w[Jose Carlos], disabled: 'Jose'
|
||||
assert_select 'select option[value=Jose][disabled=disabled]', 'Jose'
|
||||
assert_no_select 'select option[value=Carlos][disabled=disabled]', 'Carlos'
|
||||
assert_no_select 'select[disabled=disabled]'
|
||||
|
@ -242,126 +242,126 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|||
|
||||
test 'input allows overriding label and value method using a lambda for collection selects' do
|
||||
with_input_for @user, :name, :select,
|
||||
collection: ['Jose', 'Carlos'],
|
||||
label_method: lambda { |i| i.upcase },
|
||||
value_method: lambda { |i| i.downcase }
|
||||
collection: %w[Jose Carlos],
|
||||
label_method: ->(i) { i.upcase },
|
||||
value_method: ->(i) { i.downcase }
|
||||
assert_select 'select option[value=jose]', "JOSE"
|
||||
assert_select 'select option[value=carlos]', "CARLOS"
|
||||
end
|
||||
|
||||
test 'input allows overriding only label but not value method using a lambda for collection select' do
|
||||
with_input_for @user, :name, :select,
|
||||
collection: ['Jose', 'Carlos'],
|
||||
label_method: lambda { |i| i.upcase }
|
||||
collection: %w[Jose Carlos],
|
||||
label_method: ->(i) { i.upcase }
|
||||
assert_select 'select option[value=Jose]', "JOSE"
|
||||
assert_select 'select option[value=Carlos]', "CARLOS"
|
||||
end
|
||||
|
||||
test 'input allows overriding only value but not label method using a lambda for collection select' do
|
||||
with_input_for @user, :name, :select,
|
||||
collection: ['Jose', 'Carlos'],
|
||||
value_method: lambda { |i| i.downcase }
|
||||
collection: %w[Jose Carlos],
|
||||
value_method: ->(i) { i.downcase }
|
||||
assert_select 'select option[value=jose]', "Jose"
|
||||
assert_select 'select option[value=carlos]', "Carlos"
|
||||
end
|
||||
|
||||
test 'input allows symbols for collections' do
|
||||
with_input_for @user, :name, :select, collection: [:jose, :carlos]
|
||||
with_input_for @user, :name, :select, collection: %i[jose carlos]
|
||||
assert_select 'select.select#user_name'
|
||||
assert_select 'select option[value=jose]', 'jose'
|
||||
assert_select 'select option[value=carlos]', 'carlos'
|
||||
end
|
||||
|
||||
test 'collection input with select type generates required html attribute only with blank option' do
|
||||
with_input_for @user, :name, :select, include_blank: true, collection: ['Jose', 'Carlos']
|
||||
with_input_for @user, :name, :select, include_blank: true, collection: %w[Jose Carlos]
|
||||
assert_select 'select.required'
|
||||
assert_select 'select[required]'
|
||||
end
|
||||
|
||||
test 'collection input with select type generates required html attribute only with blank option or prompt' do
|
||||
with_input_for @user, :name, :select, prompt: 'Name...', collection: ['Jose', 'Carlos']
|
||||
with_input_for @user, :name, :select, prompt: 'Name...', collection: %w[Jose Carlos]
|
||||
assert_select 'select.required'
|
||||
assert_select 'select[required]'
|
||||
end
|
||||
|
||||
test 'collection input with select type does not generate required html attribute without blank option' do
|
||||
with_input_for @user, :name, :select, include_blank: false, collection: ['Jose', 'Carlos']
|
||||
with_input_for @user, :name, :select, include_blank: false, collection: %w[Jose Carlos]
|
||||
assert_select 'select.required'
|
||||
assert_no_select 'select[required]'
|
||||
assert_no_select 'select[aria-required=true]'
|
||||
end
|
||||
|
||||
test 'collection input with select type with multiple attribute generates required html attribute without blank option' do
|
||||
with_input_for @user, :name, :select, include_blank: false, input_html: { multiple: true }, collection: ['Jose', 'Carlos']
|
||||
with_input_for @user, :name, :select, include_blank: false, input_html: { multiple: true }, collection: %w[Jose Carlos]
|
||||
assert_select 'select.required'
|
||||
assert_select 'select[required]'
|
||||
end
|
||||
|
||||
test 'collection input with select type with multiple attribute generates required html attribute with blank option' do
|
||||
with_input_for @user, :name, :select, include_blank: true, input_html: { multiple: true }, collection: ['Jose', 'Carlos']
|
||||
with_input_for @user, :name, :select, include_blank: true, input_html: { multiple: true }, collection: %w[Jose Carlos]
|
||||
assert_select 'select.required'
|
||||
assert_select 'select[required]'
|
||||
end
|
||||
|
||||
test 'with a blank option, a collection input of type select has an aria-required html attribute' do
|
||||
with_input_for @user, :name, :select, include_blank: true, collection: ['Jose', 'Carlos']
|
||||
with_input_for @user, :name, :select, include_blank: true, collection: %w[Jose Carlos]
|
||||
assert_select 'select.required'
|
||||
assert_select 'select[aria-required=true]'
|
||||
end
|
||||
|
||||
test 'without a blank option, a collection input of type select does not have an aria-required html attribute' do
|
||||
with_input_for @user, :name, :select, include_blank: false, collection: ['Jose', 'Carlos']
|
||||
with_input_for @user, :name, :select, include_blank: false, collection: %w[Jose Carlos]
|
||||
assert_select 'select.required'
|
||||
assert_no_select 'select[aria-required]'
|
||||
end
|
||||
|
||||
test 'without a blank option and with a multiple option, a collection input of type select has an aria-required html attribute' do
|
||||
with_input_for @user, :name, :select, include_blank: false, input_html: { multiple: true }, collection: ['Jose', 'Carlos']
|
||||
with_input_for @user, :name, :select, include_blank: false, input_html: { multiple: true }, collection: %w[Jose Carlos]
|
||||
assert_select 'select.required'
|
||||
assert_select 'select[aria-required=true]'
|
||||
end
|
||||
|
||||
test 'with a blank option and a multiple option, a collection input of type select has an aria-required html attribute' do
|
||||
with_input_for @user, :name, :select, include_blank: true, input_html: { multiple: true }, collection: ['Jose', 'Carlos']
|
||||
with_input_for @user, :name, :select, include_blank: true, input_html: { multiple: true }, collection: %w[Jose Carlos]
|
||||
assert_select 'select.required'
|
||||
assert_select 'select[aria-required]'
|
||||
end
|
||||
|
||||
test 'input allows disabled options with a lambda for collection select' do
|
||||
with_input_for @user, :name, :select, collection: ["Carlos", "Antonio"],
|
||||
disabled: lambda { |x| x == "Carlos" }
|
||||
with_input_for @user, :name, :select, collection: %w[Carlos Antonio],
|
||||
disabled: ->(x) { x == "Carlos" }
|
||||
assert_select 'select option[value=Carlos][disabled=disabled]', 'Carlos'
|
||||
assert_select 'select option[value=Antonio]', 'Antonio'
|
||||
assert_no_select 'select option[value=Antonio][disabled]'
|
||||
end
|
||||
|
||||
test 'input allows disabled and label method with lambdas for collection select' do
|
||||
with_input_for @user, :name, :select, collection: ["Carlos", "Antonio"],
|
||||
disabled: lambda { |x| x == "Carlos" }, label_method: lambda { |x| x.upcase }
|
||||
with_input_for @user, :name, :select, collection: %w[Carlos Antonio],
|
||||
disabled: ->(x) { x == "Carlos" }, label_method: ->(x) { x.upcase }
|
||||
assert_select 'select option[value=Carlos][disabled=disabled]', 'CARLOS'
|
||||
assert_select 'select option[value=Antonio]', 'ANTONIO'
|
||||
assert_no_select 'select option[value=Antonio][disabled]'
|
||||
end
|
||||
|
||||
test 'input allows a non lambda disabled option with lambda label method for collections' do
|
||||
with_input_for @user, :name, :select, collection: ["Carlos", "Antonio"],
|
||||
disabled: "Carlos", label_method: lambda { |x| x.upcase }
|
||||
with_input_for @user, :name, :select, collection: %w[Carlos Antonio],
|
||||
disabled: "Carlos", label_method: ->(x) { x.upcase }
|
||||
assert_select 'select option[value=Carlos][disabled=disabled]', 'CARLOS'
|
||||
assert_select 'select option[value=Antonio]', 'ANTONIO'
|
||||
assert_no_select 'select option[value=Antonio][disabled]'
|
||||
end
|
||||
|
||||
test 'input allows selected and label method with lambdas for collection select' do
|
||||
with_input_for @user, :name, :select, collection: ["Carlos", "Antonio"],
|
||||
selected: lambda { |x| x == "Carlos" }, label_method: lambda { |x| x.upcase }
|
||||
with_input_for @user, :name, :select, collection: %w[Carlos Antonio],
|
||||
selected: ->(x) { x == "Carlos" }, label_method: ->(x) { x.upcase }
|
||||
assert_select 'select option[value=Carlos][selected=selected]', 'CARLOS'
|
||||
assert_select 'select option[value=Antonio]', 'ANTONIO'
|
||||
assert_no_select 'select option[value=Antonio][selected]'
|
||||
end
|
||||
|
||||
test 'input allows a non lambda selected option with lambda label method for collection select' do
|
||||
with_input_for @user, :name, :select, collection: ["Carlos", "Antonio"],
|
||||
selected: "Carlos", label_method: lambda { |x| x.upcase }
|
||||
with_input_for @user, :name, :select, collection: %w[Carlos Antonio],
|
||||
selected: "Carlos", label_method: ->(x) { x.upcase }
|
||||
assert_select 'select option[value=Carlos][selected=selected]', 'CARLOS'
|
||||
assert_select 'select option[value=Antonio]', 'ANTONIO'
|
||||
assert_no_select 'select option[value=Antonio][selected]'
|
||||
|
@ -369,8 +369,8 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|||
|
||||
test 'input does not override default selection through attribute value with label method as lambda for collection select' do
|
||||
@user.name = "Carlos"
|
||||
with_input_for @user, :name, :select, collection: ["Carlos", "Antonio"],
|
||||
label_method: lambda { |x| x.upcase }
|
||||
with_input_for @user, :name, :select, collection: %w[Carlos Antonio],
|
||||
label_method: ->(x) { x.upcase }
|
||||
assert_select 'select option[value=Carlos][selected=selected]', 'CARLOS'
|
||||
assert_select 'select option[value=Antonio]', 'ANTONIO'
|
||||
assert_no_select 'select option[value=Antonio][selected]'
|
||||
|
|
|
@ -151,26 +151,26 @@ class DateTimeInputWithoutHtml5Test < ActionView::TestCase
|
|||
end
|
||||
|
||||
test 'label uses i18n to get target for date input type' do
|
||||
store_translations(:en, date: { order: ['month', 'day', 'year'] }) do
|
||||
store_translations(:en, date: { order: %w[month day year] }) do
|
||||
with_input_for :project, :created_at, :date, html5: false
|
||||
assert_select 'label[for=project_created_at_2i]'
|
||||
end
|
||||
end
|
||||
|
||||
test 'label uses i18n to get target for datetime input type' do
|
||||
store_translations(:en, date: { order: ['month', 'day', 'year'] }) do
|
||||
store_translations(:en, date: { order: %w[month day year] }) do
|
||||
with_input_for :project, :created_at, :datetime, html5: false
|
||||
assert_select 'label[for=project_created_at_2i]'
|
||||
end
|
||||
end
|
||||
|
||||
test 'label uses order to get target when date input type' do
|
||||
with_input_for :project, :created_at, :date, order: ['month', 'year', 'day'], html5: false
|
||||
with_input_for :project, :created_at, :date, order: %w[month year day], html5: false
|
||||
assert_select 'label[for=project_created_at_2i]'
|
||||
end
|
||||
|
||||
test 'label uses order to get target when datetime input type' do
|
||||
with_input_for :project, :created_at, :datetime, order: ['month', 'year', 'day'], html5: false
|
||||
with_input_for :project, :created_at, :datetime, order: %w[month year day], html5: false
|
||||
assert_select 'label[for=project_created_at_2i]'
|
||||
end
|
||||
|
||||
|
|
|
@ -120,12 +120,12 @@ class InputTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
test 'input as select with collection is generated properly when object is not present' do
|
||||
with_input_for :project, :name, :select, collection: ['Jose', 'Carlos']
|
||||
with_input_for :project, :name, :select, collection: %w[Jose Carlos]
|
||||
assert_select 'select.select#project_name'
|
||||
end
|
||||
|
||||
test 'input does not generate empty css class' do
|
||||
swap SimpleForm, generate_additional_classes_for: [:wrapper, :label] do
|
||||
swap SimpleForm, generate_additional_classes_for: %i[wrapper label] do
|
||||
with_input_for :project, :name, :string
|
||||
assert_no_select 'input#project_name[class]'
|
||||
end
|
||||
|
|
|
@ -5,7 +5,7 @@ require 'test_helper'
|
|||
class GroupedCollectionSelectInputTest < ActionView::TestCase
|
||||
test 'grouped collection accepts array collection form' do
|
||||
with_input_for @user, :tag_ids, :grouped_select,
|
||||
collection: [['Authors', ['Jose', 'Carlos']], ['General', ['Bob', 'John']]],
|
||||
collection: [['Authors', %w[Jose Carlos]], ['General', %w[Bob John]]],
|
||||
group_method: :last
|
||||
|
||||
assert_select 'select.grouped_select#user_tag_ids' do
|
||||
|
@ -32,7 +32,7 @@ class GroupedCollectionSelectInputTest < ActionView::TestCase
|
|||
|
||||
test 'grouped collection accepts proc as collection' do
|
||||
with_input_for @user, :tag_ids, :grouped_select,
|
||||
collection: Proc.new { [['Authors', ['Jose', 'Carlos']], ['General', ['Bob', 'John']]] },
|
||||
collection: proc { [['Authors', %w[Jose Carlos]], ['General', %w[Bob John]]] },
|
||||
group_method: :last
|
||||
|
||||
assert_select 'select.grouped_select#user_tag_ids' do
|
||||
|
@ -50,7 +50,7 @@ class GroupedCollectionSelectInputTest < ActionView::TestCase
|
|||
|
||||
test 'grouped collection accepts hash collection form' do
|
||||
with_input_for @user, :tag_ids, :grouped_select,
|
||||
collection: { 'Authors' => ['Jose', 'Carlos'], 'General' => ['Bob', 'John'] },
|
||||
collection: { Authors: %w[Jose Carlos], General: %w[Bob John] },
|
||||
group_method: :last
|
||||
|
||||
assert_select 'select.grouped_select#user_tag_ids' do
|
||||
|
@ -68,7 +68,7 @@ class GroupedCollectionSelectInputTest < ActionView::TestCase
|
|||
|
||||
test 'grouped collection accepts group_label_method option' do
|
||||
with_input_for @user, :tag_ids, :grouped_select,
|
||||
collection: { ['Jose', 'Carlos'] => 'Authors' },
|
||||
collection: { %w[Jose Carlos] => 'Authors' },
|
||||
group_method: :first,
|
||||
group_label_method: :last
|
||||
|
||||
|
@ -81,7 +81,7 @@ class GroupedCollectionSelectInputTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
test 'grouped collection finds default label methods on the group objects' do
|
||||
option_list = ['Jose', 'Carlos']
|
||||
option_list = %w[Jose Carlos]
|
||||
|
||||
GroupedClass = Struct.new(:to_label, :options)
|
||||
group = GroupedClass.new("Authors", option_list)
|
||||
|
@ -118,7 +118,7 @@ class GroupedCollectionSelectInputTest < ActionView::TestCase
|
|||
|
||||
test 'grouped collection accepts label and value methods options' do
|
||||
with_input_for @user, :tag_ids, :grouped_select,
|
||||
collection: { 'Authors' => ['Jose', 'Carlos'] },
|
||||
collection: { Authors: %w[Jose Carlos] },
|
||||
group_method: :last,
|
||||
label_method: :upcase,
|
||||
value_method: :downcase
|
||||
|
@ -133,10 +133,10 @@ class GroupedCollectionSelectInputTest < ActionView::TestCase
|
|||
|
||||
test 'grouped collection allows overriding label and value methods using a lambda' do
|
||||
with_input_for @user, :tag_ids, :grouped_select,
|
||||
collection: { 'Authors' => ['Jose', 'Carlos'] },
|
||||
collection: { Authors: %w[Jose Carlos] },
|
||||
group_method: :last,
|
||||
label_method: lambda { |i| i.upcase },
|
||||
value_method: lambda { |i| i.downcase }
|
||||
label_method: ->(i) { i.upcase },
|
||||
value_method: ->(i) { i.downcase }
|
||||
|
||||
assert_select 'select.grouped_select#user_tag_ids' do
|
||||
assert_select 'optgroup[label=Authors]' do
|
||||
|
@ -149,7 +149,7 @@ class GroupedCollectionSelectInputTest < ActionView::TestCase
|
|||
test 'grouped collection with associations' do
|
||||
tag_groups = [
|
||||
TagGroup.new(1, "Group of Tags", [Tag.new(1, "Tag 1"), Tag.new(2, "Tag 2")]),
|
||||
TagGroup.new(2, "Other group", [Tag.new(3, "Tag 3"), Tag.new(4,"Tag 4")])
|
||||
TagGroup.new(2, "Other group", [Tag.new(3, "Tag 3"), Tag.new(4, "Tag 4")])
|
||||
]
|
||||
|
||||
with_input_for @user, :tag_ids, :grouped_select,
|
||||
|
|
|
@ -157,7 +157,7 @@ class NumericInputTest < ActionView::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
[:integer, :float, :decimal].each do |type|
|
||||
%i[integer float decimal].each do |type|
|
||||
test "#{type} input infers min value from attributes with greater than or equal validation" do
|
||||
with_input_for @validating_user, :age, type
|
||||
assert_select 'input[min="18"]'
|
||||
|
|
|
@ -133,7 +133,7 @@ class StringInputTest < ActionView::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
[:email, :url, :search, :tel].each do |type|
|
||||
%i[email url search tel].each do |type|
|
||||
test "input allows type #{type}" do
|
||||
with_input_for @user, :name, type
|
||||
assert_select "input.string.#{type}"
|
||||
|
|
|
@ -182,7 +182,7 @@ module MiscHelpers
|
|||
end
|
||||
|
||||
def custom_wrapper_with_label_text
|
||||
SimpleForm.build :label_text => proc { |label, required| "**#{label}**" } do |b|
|
||||
SimpleForm.build label_text: proc { |label, required| "**#{label}**" } do |b|
|
||||
b.use :label_input
|
||||
end
|
||||
end
|
||||
|
|
|
@ -21,7 +21,10 @@ class MockController
|
|||
def polymorphic_mappings(*); {}; end
|
||||
|
||||
def hash_for_user_path(*); end
|
||||
|
||||
def hash_for_validating_user_path(*); end
|
||||
|
||||
def hash_for_other_validating_user_path(*); end
|
||||
|
||||
def hash_for_users_path(*); end
|
||||
end
|
||||
|
|
|
@ -216,9 +216,9 @@ class User
|
|||
when :first_company
|
||||
Association.new(Company, association, :has_one, nil, {})
|
||||
when :special_company
|
||||
Association.new(Company, association, :belongs_to, nil, { conditions: { id: 1 } })
|
||||
Association.new(Company, association, :belongs_to, nil, conditions: { id: 1 })
|
||||
when :extra_special_company
|
||||
Association.new(Company, association, :belongs_to, nil, { conditions: proc { { id: self.id } } })
|
||||
Association.new(Company, association, :belongs_to, nil, conditions: proc { { id: self.id } })
|
||||
when :pictures
|
||||
Association.new(Picture, association, :has_many, nil, {})
|
||||
when :special_pictures
|
||||
|
@ -250,8 +250,8 @@ class ValidatingUser < User
|
|||
include ActiveModel::Validations
|
||||
validates :name, presence: true
|
||||
validates :company, presence: true
|
||||
validates :age, presence: true, if: Proc.new { |user| user.name }
|
||||
validates :amount, presence: true, unless: Proc.new { |user| user.age }
|
||||
validates :age, presence: true, if: proc { |user| user.name }
|
||||
validates :amount, presence: true, unless: proc { |user| user.age }
|
||||
|
||||
validates :action, presence: true, on: :create
|
||||
validates :credit_limit, presence: true, on: :save
|
||||
|
@ -272,7 +272,7 @@ class ValidatingUser < User
|
|||
validates_length_of :name, maximum: 25, minimum: 5
|
||||
validates_length_of :description, in: 15..50
|
||||
if ActionPack::VERSION::STRING < '5'
|
||||
validates_length_of :action, maximum: 10, tokenizer: lambda { |str| str.scan(/\w+/) }
|
||||
validates_length_of :action, maximum: 10, tokenizer: ->(str) { str.scan(/\w+/) }
|
||||
end
|
||||
validates_length_of :home_picture, is: 12
|
||||
|
||||
|
@ -300,16 +300,16 @@ class OtherValidatingUser < User
|
|||
less_than: 100,
|
||||
only_integer: true
|
||||
validates_numericality_of :amount,
|
||||
greater_than: Proc.new { |user| user.age },
|
||||
less_than: Proc.new { |user| user.age + 100 },
|
||||
greater_than: proc { |user| user.age },
|
||||
less_than: proc { |user| user.age + 100 },
|
||||
only_integer: true
|
||||
validates_numericality_of :attempts,
|
||||
greater_than_or_equal_to: Proc.new { |user| user.age },
|
||||
less_than_or_equal_to: Proc.new { |user| user.age + 100 },
|
||||
greater_than_or_equal_to: proc { |user| user.age },
|
||||
less_than_or_equal_to: proc { |user| user.age + 100 },
|
||||
only_integer: true
|
||||
|
||||
validates_format_of :country, with: /\w+/
|
||||
validates_format_of :name, with: Proc.new { /\w+/ }
|
||||
validates_format_of :name, with: proc { /\w+/ }
|
||||
validates_format_of :description, without: /\d+/
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue