Sha256: af55ed10ae5888a8bd53199ae3fd6d8c205b788467ab285f2363788bea1fbf5c

Contents?: true

Size: 639 Bytes

Versions: 64

Compression:

Stored size: 639 Bytes

Contents

class CreateStrategy
  def initialize
    @strategy = FactoryBot.strategy_by_name(:create).new
  end

  delegate :association, to: :@strategy

  def result(evaluation)
    result = nil
    evaluation.object.tap do |instance|
      evaluation.notify(:after_build, instance)
      evaluation.notify(:before_create, instance)
      result = evaluation.create(instance)
      evaluation.notify(:after_create, result)
    end

    result
  end

  # breaking change in factory_bot 6.2.1
  # https://github.com/thoughtbot/factory_bot/issues/1536
  def to_sym
    :repo_create
  end
end

FactoryBot.register_strategy(:repo_create, CreateStrategy)

Version data entries

64 entries across 64 versions & 1 rubygems

Version Path
inferno_core-0.6.2 spec/support/factory_bot.rb
inferno_core-0.6.1 spec/support/factory_bot.rb
inferno_core-0.6.0 spec/support/factory_bot.rb
inferno_core-0.5.4 spec/support/factory_bot.rb
inferno_core-0.5.3 spec/support/factory_bot.rb
inferno_core-0.5.2 spec/support/factory_bot.rb
inferno_core-0.5.1 spec/support/factory_bot.rb
inferno_core-0.5.0 spec/support/factory_bot.rb
inferno_core-0.4.44 spec/support/factory_bot.rb
inferno_core-0.4.43 spec/support/factory_bot.rb
inferno_core-0.4.42 spec/support/factory_bot.rb
inferno_core-0.4.41 spec/support/factory_bot.rb
inferno_core-0.4.40 spec/support/factory_bot.rb
inferno_core-0.4.39 spec/support/factory_bot.rb
inferno_core-0.4.38 spec/support/factory_bot.rb
inferno_core-0.4.35 spec/support/factory_bot.rb
inferno_core-0.4.34 spec/support/factory_bot.rb
inferno_core-0.4.33 spec/support/factory_bot.rb
inferno_core-0.4.32 spec/support/factory_bot.rb
inferno_core-0.4.31 spec/support/factory_bot.rb