-
-
Notifications
You must be signed in to change notification settings - Fork 357
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
Enum does not scope correctly #277
Comments
Hi @scottmalone, that sounds interesting! Would you be interested in writing a Pull Request for us with a test? Doesn't sound like it'll be too hard :) |
No prob @brendon, I'll do that. I ran into a separate issue that's really confounding me w/ model specs not updating correctly but request specs doing fine (yes, using test_after_commit). Would you prefer I open another issue or go straight to a separate PR? |
Thanks @scottmalone, yes open another issue then if you do a PR just mention that it closes that issue in the description and that should handle linking things together. |
This is a non-issue with activesupport 5.0, but prior to that, when check_scope is assigning the attributes hash, the assignment of an enum is invalid and results in a value of 0 being assigned as the scope. Assigning with the enum's setter instead. Fixes brendon#277
This is a non-issue with activesupport 5.0, but prior to that, when check_scope is assigning the attributes hash, the assignment of an enum is invalid and results in a value of 0 being assigned as the scope. Assigning with the enum's setter instead. Fixes brendon#277
This is a non-issue with activesupport 5.0, but prior to that, when check_scope is assigning the attributes hash, the assignment of an enum is invalid and results in a value of 0 being assigned as the scope. Assigning with the enum's setter instead. Fixes #277
Env: Rails 4.2.0, acts_as_list (0.9.5), postgresql.
Problem
Scope not working with enum resulting to enum being set to 0.
Solution
Change assignments within #check_scope to send to the setter.
The existing enum test in test_list.rb doesn't catch the issue because the assignment using
self[attribute] = values[0]
always assigns as 0 since the enum value of "active" or "archived" doesn't exist (active/archived are the enum keys). Assignment as 0 results in the position always being set to the first position.I ran into this because I declared an enum as
enum status: { inbox: 1, published: 2, archived: 3, deleted: 4 }
with the values starting at 1, but the existing test can be improved by just adding a second EnumArrayScopeListMixin to one of those scopes.The text was updated successfully, but these errors were encountered: