Skip to content

Commit

Permalink
Merge pull request formtastic#761 from nashby/fix-issue-743
Browse files Browse the repository at this point in the history
allow to use numbers in collection for radio and check_boxes, closes formtastic#743
  • Loading branch information
justinfrench committed Dec 18, 2011
2 parents 63528a7 + 75afc60 commit 5bb2127
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
6 changes: 5 additions & 1 deletion lib/formtastic/inputs/base/choices.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ def choice_html(choice)
end

def choice_label(choice)
choice.is_a?(Array) ? choice.first : choice
if choice.is_a?(Array)
choice.first
else
choice
end.to_s
end

def choice_value(choice)
Expand Down
40 changes: 28 additions & 12 deletions spec/inputs/radio_input_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@
end

describe "each choice" do

it 'should not give the choice label the .label class' do
output_buffer.should_not have_tag('li.choice label.label')
end

it 'should not add the required attribute to each input' do
output_buffer.should_not have_tag('li.choice input[@required]')
end


it 'should contain a label for the radio input with a nested input and label text' do
::Author.all.each do |author|
output_buffer.should have_tag('form li fieldset ol li label', /#{author.to_label}/)
Expand All @@ -67,7 +67,7 @@
output_buffer.should have_tag("form li fieldset ol li.author_#{author.id} label")
end
end

it "should have a radio input" do
::Author.all.each do |author|
output_buffer.should have_tag("form li fieldset ol li label input#post_author_id_#{author.id}")
Expand Down Expand Up @@ -201,7 +201,7 @@
output_buffer.should_not have_tag("legend.label")
output_buffer.should_not include(">")
end

it "should not cause escaped HTML" do
output_buffer.should_not include(">")
end
Expand Down Expand Up @@ -233,7 +233,7 @@
end
it_should_have_input_wrapper_with_id("custom_prefix_post_authors_input")
end

describe "when index is provided" do

before do
Expand All @@ -246,21 +246,37 @@
end)
end)
end

it 'should index the id of the wrapper' do
output_buffer.should have_tag("li#post_author_attributes_3_name_input")
end

it 'should index the id of the select tag' do
output_buffer.should have_tag("input#post_author_attributes_3_name_true")
output_buffer.should have_tag("input#post_author_attributes_3_name_false")
end

it 'should index the name of the select tag' do
output_buffer.should have_tag("input[@name='post[author_attributes][3][name]']")
end


end

describe "when collection contains integers" do
before do
@output_buffer = ''
mock_everything

concat(semantic_form_for(:project) do |builder|
concat(builder.input(:author_id, :as => :radio, :collection => [1, 2, 3]))
end)
end

it 'should output the correct labels' do
output_buffer.should have_tag("li.choice label", /1/)
output_buffer.should have_tag("li.choice label", /2/)
output_buffer.should have_tag("li.choice label", /3/)
end
end


end

0 comments on commit 5bb2127

Please sign in to comment.