From 094995bdb33899e723711159c45f3330c791dec2 Mon Sep 17 00:00:00 2001 From: Orien Madgwick <497874+orien@users.noreply.github.com> Date: Sun, 28 Dec 2025 20:47:34 +0700 Subject: [PATCH 1/6] RuboCop: resolve `Style/FrozenStringLiteralComment` issues --- .rubocop_todo.yml | 39 ------------------- Gemfile | 2 + Rakefile | 2 + bin/console | 1 + event_sourcery-postgres.gemspec | 2 + lib/event_sourcery/postgres.rb | 2 + lib/event_sourcery/postgres/config.rb | 2 + lib/event_sourcery/postgres/event_store.rb | 2 + .../postgres/optimised_event_poll_waiter.rb | 2 + lib/event_sourcery/postgres/projector.rb | 2 + .../postgres/queue_with_interval_callback.rb | 2 + lib/event_sourcery/postgres/reactor.rb | 2 + lib/event_sourcery/postgres/schema.rb | 2 + lib/event_sourcery/postgres/table_owner.rb | 2 + lib/event_sourcery/postgres/tracker.rb | 2 + lib/event_sourcery/postgres/version.rb | 4 +- script/bench_reading_events.rb | 2 + script/bench_writing_events.rb | 2 + script/demonstrate_event_sequence_id_gaps.rb | 2 + spec/event_sourcery/postgres/config_spec.rb | 2 + .../postgres/event_store_spec.rb | 2 + .../optimised_event_poll_waiter_spec.rb | 2 + .../event_sourcery/postgres/projector_spec.rb | 2 + spec/event_sourcery/postgres/reactor_spec.rb | 2 + .../postgres/table_owner_spec.rb | 2 + spec/event_sourcery/postgres/tracker_spec.rb | 2 + spec/event_sourcery/postgres_spec.rb | 2 + spec/spec_helper.rb | 2 + spec/support/db_helpers.rb | 2 + spec/support/event_helpers.rb | 2 + spec/support/logging.rb | 2 + spec/support/test_events.rb | 2 + 32 files changed, 62 insertions(+), 40 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 9619618..2274499 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -50,7 +50,6 @@ Metrics/MethodLength: - 'lib/event_sourcery/postgres/optimised_event_poll_waiter.rb' - 'lib/event_sourcery/postgres/projector.rb' - 'lib/event_sourcery/postgres/schema.rb' - - 'script/demonstrate_event_sequence_id_gaps.rb' # Configuration parameters: CountComments, Max, CountAsOne. Metrics/ModuleLength: @@ -105,44 +104,6 @@ Style/Documentation: - 'lib/event_sourcery/postgres/schema.rb' - 'lib/event_sourcery/postgres/table_owner.rb' -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: always, always_true, never -Style/FrozenStringLiteralComment: - Exclude: - - '**/*.arb' - - 'Gemfile' - - 'Rakefile' - - 'bin/console' - - 'event_sourcery-postgres.gemspec' - - 'lib/event_sourcery/postgres.rb' - - 'lib/event_sourcery/postgres/config.rb' - - 'lib/event_sourcery/postgres/event_store.rb' - - 'lib/event_sourcery/postgres/optimised_event_poll_waiter.rb' - - 'lib/event_sourcery/postgres/projector.rb' - - 'lib/event_sourcery/postgres/queue_with_interval_callback.rb' - - 'lib/event_sourcery/postgres/reactor.rb' - - 'lib/event_sourcery/postgres/schema.rb' - - 'lib/event_sourcery/postgres/table_owner.rb' - - 'lib/event_sourcery/postgres/tracker.rb' - - 'lib/event_sourcery/postgres/version.rb' - - 'script/bench_reading_events.rb' - - 'script/bench_writing_events.rb' - - 'script/demonstrate_event_sequence_id_gaps.rb' - - 'spec/event_sourcery/postgres/config_spec.rb' - - 'spec/event_sourcery/postgres/event_store_spec.rb' - - 'spec/event_sourcery/postgres/optimised_event_poll_waiter_spec.rb' - - 'spec/event_sourcery/postgres/projector_spec.rb' - - 'spec/event_sourcery/postgres/reactor_spec.rb' - - 'spec/event_sourcery/postgres/table_owner_spec.rb' - - 'spec/event_sourcery/postgres/tracker_spec.rb' - - 'spec/event_sourcery/postgres_spec.rb' - - 'spec/spec_helper.rb' - - 'spec/support/db_helpers.rb' - - 'spec/support/event_helpers.rb' - - 'spec/support/logging.rb' - - 'spec/support/test_events.rb' - # Configuration parameters: AllowedVariables. Style/GlobalVars: Exclude: diff --git a/Gemfile b/Gemfile index 1bd427d..c1ad185 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' ruby '>= 2.2.0' diff --git a/Rakefile b/Rakefile index 530bfc1..e1ae4f9 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'bundler/gem_tasks' require 'rspec/core/rake_task' require 'rubocop/rake_task' diff --git a/bin/console b/bin/console index 752fdb2..4a476a2 100755 --- a/bin/console +++ b/bin/console @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +# frozen_string_literal: true require 'bundler/setup' require 'event_sourcery/postgres' diff --git a/event_sourcery-postgres.gemspec b/event_sourcery-postgres.gemspec index ff64397..cb6ab21 100644 --- a/event_sourcery-postgres.gemspec +++ b/event_sourcery-postgres.gemspec @@ -1,3 +1,5 @@ +# frozen_string_literal: true + lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'event_sourcery/postgres/version' diff --git a/lib/event_sourcery/postgres.rb b/lib/event_sourcery/postgres.rb index ff9ef75..9505a1f 100644 --- a/lib/event_sourcery/postgres.rb +++ b/lib/event_sourcery/postgres.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'sequel' Sequel.default_timezone = :utc diff --git a/lib/event_sourcery/postgres/config.rb b/lib/event_sourcery/postgres/config.rb index 49b9845..b086af9 100644 --- a/lib/event_sourcery/postgres/config.rb +++ b/lib/event_sourcery/postgres/config.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module EventSourcery module Postgres class Config diff --git a/lib/event_sourcery/postgres/event_store.rb b/lib/event_sourcery/postgres/event_store.rb index 7fe0e03..36d19e9 100644 --- a/lib/event_sourcery/postgres/event_store.rb +++ b/lib/event_sourcery/postgres/event_store.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module EventSourcery module Postgres class EventStore diff --git a/lib/event_sourcery/postgres/optimised_event_poll_waiter.rb b/lib/event_sourcery/postgres/optimised_event_poll_waiter.rb index d952b2e..c574b0a 100644 --- a/lib/event_sourcery/postgres/optimised_event_poll_waiter.rb +++ b/lib/event_sourcery/postgres/optimised_event_poll_waiter.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module EventSourcery module Postgres # Optimise poll interval with Postgres listen/notify diff --git a/lib/event_sourcery/postgres/projector.rb b/lib/event_sourcery/postgres/projector.rb index 2b8ebea..5d85a3c 100644 --- a/lib/event_sourcery/postgres/projector.rb +++ b/lib/event_sourcery/postgres/projector.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module EventSourcery module Postgres module Projector diff --git a/lib/event_sourcery/postgres/queue_with_interval_callback.rb b/lib/event_sourcery/postgres/queue_with_interval_callback.rb index 8a880d1..8a02f24 100644 --- a/lib/event_sourcery/postgres/queue_with_interval_callback.rb +++ b/lib/event_sourcery/postgres/queue_with_interval_callback.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module EventSourcery module Postgres class QueueWithIntervalCallback < ::Queue diff --git a/lib/event_sourcery/postgres/reactor.rb b/lib/event_sourcery/postgres/reactor.rb index 84cdd71..9a04aa4 100644 --- a/lib/event_sourcery/postgres/reactor.rb +++ b/lib/event_sourcery/postgres/reactor.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module EventSourcery module Postgres module Reactor diff --git a/lib/event_sourcery/postgres/schema.rb b/lib/event_sourcery/postgres/schema.rb index f290c78..6effc07 100644 --- a/lib/event_sourcery/postgres/schema.rb +++ b/lib/event_sourcery/postgres/schema.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module EventSourcery module Postgres module Schema diff --git a/lib/event_sourcery/postgres/table_owner.rb b/lib/event_sourcery/postgres/table_owner.rb index a822db9..73334ab 100644 --- a/lib/event_sourcery/postgres/table_owner.rb +++ b/lib/event_sourcery/postgres/table_owner.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module EventSourcery module Postgres module TableOwner diff --git a/lib/event_sourcery/postgres/tracker.rb b/lib/event_sourcery/postgres/tracker.rb index a0e1ec5..7cb6f49 100644 --- a/lib/event_sourcery/postgres/tracker.rb +++ b/lib/event_sourcery/postgres/tracker.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module EventSourcery module Postgres # This will set up a persisted event id tracker for processors. diff --git a/lib/event_sourcery/postgres/version.rb b/lib/event_sourcery/postgres/version.rb index 65949e2..bb84a1c 100644 --- a/lib/event_sourcery/postgres/version.rb +++ b/lib/event_sourcery/postgres/version.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + module EventSourcery module Postgres - VERSION = '0.9.1'.freeze + VERSION = '0.9.1' end end diff --git a/script/bench_reading_events.rb b/script/bench_reading_events.rb index 47bb611..63d7b88 100644 --- a/script/bench_reading_events.rb +++ b/script/bench_reading_events.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Usage: # # ❯ bundle exec ruby script/bench_reading_events.rb diff --git a/script/bench_writing_events.rb b/script/bench_writing_events.rb index 9a6afca..04baa67 100644 --- a/script/bench_writing_events.rb +++ b/script/bench_writing_events.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Usage: # # ❯ bundle exec ruby script/bench_writing_events.rb diff --git a/script/demonstrate_event_sequence_id_gaps.rb b/script/demonstrate_event_sequence_id_gaps.rb index 72f0776..1725597 100644 --- a/script/demonstrate_event_sequence_id_gaps.rb +++ b/script/demonstrate_event_sequence_id_gaps.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Demonstrates that sequence IDs may not be inserted linearly with concurrent # writers. # diff --git a/spec/event_sourcery/postgres/config_spec.rb b/spec/event_sourcery/postgres/config_spec.rb index 30d17cf..1416784 100644 --- a/spec/event_sourcery/postgres/config_spec.rb +++ b/spec/event_sourcery/postgres/config_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe EventSourcery::Postgres::Config do subject(:config) { described_class.new } diff --git a/spec/event_sourcery/postgres/event_store_spec.rb b/spec/event_sourcery/postgres/event_store_spec.rb index 085a882..7a430da 100644 --- a/spec/event_sourcery/postgres/event_store_spec.rb +++ b/spec/event_sourcery/postgres/event_store_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'timeout' RSpec.describe EventSourcery::Postgres::EventStore do diff --git a/spec/event_sourcery/postgres/optimised_event_poll_waiter_spec.rb b/spec/event_sourcery/postgres/optimised_event_poll_waiter_spec.rb index 2bc2d28..368db37 100644 --- a/spec/event_sourcery/postgres/optimised_event_poll_waiter_spec.rb +++ b/spec/event_sourcery/postgres/optimised_event_poll_waiter_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe EventSourcery::Postgres::OptimisedEventPollWaiter do let(:after_listen) { proc {} } subject(:waiter) { described_class.new(db_connection: db_connection, after_listen: after_listen) } diff --git a/spec/event_sourcery/postgres/projector_spec.rb b/spec/event_sourcery/postgres/projector_spec.rb index 4c0613f..9e9c2ea 100644 --- a/spec/event_sourcery/postgres/projector_spec.rb +++ b/spec/event_sourcery/postgres/projector_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe EventSourcery::Postgres::Projector do let(:projector_class) do Class.new do diff --git a/spec/event_sourcery/postgres/reactor_spec.rb b/spec/event_sourcery/postgres/reactor_spec.rb index 0a3d3f8..315b8ec 100644 --- a/spec/event_sourcery/postgres/reactor_spec.rb +++ b/spec/event_sourcery/postgres/reactor_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe EventSourcery::Postgres::Reactor do TermsConfirmationEmailSent = Class.new(EventSourcery::Event) ItemViewed = Class.new(EventSourcery::Event) diff --git a/spec/event_sourcery/postgres/table_owner_spec.rb b/spec/event_sourcery/postgres/table_owner_spec.rb index 13ddbd2..0f49356 100644 --- a/spec/event_sourcery/postgres/table_owner_spec.rb +++ b/spec/event_sourcery/postgres/table_owner_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe EventSourcery::Postgres::TableOwner do let(:table_owner_class) do Class.new do diff --git a/spec/event_sourcery/postgres/tracker_spec.rb b/spec/event_sourcery/postgres/tracker_spec.rb index d4abc9f..ce307fe 100644 --- a/spec/event_sourcery/postgres/tracker_spec.rb +++ b/spec/event_sourcery/postgres/tracker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe EventSourcery::Postgres::Tracker do subject(:postgres_tracker) { described_class.new(db_connection, table_name: table_name) } let(:table_name) { :tracker } diff --git a/spec/event_sourcery/postgres_spec.rb b/spec/event_sourcery/postgres_spec.rb index 754b448..d357a4b 100644 --- a/spec/event_sourcery/postgres_spec.rb +++ b/spec/event_sourcery/postgres_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe EventSourcery::Postgres do it 'has a version number' do expect(EventSourcery::Postgres::VERSION).not_to be nil diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2f5c1db..d2ccf56 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file was generated by the `rspec --init` command. Conventionally, all # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. # The generated `.rspec` file contains `--require spec_helper` which will cause diff --git a/spec/support/db_helpers.rb b/spec/support/db_helpers.rb index 0397d9b..75e83b2 100644 --- a/spec/support/db_helpers.rb +++ b/spec/support/db_helpers.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DBHelpers extend self diff --git a/spec/support/event_helpers.rb b/spec/support/event_helpers.rb index de36b34..2982338 100644 --- a/spec/support/event_helpers.rb +++ b/spec/support/event_helpers.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module EventHelpers def new_event(aggregate_id: SecureRandom.uuid, type: 'test_event', body: {}, id: nil, version: 1, created_at: nil, uuid: SecureRandom.uuid) diff --git a/spec/support/logging.rb b/spec/support/logging.rb index f737152..2371055 100644 --- a/spec/support/logging.rb +++ b/spec/support/logging.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + # quiet logging EventSourcery.config.logger.level = Logger::FATAL diff --git a/spec/support/test_events.rb b/spec/support/test_events.rb index f4248e5..6e77399 100644 --- a/spec/support/test_events.rb +++ b/spec/support/test_events.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + ItemAdded = Class.new(EventSourcery::Event) ItemRemoved = Class.new(EventSourcery::Event) TermsAccepted = Class.new(EventSourcery::Event) From f0df6a24c4758b92af8c702e66b82292f7f194f7 Mon Sep 17 00:00:00 2001 From: Orien Madgwick <497874+orien@users.noreply.github.com> Date: Sun, 28 Dec 2025 20:48:56 +0700 Subject: [PATCH 2/6] RuboCop: resolve `Lint/NonDeterministicRequireOrder` issues --- .rubocop_todo.yml | 5 ----- spec/spec_helper.rb | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 2274499..b4a783a 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -12,11 +12,6 @@ Lint/ConstantDefinitionInBlock: Exclude: - 'spec/event_sourcery/postgres/reactor_spec.rb' -# This cop supports unsafe autocorrection (--autocorrect-all). -Lint/NonDeterministicRequireOrder: - Exclude: - - 'spec/spec_helper.rb' - # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes, Max. Metrics/AbcSize: Exclude: diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d2ccf56..d0c3ce5 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -100,4 +100,4 @@ require 'event_sourcery/postgres' require 'event_sourcery/rspec/event_store_shared_examples' -Dir.glob(File.join(__dir__, 'support/**/*.rb')) { |f| require f } +Dir.glob(File.join(__dir__, 'support/**/*.rb')).sort.each { |f| require f } From b961a302635bdbf770bce3728e6ea7a3dac0f111 Mon Sep 17 00:00:00 2001 From: Orien Madgwick <497874+orien@users.noreply.github.com> Date: Sun, 28 Dec 2025 20:51:36 +0700 Subject: [PATCH 3/6] RuboCop: resolve `Lint/ConstantDefinitionInBlock` issues --- .rubocop_todo.yml | 6 ------ spec/event_sourcery/postgres/reactor_spec.rb | 8 ++++---- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index b4a783a..670a799 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,12 +6,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Configuration parameters: AllowedMethods. -# AllowedMethods: enums -Lint/ConstantDefinitionInBlock: - Exclude: - - 'spec/event_sourcery/postgres/reactor_spec.rb' - # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes, Max. Metrics/AbcSize: Exclude: diff --git a/spec/event_sourcery/postgres/reactor_spec.rb b/spec/event_sourcery/postgres/reactor_spec.rb index 315b8ec..bb43b42 100644 --- a/spec/event_sourcery/postgres/reactor_spec.rb +++ b/spec/event_sourcery/postgres/reactor_spec.rb @@ -1,10 +1,10 @@ # frozen_string_literal: true -RSpec.describe EventSourcery::Postgres::Reactor do - TermsConfirmationEmailSent = Class.new(EventSourcery::Event) - ItemViewed = Class.new(EventSourcery::Event) - EchoEvent = Class.new(EventSourcery::Event) +TermsConfirmationEmailSent = Class.new(EventSourcery::Event) +ItemViewed = Class.new(EventSourcery::Event) +EchoEvent = Class.new(EventSourcery::Event) +RSpec.describe EventSourcery::Postgres::Reactor do let(:reactor_class) do Class.new do include EventSourcery::Postgres::Reactor From 8eebd098d39560dba17354468e3518fc96013467 Mon Sep 17 00:00:00 2001 From: Orien Madgwick <497874+orien@users.noreply.github.com> Date: Sun, 28 Dec 2025 20:53:10 +0700 Subject: [PATCH 4/6] RuboCop: resolve `Style/AccessModifierDeclarations` issues --- .rubocop_todo.yml | 7 ------- spec/support/db_helpers.rb | 18 ++++++++++-------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 670a799..a22cae2 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -72,13 +72,6 @@ Naming/VariableNumber: Exclude: - 'spec/event_sourcery/postgres/reactor_spec.rb' -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: EnforcedStyle, AllowModifiersOnSymbols, AllowModifiersOnAttrs, AllowModifiersOnAliasMethod. -# SupportedStyles: inline, group -Style/AccessModifierDeclarations: - Exclude: - - 'spec/support/db_helpers.rb' - # Configuration parameters: AllowedConstants. Style/Documentation: Exclude: diff --git a/spec/support/db_helpers.rb b/spec/support/db_helpers.rb index 75e83b2..3918107 100644 --- a/spec/support/db_helpers.rb +++ b/spec/support/db_helpers.rb @@ -7,14 +7,6 @@ def db_connection $db_connection ||= new_db_connection end - module_function def new_db_connection - Sequel.connect("#{postgres_url}event_sourcery_test").extension(:pg_json) - end - - module_function def postgres_url - ENV.fetch('POSTGRESQL_URL', 'postgres://127.0.0.1:5432/') - end - def reset_database db_connection.execute('truncate table aggregates') %w[events events_without_optimistic_locking].each do |_| @@ -34,6 +26,16 @@ def recreate_database def release_advisory_locks(connection = db_connection) connection.fetch('SELECT pg_advisory_unlock_all();').to_a end + + module_function + + def new_db_connection + Sequel.connect("#{postgres_url}event_sourcery_test").extension(:pg_json) + end + + def postgres_url + ENV.fetch('POSTGRESQL_URL', 'postgres://127.0.0.1:5432/') + end end RSpec.configure do |config| From 099d129e6816acdfb9e462a43aa6a33e4e73c454 Mon Sep 17 00:00:00 2001 From: Orien Madgwick <497874+orien@users.noreply.github.com> Date: Sun, 28 Dec 2025 20:54:46 +0700 Subject: [PATCH 5/6] RuboCop: resolve `Style/ModuleFunction` issues --- .rubocop_todo.yml | 7 ------- spec/support/db_helpers.rb | 20 +++++++++----------- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index a22cae2..ecdf84b 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -98,13 +98,6 @@ Style/HashEachMethods: Exclude: - 'lib/event_sourcery/postgres/table_owner.rb' -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: EnforcedStyle, Autocorrect. -# SupportedStyles: module_function, extend_self, forbidden -Style/ModuleFunction: - Exclude: - - 'spec/support/db_helpers.rb' - # Configuration parameters: AllowedMethods. # AllowedMethods: respond_to_missing? Style/OptionalBooleanParameter: diff --git a/spec/support/db_helpers.rb b/spec/support/db_helpers.rb index 3918107..244a0d5 100644 --- a/spec/support/db_helpers.rb +++ b/spec/support/db_helpers.rb @@ -1,12 +1,20 @@ # frozen_string_literal: true module DBHelpers - extend self + module_function def db_connection $db_connection ||= new_db_connection end + def new_db_connection + Sequel.connect("#{postgres_url}event_sourcery_test").extension(:pg_json) + end + + def postgres_url + ENV.fetch('POSTGRESQL_URL', 'postgres://127.0.0.1:5432/') + end + def reset_database db_connection.execute('truncate table aggregates') %w[events events_without_optimistic_locking].each do |_| @@ -26,16 +34,6 @@ def recreate_database def release_advisory_locks(connection = db_connection) connection.fetch('SELECT pg_advisory_unlock_all();').to_a end - - module_function - - def new_db_connection - Sequel.connect("#{postgres_url}event_sourcery_test").extension(:pg_json) - end - - def postgres_url - ENV.fetch('POSTGRESQL_URL', 'postgres://127.0.0.1:5432/') - end end RSpec.configure do |config| From a4689a0ceaa79bac5e586fa3d1e27a88dc2c3ef1 Mon Sep 17 00:00:00 2001 From: Orien Madgwick <497874+orien@users.noreply.github.com> Date: Sun, 28 Dec 2025 20:56:55 +0700 Subject: [PATCH 6/6] RuboCop: resolve `Style/SlicingWithRange` issues --- .rubocop_todo.yml | 5 ----- CHANGELOG.md | 3 ++- spec/event_sourcery/postgres/reactor_spec.rb | 2 +- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index ecdf84b..bffb860 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -111,8 +111,3 @@ Style/SafeNavigation: Exclude: - 'lib/event_sourcery/postgres/optimised_event_poll_waiter.rb' - 'lib/event_sourcery/postgres/reactor.rb' - -# This cop supports unsafe autocorrection (--autocorrect-all). -Style/SlicingWithRange: - Exclude: - - 'spec/event_sourcery/postgres/reactor_spec.rb' diff --git a/CHANGELOG.md b/CHANGELOG.md index d4bd380..c90307f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Changed -- Resolve issues as identified by RuboCop ([#78], [#82]). +- Resolve issues as identified by RuboCop ([#78], [#82], [#83]). - Minor fixups in gem metadata ([#79]). - Remove support for older Ruby versions: Ruby 2.6 or greater is now required ([#80]). @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). [#79]: https://github.com/envato/event_sourcery-postgres/pull/79 [#80]: https://github.com/envato/event_sourcery-postgres/pull/80 [#82]: https://github.com/envato/event_sourcery-postgres/pull/82 +[#83]: https://github.com/envato/event_sourcery-postgres/pull/83 ## [0.9.1] - 2022-01-20 diff --git a/spec/event_sourcery/postgres/reactor_spec.rb b/spec/event_sourcery/postgres/reactor_spec.rb index bb43b42..5390424 100644 --- a/spec/event_sourcery/postgres/reactor_spec.rb +++ b/spec/event_sourcery/postgres/reactor_spec.rb @@ -204,7 +204,7 @@ def event_count end def latest_events(n = 1) - event_source.get_next_from(0, limit: 100)[-n..-1] + event_source.get_next_from(0, limit: 100)[-n..] end context "when the event emitted doesn't take actions" do