|
12 | 12 | it "enqueues ContactCreatedJob" do
|
13 | 13 | stub_const("ContactCreatedJob", Class.new { include Sidekiq::Job })
|
14 | 14 |
|
15 |
| - EventCreatedJob.new.perform({ "id" => 1, "type" => "ContactCreatedEvent" }) |
| 15 | + EventCreatedJob.new.perform(1, "ContactCreatedEvent") |
16 | 16 |
|
17 | 17 | expect(ContactCreatedJob.jobs).to match([
|
18 |
| - hash_including("class" => "ContactCreatedJob", "args" => [1]) |
| 18 | + hash_including( |
| 19 | + "class" => "ContactCreatedJob", |
| 20 | + "args" => [1, "ContactCreatedEvent"]) |
19 | 21 | ])
|
20 | 22 | end
|
21 | 23 |
|
22 | 24 | it "enqueues Accountify::ContactCreatedJob" do
|
23 | 25 | stub_const("Accountify", Module.new)
|
24 | 26 | stub_const("Accountify::ContactCreatedJob", Class.new { include Sidekiq::Job })
|
25 | 27 |
|
26 |
| - EventCreatedJob.new.perform({ "id" => 2, "type" => "Accountify::ContactCreatedEvent" }) |
| 28 | + EventCreatedJob.new.perform(2, "Accountify::ContactCreatedEvent") |
27 | 29 |
|
28 | 30 | expect(Accountify::ContactCreatedJob.jobs).to match([
|
29 |
| - hash_including("class" => "Accountify::ContactCreatedJob", "args" => [2]) |
| 31 | + hash_including( |
| 32 | + "class" => "Accountify::ContactCreatedJob", |
| 33 | + "args" => [2, "Accountify::ContactCreatedEvent"]) |
30 | 34 | ])
|
31 | 35 | end
|
32 | 36 |
|
33 | 37 | it "enqueues Accountify::InvoiceUpdatedJob" do
|
34 | 38 | stub_const("Accountify", Module.new) unless defined?(Accountify)
|
35 | 39 | stub_const("Accountify::InvoiceUpdatedJob", Class.new { include Sidekiq::Job })
|
36 | 40 |
|
37 |
| - EventCreatedJob.new.perform({ "id" => 3, "type" => "Accountify::InvoiceUpdatedEvent" }) |
| 41 | + EventCreatedJob.new.perform(3, "Accountify::InvoiceUpdatedEvent") |
38 | 42 |
|
39 | 43 | expect(Accountify::InvoiceUpdatedJob.jobs).to match([
|
40 |
| - hash_including("class" => "Accountify::InvoiceUpdatedJob", "args" => [3]) |
| 44 | + hash_including( |
| 45 | + "class" => "Accountify::InvoiceUpdatedJob", |
| 46 | + "args" => [3, "Accountify::InvoiceUpdatedEvent"]) |
41 | 47 | ])
|
42 | 48 | end
|
43 | 49 |
|
|
46 | 52 | stub_const("Accountify::Invoice", Module.new)
|
47 | 53 | stub_const("Accountify::Invoice::CreatedJob", Class.new { include Sidekiq::Job })
|
48 | 54 |
|
49 |
| - EventCreatedJob.new.perform({ "id" => 4, "type" => "Accountify::Invoice::CreatedEvent" }) |
| 55 | + EventCreatedJob.new.perform(4, "Accountify::Invoice::CreatedEvent") |
50 | 56 |
|
51 | 57 | expect(Accountify::Invoice::CreatedJob.jobs).to match([
|
52 |
| - hash_including("class" => "Accountify::Invoice::CreatedJob", "args" => [4]) |
| 58 | + hash_including( |
| 59 | + "class" => "Accountify::Invoice::CreatedJob", |
| 60 | + "args" => [4, "Accountify::Invoice::CreatedEvent"]) |
53 | 61 | ])
|
54 | 62 | end
|
55 | 63 |
|
56 | 64 | it "enqueues MyApp::Domain::Event::UserSignedUpJob" do
|
57 | 65 | stub_const("MyApp", Module.new)
|
58 | 66 | stub_const("MyApp::Domain", Module.new)
|
59 | 67 | stub_const("MyApp::Domain::Event", Module.new)
|
60 |
| - stub_const("MyApp::Domain::Event::UserSignedUpJob", Class.new { include Sidekiq::Job }) |
| 68 | + stub_const("MyApp::Domain::Event::UserSignedUpJob", |
| 69 | + Class.new { include Sidekiq::Job }) |
61 | 70 |
|
62 | 71 | EventCreatedJob.new.perform(
|
63 |
| - { "id" => 5, "type" => "MyApp::Domain::Event::UserSignedUpEvent" }) |
| 72 | + 5, |
| 73 | + "MyApp::Domain::Event::UserSignedUpEvent") |
64 | 74 |
|
65 | 75 | expect(MyApp::Domain::Event::UserSignedUpJob.jobs).to match([
|
66 |
| - hash_including("class" => "MyApp::Domain::Event::UserSignedUpJob", "args" => [5]) |
| 76 | + hash_including( |
| 77 | + "class" => "MyApp::Domain::Event::UserSignedUpJob", |
| 78 | + "args" => [5, "MyApp::Domain::Event::UserSignedUpEvent"]) |
67 | 79 | ])
|
68 | 80 | end
|
69 | 81 |
|
70 | 82 | it "handles leading :: in type" do
|
71 | 83 | stub_const("ContactCreatedJob", Class.new { include Sidekiq::Job })
|
72 | 84 |
|
73 |
| - EventCreatedJob.new.perform({ "id" => 6, "type" => "::ContactCreatedEvent" }) |
| 85 | + EventCreatedJob.new.perform(6, "::ContactCreatedEvent") |
74 | 86 |
|
75 | 87 | expect(ContactCreatedJob.jobs).to match([
|
76 |
| - hash_including("class" => "ContactCreatedJob", "args" => [6]) |
| 88 | + hash_including( |
| 89 | + "class" => "ContactCreatedJob", |
| 90 | + "args" => [6, "::ContactCreatedEvent"]) |
77 | 91 | ])
|
78 | 92 | end
|
79 | 93 |
|
80 | 94 | it "does not enqueue for invalid type format" do
|
81 |
| - EventCreatedJob.new.perform({ "id" => 7, "type" => "contact_created_event" }) |
| 95 | + EventCreatedJob.new.perform(7, "contact_created_event") |
82 | 96 | expect(Sidekiq::Worker.jobs.size).to eq(0)
|
83 | 97 | end
|
84 | 98 |
|
85 | 99 | it "does not enqueue for empty string" do
|
86 |
| - EventCreatedJob.new.perform({ "id" => 8, "type" => "" }) |
| 100 | + EventCreatedJob.new.perform(8, "") |
87 | 101 | expect(Sidekiq::Worker.jobs.size).to eq(0)
|
88 | 102 | end
|
89 | 103 |
|
90 | 104 | it "does not enqueue if type does not end in Event" do
|
91 |
| - EventCreatedJob.new.perform({ "id" => 9, "type" => "SomethingCreated" }) |
| 105 | + EventCreatedJob.new.perform(9, "SomethingCreated") |
92 | 106 | expect(Sidekiq::Worker.jobs.size).to eq(0)
|
93 | 107 | end
|
94 | 108 |
|
95 | 109 | it "does not enqueue for missing job class" do
|
96 |
| - EventCreatedJob.new.perform({ "id" => 10, "type" => "ImaginaryThingEvent" }) |
| 110 | + EventCreatedJob.new.perform(10, "ImaginaryThingEvent") |
97 | 111 | expect(Sidekiq::Worker.jobs.size).to eq(0)
|
98 | 112 | end
|
99 | 113 |
|
100 | 114 | it "does not enqueue for invalid type constant path" do
|
101 |
| - EventCreatedJob.new.perform({ "id" => 11, "type" => "123::@@@Invalid" }) |
| 115 | + EventCreatedJob.new.perform(11, "123::@@@Invalid") |
102 | 116 | expect(Sidekiq::Worker.jobs.size).to eq(0)
|
103 | 117 | end
|
104 | 118 |
|
105 | 119 | it "does not enqueue if type is exactly 'Event'" do
|
106 |
| - EventCreatedJob.new.perform({ "id" => 12, "type" => "Event" }) |
| 120 | + EventCreatedJob.new.perform(12, "Event") |
107 | 121 | expect(Sidekiq::Worker.jobs.size).to eq(0)
|
108 | 122 | end
|
109 | 123 |
|
110 | 124 | it "logs debug message when type is invalid" do
|
111 | 125 | expect(Sidekiq.logger).to receive(:debug).with(
|
112 | 126 | "Could not get job class name from event type: bad_type")
|
113 | 127 |
|
114 |
| - EventCreatedJob.new.perform({ "id" => 13, "type" => "bad_type" }) |
| 128 | + EventCreatedJob.new.perform(13, "bad_type") |
115 | 129 | end
|
116 | 130 |
|
117 | 131 | it "logs debug message when job class name is not constantizable" do
|
118 | 132 | expect(Sidekiq.logger).to receive(:debug).with(
|
119 | 133 | "Could not constantize job class name: ImaginaryThingJob")
|
120 | 134 |
|
121 |
| - EventCreatedJob.new.perform({ "id" => 14, "type" => "ImaginaryThingEvent" }) |
| 135 | + EventCreatedJob.new.perform(14, "ImaginaryThingEvent") |
122 | 136 | end
|
123 | 137 | end
|
124 | 138 |
|
|
128 | 142 | it "enqueues ContactCreatedJob through perform_async" do
|
129 | 143 | stub_const("ContactCreatedJob", Class.new { include Sidekiq::Job })
|
130 | 144 |
|
131 |
| - EventCreatedJob.perform_async({ "id" => 1, "type" => "ContactCreatedEvent" }) |
| 145 | + EventCreatedJob.perform_async(1, "ContactCreatedEvent") |
132 | 146 | EventCreatedJob.drain
|
133 | 147 |
|
134 | 148 | expect(ContactCreatedJob.jobs).to match([
|
135 |
| - hash_including("class" => "ContactCreatedJob", "args" => [1]) |
| 149 | + hash_including( |
| 150 | + "class" => "ContactCreatedJob", |
| 151 | + "args" => [1, "ContactCreatedEvent"]) |
136 | 152 | ])
|
137 | 153 | end
|
138 | 154 |
|
139 | 155 | it "enqueues Accountify::ContactCreatedJob through perform_async" do
|
140 | 156 | stub_const("Accountify", Module.new)
|
141 | 157 | stub_const("Accountify::ContactCreatedJob", Class.new { include Sidekiq::Job })
|
142 | 158 |
|
143 |
| - EventCreatedJob.perform_async({ "id" => 2, "type" => "Accountify::ContactCreatedEvent" }) |
| 159 | + EventCreatedJob.perform_async(2, "Accountify::ContactCreatedEvent") |
144 | 160 | EventCreatedJob.drain
|
145 | 161 |
|
146 | 162 | expect(Accountify::ContactCreatedJob.jobs).to match([
|
147 |
| - hash_including("class" => "Accountify::ContactCreatedJob", "args" => [2]) |
| 163 | + hash_including( |
| 164 | + "class" => "Accountify::ContactCreatedJob", |
| 165 | + "args" => [2, "Accountify::ContactCreatedEvent"]) |
148 | 166 | ])
|
149 | 167 | end
|
150 | 168 |
|
151 | 169 | it "enqueues Accountify::InvoiceUpdatedJob through perform_async" do
|
152 | 170 | stub_const("Accountify", Module.new) unless defined?(Accountify)
|
153 | 171 | stub_const("Accountify::InvoiceUpdatedJob", Class.new { include Sidekiq::Job })
|
154 | 172 |
|
155 |
| - EventCreatedJob.perform_async({ "id" => 3, "type" => "Accountify::InvoiceUpdatedEvent" }) |
| 173 | + EventCreatedJob.perform_async(3, "Accountify::InvoiceUpdatedEvent") |
156 | 174 | EventCreatedJob.drain
|
157 | 175 |
|
158 | 176 | expect(Accountify::InvoiceUpdatedJob.jobs).to match([
|
159 |
| - hash_including("class" => "Accountify::InvoiceUpdatedJob", "args" => [3]) |
| 177 | + hash_including( |
| 178 | + "class" => "Accountify::InvoiceUpdatedJob", |
| 179 | + "args" => [3, "Accountify::InvoiceUpdatedEvent"]) |
160 | 180 | ])
|
161 | 181 | end
|
162 | 182 |
|
|
165 | 185 | stub_const("Accountify::Invoice", Module.new)
|
166 | 186 | stub_const("Accountify::Invoice::CreatedJob", Class.new { include Sidekiq::Job })
|
167 | 187 |
|
168 |
| - EventCreatedJob.perform_async({ "id" => 4, "type" => "Accountify::Invoice::CreatedEvent" }) |
| 188 | + EventCreatedJob.perform_async(4, "Accountify::Invoice::CreatedEvent") |
169 | 189 | EventCreatedJob.drain
|
170 | 190 |
|
171 | 191 | expect(Accountify::Invoice::CreatedJob.jobs).to match([
|
172 |
| - hash_including("class" => "Accountify::Invoice::CreatedJob", "args" => [4]) |
| 192 | + hash_including( |
| 193 | + "class" => "Accountify::Invoice::CreatedJob", |
| 194 | + "args" => [4, "Accountify::Invoice::CreatedEvent"]) |
173 | 195 | ])
|
174 | 196 | end
|
175 | 197 |
|
176 | 198 | it "enqueues MyApp::Domain::Event::UserSignedUpJob through perform_async" do
|
177 | 199 | stub_const("MyApp", Module.new)
|
178 | 200 | stub_const("MyApp::Domain", Module.new)
|
179 | 201 | stub_const("MyApp::Domain::Event", Module.new)
|
180 |
| - stub_const("MyApp::Domain::Event::UserSignedUpJob", Class.new { include Sidekiq::Job }) |
| 202 | + stub_const("MyApp::Domain::Event::UserSignedUpJob", |
| 203 | + Class.new { include Sidekiq::Job }) |
181 | 204 |
|
182 |
| - EventCreatedJob.perform_async({ |
183 |
| - "id" => 5, |
184 |
| - "type" => "MyApp::Domain::Event::UserSignedUpEvent" |
185 |
| - }) |
| 205 | + EventCreatedJob.perform_async( |
| 206 | + 5, |
| 207 | + "MyApp::Domain::Event::UserSignedUpEvent") |
186 | 208 | EventCreatedJob.drain
|
187 | 209 |
|
188 | 210 | expect(MyApp::Domain::Event::UserSignedUpJob.jobs).to match([
|
189 |
| - hash_including("class" => "MyApp::Domain::Event::UserSignedUpJob", "args" => [5]) |
| 211 | + hash_including( |
| 212 | + "class" => "MyApp::Domain::Event::UserSignedUpJob", |
| 213 | + "args" => [5, "MyApp::Domain::Event::UserSignedUpEvent"]) |
190 | 214 | ])
|
191 | 215 | end
|
192 | 216 |
|
193 | 217 | it "handles leading :: in type through perform_async" do
|
194 | 218 | stub_const("ContactCreatedJob", Class.new { include Sidekiq::Job })
|
195 | 219 |
|
196 |
| - EventCreatedJob.perform_async({ "id" => 6, "type" => "::ContactCreatedEvent" }) |
| 220 | + EventCreatedJob.perform_async(6, "::ContactCreatedEvent") |
197 | 221 | EventCreatedJob.drain
|
198 | 222 |
|
199 | 223 | expect(ContactCreatedJob.jobs).to match([
|
200 |
| - hash_including("class" => "ContactCreatedJob", "args" => [6]) |
| 224 | + hash_including( |
| 225 | + "class" => "ContactCreatedJob", |
| 226 | + "args" => [6, "::ContactCreatedEvent"]) |
201 | 227 | ])
|
202 | 228 | end
|
203 | 229 |
|
204 | 230 | it "does not enqueue job for invalid type format" do
|
205 | 231 | expect do
|
206 |
| - EventCreatedJob.perform_async({ "id" => 7, "type" => "contact_created_event" }) |
| 232 | + EventCreatedJob.perform_async(7, "contact_created_event") |
207 | 233 | end.not_to change(EventCreatedJob.jobs, :size)
|
208 | 234 | end
|
209 | 235 |
|
210 | 236 | it "does not enqueue job for empty string" do
|
211 | 237 | expect do
|
212 |
| - EventCreatedJob.perform_async({ "id" => 8, "type" => "" }) |
| 238 | + EventCreatedJob.perform_async(8, "") |
213 | 239 | end.not_to change(EventCreatedJob.jobs, :size)
|
214 | 240 | end
|
215 | 241 |
|
216 | 242 | it "does not enqueue job if type does not end in Event" do
|
217 | 243 | expect do
|
218 |
| - EventCreatedJob.perform_async({ "id" => 9, "type" => "SomethingCreated" }) |
| 244 | + EventCreatedJob.perform_async(9, "SomethingCreated") |
219 | 245 | end.not_to change(EventCreatedJob.jobs, :size)
|
220 | 246 | end
|
221 | 247 |
|
222 | 248 | it "skips perform_async for missing job class" do
|
223 |
| - EventCreatedJob.perform_async({ "id" => 10, "type" => "ImaginaryThingEvent" }) |
| 249 | + EventCreatedJob.perform_async(10, "ImaginaryThingEvent") |
224 | 250 | EventCreatedJob.drain
|
225 | 251 |
|
226 | 252 | expect(Sidekiq::Worker.jobs.size).to eq(0)
|
227 | 253 | end
|
228 | 254 |
|
229 | 255 | it "skips perform_async for invalid constant path" do
|
230 |
| - EventCreatedJob.perform_async({ "id" => 11, "type" => "123::@@@Invalid" }) |
| 256 | + EventCreatedJob.perform_async(11, "123::@@@Invalid") |
231 | 257 | EventCreatedJob.drain
|
232 | 258 |
|
233 | 259 | expect(Sidekiq::Worker.jobs.size).to eq(0)
|
234 | 260 | end
|
235 | 261 |
|
236 | 262 | it "skips perform_async if type is exactly 'Event'" do
|
237 |
| - EventCreatedJob.perform_async({ "id" => 12, "type" => "Event" }) |
| 263 | + EventCreatedJob.perform_async(12, "Event") |
238 | 264 | EventCreatedJob.drain
|
239 | 265 |
|
240 | 266 | expect(Sidekiq::Worker.jobs.size).to eq(0)
|
241 | 267 | end
|
242 | 268 |
|
243 | 269 | it "returns nil for invalid type" do
|
244 |
| - result = EventCreatedJob.perform_async({ "id" => 13, "type" => "bad_type" }) |
| 270 | + result = EventCreatedJob.perform_async(13, "bad_type") |
245 | 271 | expect(result).to be_nil
|
246 | 272 | end
|
247 | 273 |
|
248 | 274 | it "returns job ID when enqueued" do
|
249 | 275 | stub_const("ContactCreatedJob", Class.new { include Sidekiq::Job })
|
250 | 276 |
|
251 |
| - result = EventCreatedJob.perform_async({ "id" => 14, "type" => "ContactCreatedEvent" }) |
| 277 | + result = EventCreatedJob.perform_async(14, "ContactCreatedEvent") |
| 278 | + EventCreatedJob.drain |
| 279 | + |
252 | 280 | expect(result).to be_a(String)
|
| 281 | + expect(ContactCreatedJob.jobs).to match([ |
| 282 | + hash_including( |
| 283 | + "class" => "ContactCreatedJob", |
| 284 | + "args" => [14, "ContactCreatedEvent"]) |
| 285 | + ]) |
253 | 286 | end
|
254 | 287 | end
|
255 | 288 | end
|
0 commit comments