From dc12cba44cf26440dc8147a36522a2e1f16a7031 Mon Sep 17 00:00:00 2001 From: bedrock-adam Date: Sat, 6 Apr 2024 16:33:14 +1100 Subject: [PATCH] remove application interface bangs --- README.md | 12 ++++---- lib/outboxer/database.rb | 4 +-- lib/outboxer/message.rb | 30 +++++++++---------- lib/outboxer/messages.rb | 10 +++---- spec/lib/outboxer/database/connect_spec.rb | 14 ++++----- spec/lib/outboxer/database/disconnect_spec.rb | 8 ++--- spec/lib/outboxer/message/backlog_spec.rb | 4 +-- spec/lib/outboxer/message/delete_spec.rb | 2 +- spec/lib/outboxer/message/failed_spec.rb | 8 ++--- spec/lib/outboxer/message/find_by_id_spec.rb | 6 ++-- spec/lib/outboxer/message/publish_spec.rb | 14 ++++----- spec/lib/outboxer/message/published_spec.rb | 8 ++--- spec/lib/outboxer/message/publishing_spec.rb | 8 ++--- spec/lib/outboxer/message/republish_spec.rb | 8 ++--- spec/lib/outboxer/messages/delete_all_spec.rb | 4 +-- .../outboxer/messages/delete_selected_spec.rb | 6 ++-- spec/lib/outboxer/messages/queue_spec.rb | 4 +-- .../outboxer/messages/republish_all_spec.rb | 4 +-- .../messages/republish_selected_spec.rb | 6 ++-- spec/spec_helper.rb | 2 +- tasks/database.rake | 8 ++--- 21 files changed, 86 insertions(+), 84 deletions(-) diff --git a/README.md b/README.md index 55021a9e..902e4bb5 100644 --- a/README.md +++ b/README.md @@ -37,14 +37,16 @@ bin/rails g outboxer:schema bin/rake db:migrate ``` -### create an outboxer message in the same transaction as the event record +### when an event is created, backlog an outboxer message (in same transaction) ```ruby class Event < ActiveRecord::Base # ... after_create do |event| - Outboxer::Message.backlog!(messageable_type: event.class.name, messageable_id: event.id) + Outboxer::Message.backlog( + messageable_type: event.class.name, + messageable_id: event.id) end end ``` @@ -73,10 +75,10 @@ bin/rails g outboxer:sidekiq_publisher ### update the publish block to add an event created job ```ruby -Outboxer::Publisher.publish! do |outboxer_message| - case outboxer_message.messageable_type +Outboxer::Publisher.publish do |outboxer_message| + case outboxer_message['messageable_type'] when 'Event' - EventCreatedJob.perform_async({ 'id' => outboxer_message.messageable_id }) + EventCreatedJob.perform_async({ 'id' => outboxer_message['messageable_id'] }) end end ``` diff --git a/lib/outboxer/database.rb b/lib/outboxer/database.rb index 076a948a..2c7987a0 100644 --- a/lib/outboxer/database.rb +++ b/lib/outboxer/database.rb @@ -15,7 +15,7 @@ def config(environment: ENV['RAILS_ENV'] || 'development', path: 'config/databas YAML.safe_load(db_config_erb_result, aliases: true)[environment] end - def connect!(config:, logger: nil) + def connect(config:, logger: nil) ActiveRecord::Base.logger = logger if logger ActiveRecord::Base.establish_connection(config) @@ -33,7 +33,7 @@ def connected? class DisconnectError < Error; end - def disconnect! + def disconnect ActiveRecord::Base.connection_handler.clear_active_connections! ActiveRecord::Base.connection_handler.connection_pool_list.each(&:disconnect!) rescue => error diff --git a/lib/outboxer/message.rb b/lib/outboxer/message.rb index 084bcd5e..2bf325ac 100644 --- a/lib/outboxer/message.rb +++ b/lib/outboxer/message.rb @@ -9,7 +9,7 @@ class Error < Outboxer::Error; end; class NotFound < Error; end class InvalidTransition < Error; end - def backlog!(messageable_type:, messageable_id:) + def backlog(messageable_type:, messageable_id:) ActiveRecord::Base.connection_pool.with_connection do ActiveRecord::Base.transaction do message = Models::Message.create!( @@ -22,7 +22,7 @@ def backlog!(messageable_type:, messageable_id:) end end - def find_by_id!(id:) + def find_by_id(id:) ActiveRecord::Base.connection_pool.with_connection do ActiveRecord::Base.transaction do message = Models::Message.includes(exceptions: :frames).find_by!(id: id) @@ -55,7 +55,7 @@ def find_by_id!(id:) raise NotFound, "Couldn't find Outboxer::Models::Message with id #{id}" end - def publishing!(id:) + def publishing(id:) ActiveRecord::Base.connection_pool.with_connection do ActiveRecord::Base.transaction do message = Models::Message.lock.find_by!(id: id) @@ -79,7 +79,7 @@ def publishing!(id:) end - def published!(id:) + def published(id:) ActiveRecord::Base.connection_pool.with_connection do ActiveRecord::Base.transaction do message = Models::Message.lock.find_by!(id: id) @@ -99,7 +99,7 @@ def published!(id:) end end - def failed!(id:, exception:) + def failed(id:, exception:) ActiveRecord::Base.connection_pool.with_connection do ActiveRecord::Base.transaction do message = Models::Message.order(created_at: :asc).lock.find_by!(id: id) @@ -124,7 +124,7 @@ def failed!(id:, exception:) end end - def delete!(id:) + def delete(id:) ActiveRecord::Base.connection_pool.with_connection do ActiveRecord::Base.transaction do message = Models::Message.includes(exceptions: :frames).lock.find_by!(id: id) @@ -138,7 +138,7 @@ def delete!(id:) end end - def republish!(id:) + def republish(id:) ActiveRecord::Base.connection_pool.with_connection do ActiveRecord::Base.transaction do message = Models::Message.lock.find_by!(id: id) @@ -156,14 +156,14 @@ def republish!(id:) end end - def stop_publishing! + def stop_publishing @publishing = false end - def publish!(threads: 5, queue: 10, poll: 1, + def publish(threads: 5, queue: 10, poll: 1, logger: Logger.new($stdout, level: ::Logger::INFO), kernel: Kernel, &block) - Database.connect!(config: Database.config, logger: logger) unless Database.connected? + Database.connect(config: Database.config, logger: logger) unless Database.connected? ruby_queue = Queue.new @@ -184,19 +184,19 @@ def publish!(threads: 5, queue: 10, poll: 1, end logger.info "Publishing message (id: #{message['id']}) }" - message = Message.publishing!(id: message['id']) + message = Message.publishing(id: message['id']) begin block.call(message) rescue Exception => exception logger.error "Failed to publish message { id: #{message['id']}, error: #{exception} }" - Message.failed!(id: message['id'], exception: exception) + Message.failed(id: message['id'], exception: exception) raise end logger.info "Published message { id: #{message['id']} }" - Message.published!(id: message['id']) + Message.published(id: message['id']) rescue => exception logger.error "#{exception.class}: #{exception.message}" rescue Exception => exception @@ -221,7 +221,7 @@ def publish!(threads: 5, queue: 10, poll: 1, messages = [] queue_remaining = queue - ruby_queue.length - messages = (queue_remaining > 0) ? Messages.queue!(limit: queue_remaining) : [] + messages = (queue_remaining > 0) ? Messages.queue(limit: queue_remaining) : [] messages.each { |message| ruby_queue.push({ 'id' => message['id'] }) } kernel.sleep(poll) if messages.empty? || (ruby_queue.length >= queue) @@ -241,7 +241,7 @@ def publish!(threads: 5, queue: 10, poll: 1, logger.info "Stopped publishing queued messages" - Database.disconnect! + Database.disconnect logger.info "Shut down gracefully" end diff --git a/lib/outboxer/messages.rb b/lib/outboxer/messages.rb index 4584238a..3789a231 100644 --- a/lib/outboxer/messages.rb +++ b/lib/outboxer/messages.rb @@ -22,7 +22,7 @@ def counts_by_status end end - def queue!(limit: 1) + def queue(limit: 1) ActiveRecord::Base.connection_pool.with_connection do ActiveRecord::Base.transaction do ids = Models::Message @@ -99,7 +99,7 @@ def list(status: nil, sort: :updated_at, order: :asc, page: 1, per_page: 100) end end - def republish_all!(batch_size: 100) + def republish_all(batch_size: 100) updated_total_count = 0 ActiveRecord::Base.connection_pool.with_connection do @@ -130,7 +130,7 @@ def republish_all!(batch_size: 100) { 'count' => updated_total_count } end - def republish_selected!(ids:) + def republish_selected(ids:) updated_count = 0 ActiveRecord::Base.connection_pool.with_connection do @@ -154,7 +154,7 @@ def republish_selected!(ids:) { 'count' => updated_count } end - def delete_all!(batch_size: 100) + def delete_all(batch_size: 100) deleted_total_count = 0 ActiveRecord::Base.connection_pool.with_connection do @@ -184,7 +184,7 @@ def delete_all!(batch_size: 100) { 'count' => deleted_total_count } end - def delete_selected!(ids:) + def delete_selected(ids:) deleted_count = 0 ActiveRecord::Base.connection_pool.with_connection do diff --git a/spec/lib/outboxer/database/connect_spec.rb b/spec/lib/outboxer/database/connect_spec.rb index 95b991b0..e7b32128 100644 --- a/spec/lib/outboxer/database/connect_spec.rb +++ b/spec/lib/outboxer/database/connect_spec.rb @@ -4,12 +4,12 @@ module Outboxer RSpec.describe Database do - describe '.connect!' do - before(:each) { Database.disconnect! } + describe '.connect' do + before(:each) { Database.disconnect } after(:all) do config = Database.config(environment: 'test') - Database.connect!(config: config) + Database.connect(config: config) end context 'when db config not valid' do @@ -23,13 +23,13 @@ module Outboxer it 'establishes a connection without errors' do expect do - Database.connect!(config: config) + Database.connect(config: config) end.to raise_error(Database::ConnectError) end it 'does not connect to the database' do begin - Database.connect!(config: config) + Database.connect(config: config) rescue Database::ConnectError # ignore end @@ -42,11 +42,11 @@ module Outboxer let(:config) { Database.config(environment: 'test') } it 'establishes a connection without errors' do - expect { Database.connect!(config: config) }.not_to raise_error + expect { Database.connect(config: config) }.not_to raise_error end it 'actually connects to the database' do - Database.connect!(config: config) + Database.connect(config: config) expect(Database.connected?).to be true end diff --git a/spec/lib/outboxer/database/disconnect_spec.rb b/spec/lib/outboxer/database/disconnect_spec.rb index c72cb4bd..21c4ac86 100644 --- a/spec/lib/outboxer/database/disconnect_spec.rb +++ b/spec/lib/outboxer/database/disconnect_spec.rb @@ -2,14 +2,14 @@ module Outboxer RSpec.describe Database do - describe '.disconnect!' do + describe '.disconnect' do context 'when successful' do it 'does not raise an error' do - expect { Database.disconnect! }.not_to raise_error + expect { Database.disconnect }.not_to raise_error end it 'returns connected false' do - Database.disconnect! + Database.disconnect expect(Database.connected?).to be false end @@ -22,7 +22,7 @@ module Outboxer end it 'raises a DisconnectError' do - expect { Database.disconnect! }.to raise_error(Database::DisconnectError) + expect { Database.disconnect }.to raise_error(Database::DisconnectError) end end end diff --git a/spec/lib/outboxer/message/backlog_spec.rb b/spec/lib/outboxer/message/backlog_spec.rb index 8347b271..0c46c8d3 100644 --- a/spec/lib/outboxer/message/backlog_spec.rb +++ b/spec/lib/outboxer/message/backlog_spec.rb @@ -2,9 +2,9 @@ module Outboxer RSpec.describe Message do - describe '.backlog!' do + describe '.backlog' do let!(:backlogged_message) do - Message.backlog!(messageable_type: 'Event', messageable_id: '1') + Message.backlog(messageable_type: 'Event', messageable_id: '1') end it 'returns backlogged message' do diff --git a/spec/lib/outboxer/message/delete_spec.rb b/spec/lib/outboxer/message/delete_spec.rb index 927f3f51..b5a33877 100644 --- a/spec/lib/outboxer/message/delete_spec.rb +++ b/spec/lib/outboxer/message/delete_spec.rb @@ -7,7 +7,7 @@ module Outboxer let!(:exception) { create(:outboxer_exception, message: message) } let!(:frame) { create(:outboxer_frame, exception: exception) } - let!(:result) { Message.delete!(id: message.id) } + let!(:result) { Message.delete(id: message.id) } it 'deletes the message' do expect(Models::Message).not_to exist(message.id) diff --git a/spec/lib/outboxer/message/failed_spec.rb b/spec/lib/outboxer/message/failed_spec.rb index 58174804..65770709 100644 --- a/spec/lib/outboxer/message/failed_spec.rb +++ b/spec/lib/outboxer/message/failed_spec.rb @@ -2,7 +2,7 @@ module Outboxer RSpec.describe Message do - describe '.failed!' do + describe '.failed' do let(:exception) do def raise_exception begin @@ -18,7 +18,7 @@ def raise_exception context 'when published message' do let!(:publishing_message) { create(:outboxer_message, :publishing) } - let!(:failed_message) { Message.failed!(id: publishing_message.id, exception: exception) } + let!(:failed_message) { Message.failed(id: publishing_message.id, exception: exception) } it 'returns updated message' do expect(failed_message['id']).to eq(publishing_message.id) @@ -54,7 +54,7 @@ def raise_exception it 'raises invalid transition error' do expect do - Message.failed!(id: backlogged_message.id, exception: exception) + Message.failed(id: backlogged_message.id, exception: exception) end.to raise_error( Message::InvalidTransition, "cannot transition outboxer message #{backlogged_message.id} " + @@ -63,7 +63,7 @@ def raise_exception it 'does not delete backlogged message' do begin - Message.failed!(id: backlogged_message.id, exception: exception) + Message.failed(id: backlogged_message.id, exception: exception) rescue Message::InvalidTransition # ignore end diff --git a/spec/lib/outboxer/message/find_by_id_spec.rb b/spec/lib/outboxer/message/find_by_id_spec.rb index b8be6898..4aaf2942 100644 --- a/spec/lib/outboxer/message/find_by_id_spec.rb +++ b/spec/lib/outboxer/message/find_by_id_spec.rb @@ -2,14 +2,14 @@ module Outboxer RSpec.describe Message do - describe '.find_by_id!' do + describe '.find_by_id' do context 'when a failed message exists' do let!(:message) { create(:outboxer_message, :failed) } let!(:exception) { create(:outboxer_exception, message: message) } let!(:frame) { create(:outboxer_frame, exception: exception) } it 'returns the message, exceptions and frames' do - result = Message.find_by_id!(id: message.id) + result = Message.find_by_id(id: message.id) expect(result['id']).to eq(message.id) expect(result['status']).to eq('failed') @@ -26,7 +26,7 @@ module Outboxer context 'when the message does not exist' do it 'raises a NotFound error' do - expect { Message.find_by_id!(id: -1) }.to raise_error(Message::NotFound) + expect { Message.find_by_id(id: -1) }.to raise_error(Message::NotFound) end end end diff --git a/spec/lib/outboxer/message/publish_spec.rb b/spec/lib/outboxer/message/publish_spec.rb index 5b395509..6098be93 100644 --- a/spec/lib/outboxer/message/publish_spec.rb +++ b/spec/lib/outboxer/message/publish_spec.rb @@ -2,7 +2,7 @@ module Outboxer RSpec.describe Message do - describe '.publish!' do + describe '.publish' do let(:queue) { 1 } let(:threads) { 1 } let(:poll) { 1 } @@ -17,7 +17,7 @@ module Outboxer context 'when message published successfully' do it 'deletes existing message' do - Message.publish!( + Message.publish( queue: queue, threads: threads, poll: poll, @@ -29,7 +29,7 @@ module Outboxer expect(message['messageable_id']).to eq(backlogged_message.messageable_id) expect(message['status']).to eq(Models::Message::Status::PUBLISHING) - Message.stop_publishing! + Message.stop_publishing end expect(Models::Message.count).to eq(0) @@ -41,14 +41,14 @@ module Outboxer let(:standard_error) { StandardError.new('some error') } before do - Message.publish!( + Message.publish( queue: queue, threads: threads, poll: poll, logger: logger, kernel: kernel ) do |message| - Message.stop_publishing! + Message.stop_publishing raise standard_error end @@ -83,14 +83,14 @@ module Outboxer let(:no_memory_error) { NoMemoryError.new } before do - Message.publish!( + Message.publish( queue: queue, threads: threads, poll: poll, logger: logger, kernel: kernel ) do |queued_message| - Message.stop_publishing! + Message.stop_publishing raise no_memory_error end diff --git a/spec/lib/outboxer/message/published_spec.rb b/spec/lib/outboxer/message/published_spec.rb index 082a69d9..041999fc 100644 --- a/spec/lib/outboxer/message/published_spec.rb +++ b/spec/lib/outboxer/message/published_spec.rb @@ -2,11 +2,11 @@ module Outboxer RSpec.describe Message do - describe '.published!' do + describe '.published' do context 'when publishing message' do let!(:publishing_message) { create(:outboxer_message, :publishing) } - let!(:published_message) { Message.published!(id: publishing_message.id) } + let!(:published_message) { Message.published(id: publishing_message.id) } it 'returns nil' do expect(published_message).to eq({ 'id' => publishing_message.id }) @@ -22,7 +22,7 @@ module Outboxer it 'raises invalid transition error' do expect do - Message.published!(id: backlogged_message.id) + Message.published(id: backlogged_message.id) end.to raise_error( Message::InvalidTransition, "cannot transition outboxer message #{backlogged_message.id} " + @@ -31,7 +31,7 @@ module Outboxer it 'does not delete backlogged message' do begin - Message.published!(id: backlogged_message.id) + Message.published(id: backlogged_message.id) rescue Message::InvalidTransition # ignore end diff --git a/spec/lib/outboxer/message/publishing_spec.rb b/spec/lib/outboxer/message/publishing_spec.rb index 789d8ac4..298f3041 100644 --- a/spec/lib/outboxer/message/publishing_spec.rb +++ b/spec/lib/outboxer/message/publishing_spec.rb @@ -2,10 +2,10 @@ module Outboxer RSpec.describe Message do - describe '.publishing!' do + describe '.publishing' do context 'when queued message' do let!(:queued_message) { create(:outboxer_message, :queued) } - let!(:publishing_message) { Message.publishing!(id: queued_message.id) } + let!(:publishing_message) { Message.publishing(id: queued_message.id) } it 'returns publishing message' do expect(publishing_message['id']).to eq(Models::Message.publishing.last.id) @@ -17,7 +17,7 @@ module Outboxer it 'raises invalid transition error' do expect do - Message.publishing!(id: backlogged_message.id) + Message.publishing(id: backlogged_message.id) end.to raise_error( Message::InvalidTransition, "cannot transition outboxer message #{backlogged_message.id} " + @@ -26,7 +26,7 @@ module Outboxer it 'does not delete backlogged message' do begin - Message.publishing!(id: backlogged_message.id) + Message.publishing(id: backlogged_message.id) rescue Message::InvalidTransition # ignore end diff --git a/spec/lib/outboxer/message/republish_spec.rb b/spec/lib/outboxer/message/republish_spec.rb index 11230c3b..9aeb9d5c 100644 --- a/spec/lib/outboxer/message/republish_spec.rb +++ b/spec/lib/outboxer/message/republish_spec.rb @@ -2,11 +2,11 @@ module Outboxer RSpec.describe Message do - describe '.republish!' do + describe '.republish' do context 'when failed message' do let!(:failed_message) { create(:outboxer_message, :failed) } - let!(:backlogged_message) { Message.republish!(id: failed_message.id) } + let!(:backlogged_message) { Message.republish(id: failed_message.id) } it 'returns backlogged message' do expect(backlogged_message['id']).to eq(failed_message.id) @@ -24,7 +24,7 @@ module Outboxer it 'raises invalid transition error' do expect do - Message.republish!(id: backlogged_message.id) + Message.republish(id: backlogged_message.id) end.to raise_error( Message::InvalidTransition, "cannot transition outboxer message #{backlogged_message.id} " + @@ -33,7 +33,7 @@ module Outboxer it 'does not delete backlogged message' do begin - Message.published!(id: backlogged_message.id) + Message.published(id: backlogged_message.id) rescue Message::InvalidTransition # ignore end diff --git a/spec/lib/outboxer/messages/delete_all_spec.rb b/spec/lib/outboxer/messages/delete_all_spec.rb index abda78aa..ac4479b0 100644 --- a/spec/lib/outboxer/messages/delete_all_spec.rb +++ b/spec/lib/outboxer/messages/delete_all_spec.rb @@ -2,7 +2,7 @@ module Outboxer RSpec.describe Messages do - describe '.delete_all!' 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) } @@ -11,7 +11,7 @@ module Outboxer let!(:exception_2) { create(:outboxer_exception, message: message_2) } let!(:frame) { create(:outboxer_frame, exception: exception_2) } - let!(:result) { Messages.delete_all! } + let!(:result) { Messages.delete_all } it 'deletes all messages' do expect(Models::Message.count).to eq(0) diff --git a/spec/lib/outboxer/messages/delete_selected_spec.rb b/spec/lib/outboxer/messages/delete_selected_spec.rb index fc780094..051cb493 100644 --- a/spec/lib/outboxer/messages/delete_selected_spec.rb +++ b/spec/lib/outboxer/messages/delete_selected_spec.rb @@ -2,7 +2,7 @@ module Outboxer RSpec.describe Messages do - describe '.delete_selected!' do + describe '.delete_selected' do let!(:message_1) { create(:outboxer_message, :backlogged) } let!(:message_2) { create(:outboxer_message, :queued) } @@ -15,7 +15,7 @@ module Outboxer describe 'when ids exist' do let!(:ids) { [message_1.id, message_2.id, message_3.id] } - let!(:result) { Messages.delete_selected!(ids: ids) } + let!(:result) { Messages.delete_selected(ids: ids) } it 'deletes selected messages' do expect(Models::Frame.count).to eq(0) @@ -32,7 +32,7 @@ module Outboxer let(:nonexistent_id) { 5 } it 'raises NotFound' do - expect { Messages.delete_selected!(ids: [message_1.id, nonexistent_id]) } + expect { Messages.delete_selected(ids: [message_1.id, nonexistent_id]) } .to raise_error(NotFound, "Some IDs could not be found: #{nonexistent_id}") end diff --git a/spec/lib/outboxer/messages/queue_spec.rb b/spec/lib/outboxer/messages/queue_spec.rb index 901082bc..f2636299 100644 --- a/spec/lib/outboxer/messages/queue_spec.rb +++ b/spec/lib/outboxer/messages/queue_spec.rb @@ -2,7 +2,7 @@ module Outboxer RSpec.describe Messages do - describe '.queue!' do + describe '.queue' do context 'when there are 2 backlogged messages' do let!(:backlogged_messages) do [ @@ -12,7 +12,7 @@ module Outboxer end context 'when limit is 1' do - let!(:queued_messages) { Messages.queue!(limit: 1) } + let!(:queued_messages) { Messages.queue(limit: 1) } it 'returns first backlogged message' do expect(queued_messages.count).to eq(1) diff --git a/spec/lib/outboxer/messages/republish_all_spec.rb b/spec/lib/outboxer/messages/republish_all_spec.rb index 97768df3..a98cb8d0 100644 --- a/spec/lib/outboxer/messages/republish_all_spec.rb +++ b/spec/lib/outboxer/messages/republish_all_spec.rb @@ -2,7 +2,7 @@ module Outboxer RSpec.describe Messages do - describe '.republish_all!' do + describe '.republish_all' do let!(:message_1) { create(:outboxer_message, :backlogged) } let!(:exception_1) { create(:outboxer_exception, message: message_1) } let!(:frame_1) { create(:outboxer_frame, exception: exception_1) } @@ -19,7 +19,7 @@ module Outboxer let!(:exception_4) { create(:outboxer_exception, message: message_4) } let!(:frame_4) { create(:outboxer_frame, exception: exception_4) } - let!(:result) { Messages.republish_all!(batch_size: 1) } + let!(:result) { Messages.republish_all(batch_size: 1) } it 'sets failed messages to backlogged' do expect( diff --git a/spec/lib/outboxer/messages/republish_selected_spec.rb b/spec/lib/outboxer/messages/republish_selected_spec.rb index 731e7841..c95985dd 100644 --- a/spec/lib/outboxer/messages/republish_selected_spec.rb +++ b/spec/lib/outboxer/messages/republish_selected_spec.rb @@ -2,7 +2,7 @@ module Outboxer RSpec.describe Messages do - describe '.republish_selected!' do + describe '.republish_selected' 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) } @@ -12,7 +12,7 @@ module Outboxer let!(:frame_2) { create(:outboxer_frame, exception: exception_2) } let!(:ids) { [message_1.id, message_2.id] } - let!(:result) { Messages.republish_selected!(ids: ids) } + let!(:result) { Messages.republish_selected(ids: ids) } describe 'when ids exist' do it 'sets message status to backlogged' do @@ -33,7 +33,7 @@ module Outboxer let(:nonexistent_id) { 5 } it 'raises NotFound' do - expect { Messages.republish_selected!(ids: [nonexistent_id]) } + expect { Messages.republish_selected(ids: [nonexistent_id]) } .to raise_error(NotFound, "Some IDs could not be found: #{nonexistent_id}") end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a63a01c1..ca127e79 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -21,7 +21,7 @@ config.before(:all) do db_config = Outboxer::Database.config(environment: 'test') - Outboxer::Database.connect!(config: db_config) + Outboxer::Database.connect(config: db_config) DatabaseCleaner.strategy = :truncation end diff --git a/tasks/database.rake b/tasks/database.rake index a3cb3784..c916b5ec 100644 --- a/tasks/database.rake +++ b/tasks/database.rake @@ -11,7 +11,7 @@ namespace :outboxer do ActiveRecord::Base.establish_connection(db_config.merge('database' => 'postgres')) ActiveRecord::Base.connection.drop_database(db_config['database']) - ActiveRecord::Base.connection.disconnect! + ActiveRecord::Base.connection.disconnect end task :create do @@ -20,7 +20,7 @@ namespace :outboxer do ActiveRecord::Base.establish_connection(db_config.merge('database' => 'postgres')) ActiveRecord::Base.connection.create_database(db_config['database']) - ActiveRecord::Base.connection.disconnect! + ActiveRecord::Base.connection.disconnect end task :migrate do @@ -37,7 +37,7 @@ namespace :outboxer do require_relative "../db/migrate/create_outboxer_frames" CreateOutboxerFrames.new.up - ActiveRecord::Base.connection.disconnect! + ActiveRecord::Base.connection.disconnect end task :seed do @@ -47,7 +47,7 @@ namespace :outboxer do require_relative "../db/seeds" - ActiveRecord::Base.connection.disconnect! + ActiveRecord::Base.connection.disconnect end task :setup => [:create, :migrate, :seed]