ValidationErrors#on: allow String field_name
This commit is contained in:
parent
49d19e2a29
commit
125689cd34
2 changed files with 7 additions and 1 deletions
|
@ -89,7 +89,7 @@ module CouchRest
|
|||
#
|
||||
# @param <Symbol> field_name the name of the field you want an error for
|
||||
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
|
||||
end
|
||||
|
||||
|
|
|
@ -59,6 +59,12 @@ describe "ExtendedDocument properties" do
|
|||
@card.errors.should_not be_empty
|
||||
@card.errors.on(:first_name).should == ["First name must not be blank"]
|
||||
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
|
||||
@invoice.clear
|
||||
|
|
Loading…
Reference in a new issue