From 52f37f898044f1ed1acedb6b41130a5a2be8bbba Mon Sep 17 00:00:00 2001 From: Alexander Starovojtov <37301326+AS-AlStar@users.noreply.github.com> Date: Thu, 9 Dec 2021 13:00:37 +0300 Subject: [PATCH] Fix bug with routing key (#63) * main * spec * Fix rubocop * fix * Version and Changelog --- CHANGELOG.md | 4 ++++ Gemfile.lock | 2 +- lib/table_sync/publishing/message/batch.rb | 2 +- lib/table_sync/publishing/message/raw.rb | 2 +- lib/table_sync/version.rb | 2 +- spec/publishing/batch_spec.rb | 13 ++++++++++++- spec/publishing/raw_spec.rb | 9 +++++++++ spec/publishing/single_spec.rb | 11 +++++++++++ spec/support/shared/publishers.rb | 2 +- 9 files changed, 41 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 40a967f..607c9f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Changelog All notable changes to this project will be documented in this file. +## [6.0.3] - 2021-12-09 +### Fixed +Fixed bug when routing key is nil. + ## [6.0.2] - 2021-12-01 ### Fixed - Fixed bug: skip publish when object is new and event is destroy for ActiveRecord diff --git a/Gemfile.lock b/Gemfile.lock index cceab65..2c51ab9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - table_sync (6.0.2) + table_sync (6.0.3) memery rabbit_messaging rails diff --git a/lib/table_sync/publishing/message/batch.rb b/lib/table_sync/publishing/message/batch.rb index f05e0e0..d45a9d4 100644 --- a/lib/table_sync/publishing/message/batch.rb +++ b/lib/table_sync/publishing/message/batch.rb @@ -7,7 +7,7 @@ class Batch < Base def params TableSync::Publishing::Params::Batch.new( - object_class: object_class, headers: headers, routing_key: routing_key, + attributes.slice(:object_class, :headers, :routing_key).compact, ).construct end end diff --git a/lib/table_sync/publishing/message/raw.rb b/lib/table_sync/publishing/message/raw.rb index 3cf0a69..2fc10ef 100644 --- a/lib/table_sync/publishing/message/raw.rb +++ b/lib/table_sync/publishing/message/raw.rb @@ -47,7 +47,7 @@ def data def params TableSync::Publishing::Params::Raw.new( - object_class: object_class, routing_key: routing_key, headers: headers, + attributes.slice(:object_class, :headers, :routing_key).compact, ).construct end end diff --git a/lib/table_sync/version.rb b/lib/table_sync/version.rb index 7053f00..ebd41c8 100644 --- a/lib/table_sync/version.rb +++ b/lib/table_sync/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module TableSync - VERSION = "6.0.2" + VERSION = "6.0.3" end diff --git a/spec/publishing/batch_spec.rb b/spec/publishing/batch_spec.rb index 9c04c0c..5d9a4ea 100644 --- a/spec/publishing/batch_spec.rb +++ b/spec/publishing/batch_spec.rb @@ -9,7 +9,8 @@ let(:event) { :update } let(:object_class) { "ARecordUser" } let(:routing_key) { object_class.tableize } - let(:headers) { { klass: object_class } } + let(:expected_routing_key) { "a_record_users" } + let(:headers) { { klass: object_class } } let(:attributes) do { @@ -27,6 +28,16 @@ context "real user" do context "sequel" do let(:object_class) { "SequelUser" } + let(:expected_routing_key) { "sequel_users" } + + include_examples "publisher#publish_now with real user, for given orm", + :sequel + end + + context "when routing key is nil" do + let(:object_class) { "SequelUser" } + let(:routing_key) { nil } + let(:expected_routing_key) { "sequel_users" } include_examples "publisher#publish_now with real user, for given orm", :sequel diff --git a/spec/publishing/raw_spec.rb b/spec/publishing/raw_spec.rb index b8f016f..25b75d0 100644 --- a/spec/publishing/raw_spec.rb +++ b/spec/publishing/raw_spec.rb @@ -4,6 +4,7 @@ let(:object_class) { "SequelUser" } let(:event) { :update } let(:routing_key) { "custom_routing_key" } + let(:expected_routing_key) { "custom_routing_key" } let(:headers) { { some_key: "123" } } let(:original_attributes) { [{ id: 1, name: "purum" }] } @@ -24,4 +25,12 @@ include_examples "publisher#publish_now without stubbed message", TableSync::Publishing::Message::Raw + + context "when routing_key is nil" do + let(:routing_key) { nil } + let(:expected_routing_key) { "sequel_users" } + + include_examples "publisher#publish_now without stubbed message", + TableSync::Publishing::Message::Raw + end end diff --git a/spec/publishing/single_spec.rb b/spec/publishing/single_spec.rb index 5ee7bb1..b99897b 100644 --- a/spec/publishing/single_spec.rb +++ b/spec/publishing/single_spec.rb @@ -8,6 +8,7 @@ let(:event) { :update } let(:object_class) { "ARecordUser" } let(:routing_key) { object_class.tableize } + let(:expected_routing_key) { "a_record_users" } let(:headers) { { klass: object_class } } let(:debounce_time) { 30 } @@ -27,6 +28,16 @@ context "real user" do context "sequel" do let(:object_class) { "SequelUser" } + let(:expected_routing_key) { "sequel_users" } + + include_examples "publisher#publish_now with real user, for given orm", + :sequel + end + + context "when routing key is nil" do + let(:object_class) { "SequelUser" } + let(:routing_key) { nil } + let(:expected_routing_key) { "sequel_users" } include_examples "publisher#publish_now with real user, for given orm", :sequel diff --git a/spec/support/shared/publishers.rb b/spec/support/shared/publishers.rb index 504dbd3..8452c37 100644 --- a/spec/support/shared/publishers.rb +++ b/spec/support/shared/publishers.rb @@ -40,7 +40,7 @@ model: object_class, version: an_instance_of(Float), ), - routing_key: routing_key, # defined by callable by default + routing_key: expected_routing_key, # defined by callable by default headers: headers, # defined by callable by default ) end