How to test for (ActiveRecord) object equality

前端 未结 6 1296
礼貌的吻别
礼貌的吻别 2020-11-29 05:55

In Ruby 1.9.2 on Rails 3.0.3, I\'m attempting to test for object equality between two Friend (class inherits from ActiveRecord::

6条回答
  •  情书的邮戳
    2020-11-29 06:12

     META = [:id, :created_at, :updated_at, :interacted_at, :confirmed_at]
    
     def eql_attributes?(original,new)
       original = original.attributes.with_indifferent_access.except(*META)
       new = new.attributes.symbolize_keys.with_indifferent_access.except(*META)
       original == new
     end
    
     eql_attributes? attrs, attrs2
    

提交回复
热议问题