Skip to content
This repository has been archived by the owner on Dec 1, 2021. It is now read-only.

Commit

Permalink
label_str_method properly overridden if i18n present.
Browse files Browse the repository at this point in the history
  • Loading branch information
lardawge authored and justinfrench committed Jan 2, 2010
1 parent 4ac2f58 commit 6879050
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/formtastic.rb
Expand Up @@ -1507,8 +1507,13 @@ def sanitized_object_name #:nodoc:
end

def humanized_attribute_name(method) #:nodoc:
if @object && @object.class.respond_to?(:human_attribute_name) && @@label_str_method == :humanize
@object.class.human_attribute_name(method.to_s)
if @object && @object.class.respond_to?(:human_attribute_name)
humanized_name = @object.class.human_attribute_name(method.to_s)
if humanized_name == method.to_s.send(:humanize)
method.to_s.send(@@label_str_method)
else
humanized_name
end
else
method.to_s.send(@@label_str_method)
end
Expand Down
20 changes: 20 additions & 0 deletions spec/input_spec.rb
Expand Up @@ -399,6 +399,26 @@ def should_be_required(options)
end

describe 'when not provided' do
describe 'when localized label is provided' do
describe 'and object is given' do
describe 'and label_str_method not default' do
it 'should render a label with localized label (I18n)' do
with_config :label_str_method, :capitalize do
@localized_label_text = 'Localized title'
@new_post.stub!(:meta_description)
@new_post.class.should_receive(:human_attribute_name).with('meta_description').and_return(@localized_label_text)

semantic_form_for(@new_post) do |builder|
concat(builder.input(:meta_description))
end

output_buffer.should have_tag('form li label', @localized_label_text)
end
end
end
end
end

describe 'when localized label is NOT provided' do
describe 'and object is not given' do
it 'should default the humanized method name, passing it down to the label tag' do
Expand Down

0 comments on commit 6879050

Please sign in to comment.