ValidationErrors#on: allow String field_name
This commit is contained in:
parent
49d19e2a29
commit
125689cd34
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue