makandra / active_type

Make any Ruby object quack like ActiveRecord
MIT License
1.09k stars 74 forks source link

After casting an ActiveRecord instance to ActiveType::Record, instance#errors.add won't recognize attributes defined in ActiveType instance #44

Closed snow closed 6 years ago

snow commented 9 years ago
class User < ActiveRecord::Base
end

class Users::ChangePassword < ActiveType::Record[User]
  attribute :old_password, :string
  validates :old_password, presence: true
end

u = User.find 1
form = ActiveType.cast u, Users::ChangePassword
form.update old_password: ''

will get "undefind method old_password", because form.errors's instance var @base is still u

I've fixed it in https://github.com/snow/active_type/commit/cafe7ed1bd4b73b6922d1000a8b2647e81585284 But when I ran the specs, find out it requires PgSQL. It's 03:47+0800 now, I'm so tired and all I want is Vodka and sleep, so I will setup PgSQL, run the spec and create a PR some days later. Maybe in this weekend.

kratob commented 6 years ago

This is already fixed.