Как вы создаете родительские объекты для фабрики, используя before (: create), не вызывая родительский обратный вызов after_create? - PullRequest
0 голосов
/ 25 января 2019

Я пытаюсь передать эту спецификацию:

it "queues up AbsenteeReservationEmailerJob" do
  ActiveJob::Base.queue_adapter = :test
  expect { subject }.to enqueue_job(AbsenteeReservationEmailerJob)
end

Моя фабрика выглядит так:

FactoryBot.define do
  factory :absentee_reservation do
    amount_cents { 10_000 + rand(1_000_000) }
    creator { create(:user) }

    before(:create) do |absentee_reservation|
      auction = create(:auction_with_one_item_one_bidder)
      item = auction.items.first

      absentee_reservation.auction = auction
      absentee_reservation.bidder = auction.bidders.first
      absentee_reservation.lot = item.current_lot
      absentee_reservation.item = item
    end
  end
end

Как видите, я ожидаю, что AbsenteeReservationEmailerJobбыть в безопасности, и это так.Однако другая родительская фабрика (:auction_with_one_item_one_bidder) создает пользователя, который вызывает у меня MailchimpSubscribeUserJob, и я получаю следующую ошибку:

Failures:

  1) AbsenteeReservation#absentee_reservation_email queues up AbsenteeReservationEmailerJob
     Failure/Error: expect { subject }.to enqueue_job(AbsenteeReservationEmailerJob)

       expected to enqueue exactly 1 jobs, but enqueued 2
       Queued jobs:
         MailchimpSubscribeUserJob job with [{:user=>#<User id: 496, email: "jewellhackett@west.co", created_at: "2019-01-25 18:01:37", updated_at: "2019-01-25 18:01:37", title: nil, company: nil, salutation: "Miss", first_name: "Randell", last_name: "Rohan", roles: 0, lha_id: nil, notes: nil, tax_exempt: false, tax_id: nil, tax_id_expires_at: nil, email_opt_in: true, rep_id: nil, account_executive_id: nil, rfc_data: nil>}], on queue default
         MailchimpSubscribeUserJob job with [{:user=>#<User id: 497, email: "aureagerhold@bahringerschaden.org", created_at: "2019-01-25 18:01:37", updated_at: "2019-01-25 18:01:37", title: nil, company: nil, salutation: "Miss", first_name: "Erica", last_name: "Fadel", roles: 0, lha_id: nil, notes: nil, tax_exempt: false, tax_id: nil, tax_id_expires_at: nil, email_opt_in: true, rep_id: nil, account_executive_id: nil, rfc_data: nil>}], on queue default

Могу ли я ожидать только один тип работы ставится в очередь, AbsenteeReservationEmailerJob?Если так, то, пожалуйста, не стесняйтесь видеть мой другой вопрос: Можете ли вы ожидать, что в Rspec будет поставлен только один тип работы?

PS: Я также посмотрел на Пропуск обратных вызовов на Factory Girl и Rspec и User.skip_callback(:create), похоже, игнорируется, если я помещаю его в блок before перед спецификацией или в блок before перед фабрикой :absentee_reservation.

Спасибо!

...