thoughtbot / thoughtbot/factory_bot

enum traits do not use prefix

Open
#1,452 11 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Ruby
Stars
8.2k
Forks
2.6k
PR merge metrics
No merged PRs in 30d

Description

Description

When defining enums with a prefix or suffix the trait that is automatically generated does not take into account the prefix or suffix.

Reproduction Steps
class Foo
  enum bar: [:baz, :bing], _prefix: :bang 
end

FactoryBot.define do
  factory :foo do
    ...
  end
end

# in a test
create(:foo, :bang_baz)
Expected behavior

I would expect the trait to correspond to the predicate or bang methods defined with the enum.
in the above examples an instance of Foo would have methods bang_baz? and bang_baz!.

Actual behavior

The traits are defined from only the enum values. So in the above example the traits would be used:

create(:foo, :baz)
create(:foo, :bing)
System configuration

factory_bot version: 6.1.0
rails version: 5.2.4.4
ruby version: 2.5.5

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the enum and FactoryBot reproduction shown in the issue, then locate the code that generates traits from enum values. Confirm that prefixed and suffixed enum methods determine the trait names, and verify the expected behavior with the provided create(:foo, :bang_baz) example.

Written by the indexing model from the issue text.

Assessment

Tech stack
rails, ruby
Domain
testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.