How can I reset a factory_girl sequence?

后端 未结 9 1933
梦毁少年i
梦毁少年i 2020-12-16 10:17

Provided that I have a project factory

Factory.define :project do |p|
  p.sequence(:title)    { |n| \"project #{n} title\"                  }
  p.sequence(:         


        
9条回答
  •  北海茫月
    2020-12-16 10:56

    This is pretty old, but it's the top result on google for the relevant keywords. For anyone else stumbling across this.

    There is a class method called sequence_by_name to fetch a sequence by name, and then you can call rewind and it'll reset to 1.

    FactoryBot.sequence_by_name(:order).rewind
    

    Or if you want to reset all.

    FactoryBot.rewind_sequences
    

    Here is the link to the file on github

提交回复
热议问题