From 125689cd34e11f47eef1f125549ac593427abf40 Mon Sep 17 00:00:00 2001 From: Geoff Buesing Date: Tue, 24 Mar 2009 17:37:52 -0500 Subject: [PATCH] ValidationErrors#on: allow String field_name --- lib/couchrest/validation/validation_errors.rb | 2 +- spec/couchrest/more/property_spec.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) 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