Sha256: 2cf5844ea38339d6de215673e2c2224dfae8dd85c614ac53d948fb584f531abf

Contents?: true

Size: 867 Bytes

Versions: 3

Compression:

Stored size: 867 Bytes

Contents

module NulogyMessageBusConsumer
  module Tasks
    RSpec.describe PruneProcessedMessages do
      let(:logger) { spy }
      let(:task) { described_class.new(logger, 10, 1.minute) }

      it "prunes old messages" do
        processed_message(2.minutes.ago)
        processed_message(1.minute.ago)

        task.call

        expect(ProcessedMessage.count).to be(0)
        expect(logger).to have_received(:info).with(/Pruned 2 processed messages/)
      end

      it "does not prune newer messages" do
        processed_message(2.minutes.ago)
        processed_message(1.minute.ago)
        keep = processed_message(1.minute.from_now)

        task.call

        expect(ProcessedMessage.ids).to contain_exactly(keep.id)
      end

      def processed_message(ago)
        ProcessedMessage.create!(id: SecureRandom.uuid, created_at: ago)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
nulogy_message_bus_consumer-2.0.1 spec/integration/nulogy_message_bus_consumer/tasks/prune_processed_messages_spec.rb
nulogy_message_bus_consumer-2.0.0 spec/integration/nulogy_message_bus_consumer/tasks/prune_processed_messages_spec.rb
nulogy_message_bus_consumer-1.0.0 spec/integration/nulogy_message_bus_consumer/tasks/prune_processed_messages_spec.rb