From f67db83ac0883a13b32011721004843aed81fb05 Mon Sep 17 00:00:00 2001 From: Santiago C Date: Tue, 26 May 2026 13:03:20 -0300 Subject: [PATCH] Revert "feat: raise on unknown options in Session.new (#44)" This reverts commit 62d4e3a44844423e65fb3204ff784374bc40caa5. --- lib/staging_table/session.rb | 35 +----------------------- spec/staging_table/session_spec.rb | 44 ------------------------------ 2 files changed, 1 insertion(+), 78 deletions(-) diff --git a/lib/staging_table/session.rb b/lib/staging_table/session.rb index 24356cc..e180ae1 100644 --- a/lib/staging_table/session.rb +++ b/lib/staging_table/session.rb @@ -13,28 +13,14 @@ class Session # - after_transfer: ->(session, result) { ... } CALLBACK_OPTIONS = %i[before_insert after_insert before_transfer after_transfer].freeze - # All non-callback options the session understands. Any other keyword - # passed to `.new` raises `ConfigurationError` so typos surface up front - # instead of silently disappearing (see issue #33). - KNOWN_OPTIONS = %i[ - batch_size - transfer_strategy - conflict_target - conflict_action - excluded_columns - include_indexes - ].freeze - def initialize(source_model, **options) @source_model = source_model config = StagingTable.configuration @callbacks = options.slice(*CALLBACK_OPTIONS) - non_callback_options = options.except(*CALLBACK_OPTIONS) - validate_options!(non_callback_options) @options = { batch_size: config.default_batch_size, transfer_strategy: config.default_transfer_strategy - }.merge(non_callback_options) + }.merge(options.except(*CALLBACK_OPTIONS)) @table_created = false end @@ -196,24 +182,5 @@ def normalize_record(record) record.attributes_for_database end - - def validate_options!(options) - unknown = options.keys - KNOWN_OPTIONS - return if unknown.empty? - - messages = unknown.map do |key| - suggestion = DidYouMean::SpellChecker.new(dictionary: KNOWN_OPTIONS.map(&:to_s)).correct(key.to_s).first - if suggestion - "#{key.inspect} (did you mean #{suggestion.to_sym.inspect}?)" - else - key.inspect - end - end - - allowed = (KNOWN_OPTIONS + CALLBACK_OPTIONS).sort.map(&:inspect).join(", ") - raise ConfigurationError, - "Unknown option(s) for StagingTable::Session: #{messages.join(', ')}. " \ - "Allowed options: #{allowed}." - end end end diff --git a/spec/staging_table/session_spec.rb b/spec/staging_table/session_spec.rb index f90a504..c8057f9 100644 --- a/spec/staging_table/session_spec.rb +++ b/spec/staging_table/session_spec.rb @@ -249,50 +249,6 @@ end end - describe ".new option validation" do - it "accepts all documented KNOWN_OPTIONS" do - expect { - described_class.new(TestUser, - batch_size: 500, - transfer_strategy: :insert, - conflict_target: [:email], - conflict_action: :update, - excluded_columns: %w[created_at], - include_indexes: true) - }.not_to raise_error - end - - it "still accepts callback options alongside known options" do - expect { - described_class.new(TestUser, - batch_size: 100, - before_insert: ->(_) {}, - after_transfer: ->(_, _) {}) - }.not_to raise_error - end - - it "raises ConfigurationError on a typo'd option" do - expect { - described_class.new(TestUser, transfer_stratgy: :upsert) - }.to raise_error(StagingTable::ConfigurationError, /:transfer_stratgy/) - end - - it "suggests the closest known option in the error message" do - expect { - described_class.new(TestUser, confict_target: [:email]) - }.to raise_error(StagingTable::ConfigurationError, /did you mean :conflict_target/) - end - - it "lists every unknown option when multiple are passed" do - expect { - described_class.new(TestUser, transfer_stratgy: :upsert, made_up: 1) - }.to raise_error(StagingTable::ConfigurationError) { |e| - expect(e.message).to include(":transfer_stratgy") - expect(e.message).to include(":made_up") - } - end - end - context "with MySQL", :mysql do include_examples "session" end