Skip to content
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

Enums declared with the wrong syntax should throw an error #33961

Closed
thomassnielsen opened this issue Sep 24, 2018 · 3 comments
Closed

Enums declared with the wrong syntax should throw an error #33961

thomassnielsen opened this issue Sep 24, 2018 · 3 comments

Comments

@thomassnielsen
Copy link

thomassnielsen commented Sep 24, 2018

Steps to reproduce

Create an ActiveRecord model with an enum, where the values are declared as array with an object:

enum status: [
  first: 10,
  second: 20
]

(What happened here for us is that we accidentally used [] instead of {} when setting up the enum. It took longer to debug than it would have if this raised an error).

Demo project: https://github.com/thomassnielsen/enum-demo

Expected behavior

There should be some kind of error explaining that enums should not be an array of objects, rather an array of symbols or an object.

Actual behavior

No error was given, but enum did not work as expected.

System configuration

Rails version: 5.2.1

Ruby version: 2.5.1p57

@dillonwelch
Copy link
Contributor

No error was given, but enum did not work as expected.

What actually did happen?

@thomassnielsen
Copy link
Author

The error we got in our app was quite a few degrees removed from the actual issue. I'll see if I can cook up a simpler example project to demonstrate the issue.

@thomassnielsen
Copy link
Author

Error:
OrderTest#test_statuses:
ArgumentError: 'draft' is not a valid status
    test/models/order_test.rb:6:in `block in <class:OrderTest>'

See the model and the test for the setup I used.

The current error makes sense when seen in this simple case, but I'd argue that passing an array with an object is invalid input to enum, as the enum will be completely unusable.

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