Skip to content

Incompatible with ActiveRecord normalizes #459

Open
@Timmitry

Description

@Timmitry

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions