Skip to content

Commit

Permalink
ignore :base in semantic_errors, since base errors are always rendere…
Browse files Browse the repository at this point in the history
…d, avoids duplicates (fixes #576)
  • Loading branch information
justinfrench committed May 31, 2011
1 parent 4f4b069 commit 90e674f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/formtastic/helpers/errors_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module ErrorsHelper
# <% end %>
def semantic_errors(*args)
html_options = args.extract_options!
args = args - [:base]
full_errors = args.inject([]) do |array, method|
attribute = localized_string(method, method.to_sym, :label) || humanized_attribute_name(method)
errors = Array(@object.errors[method.to_sym]).to_sentence
Expand Down
14 changes: 14 additions & 0 deletions spec/helpers/semantic_errors_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,18 @@
end
end
end

describe 'when :base is passed in as an argument' do
before do
@errors.stub!(:[]).with(:base).and_return(@base_error)
end

it 'should ignore :base and only render base errors once' do
semantic_form_for(@new_post) do |builder|
builder.semantic_errors(:base).should have_tag('ul li', :count => 1)
builder.semantic_errors(:base).should_not have_tag('ul li', "Base #{@base_error}")
end
end
end

end

0 comments on commit 90e674f

Please sign in to comment.