Skip to content

Commit

Permalink
Test default outbox class with ID config instead of reduntant specifi…
Browse files Browse the repository at this point in the history
…c ID one
  • Loading branch information
guillermoap committed Nov 10, 2023
1 parent ce7801e commit 6bbe53a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
4 changes: 2 additions & 2 deletions spec/lib/active_outbox/outboxable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,8 @@ def create_event_name(action)
end

context 'when model has default primary_key' do
let(:fake_model_class) { Id::FakeModel }
let(:outbox_class) { Id::Outbox }
let(:fake_model_class) { FakeModel }
let(:outbox_class) { Outbox }
let(:identifier) { 2 }
let(:new_identifier) { 6 }
let(:test_field) { 'test' }
Expand Down
2 changes: 1 addition & 1 deletion spec/support/00_outbox_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

ActiveOutbox.configure do |config|
config.outbox_mapping.merge!(
'id' => 'Id::Outbox',
'default' => 'Outbox',
'uuid' => 'Uuid::Outbox'
)
end
22 changes: 7 additions & 15 deletions spec/support/outbox_models.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

Object.const_set('Uuid', Module.new)
Object.const_set('Id', Module.new)

Uuid::Outbox = Class.new(ActiveRecord::Base) do
def self.name
'Uuid::Outbox'
Expand All @@ -14,13 +14,9 @@ def self.table_name
validates_presence_of :identifier, :payload, :aggregate, :aggregate_identifier, :event
end

Id::Outbox = Class.new(ActiveRecord::Base) do
Outbox = Class.new(ActiveRecord::Base) do
def self.name
'Id::Outbox'
end

def self.table_name
'id_outboxes'
'Outbox'
end

validates_presence_of :identifier, :payload, :aggregate, :aggregate_identifier, :event
Expand All @@ -39,13 +35,9 @@ def self.table_name
include ActiveOutbox::Outboxable
end

Id::FakeModel = Class.new(ActiveRecord::Base) do
FakeModel = Class.new(ActiveRecord::Base) do
def self.name
'Id::FakeModel'
end

def self.table_name
'id_fake_models'
'FakeModel'
end

validates_presence_of :test_field
Expand All @@ -58,11 +50,11 @@ def create_migrations
end

def id_migrations
ActiveRecord::Base.connection.create_table :id_fake_models, if_not_exists: true do |t|
ActiveRecord::Base.connection.create_table :fake_models, if_not_exists: true do |t|
t.string :test_field
end

ActiveRecord::Base.connection.create_table :id_outboxes, if_not_exists: true do |t|
ActiveRecord::Base.connection.create_table :outboxes, if_not_exists: true do |t|
t.send(ActiveOutbox::AdapterHelper.uuid_type, :identifier, null: false, index: { unique: true })
t.string :event, null: false
t.send(ActiveOutbox::AdapterHelper.json_type, :payload)
Expand Down

0 comments on commit 6bbe53a

Please sign in to comment.