factory_bot icon indicating copy to clipboard operation
factory_bot copied to clipboard

Don't allow duplicate traits

Open dorianmarie opened this issue 3 years ago • 1 comments

Description

A factory can have the same trait multiple times

Reproduction Steps

FactoryBot.define do
  factory :user, class: OpenStruct do
    trait :admin do
       name { "Admin" }
    end

    trait :admin do
       name { "Administrator" }
    end
  end
end

Expected behavior

Raises an error when defining the second trait

Actual behavior

Lets me define a second trait but keeps only the first trait

System configuration

factory_bot version: 6.1.0 rails version: 6.1.3.1 ruby version: 2.7.3

dorianmarie avatar Apr 23 '21 04:04 dorianmarie

Related to https://github.com/thoughtbot/factory_bot/pull/1064#issuecomment-448075022

composerinteralia avatar Apr 23 '21 11:04 composerinteralia