diff --git a/lib/couchrest/validation/validation_errors.rb b/lib/couchrest/validation/validation_errors.rb index b5aa106..4ddbb6e 100644 --- a/lib/couchrest/validation/validation_errors.rb +++ b/lib/couchrest/validation/validation_errors.rb @@ -89,7 +89,7 @@ module CouchRest # # @param 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 diff --git a/spec/couchrest/more/property_spec.rb b/spec/couchrest/more/property_spec.rb index 723c9ac..146f0f8 100644 --- a/spec/couchrest/more/property_spec.rb +++ b/spec/couchrest/more/property_spec.rb @@ -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