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

Enum matcher should check for _prefix and _suffix #961

Closed
tejasbubane opened this issue Sep 10, 2016 · 1 comment · Fixed by #1077
Closed

Enum matcher should check for _prefix and _suffix #961

tejasbubane opened this issue Sep 10, 2016 · 1 comment · Fixed by #1077

Comments

@tejasbubane
Copy link

tejasbubane commented Sep 10, 2016

define_enum_for matcher should also have an option to check for _prefix and _suffix. Something like this:

conversation.rb

class Conversation < ActiveRecord::Base
  enum status: [:active, :archived], _suffix: true
  enum comments_status: [:active, :inactive], _prefix: :comments
end

conversation_spec.rb

expect(Conversation).to define_enum_for(:status).with([:active, :archived])
                                                .and(_suffix: true)

expect(Conversation).to define_enum_for(:comments).with([:active, :inactive])
                                                  .and(_prefix: :comments)
@tejasbubane tejasbubane changed the title Enum matchers should check for _prefix and _suffix Enum matcher should check for _prefix and _suffix Sep 10, 2016
@mcmire
Copy link
Collaborator

mcmire commented Sep 11, 2016

Wow. What did they do to that API?

Well... anyway... I think in order to test that option, I'll have to reimplement how define_enum_for works. ActiveRecord keeps track of which columns are enum columns by storing them in a class-level defined_enums hash. Each key is the column and each value is an array of possible values that the column takes. In this case, _prefix and _suffix change which methods get created, and that information is not stored in defined_enums. So what I may have to do here is change the matcher so that it checks which methods get created as well.

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

Successfully merging a pull request may close this issue.

2 participants