davydovanton / shallow_attributes

Simple and lightweight Virtus analog.
MIT License
101 stars 18 forks source link

Raise an error if object isn't valid #4

Closed FanaHOVA closed 6 years ago

FanaHOVA commented 7 years ago

If an object is created that doesn't satisfy the validations there's no errors raised, but you can see them in object.errors. An error should be raised to warn the user. Example:

class User
  include ShallowAttributes

  attribute :name, String
  validates :name, presence: true
end
> u = User.new(name: nil)
> #<TextDispatcher name=nil>
> u.errors
>  #<ActiveModel::Errors:0x007fc153323090 @base=#<TextDispatcher name=nil>, @messages={:name=>["can't be blank"]}>

I'd expect

> u = User.new(name: nil)
> Error: name can't be blank
nesaulov commented 6 years ago

I guess this can be closed now (due to #17)

davydovanton commented 6 years ago

@nesaulov yep, thanks!