Move label I18n test with defaults for associations to labels test file
Also reorganize some hashes and spaces.
This commit is contained in:
parent
f3d7ba7c12
commit
120c364f7d
|
@ -38,7 +38,7 @@ class IsolatedLabelTest < ActionView::TestCase
|
||||||
@controller.action_name = "new"
|
@controller.action_name = "new"
|
||||||
store_translations(:en, :simple_form => { :labels => { :user => {
|
store_translations(:en, :simple_form => { :labels => { :user => {
|
||||||
:new => { :description => 'Nova descrição' }
|
:new => { :description => 'Nova descrição' }
|
||||||
} } } ) do
|
} } }) do
|
||||||
with_label_for @user, :description, :text
|
with_label_for @user, :description, :text
|
||||||
assert_select 'label[for=user_description]', /Nova descrição/
|
assert_select 'label[for=user_description]', /Nova descrição/
|
||||||
end
|
end
|
||||||
|
@ -48,7 +48,7 @@ class IsolatedLabelTest < ActionView::TestCase
|
||||||
@controller.action_name = "create"
|
@controller.action_name = "create"
|
||||||
store_translations(:en, :simple_form => { :labels => { :user => {
|
store_translations(:en, :simple_form => { :labels => { :user => {
|
||||||
:new => { :description => 'Nova descrição' }
|
:new => { :description => 'Nova descrição' }
|
||||||
} } } ) do
|
} } }) do
|
||||||
with_label_for @user, :description, :text
|
with_label_for @user, :description, :text
|
||||||
assert_select 'label[for=user_description]', /Nova descrição/
|
assert_select 'label[for=user_description]', /Nova descrição/
|
||||||
end
|
end
|
||||||
|
@ -66,43 +66,53 @@ class IsolatedLabelTest < ActionView::TestCase
|
||||||
test 'label should use i18n based on model and attribute to lookup translation' do
|
test 'label should use i18n based on model and attribute to lookup translation' do
|
||||||
store_translations(:en, :simple_form => { :labels => { :user => {
|
store_translations(:en, :simple_form => { :labels => { :user => {
|
||||||
:description => 'Descrição'
|
:description => 'Descrição'
|
||||||
} } } ) do
|
} } }) do
|
||||||
with_label_for @user, :description, :text
|
with_label_for @user, :description, :text
|
||||||
assert_select 'label[for=user_description]', /Descrição/
|
assert_select 'label[for=user_description]', /Descrição/
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'input should use i18n under defaults to lookup translation' do
|
test 'label should use i18n under defaults to lookup translation' do
|
||||||
store_translations(:en, :simple_form => { :labels => { :defaults => {:age => 'Idade'} } } ) do
|
store_translations(:en, :simple_form => { :labels => { :defaults => { :age => 'Idade' } } }) do
|
||||||
with_label_for @user, :age, :integer
|
with_label_for @user, :age, :integer
|
||||||
assert_select 'label[for=user_age]', /Idade/
|
assert_select 'label[for=user_age]', /Idade/
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'input should not use i18n label if translate is false' do
|
test 'label should not use i18n label if translate is false' do
|
||||||
swap SimpleForm, :translate_labels => false do
|
swap SimpleForm, :translate_labels => false do
|
||||||
store_translations(:en, :simple_form => { :labels => { :defaults => {:age => 'Idade'} } } ) do
|
store_translations(:en, :simple_form => { :labels => { :defaults => { :age => 'Idade' } } }) do
|
||||||
with_label_for @user, :age, :integer
|
with_label_for @user, :age, :integer
|
||||||
assert_select 'label[for=user_age]', /Age/
|
assert_select 'label[for=user_age]', /Age/
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'label should use i18n with lookup for association name' do
|
test 'label uses i18n with lookup for association name' do
|
||||||
store_translations(:en, :simple_form => { :labels => {
|
store_translations(:en, :simple_form => { :labels => {
|
||||||
:user => { :company => 'My company!' }
|
:user => { :company => 'My company!' }
|
||||||
} } ) do
|
} }) do
|
||||||
with_label_for @user, :company_id, :string, :setup_association => true
|
with_label_for @user, :company_id, :string, :setup_association => true
|
||||||
assert_select 'label[for=user_company_id]', /My company!/
|
assert_select 'label[for=user_company_id]', /My company!/
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test 'label uses i18n under defaults namespace to lookup for association name' do
|
||||||
|
store_translations(:en, :simple_form => { :labels => {
|
||||||
|
:defaults => { :company => 'Plataformatec' }
|
||||||
|
} }) do
|
||||||
|
with_label_for @user, :company, :string, :setup_association => true
|
||||||
|
|
||||||
|
assert_select 'form label', /Plataformatec/
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
test 'label should do correct i18n lookup for nested models with nested translation' do
|
test 'label should do correct i18n lookup for nested models with nested translation' do
|
||||||
@user.company = Company.new(1, 'Empresa')
|
@user.company = Company.new(1, 'Empresa')
|
||||||
|
|
||||||
store_translations(:en, :simple_form => { :labels => {
|
store_translations(:en, :simple_form => { :labels => {
|
||||||
:user => { :name => 'Usuario', :company => { :name => 'Nome da empresa' } }
|
:user => { :name => 'Usuario', :company => { :name => 'Nome da empresa' } }
|
||||||
} } ) do
|
} }) do
|
||||||
with_concat_form_for @user do |f|
|
with_concat_form_for @user do |f|
|
||||||
concat f.input :name
|
concat f.input :name
|
||||||
concat(f.simple_fields_for(:company) do |company_form|
|
concat(f.simple_fields_for(:company) do |company_form|
|
||||||
|
@ -121,7 +131,7 @@ class IsolatedLabelTest < ActionView::TestCase
|
||||||
store_translations(:en, :simple_form => { :labels => {
|
store_translations(:en, :simple_form => { :labels => {
|
||||||
:user => { :name => 'Usuario' },
|
:user => { :name => 'Usuario' },
|
||||||
:company => { :name => 'Nome da empresa' }
|
:company => { :name => 'Nome da empresa' }
|
||||||
} } ) do
|
} }) do
|
||||||
with_concat_form_for @user do |f|
|
with_concat_form_for @user do |f|
|
||||||
concat f.input :name
|
concat f.input :name
|
||||||
concat(f.simple_fields_for(:company) do |company_form|
|
concat(f.simple_fields_for(:company) do |company_form|
|
||||||
|
@ -140,7 +150,7 @@ class IsolatedLabelTest < ActionView::TestCase
|
||||||
store_translations(:en, :simple_form => { :labels => {
|
store_translations(:en, :simple_form => { :labels => {
|
||||||
:user => { :name => 'Usuario' },
|
:user => { :name => 'Usuario' },
|
||||||
:tags => { :name => 'Nome da empresa' }
|
:tags => { :name => 'Nome da empresa' }
|
||||||
} } ) do
|
} }) do
|
||||||
with_concat_form_for @user do |f|
|
with_concat_form_for @user do |f|
|
||||||
concat f.input :name
|
concat f.input :name
|
||||||
concat(f.simple_fields_for(:tags, :child_index => "new_index") do |tags_form|
|
concat(f.simple_fields_for(:tags, :child_index => "new_index") do |tags_form|
|
||||||
|
@ -232,21 +242,21 @@ class IsolatedLabelTest < ActionView::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'label should use i18n to find required text' do
|
test 'label should use i18n to find required text' do
|
||||||
store_translations(:en, :simple_form => { :required => { :text => 'campo requerido' }}) do
|
store_translations(:en, :simple_form => { :required => { :text => 'campo requerido' } }) do
|
||||||
with_label_for @user, :name, :string
|
with_label_for @user, :name, :string
|
||||||
assert_select 'form label abbr[title=campo requerido]', '*'
|
assert_select 'form label abbr[title=campo requerido]', '*'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'label should use i18n to find required mark' do
|
test 'label should use i18n to find required mark' do
|
||||||
store_translations(:en, :simple_form => { :required => { :mark => '*-*' }}) do
|
store_translations(:en, :simple_form => { :required => { :mark => '*-*' } }) do
|
||||||
with_label_for @user, :name, :string
|
with_label_for @user, :name, :string
|
||||||
assert_select 'form label abbr', '*-*'
|
assert_select 'form label abbr', '*-*'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'label should use i18n to find required string tag' do
|
test 'label should use i18n to find required string tag' do
|
||||||
store_translations(:en, :simple_form => { :required => { :html => '<span class="required" title="requerido">*</span>' }}) do
|
store_translations(:en, :simple_form => { :required => { :html => '<span class="required" title="requerido">*</span>' } }) do
|
||||||
with_label_for @user, :name, :string
|
with_label_for @user, :name, :string
|
||||||
assert_no_select 'form label abbr'
|
assert_no_select 'form label abbr'
|
||||||
assert_select 'form label span.required[title=requerido]', '*'
|
assert_select 'form label span.required[title=requerido]', '*'
|
||||||
|
@ -264,7 +274,7 @@ class IsolatedLabelTest < ActionView::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'label should allow overwriting of for attribute with input_html not containing id' do
|
test 'label should allow overwriting of for attribute with input_html not containing id' do
|
||||||
with_label_for @user, :name, :string, :label_html => { :for => 'my_new_id' }, :input_html => {:class => 'foo'}
|
with_label_for @user, :name, :string, :label_html => { :for => 'my_new_id' }, :input_html => { :class => 'foo' }
|
||||||
assert_select 'label[for=my_new_id]'
|
assert_select 'label[for=my_new_id]'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -286,7 +296,7 @@ class IsolatedLabelTest < ActionView::TestCase
|
||||||
test 'label should use i18n properly when object is not present' do
|
test 'label should use i18n properly when object is not present' do
|
||||||
store_translations(:en, :simple_form => { :labels => {
|
store_translations(:en, :simple_form => { :labels => {
|
||||||
:project => { :name => 'Nome' }
|
:project => { :name => 'Nome' }
|
||||||
} } ) do
|
} }) do
|
||||||
with_label_for :project, :name, :string
|
with_label_for :project, :name, :string
|
||||||
assert_select 'label[for=project_name]', /Nome/
|
assert_select 'label[for=project_name]', /Nome/
|
||||||
end
|
end
|
||||||
|
|
|
@ -183,14 +183,4 @@ class AssociationTest < ActionView::TestCase
|
||||||
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)
|
options)
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'builder association uses i18n under defaults namespace to lookup translation' do
|
|
||||||
store_translations(:en, :simple_form => {
|
|
||||||
:labels => {:defaults => {:company => 'Plataformatec' } }
|
|
||||||
}) do
|
|
||||||
with_association_for @user, :company, :required => false
|
|
||||||
|
|
||||||
assert_select 'form label', 'Plataformatec'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue