Skip to content

Commit

Permalink
Fix a bug when an error is raised if label is called with just one ar…
Browse files Browse the repository at this point in the history
…gument.

Signed-off-by: Justin French <justin@indent.com.au>
  • Loading branch information
josevalim authored and justinfrench committed Apr 21, 2009
1 parent fdf83cf commit ac3d659
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/formtastic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def semantic_fields_for(record_or_name_or_array, *args, &block)
# :required can be also sent as option. When true, marks a filed as required,
# when false marks it as optional. When nil, does nothing.
#
def label(method, text, options={}, as_span=false)
def label(method, text=nil, options={}, as_span=false)
text ||= humanized_attribute_name(method)
text << required_or_optional_string(options.delete(:required))

Expand Down
20 changes: 20 additions & 0 deletions spec/formtastic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,26 @@ def custom(arg1, arg2, options = {})
end
end

describe '#label' do
it 'should humanize the given attribute' do
semantic_form_for(@new_post) do |builder|
builder.label(:login).should have_tag('label', :with => /Login/)
end
end

it 'should append required note' do
semantic_form_for(@new_post) do |builder|
builder.label(:login, nil, :required => true).should have_tag('label abbr')
end
end

it 'should be printed as span' do
semantic_form_for(@new_post) do |builder|
builder.label(:login, nil, { :required => true }, true).should have_tag('span.label abbr')
end
end
end

describe '#input' do

before do
Expand Down

0 comments on commit ac3d659

Please sign in to comment.