From 65a81f97482895622124458a3a3acb032ba32bd7 Mon Sep 17 00:00:00 2001 From: Guillermo Aguirre Date: Thu, 25 Apr 2024 12:41:34 -0300 Subject: [PATCH] Rename Events to ActiveOutbox::Events to avoid conflicts. Bump to 0.2.0 (#22) * Rename Events to ActiveOutboxEvents to avoid conflicts. * Issue was raised that the Events const name was pretty common and this could cause conflicts. * Added false in const_defined so it won't lookup to ancestors. * Change spec definition ordering to make suite fail * Move CRUD specs to its own file * Namespace events constant with ActiveOutbox * Bump version to 0.2.0 * Cleanup Rubocop constraints --- .rubocop.yml | 8 ++++++ Gemfile.lock | 2 +- active_outbox.gemspec | 2 +- lib/active_outbox/outboxable.rb | 13 ++++++--- .../crud_spec.rb} | 0 spec/support/outbox_models.rb | 27 ++++++++++--------- 6 files changed, 34 insertions(+), 18 deletions(-) rename spec/lib/active_outbox/{outboxable_spec.rb => outboxable/crud_spec.rb} (100%) diff --git a/.rubocop.yml b/.rubocop.yml index 0b37a17..ee45021 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -33,5 +33,13 @@ RSpec/MultipleMemoizedHelpers: RSpec/NestedGroups: Max: 7 +RSpec/FilePath: + Exclude: + - spec/lib/active_outbox/outboxable/* + +RSpec/SpecFilePathFormat: + Exclude: + - spec/lib/active_outbox/outboxable/* + Style/Documentation: Enabled: false diff --git a/Gemfile.lock b/Gemfile.lock index c125514..ac3e31b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - active_outbox (0.1.4) + active_outbox (0.2.0) dry-configurable (~> 1.0) rails (>= 6.1) diff --git a/active_outbox.gemspec b/active_outbox.gemspec index 2bf3690..7d20961 100644 --- a/active_outbox.gemspec +++ b/active_outbox.gemspec @@ -5,7 +5,7 @@ Gem::Specification.new do |spec| spec.files = Dir['LICENSE.txt', 'README.md', 'lib/**/*', 'lib/active_outbox.rb'] spec.name = 'active_outbox' spec.summary = 'A Transactional Outbox implementation for ActiveRecord' - spec.version = '0.1.4' + spec.version = '0.2.0' spec.email = 'guillermoaguirre1@gmail.com' spec.executables = ['outbox'] diff --git a/lib/active_outbox/outboxable.rb b/lib/active_outbox/outboxable.rb index 38377c9..b70497f 100644 --- a/lib/active_outbox/outboxable.rb +++ b/lib/active_outbox/outboxable.rb @@ -10,16 +10,21 @@ module Outboxable *namespace, klass = name.underscore.upcase.split('/') namespace = namespace.reverse.join('.') - module_parent.const_set('Events', Module.new) unless module_parent.const_defined?('Events') + module_parent.const_set('ActiveOutbox', Module.new) unless module_parent.const_defined?('ActiveOutbox', false) + + unless module_parent::ActiveOutbox.const_defined?('Events', false) + module_parent::ActiveOutbox.const_set('Events', Module.new) + end { create: 'CREATED', update: 'UPDATED', destroy: 'DESTROYED' }.each do |key, value| const_name = "#{klass}_#{value}" - unless module_parent::Events.const_defined?(const_name) - module_parent::Events.const_set(const_name, "#{const_name}#{namespace.blank? ? '' : '.'}#{namespace}") + unless module_parent::ActiveOutbox::Events.const_defined?(const_name) + module_parent::ActiveOutbox::Events.const_set(const_name, + "#{const_name}#{namespace.blank? ? '' : '.'}#{namespace}") end - event_name = module_parent::Events.const_get(const_name) + event_name = module_parent::ActiveOutbox::Events.const_get(const_name) send("after_#{key}") { create_outbox!(key, event_name) } end diff --git a/spec/lib/active_outbox/outboxable_spec.rb b/spec/lib/active_outbox/outboxable/crud_spec.rb similarity index 100% rename from spec/lib/active_outbox/outboxable_spec.rb rename to spec/lib/active_outbox/outboxable/crud_spec.rb diff --git a/spec/support/outbox_models.rb b/spec/support/outbox_models.rb index f22cf0f..7eaeb4c 100644 --- a/spec/support/outbox_models.rb +++ b/spec/support/outbox_models.rb @@ -1,7 +1,18 @@ # frozen_string_literal: true +# NOTICE: +# Class definition ordering matters in this file. Do not change unless deemed necessary + Object.const_set('Uuid', Module.new) +Outbox = Class.new(ActiveRecord::Base) do + def self.name + 'Outbox' + end + + validates_presence_of :identifier, :payload, :aggregate, :aggregate_identifier, :event +end + Uuid::Outbox = Class.new(ActiveRecord::Base) do def self.name 'Uuid::Outbox' @@ -14,12 +25,13 @@ def self.table_name validates_presence_of :identifier, :payload, :aggregate, :aggregate_identifier, :event end -Outbox = Class.new(ActiveRecord::Base) do +FakeModel = Class.new(ActiveRecord::Base) do def self.name - 'Outbox' + 'FakeModel' end - validates_presence_of :identifier, :payload, :aggregate, :aggregate_identifier, :event + validates_presence_of :test_field + include ActiveOutbox::Outboxable end Uuid::FakeModel = Class.new(ActiveRecord::Base) do @@ -35,15 +47,6 @@ def self.table_name include ActiveOutbox::Outboxable end -FakeModel = Class.new(ActiveRecord::Base) do - def self.name - 'FakeModel' - end - - validates_presence_of :test_field - include ActiveOutbox::Outboxable -end - def create_migrations id_migrations uuid_migrations