mailjet / mailjet-gem

[API v3] Mailjet official Ruby GEM

Home Page:https://dev.mailjet.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

persisted is never updated

MathieuDerelle opened this issue · comments

the persisted attribute is never changed to false when we modify an object

[43] irb>  x = Mailjet::Contact.first
#<Mailjet::Contact:0x007fdc6d8b32a0 @attributes={"persisted"=>true, "created_at"=>Wed, 18 Jul 2018 13:29:29 +0000, "delivered_count"=>0, "email"=>"bla@bla.test", "exclusion_from_campaigns_updated_at"=>"", "id"=>XXX, "is_excluded_from_campaigns"=>false, "is_opt_in_pending"=>false, "is_spam_complaining"=>false, "last_activity_at"=>Tue, 09 Oct 2018 12:50:45 +0000, "last_update_at"=>Tue, 09 Oct 2018 12:50:45 +0000, "name"=>"Gregory", "unsubscribed_at"=>"", "unsubscribed_by"=>""}>
[44] irb>  x.persisted?
true
[45] irb>  x.name = 'Jeff'
"Jeff"
[46] irb>  x.persisted?
true
[47] irb>  x.save!
true
[49] irb>  x.persisted?
true
[50] irb>  x = Mailjet::Contact.first
#<Mailjet::Contact:0x007fdc7da95ec8 @attributes={"persisted"=>true, "created_at"=>Wed, 18 Jul 2018 13:29:29 +0000, "delivered_count"=>0, "email"=>"bla@bla.test", "exclusion_from_campaigns_updated_at"=>"", "id"=>XXX, "is_excluded_from_campaigns"=>false, "is_opt_in_pending"=>false, "is_spam_complaining"=>false, "last_activity_at"=>Tue, 09 Oct 2018 12:51:18 +0000, "last_update_at"=>Tue, 09 Oct 2018 12:51:18 +0000, "name"=>"Jeff", "unsubscribed_at"=>"", "unsubscribed_by"=>""}>

It was a confusion with dirty methods like ActiveRecord's changed?

persisted only tells if object has already been created or not