Skip to content

Commit

Permalink
Fix bug with routing key (#63)
Browse files Browse the repository at this point in the history
* main

* spec

* Fix rubocop

* fix

* Version and Changelog
  • Loading branch information
AS-AlStar authored Dec 9, 2021
1 parent 77eb529 commit 52f37f8
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
table_sync (6.0.2)
table_sync (6.0.3)
memery
rabbit_messaging
rails
Expand Down
2 changes: 1 addition & 1 deletion lib/table_sync/publishing/message/batch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/table_sync/publishing/message/raw.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/table_sync/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module TableSync
VERSION = "6.0.2"
VERSION = "6.0.3"
end
13 changes: 12 additions & 1 deletion spec/publishing/batch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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
Expand Down
9 changes: 9 additions & 0 deletions spec/publishing/raw_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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" }] }

Expand All @@ -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
11 changes: 11 additions & 0 deletions spec/publishing/single_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/support/shared/publishers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 52f37f8

Please sign in to comment.