Skip to content

Commit

Permalink
add Messages.delete_all! (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
bedrock-adam authored Mar 16, 2024
1 parent 662d0f8 commit 653a2ef
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/outboxer/messages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,17 @@ def unpublished!(limit: 1, order: :asc)
.to_a
end
end

def delete_all!
ActiveRecord::Base.connection_pool.with_connection do
ActiveRecord::Base.transaction do
Models::Frame.delete_all
Models::Exception.delete_all
Models::Message.delete_all
end
end

nil
end
end
end
33 changes: 33 additions & 0 deletions spec/lib/outboxer/messages/delete_all_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require 'spec_helper'

module Outboxer
RSpec.describe Messages do
describe '.delete_all!' do
let!(:message_1) { create(:outboxer_message, :failed) }
let!(:exception_1) { create(:outboxer_exception, message: message_1) }
let!(:frame_1) { create(:outboxer_frame, exception: exception_1) }

let!(:message_2) { create(:outboxer_message, :failed) }
let!(:exception_2) { create(:outboxer_exception, message: message_2) }
let!(:frame) { create(:outboxer_frame, exception: exception_2) }

let!(:result) { Messages.delete_all! }

it 'deletes all messages' do
expect(Models::Message.count).to eq(0)
end

it 'deletes all exceptions' do
expect(Models::Exception.count).to eq(0)
end

it 'deletes all frames' do
expect(Models::Frame.count).to eq(0)
end

it 'returns nil' do
expect(result).to be_nil
end
end
end
end

0 comments on commit 653a2ef

Please sign in to comment.