module ModelStubbingHelpers
  def stub_record(type, options = {})
    build_stubbed(type, options)
  end

  def stub_edition(type, options = {})
    document = stub_record(:document)
    document.stubs(:to_param).returns(document.slug)
    stub_record(type, options.merge(document: document))
  end

  def next_record_id
    @next_id ||= 0
    @next_id += 1
  end
end

module ModelStubbingHelpers
  def stub_record(type, options = {})
    result = build(type, options)
    result.stubs(:id).returns(next_record_id)
    result.stubs(:new_record?).returns(false)
    result.stubs(:created_at).returns(Time.zone.now) if result.respond_to?(:created_at)
    result.stubs(:updated_at).returns(Time.zone.now) if result.respond_to?(:updated_at)
    result
  end

  def stub_edition(type, options = {})
    document = stub_record(:document)
    document.stubs(:to_param).returns(document.slug)
    stub_record(type, options.merge(document: document))
  end

  def next_record_id
    @next_id ||= 0
    @next_id += 1
  end
end

Revert "Use FactoryGirl.build_stubbed instead of a hand-rolled solution."
Revert "Use FactoryGirl.build_stubbed instead of a hand-rolled solution."

This reverts commit 13237e4ea7e54c4d3bc9bd8d244fe08ff0655b2f.

For some reason this was causing a seg fault on CI.
