Fix tests with latest changes using :defaults in translation

Also expand tests to check for :defaults and specific object name
namespace for translations, and add check boxes tests.
This commit is contained in:
Carlos Antonio da Silva 2012-01-24 15:04:37 -02:00
parent b4e297f98c
commit 68b9f6c098
2 changed files with 53 additions and 6 deletions

View File

@ -92,7 +92,7 @@ module SimpleForm
end
def translate_collection
@collection = collection.map {|value| [translate(:options, value.to_s), value.to_s]}
@collection = collection.map { |value| [translate(:options, value.to_s), value.to_s] }
end
end
end

View File

@ -55,10 +55,21 @@ class CollectionInputTest < ActionView::TestCase
assert_select 'select option', 'Carlos'
end
test 'input should allow translating collection for select types' do
store_translations(:en, :simple_form => { :options => {
test 'input should do automatic collection translation for select types using defaults key' do
store_translations(:en, :simple_form => { :options => { :defaults => {
:gender => { :male => 'Male', :female => 'Female'}
} } ) do
} } } ) do
with_input_for @user, :gender, :select, :collection => [:male, :female]
assert_select 'select.select#user_gender'
assert_select 'select option', 'Male'
assert_select 'select option', 'Female'
end
end
test 'input should do automatic collection translation for select types using specific object key' do
store_translations(:en, :simple_form => { :options => { :user => {
:gender => { :male => 'Male', :female => 'Female'}
} } } ) do
with_input_for @user, :gender, :select, :collection => [:male, :female]
assert_select 'select.select#user_gender'
assert_select 'select option', 'Male'
@ -158,10 +169,22 @@ class CollectionInputTest < ActionView::TestCase
assert_select 'label.collection_radio', 'Carlos'
end
test 'input should allow translation of collection for radio types' do
test 'input should do automatic collection translation for radio types using defaults key' do
store_translations(:en, :simple_form => { :options => { :defaults => {
:gender => { :male => 'Male', :female => 'Female'}
} } } ) do
with_input_for @user, :gender, :radio, :collection => [:male, :female]
assert_select 'input[type=radio][value=male]'
assert_select 'input[type=radio][value=female]'
assert_select 'label.collection_radio', 'Male'
assert_select 'label.collection_radio', 'Female'
end
end
test 'input should do automatic collection translation for radio types using specific object key' do
store_translations(:en, :simple_form => { :options => { :user => {
:gender => { :male => 'Male', :female => 'Female'}
} } }) do
} } } ) do
with_input_for @user, :gender, :radio, :collection => [:male, :female]
assert_select 'input[type=radio][value=male]'
assert_select 'input[type=radio][value=female]'
@ -304,6 +327,30 @@ class CollectionInputTest < ActionView::TestCase
assert_no_select 'input[required]'
end
test 'input should do automatic collection translation for check_box types using defaults key' do
store_translations(:en, :simple_form => { :options => { :defaults => {
:gender => { :male => 'Male', :female => 'Female'}
} } } ) do
with_input_for @user, :gender, :check_boxes, :collection => [:male, :female]
assert_select 'input[type=checkbox][value=male]'
assert_select 'input[type=checkbox][value=female]'
assert_select 'label.collection_check_boxes', 'Male'
assert_select 'label.collection_check_boxes', 'Female'
end
end
test 'input should do automatic collection translation for check_box types using specific object key' do
store_translations(:en, :simple_form => { :options => { :user => {
:gender => { :male => 'Male', :female => 'Female'}
} } } ) do
with_input_for @user, :gender, :check_boxes, :collection => [:male, :female]
assert_select 'input[type=checkbox][value=male]'
assert_select 'input[type=checkbox][value=female]'
assert_select 'label.collection_check_boxes', 'Male'
assert_select 'label.collection_check_boxes', 'Female'
end
end
test 'input should allow disabled options with a lambda for collection select' do
with_input_for @user, :name, :select, :collection => ["Carlos", "Antonio"],
:disabled => lambda { |x| x == "Carlos" }