Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Always cast enummer values to symbols
Support for using strings as setters was added in 441cdf6, but the initial implementation suffers from an idempotency issue, as changes would be committed to the DB even if the values were the same. Consider the following scenario: u = User.last => #<User:0x00007c747d137810 id: 3, permissions: [:read, :write], facial_features: [], diets: [], transport: [], home: []> u.permissions = u.permissions.map(&:to_s) => ["read", "write"] u.changes => {"permissions"=>[[:read, :write], ["read", "write"]]} Because we cast the values to symbols when serializing, we set the correct bitmask but this comes with the drawback of altering the DB even if the new values are the same. A better way to handle this issue is to delegate the responsibility to the `cast` method. If we do this we can drop the initial fix, as values will _always_ be symbols. It's tricky to test something like this, so I've opted to hook into ActiveRecord notifications and confirm no SQL UPDATE is being triggered if the values are the same.
- Loading branch information