Skip to content

Commit

Permalink
Use @output_buffer variable instead of concat in tests
Browse files Browse the repository at this point in the history
[Carlos Antonio da Silva + Rafael Mendonça França]
  • Loading branch information
carlosantoniodasilva committed Feb 2, 2012
1 parent 6028c15 commit e39f8a2
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions actionpack/test/template/form_collections_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ def assert_no_select(selector, value = nil)
end

def with_collection_radio_buttons(*args, &block)
concat collection_radio_buttons(*args, &block)
@output_buffer = collection_radio_buttons(*args, &block)
end

def with_collection_check_boxes(*args, &block)
concat collection_check_boxes(*args, &block)
@output_buffer = collection_check_boxes(*args, &block)
end

# COLLECTION RADIO BUTTONS
Expand Down Expand Up @@ -172,7 +172,7 @@ def with_collection_check_boxes(*args, &block)

test 'collection radio accepts a block to render the radio and label as required' do
with_collection_radio_buttons :user, :active, [true, false], :to_s, :to_s do |label_for, text, value, html_options|
concat label(:user, label_for, text) { radio_button(:user, :active, value, html_options) }
label(:user, label_for, text) { radio_button(:user, :active, value, html_options) }
end

assert_select 'label[for=user_active_true] > input#user_active_true[type=radio]'
Expand All @@ -181,9 +181,9 @@ def with_collection_check_boxes(*args, &block)

test 'collection radio buttons with fields for' do
collection = [Category.new(1, 'Category 1'), Category.new(2, 'Category 2')]
concat(fields_for(:post) do |p|
@output_buffer = fields_for(:post) do |p|
p.collection_radio_buttons :category_id, collection, :id, :name
end)
end

assert_select 'input#post_category_id_1[type=radio][value=1]'
assert_select 'input#post_category_id_2[type=radio][value=2]'
Expand All @@ -192,7 +192,6 @@ def with_collection_check_boxes(*args, &block)
assert_select 'label.collection_radio_buttons[for=post_category_id_2]', 'Category 2'
end


# COLLECTION CHECK BOXES
test 'collection check boxes accepts a collection and generate a serie of checkboxes for value method' do
collection = [Category.new(1, 'Category 1'), Category.new(2, 'Category 2')]
Expand Down Expand Up @@ -252,9 +251,9 @@ def with_collection_check_boxes(*args, &block)
user = Struct.new(:category_ids).new(2)
collection = (1..3).map{|i| [i, "Category #{i}"] }

concat(fields_for(:user, user) do |p|
@output_buffer = fields_for(:user, user) do |p|
p.collection_check_boxes :category_ids, collection, :first, :last, :checked => [1, 3]
end)
end

assert_select 'input[type=checkbox][value=1][checked=checked]'
assert_select 'input[type=checkbox][value=3][checked=checked]'
Expand Down Expand Up @@ -298,9 +297,9 @@ def with_collection_check_boxes(*args, &block)

test 'collection check boxes with fields for' do
collection = [Category.new(1, 'Category 1'), Category.new(2, 'Category 2')]
concat(fields_for(:post) do |p|
@output_buffer = fields_for(:post) do |p|
p.collection_check_boxes :category_ids, collection, :id, :name
end)
end

assert_select 'input#post_category_ids_1[type=checkbox][value=1]'
assert_select 'input#post_category_ids_2[type=checkbox][value=2]'
Expand Down

0 comments on commit e39f8a2

Please sign in to comment.