Permalink
Browse files

Add test case for template leakage

  • Loading branch information...
1 parent 51dd494 commit 41522271eccda5731d661960156f134055bd7689 @rafaelfranca rafaelfranca committed Jan 22, 2013
Showing with 36 additions and 0 deletions.
  1. +36 −0 test/action_view_extensions/builder_test.rb
@@ -242,6 +242,24 @@ def with_collection_check_boxes(object, attribute, collection, value_method, tex
end
end
+ test "collection radio with block helpers does not leak the template" do
+ with_concat_form_for(@user) do |f|
+ collection_input = f.collection_radio_buttons :active, [true, false], :to_s, :to_s do |b|
+ b.label(:class => b.object) { b.radio_button + b.text }
+ end
+ concat collection_input
+
+ concat f.hidden_field :name
+ end
+
+ assert_select 'label.true[for=user_active_true]', text: 'true', count: 1 do
+ assert_select 'input#user_active_true[type=radio]'
+ end
+ assert_select 'label.false[for=user_active_false]', text: 'false', count: 1 do
+ assert_select 'input#user_active_false[type=radio]'
+ end
+ end
+
test "collection_radio helper is deprecated in favor of collection_radio_buttons" do
assert_deprecated "[SIMPLE_FORM] The `collection_radio` helper is deprecated, " \
"please use `collection_radio_buttons` instead" do
@@ -535,6 +553,24 @@ def with_collection_check_boxes(object, attribute, collection, value_method, tex
end
end
+ test "collection check boxes with block helpers does not leak the template" do
+ with_concat_form_for(@user) do |f|
+ collection_input = f.collection_check_boxes :active, [true, false], :to_s, :to_s do |b|
+ b.label(:class => b.object) { b.check_box + b.text }
+ end
+ concat collection_input
+
+ concat f.hidden_field :name
+ end
+
+ assert_select 'label.true[for=user_active_true]', text: 'true', count: 1 do
+ assert_select 'input#user_active_true[type=checkbox]'
+ end
+ assert_select 'label.false[for=user_active_false]', text: 'false', count: 1 do
+ assert_select 'input#user_active_false[type=checkbox]'
+ end
+ end
+
# SIMPLE FIELDS
test "simple fields for is available and yields an instance of FormBuilder" do
with_concat_form_for(@user) do |f|

1 comment on commit 4152227

Collaborator

carlosantoniodasilva commented on 4152227 Jan 24, 2013

❤️

Please sign in to comment.