rails/rails — pull request #13542 by robin850 (2013-12-30 17:01:18+00:00)
Title: Improve enum fields

Hello,

This is just a little pull request that resolves some issues mentioned in #13530. Basically, the problem is described in [this gist](https://gist.github.com/robin850/6e3dd87e4dc34833aeac). Previously, a call to:

~~~ruby
Book.where(status: 0).first_or_initialize
~~~

Would fail (an `ArgumentError` would be raised) because only the symbol version of the enum was checked when calling its writer method. I guess that `find_or_initialize` is calling it through the `initialize` (new) method.

I also added a mention about the scopes generated dynamically based on the allowed values of the field in the documentation.

I'm not really comfortable with Active Record and its internals so I'm certainly not very clear ; therefore, sorry. Let me know if I should update anything.

By the way, the issue mentioned above is not totally resolved since the `where` method doesn't generate the same queries with either a symbol or a numeric value on enum fields.

Have a nice day.