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

Allow strings as enum values #444

Merged
merged 9 commits into from
Oct 3, 2018
Merged

Conversation

s-mage
Copy link
Contributor

@s-mage s-mage commented Sep 22, 2017

Active Record 5 improved work with enums. So now we can use strings or symbols instead of integers. For example:

# ActiveRecord4Adapter
@ability.can :read, Shape, color: Shape.colors[:green]

# ActiveRecord5Adapter
@ability.can :read, Shape, color: :green

ActiveRecord5Adapter is compatible with ActiveRecord4Adapter so you can use numbers as well.

@Schwad
Copy link

Schwad commented Nov 17, 2017

@s-mage do you think these checks are failing for ruby 2.0 here because of your changes or has CanCanCan 2.0 dropped support for Ruby 2.0?

@Schwad
Copy link

Schwad commented Nov 17, 2017

As a fan of enums and Rails 5 I think this would be a handy addition!

@s-mage
Copy link
Contributor Author

s-mage commented Nov 17, 2017

@Schwad https:/ruby/ruby/blob/ruby_2_3/NEWS I looked through the file and can't see anything incompatible in the diff, do you?

@s-mage
Copy link
Contributor Author

s-mage commented Nov 17, 2017

@Schwad, I merged develop here and it started fail in the same rubies where develop fails

Copy link
Member

@coorasse coorasse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does it behave when we use strings for enums? Imagine the following definition:

enum size: { big: 'big', medium: 'average', small: 'small' }

could you please add a test for it so is more clear how it behaves? Thanks

@coorasse coorasse changed the base branch from develop to feature/2.2.0 March 12, 2018 18:36
@s-mage
Copy link
Contributor Author

s-mage commented Aug 12, 2018

hi @coorasse, it's been a while. I've added a patch for working with enums you described, now it's consistent (works both for keys and values).

@coorasse coorasse changed the base branch from feature/2.2.0 to develop September 16, 2018 14:28
@coorasse coorasse changed the base branch from develop to feature/2.4.0 September 16, 2018 14:28
@coorasse coorasse changed the title Add active_record_5_adapter Allow strings as enum values Sep 16, 2018
@coorasse coorasse merged commit ab84a35 into CanCanCommunity:feature/2.4.0 Oct 3, 2018
@coorasse
Copy link
Member

coorasse commented Oct 3, 2018

scheduled for version 2.4.0. Thanks! 🙇

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

Successfully merging this pull request may close these issues.

3 participants