diff --git a/CHANGELOG.md b/CHANGELOG.md index 602c60c64..fbb0ed1fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +## 1.3.3 - 2024-04-02 +### Changed +- add `parent_record` configuration so it can be easily overwritten + ## 1.3.2 - 2024-03-01 ### Changed - Updated dependencies to fix a security vulnerability diff --git a/Gemfile.lock b/Gemfile.lock index 7f49b64c6..38920b412 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - eventsimple (1.3.2) + eventsimple (1.3.3) dry-struct (~> 1.6) dry-types (~> 1.7) pg (~> 1.4) @@ -358,6 +358,7 @@ GEM PLATFORMS arm64-darwin-22 + arm64-darwin-23 x86_64-linux DEPENDENCIES diff --git a/lib/eventsimple/configuration.rb b/lib/eventsimple/configuration.rb index 6e0ae740f..923578e1d 100644 --- a/lib/eventsimple/configuration.rb +++ b/lib/eventsimple/configuration.rb @@ -4,6 +4,7 @@ module Eventsimple class Configuration attr_reader :max_concurrency_retries attr_writer :metadata_klass + attr_writer :parent_record_klass attr_accessor :retry_reactor_on_record_not_found attr_accessor :ui_visible_models @@ -12,6 +13,7 @@ def initialize @dispatchers = [] @max_concurrency_retries = 2 @metadata_klass = 'Eventsimple::Metadata' + @parent_record_klass = 'ApplicationRecord' @retry_reactor_on_record_not_found = false @ui_visible_models = [] # internal use only @@ -39,6 +41,10 @@ def dispatchers def metadata_klass @metadata_klass_const ||= @metadata_klass.constantize end + + def parent_record_klass + @parent_record_const ||= @parent_record_klass.constantize + end # rubocop:enable Naming/MemoizedInstanceVariableName end end diff --git a/lib/eventsimple/outbox/models/cursor.rb b/lib/eventsimple/outbox/models/cursor.rb index 04d3a562a..b8c5435af 100644 --- a/lib/eventsimple/outbox/models/cursor.rb +++ b/lib/eventsimple/outbox/models/cursor.rb @@ -2,7 +2,7 @@ module Eventsimple module Outbox - class Cursor < ApplicationRecord + class Cursor < Eventsimple.configuration.parent_record_klass self.table_name = 'eventsimple_outbox_cursors' def self.fetch(event_klass, group_number) diff --git a/lib/eventsimple/version.rb b/lib/eventsimple/version.rb index af68aa7e8..b2a3f355e 100644 --- a/lib/eventsimple/version.rb +++ b/lib/eventsimple/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Eventsimple - VERSION = '1.3.2' + VERSION = '1.3.3' end diff --git a/spec/dummy/app/models/common/secondary_application_record.rb b/spec/dummy/app/models/common/secondary_application_record.rb new file mode 100644 index 000000000..4ee44ce59 --- /dev/null +++ b/spec/dummy/app/models/common/secondary_application_record.rb @@ -0,0 +1,5 @@ +module Common + class SecondaryApplicationRecord < ActiveRecord::Base # rubocop:disable Rails/ApplicationRecord + self.abstract_class = true + end +end diff --git a/spec/dummy/db/schema.rb b/spec/dummy/db/schema.rb index 448630da2..d6a9864cd 100644 --- a/spec/dummy/db/schema.rb +++ b/spec/dummy/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2022_09_17_150839) do +ActiveRecord::Schema[7.1].define(version: 2022_09_17_150839) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -36,6 +36,7 @@ t.datetime "deleted_at" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.index ["canonical_id"], name: "index_users_on_canonical_id", unique: true end end diff --git a/spec/lib/eventsimple/configuration_spec.rb b/spec/lib/eventsimple/configuration_spec.rb index 8e662af55..1e03e3cb4 100644 --- a/spec/lib/eventsimple/configuration_spec.rb +++ b/spec/lib/eventsimple/configuration_spec.rb @@ -42,4 +42,20 @@ expect { config.metadata_klass }.to raise_error(NameError) end end + + describe '#parent_record_klass' do + it 'defaults to ApplicationRecord' do + expect(config.parent_record_klass).to eq(ApplicationRecord) + end + + it "raises when class name cannot be constantized" do + config.parent_record_klass = "Eventsimple::OtherClass" + expect { config.parent_record_klass }.to raise_error(NameError) + end + + it "sets to expected name when changed" do + config.parent_record_klass = "Common::SecondaryApplicationRecord" + expect(config.parent_record_klass).to eq(Common::SecondaryApplicationRecord) + end + end end