diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-02-01 19:46:48 -0200 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-02-02 14:52:33 -0200 |
commit | 0f234261552dae68b66d3d0271ef39c343082c36 (patch) | |
tree | 2931d9b467e0fd403ff64df26da14a2bc2f4d6a4 /actionpack/test/template | |
parent | f506c8063b3084f54aa8bd157d94f10b7aed2bf0 (diff) | |
download | rails-0f234261552dae68b66d3d0271ef39c343082c36.tar.gz rails-0f234261552dae68b66d3d0271ef39c343082c36.tar.bz2 rails-0f234261552dae68b66d3d0271ef39c343082c36.zip |
Allow collection radio_buttons/check_boxes to access current text/value
[Carlos Antonio da Silva + Rafael Mendonça França]
Diffstat (limited to 'actionpack/test/template')
-rw-r--r-- | actionpack/test/template/form_collections_helper_test.rb | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/actionpack/test/template/form_collections_helper_test.rb b/actionpack/test/template/form_collections_helper_test.rb index 3839aa2a00..41b6702c9d 100644 --- a/actionpack/test/template/form_collections_helper_test.rb +++ b/actionpack/test/template/form_collections_helper_test.rb @@ -101,6 +101,28 @@ class FormCollectionsHelperTest < ActionView::TestCase assert_select 'label[for=user_active_false] + input#user_active_false[type=radio]' end + test 'collection radio with block helpers accept extra html options' do + with_collection_radio_buttons :user, :active, [true, false], :to_s, :to_s do |b| + b.label(:class => "radio_button") + b.radio_button(:class => "radio_button") + end + + assert_select 'label.radio_button[for=user_active_true] + input#user_active_true.radio_button[type=radio]' + assert_select 'label.radio_button[for=user_active_false] + input#user_active_false.radio_button[type=radio]' + end + + test 'collection radio with block helpers allows access to current text and value' do + with_collection_radio_buttons :user, :active, [true, false], :to_s, :to_s do |b| + b.label(:"data-value" => b.value) { b.radio_button + b.text } + end + + assert_select 'label[for=user_active_true][data-value=true]', 'true' do + assert_select 'input#user_active_true[type=radio]' + end + assert_select 'label[for=user_active_false][data-value=false]', 'false' do + assert_select 'input#user_active_false[type=radio]' + end + end + test 'collection radio buttons with fields for' do collection = [Category.new(1, 'Category 1'), Category.new(2, 'Category 2')] @output_buffer = fields_for(:post) do |p| @@ -254,4 +276,26 @@ class FormCollectionsHelperTest < ActionView::TestCase assert_select 'label[for=user_active_true] + input#user_active_true[type=checkbox]' assert_select 'label[for=user_active_false] + input#user_active_false[type=checkbox]' end + + test 'collection check boxes with block helpers accept extra html options' do + with_collection_check_boxes :user, :active, [true, false], :to_s, :to_s do |b| + b.label(:class => "check_box") + b.check_box(:class => "check_box") + end + + assert_select 'label.check_box[for=user_active_true] + input#user_active_true.check_box[type=checkbox]' + assert_select 'label.check_box[for=user_active_false] + input#user_active_false.check_box[type=checkbox]' + end + + test 'collection check boxes with block helpers allows access to current text and value' do + with_collection_check_boxes :user, :active, [true, false], :to_s, :to_s do |b| + b.label(:"data-value" => b.value) { b.check_box + b.text } + end + + assert_select 'label[for=user_active_true][data-value=true]', 'true' do + assert_select 'input#user_active_true[type=checkbox]' + end + assert_select 'label[for=user_active_false][data-value=false]', 'false' do + assert_select 'input#user_active_false[type=checkbox]' + end + end end |