Sha256: 3be573097f6f6f7679cf3d31b97a4a6e7a9176269a5ed90c864d31eb9f955e6a

Contents?: true

Size: 669 Bytes

Versions: 2

Compression:

Stored size: 669 Bytes

Contents

# frozen_string_literal: true
# @see https://github.com/thoughtbot/factory_bot/blob/master/GETTING_STARTED.md#custom-strategies
# @example
#   let(:resource) { FactoryBot.valkyrie_create(:hyrax_work) }
class ValkyrieCreateStrategy
  def initialize
    @strategy = FactoryBot.strategy_by_name(:create).new
  end

  delegate :association, to: :@strategy

  def result(evaluation)
    evaluation.notify(:after_build, evaluation.object)
    evaluation.notify(:before_create, evaluation.object)

    result = persister.save(resource: evaluation.object)

    evaluation.notify(:after_create, result)
    result
  end

  private

  def persister
    Hyrax.persister
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hyrax-3.6.0 lib/hyrax/specs/shared_specs/factories/strategies/valkyrie_resource.rb
hyrax-3.5.0 lib/hyrax/specs/shared_specs/factories/strategies/valkyrie_resource.rb