Factory Girl sequences not incrementing

前端 未结 2 1992
执笔经年
执笔经年 2020-12-16 18:04

I\'m trying to get FactoryGirl to generate some names for me, but the sequence doesn\'t seem to increment.

# spec/factories/vessel.rb
require \'factory_girl\         


        
2条回答
  •  时光说笑
    2020-12-16 18:15

    And the answer is:

    require 'factory_girl'
    
    FactoryGirl.define do
    
      sequence :vessel_name do |n|
        "TK42#{n}"
      end
    
      factory :vessel do
        vessel_type 'fermenter'
        volume_scalar 100.0
        volume_units 'bbl'
        after :build do |v|
          v.name = FactoryGirl.generate(:vessel_name)
        end
      end
    end
    

提交回复
热议问题