Only translate prompts and include_blank if value is :translate

This commit is contained in:
Rafael Mendonça França 2014-04-03 15:22:09 -03:00
parent 0b4d83082a
commit 5ce1d04362
2 changed files with 13 additions and 39 deletions

View File

@ -107,18 +107,12 @@ module SimpleForm
end
def translate_option(options, key)
return unless options[key].is_a? Symbol
if options[key] == :translate
namespace = key.to_s.pluralize
namespace = key.to_s.pluralize
options[key] = case options[key]
when :translate, :t
translate(namespace, true)
else
I18n.t(options[key], scope: :"simple_form.#{namespace}")
options[key] = translate(namespace, true)
end
end
end
end
end

View File

@ -105,27 +105,17 @@ class CollectionSelectInputTest < ActionView::TestCase
test 'input should translate include blank when set to :translate' do
store_translations(:en, simple_form: { include_blanks: { user: {
age: 'Rather not say'
} } } ) do
} } }) do
with_input_for @user, :age, :select, collection: 18..30, include_blank: :translate
assert_select 'select option[value=]', 'Rather not say'
end
end
test 'input should translate include blank when set to :t' do
store_translations(:en, simple_form: { include_blanks: { user: {
age: 'Rather not say'
} } } ) do
with_input_for @user, :age, :select, collection: 18..30, include_blank: :t
assert_select 'select option[value=]', 'Rather not say'
end
end
test 'input should translate include blank with a particular key' do
store_translations(:en, simple_form: { include_blanks: {
test 'input should translate include blank with a default' do
store_translations(:en, simple_form: { include_blanks: { defaults: {
age: 'Rather not say',
user: { age: 'Should be overridden' }
} } ) do
with_input_for @user, :age, :select, collection: 18..30, include_blank: :age
} } }) do
with_input_for @user, :age, :select, collection: 18..30, include_blank: :translate
assert_select 'select option[value=]', 'Rather not say'
end
end
@ -184,27 +174,17 @@ class CollectionSelectInputTest < ActionView::TestCase
test 'input should translate prompt when set to :translate' do
store_translations(:en, simple_form: { prompts: { user: {
age: 'Select age:'
} } } ) do
} } }) do
with_input_for @user, :age, :select, collection: 18..30, prompt: :translate
assert_select 'select option[value=]', 'Select age:'
end
end
test 'input should translate prompt when set to :t' do
store_translations(:en, simple_form: { prompts: { user: {
age: 'Select age:'
} } } ) do
with_input_for @user, :age, :select, collection: 18..30, prompt: :t
assert_select 'select option[value=]', 'Select age:'
end
end
test 'input should translate prompt with a particular key' do
store_translations(:en, simple_form: { prompts: {
test 'input should translate prompt with a default' do
store_translations(:en, simple_form: { prompts: { defaults: {
age: 'Select age:',
user: { age: 'Should be overridden' }
} } ) do
with_input_for @user, :age, :select, collection: 18..30, prompt: :age
} } }) do
with_input_for @user, :age, :select, collection: 18..30, prompt: :translate
assert_select 'select option[value=]', 'Select age:'
end
end