1
0
Fork 0
mirror of https://github.com/heartcombo/simple_form.git synced 2022-11-09 12:19:26 -05:00

Stylistic improvements

This commit is contained in:
Carlos Antonio da Silva 2013-04-13 19:50:14 -03:00
parent b2046da174
commit 1c6ca9e1f7
6 changed files with 32 additions and 32 deletions

View file

@ -299,7 +299,7 @@ class BuilderTest < ActionView::TestCase
test "collection check box checks the correct value to local variables" do
user = User.new
user.tag_ids = [1, 3]
collection = (1..3).map{|i| [i, "Tag #{i}"] }
collection = (1..3).map { |i| [i, "Tag #{i}"] }
with_collection_check_boxes user, :tag_ids, collection, :first, :last
assert_select 'form input[type=checkbox][value=1][checked=checked]'
@ -308,7 +308,7 @@ class BuilderTest < ActionView::TestCase
end
test "collection check box accepts selected values as :checked option" do
collection = (1..3).map{|i| [i, "Tag #{i}"] }
collection = (1..3).map { |i| [i, "Tag #{i}"] }
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, checked: [1, 3]
assert_select 'form input[type=checkbox][value=1][checked=checked]'
@ -317,7 +317,7 @@ class BuilderTest < ActionView::TestCase
end
test "collection check boxes accepts selected string values as :checked option" do
collection = (1..3).map{|i| [i, "Category #{i}"] }
collection = (1..3).map { |i| [i, "Category #{i}"] }
with_collection_check_boxes :user, :category_ids, collection, :first, :last, checked: ['1', '3']
assert_select 'input[type=checkbox][value=1][checked=checked]'
@ -326,7 +326,7 @@ class BuilderTest < ActionView::TestCase
end
test "collection check box accepts a single checked value" do
collection = (1..3).map{|i| [i, "Tag #{i}"] }
collection = (1..3).map { |i| [i, "Tag #{i}"] }
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, checked: 3
assert_select 'form input[type=checkbox][value=3][checked=checked]'
@ -335,7 +335,7 @@ class BuilderTest < ActionView::TestCase
end
test "collection check box accepts selected values as :checked option and override the model values" do
collection = (1..3).map{|i| [i, "Tag #{i}"] }
collection = (1..3).map { |i| [i, "Tag #{i}"] }
@user.tag_ids = [2]
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, checked: [1, 3]
@ -345,7 +345,7 @@ class BuilderTest < ActionView::TestCase
end
test "collection check box accepts multiple disabled items" do
collection = (1..3).map{|i| [i, "Tag #{i}"] }
collection = (1..3).map { |i| [i, "Tag #{i}"] }
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, disabled: [1, 3]
assert_select 'form input[type=checkbox][value=1][disabled=disabled]'
@ -354,7 +354,7 @@ class BuilderTest < ActionView::TestCase
end
test "collection check box accepts single disable item" do
collection = (1..3).map{|i| [i, "Tag #{i}"] }
collection = (1..3).map { |i| [i, "Tag #{i}"] }
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, disabled: 1
assert_select 'form input[type=checkbox][value=1][disabled=disabled]'
@ -363,7 +363,7 @@ class BuilderTest < ActionView::TestCase
end
test "collection check box accepts a proc to disabled items" do
collection = (1..3).map{|i| [i, "Tag #{i}"] }
collection = (1..3).map { |i| [i, "Tag #{i}"] }
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, disabled: proc { |i| i.first == 1 }
assert_select 'form input[type=checkbox][value=1][disabled=disabled]'

View file

@ -94,7 +94,7 @@ class HintTest < ActionView::TestCase
test 'hint should use i18n under defaults namespace to lookup translation' do
store_translations(:en, simple_form: {
hints: {defaults: {name: 'Content of this input will be downcased...' } }
hints: { defaults: { name: 'Content of this input will be downcased...' } }
}) do
with_hint_for @user, :name
assert_select 'span.hint', 'Content of this input will be downcased...'

View file

@ -18,13 +18,13 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
end
test 'collection input with check_boxes type should not generate required html attribute' do
with_input_for @user, :name, :check_boxes, collection: ['Jose' , 'Carlos']
with_input_for @user, :name, :check_boxes, collection: ['Jose', 'Carlos']
assert_select 'input.required'
assert_no_select 'input[required]'
end
test 'collection input with check_boxes type should 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: ['Jose', 'Carlos']
assert_select 'input.required'
assert_no_select 'input[aria-required]'
end

View file

@ -98,7 +98,7 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
test 'input should allow overriding only label method for collections' do
with_input_for @user, :name, :radio_buttons,
collection: ['Jose' , 'Carlos'],
collection: ['Jose', 'Carlos'],
label_method: :upcase
assert_select 'label.collection_radio_buttons', 'JOSE'
assert_select 'label.collection_radio_buttons', 'CARLOS'
@ -106,7 +106,7 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
test 'input should allow overriding only value method for collections' do
with_input_for @user, :name, :radio_buttons,
collection: ['Jose' , 'Carlos'],
collection: ['Jose', 'Carlos'],
value_method: :upcase
assert_select 'input[type=radio][value=JOSE]'
assert_select 'input[type=radio][value=CARLOS]'
@ -114,7 +114,7 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
test 'input should allow overriding label and value method for collections' do
with_input_for @user, :name, :radio_buttons,
collection: ['Jose' , 'Carlos'],
collection: ['Jose', 'Carlos'],
label_method: :upcase,
value_method: :downcase
assert_select 'input[type=radio][value=jose]'
@ -125,7 +125,7 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
test 'input should allow overriding label and value method using a lambda for collections' do
with_input_for @user, :name, :radio_buttons,
collection: ['Jose' , 'Carlos'],
collection: ['Jose', 'Carlos'],
label_method: lambda { |i| i.upcase },
value_method: lambda { |i| i.downcase }
assert_select 'input[type=radio][value=jose]'
@ -135,13 +135,13 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
end
test 'collection input with radio type should generate required html attribute' do
with_input_for @user, :name, :radio_buttons, collection: ['Jose' , 'Carlos']
with_input_for @user, :name, :radio_buttons, collection: ['Jose', 'Carlos']
assert_select 'input[type=radio].required'
assert_select 'input[type=radio][required]'
end
test 'collection input with radio type should generate aria-required html attribute' do
with_input_for @user, :name, :radio_buttons, collection: ['Jose' , 'Carlos']
with_input_for @user, :name, :radio_buttons, collection: ['Jose', 'Carlos']
assert_select 'input[type=radio].required'
assert_select 'input[type=radio][aria-required=true]'
end

View file

@ -136,7 +136,7 @@ class CollectionSelectInputTest < ActionView::TestCase
test 'input should allow overriding label and value method using a lambda for collection selects' do
with_input_for @user, :name, :select,
collection: ['Jose' , 'Carlos'],
collection: ['Jose', 'Carlos'],
label_method: lambda { |i| i.upcase },
value_method: lambda { |i| i.downcase }
assert_select 'select option[value=jose]', "JOSE"
@ -145,7 +145,7 @@ class CollectionSelectInputTest < ActionView::TestCase
test 'input should allow overriding only label but not value method using a lambda for collection select' do
with_input_for @user, :name, :select,
collection: ['Jose' , 'Carlos'],
collection: ['Jose', 'Carlos'],
label_method: lambda { |i| i.upcase }
assert_select 'select option[value=Jose]', "JOSE"
assert_select 'select option[value=Carlos]', "CARLOS"
@ -153,7 +153,7 @@ class CollectionSelectInputTest < ActionView::TestCase
test 'input should allow overriding only value but not label method using a lambda for collection select' do
with_input_for @user, :name, :select,
collection: ['Jose' , 'Carlos'],
collection: ['Jose', 'Carlos'],
value_method: lambda { |i| i.downcase }
assert_select 'select option[value=jose]', "Jose"
assert_select 'select option[value=carlos]', "Carlos"
@ -167,50 +167,50 @@ class CollectionSelectInputTest < ActionView::TestCase
end
test 'collection input with select type should generate 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: ['Jose', 'Carlos']
assert_select 'select.required'
assert_select 'select[required]'
end
test 'collection input with select type should 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: ['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 should generate 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: ['Jose', 'Carlos']
assert_select 'select.required'
assert_select 'select[required]'
end
test 'collection input with select type with multiple attribute should generate 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: ['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: ['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: ['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: ['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: ['Jose', 'Carlos']
assert_select 'select.required'
assert_select 'select[aria-required]'
end

View file

@ -12,7 +12,7 @@ class Company < Struct.new(:id, :name)
include ActiveModel::Conversion
def self.all(options={})
all = (1..3).map{|i| Company.new(i, "Company #{i}")}
all = (1..3).map { |i| Company.new(i, "Company #{i}") }
return [all.first] if options[:conditions].present?
return [all.last] if options[:order].present?
return all[0..1] if options[:include].present?
@ -31,7 +31,7 @@ end
class Tag < Company
def self.all(options={})
(1..3).map{|i| Tag.new(i, "Tag #{i}")}
(1..3).map { |i| Tag.new(i, "Tag #{i}") }
end
end
@ -187,11 +187,11 @@ class OtherValidatingUser < User
only_integer: true
validates_numericality_of :amount,
greater_than: Proc.new { |user| user.age },
less_than: Proc.new { |user| user.age + 100},
less_than: Proc.new { |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},
less_than_or_equal_to: Proc.new { |user| user.age + 100 },
only_integer: true
validates_format_of :country, with: /\w+/