Skip to content
This repository was archived by the owner on Apr 17, 2018. It is now read-only.
This repository was archived by the owner on Apr 17, 2018. It is now read-only.

Custom error messages for all inferred validations #66

@nblumoe

Description

@nblumoe

I would like to use custom error messages for all inferred validations.
What I want to do is shown in this spec (based on this):

 it "should have correct error messages" do
    custom_boat = Class.new do
      include DataMapper::Resource

      def self.name
        'Boat'
      end

      property :id,   DataMapper::Property::Serial
      property :length, Integer, :min => 1,
               :messages => {
                 :greater_than_or_equal_to => "Length must be at least 1"
               }
     end

    boat = custom_boat.new

    boat.length = 0
    boat.should_not be_valid
    boat.errors.on(:length).should == [ 'Length must be at least 1' ]

    boat.length = 3
    boat.should be_valid
    boat.errors.on(:length).should be_nil

As you can see I would like to override the default error message for the auto validation derived from :min => 1.
Currently this spec fails:

'Inferred validations should have correct error messages' FAILED
expected: ["Length must be at least 1"],
     got: [#<DataMapper::Validation::Violation @resource=#<Boat @id=nil @name="superboat" @length=0> @rule=#<Dat
aMapper::Validation::Rule::Numericalness::GreaterThanOrEqual @attribute_name=:length @allow_nil=true @allow_blan
k=nil @custom_message=nil @if_clause=nil @unless_clause=nil @expected=1> @custom_message=nil @attribute_name=:le
ngth>] (using ==) 

Is there a good reason why boat.errors does not get a string attached due to the failed validation but this Violation instance instead? Does it make sense to change that?

I would love to provide a pull request if you think this change makes sense.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions