When using auto_increment it wouldn't save the model. It would continue as persisted and not new_record, but was flagged changed. When I had a different instance of the user the counter would never match, but always be zero.
If I only used the in-memory/cached user object then it would work just fine.
E.g.,
u = User.find(1)
u.otp_counter #=> 0
u.otp_code() #=> "226630"
u.otp_code(auto_increment: true) #=> "279079"
u.otp_counter #=> 1
u = User.find(1)
u.otp_counter #=> 0 (expected 1)
When using auto_increment it wouldn't save the model. It would continue as persisted and not new_record, but was flagged changed. When I had a different instance of the user the counter would never match, but always be zero.
If I only used the in-memory/cached user object then it would work just fine. E.g., u = User.find(1) u.otp_counter #=> 0 u.otp_code() #=> "226630" u.otp_code(auto_increment: true) #=> "279079" u.otp_counter #=> 1 u = User.find(1) u.otp_counter #=> 0 (expected 1)