Files
nairobi/spec/factory_bot/strategy/insert.rb
Javi Martín a56e1bf3cf Simplify strategy to insert records in tests
Since Rails 7.0, the `insert` method automatically generates timestamps.
2024-07-22 17:50:40 +02:00

21 lines
513 B
Ruby

module FactoryBot
module Strategy
class Insert
def initialize
@strategy = FactoryBot.strategy_by_name(:attributes_for).new
end
delegate :association, to: :@strategy
def result(evaluation)
build_class = evaluation.instance_variable_get(:@attribute_assigner)
.instance_variable_get(:@build_class)
build_class.insert!(@strategy.result(evaluation))
end
end
FactoryBot.register_strategy(:insert, Insert)
end
end