sxross / MotionModel

Simple Model and Validation Mixins for RubyMotion
MIT License
192 stars 67 forks source link

Validators only return first error #56

Closed forrestgrant closed 11 years ago

forrestgrant commented 11 years ago

I have the following class

class User
  include MotionModel::Model
  include MotionModel::ArrayModelAdapter
  include MotionModel::Validatable

  columns :first_name        => :string,
          :last_name   => :string,
          :email    => :string

  validates :first_name, presence: true
  validates :last_name, presence: true
  validates :email, presence: true
end

When I try this

(main)> u = User.new
=> User#1:0x7e248f0
(main)> u.valid?
=> false

All is good, but error messages only contain one error:

(main)> u.error_messages
=> [{:first_name=>"incorrect value supplied for first_name -- should be non-empty."}]

It should be:

=> [{:first_name=>"incorrect value supplied for first_name -- should be non-empty.",:last_name=>"incorrect value supplied for last_name -- should be non-empty.",:email=>"incorrect value supplied for email -- should be non-empty."}]
sxross commented 11 years ago

Can you write a failing spec? That would really help.

On Jun 14, 2013, at 6:15 AM, Forrest Grant notifications@github.com wrote:

I have the following class

class User include MotionModel::Model include MotionModel::ArrayModelAdapter include MotionModel::Validatable

columns :first_name => :string, :last_name => :string, :email => :string

validates :first_name, presence: true validates :last_name, presence: true validates :email, presence: true end When I try this

(main)> u = User.new => User#1:0x7e248f0 (main)> u.valid? => false All is good, but error messages only contain one error:

(main)> u.error_messages => [{:first_name=>"incorrect value supplied for first_name -- should be non-empty."}] It should be:

=> [{:first_name=>"incorrect value supplied for first_name -- should be non-empty.",:last_name=>"incorrect value supplied for last_name -- should be non-empty.",:email=>"incorrect value supplied for email -- should be non-empty."}] — Reply to this email directly or view it on GitHub.

forrestgrant commented 11 years ago

Written and failing. Included in #57 pull request.

sxross commented 11 years ago

cb81a7f4fd2cb6c694c57438c4acc2c4cbed2f19 fixes this. You should be able to get this using bundler:

gem motion_model, :git => "https://github.com/sxross/MotionModel.git", :tag => "VERSION_0_4_6"
forrestgrant commented 11 years ago

This works, thanks!