Skip to content

Incompatible with ActiveRecord normalizes #459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Timmitry opened this issue Mar 12, 2025 · 2 comments
Open

Incompatible with ActiveRecord normalizes #459

Timmitry opened this issue Mar 12, 2025 · 2 comments

Comments

@Timmitry
Copy link

I tried to use enumerize (love it!) together with the relatively new normalizes-Method from ActiveRecord. This does not work - the normalization does not happen. Pseudo example:

class MyModel < ApplicationRecord
    normalizes :locale, with: ->(value) { value.downcase.strip.presence }
    enumerize :locale, in: %w[de en pl]
end

MyModel.new(locale: " DE ").valid? # => false

Without enumerize, the " DE " would be converted to de, and thus be valid. With enumerize, this is skipped, and enumerize reports it as invalid.

My guess is that this is due to enumerize overwriting the getter and setter for the attribute here.

Rails, on the other hand, decorates the existing attribute here (not sure yet what exactly happens there).

I could try to create a minimal reproduction, but first wanted to ask if this would be out of scope anyway.

@nashby
Copy link
Member

nashby commented Mar 12, 2025

@Timmitry hey! It looks like something I'd like to be fixed! So a failing test or even a fix would be much appreciated.

@Timmitry
Copy link
Author

@nashby Thanks for looking into this! I added two failing test cases in #460. Commenting out enumerize :locale, ... will make the tests green.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants