|
12 | 12 | message_id: "uuid", |
13 | 13 | } |
14 | 14 | end |
| 15 | + let(:additional_params) { {} } |
15 | 16 |
|
16 | 17 | before do |
17 | 18 | Rabbit.config.queue_name_conversion = -> (queue) { "#{queue}_prepared" } |
|
52 | 53 |
|
53 | 54 | it "publishes" do |
54 | 55 | if expect_to_use_job |
55 | | - set_params = { queue: "default_prepared" } |
56 | | - expect(Rabbit::Publishing::Job).to receive(:set).with(set_params).and_call_original |
| 56 | + set_params = { queue: expected_queue } |
| 57 | + expect(job_class).to receive(:set).with(set_params).and_call_original |
57 | 58 | perform_params = { |
58 | 59 | routing_key: "some_queue", |
59 | 60 | event: "some_event", |
|
68 | 69 | .to receive(:perform_later).with(perform_params).and_call_original |
69 | 70 |
|
70 | 71 | else |
71 | | - expect(Rabbit::Publishing::Job).not_to receive(:perform_later) |
| 72 | + expect(job_class).not_to receive(:perform_later) |
72 | 73 | end |
73 | 74 |
|
74 | 75 | expect(publish_logger).to receive(:debug).with(<<~MSG.strip) |
|
79 | 80 | test_group_id.test_project_id.some_exchange / some_queue / {"foo":"bar"} / some_event / \ |
80 | 81 | confirm: ...world"} |
81 | 82 | MSG |
82 | | - described_class.publish(message_options) |
| 83 | + described_class.publish(**message_options, **additional_params) |
83 | 84 | end |
84 | 85 |
|
85 | 86 | after do |
|
96 | 97 | let(:publish_logger) { double("publish_logger") } |
97 | 98 | let(:bunny) { double("bunny") } |
98 | 99 | let(:channel) { double("channel") } |
| 100 | + let(:job_class) { Rabbit::Publishing::Job } |
99 | 101 |
|
100 | 102 | before do |
101 | 103 | allow(Bunny).to receive_message_chain(:new, :start).and_return(bunny) |
|
132 | 134 | confirm: {"hello":"world"} |
133 | 135 | MSG |
134 | 136 |
|
135 | | - expect { described_class.publish(message_options) }.not_to raise_error |
| 137 | + expect { described_class.publish(**message_options) }.not_to raise_error |
136 | 138 | end |
137 | 139 |
|
138 | 140 | it "raises the last exception after max retries" do |
139 | 141 | allow(channel).to receive(:basic_publish).and_raise(Bunny::ConnectionClosedError.new("")) |
140 | 142 |
|
141 | | - expect { described_class.publish(message_options) } |
| 143 | + expect { described_class.publish(**message_options) } |
142 | 144 | .to raise_error(Bunny::ConnectionClosedError) |
143 | 145 | end |
144 | 146 | end |
145 | 147 |
|
146 | 148 | context "realtime" do |
147 | 149 | let(:realtime) { true } |
148 | 150 | let(:expect_to_use_job) { false } |
| 151 | + let(:expected_queue) { "default_prepared" } |
| 152 | + let(:job_class) { Rabbit::Publishing::Job } |
149 | 153 |
|
150 | 154 | include_examples "publishes" |
151 | 155 | end |
152 | 156 |
|
153 | 157 | context "not realtime" do |
154 | 158 | let(:realtime) { false } |
155 | 159 | let(:expect_to_use_job) { true } |
| 160 | + let(:expected_queue) { "default_prepared" } |
| 161 | + let(:job_class) { Rabbit::Publishing::Job } |
| 162 | + |
| 163 | + include_examples "publishes" |
| 164 | + end |
| 165 | + |
| 166 | + context "with custom job class" do |
| 167 | + let(:realtime) { false } |
| 168 | + let(:expect_to_use_job) { true } |
| 169 | + let(:expected_queue) { "default_prepared" } |
| 170 | + let(:job_class) { Class.new(Rabbit::Publishing::Job) } |
| 171 | + |
| 172 | + before do |
| 173 | + stub_const("CustomJobClass", job_class) |
| 174 | + allow(Rabbit.config).to receive(:publishing_job_class_callable).and_return(job_class) |
| 175 | + end |
| 176 | + |
| 177 | + include_examples "publishes" |
| 178 | + end |
| 179 | + |
| 180 | + context "with custom default_publishing_job_queue" do |
| 181 | + let(:realtime) { false } |
| 182 | + let(:expect_to_use_job) { true } |
| 183 | + let(:job_class) { Rabbit::Publishing::Job } |
| 184 | + let(:default_publishing_job_queue) { :custom_queue } |
| 185 | + let(:expected_queue) { "passed_to_method_queue" } |
| 186 | + let(:additional_params) { { custom_queue_name: "passed_to_method_queue" } } |
| 187 | + |
| 188 | + before do |
| 189 | + allow(Rabbit.config).to( |
| 190 | + receive(:default_publishing_job_queue).and_return(default_publishing_job_queue), |
| 191 | + ) |
| 192 | + end |
| 193 | + |
| 194 | + include_examples "publishes" |
| 195 | + end |
| 196 | + |
| 197 | + context "with custom queue name" do |
| 198 | + let(:realtime) { false } |
| 199 | + let(:expect_to_use_job) { true } |
| 200 | + let(:job_class) { Rabbit::Publishing::Job } |
| 201 | + let(:default_publishing_job_queue) { :custom_queue } |
| 202 | + let(:expected_queue) { "custom_queue_prepared" } |
| 203 | + |
| 204 | + before do |
| 205 | + allow(Rabbit.config).to( |
| 206 | + receive(:default_publishing_job_queue).and_return(default_publishing_job_queue), |
| 207 | + ) |
| 208 | + end |
156 | 209 |
|
157 | 210 | include_examples "publishes" |
158 | 211 | end |
|
0 commit comments