From d044705ca4ed3043936a4f13f5818c1f8d155013 Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Sat, 20 Jan 2024 14:49:25 +0100 Subject: [PATCH] Add spec for inbox cleanup scheduler job --- .../scheduler/inbox_cleanup_scheduler_spec.rb | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 spec/workers/scheduler/inbox_cleanup_scheduler_spec.rb diff --git a/spec/workers/scheduler/inbox_cleanup_scheduler_spec.rb b/spec/workers/scheduler/inbox_cleanup_scheduler_spec.rb new file mode 100644 index 00000000..81763b6c --- /dev/null +++ b/spec/workers/scheduler/inbox_cleanup_scheduler_spec.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +require "rails_helper" + +describe Scheduler::InboxCleanupScheduler do + let(:user) { FactoryBot.create(:user) } + let(:inbox) { FactoryBot.create(:inbox, user:) } + + describe "#perform" do + before do + inbox.question_id = nil + inbox.save(validate: false) + end + + subject { described_class.new.perform } + + it "should delete orphaned inbox entries" do + expect { subject } + .to( + change { Inbox.where(question_id: nil).count } + .from(1) + .to(0), + ) + end + end +end