ValidationErrors#on: allow String field_name

This commit is contained in:
Geoff Buesing 2009-03-24 17:37:52 -05:00 committed by Matt Aimonetti
parent 49d19e2a29
commit 125689cd34
2 changed files with 7 additions and 1 deletions

View file

@ -89,7 +89,7 @@ module CouchRest
# #
# @param <Symbol> field_name the name of the field you want an error for # @param <Symbol> field_name the name of the field you want an error for
def on(field_name) def on(field_name)
errors_for_field = errors[field_name] errors_for_field = errors[field_name.to_sym]
errors_for_field.blank? ? nil : errors_for_field errors_for_field.blank? ? nil : errors_for_field
end end

View file

@ -60,6 +60,12 @@ describe "ExtendedDocument properties" do
@card.errors.on(:first_name).should == ["First name must not be blank"] @card.errors.on(:first_name).should == ["First name must not be blank"]
end end
it "should let you look up errors for a field by a string name" do
@card.first_name = nil
@card.should_not be_valid
@card.errors.on('first_name').should == ["First name must not be blank"]
end
it "should validate the presence of 2 attributes" do it "should validate the presence of 2 attributes" do
@invoice.clear @invoice.clear
@invoice.should_not be_valid @invoice.should_not be_valid