|
1 |
| -require 'spec_helper' |
| 1 | +# frozen_string_literal: true |
2 | 2 |
|
3 |
| -describe "Publishing an event in the future" do |
| 3 | +require 'spec_helper' |
4 | 4 |
|
| 5 | +describe 'Publishing an event in the future' do |
5 | 6 | before(:each) do
|
6 | 7 | Timecop.freeze(now)
|
7 |
| - allow(QueueBus).to receive(:generate_uuid).and_return("idfhlkj") |
| 8 | + allow(QueueBus).to receive(:generate_uuid).and_return('idfhlkj') |
8 | 9 | end
|
9 | 10 | after(:each) do
|
10 | 11 | Timecop.return
|
11 | 12 | end
|
12 |
| - let(:delayed_attrs) { { |
13 |
| - "bus_delayed_until" => future.to_i, |
14 |
| - "bus_id" => "#{now.to_i}-idfhlkj", |
15 |
| - "bus_app_hostname" => `hostname 2>&1`.strip.sub(/.local/,'')} } |
| 13 | + let(:delayed_attrs) do |
| 14 | + { |
| 15 | + 'bus_delayed_until' => future.to_i, |
| 16 | + 'bus_id' => "#{now.to_i}-idfhlkj", |
| 17 | + 'bus_app_hostname' => `hostname 2>&1`.strip.sub(/.local/, '') |
| 18 | + } |
| 19 | + end |
16 | 20 |
|
17 |
| - let(:bus_attrs) { delayed_attrs.merge({"bus_published_at" => worktime.to_i})} |
18 |
| - let(:now) { Time.parse("01/01/2013 5:00")} |
| 21 | + let(:bus_attrs) { delayed_attrs.merge('bus_published_at' => worktime.to_i) } |
| 22 | + let(:now) { Time.parse('01/01/2013 5:00') } |
19 | 23 | let(:future) { Time.at(now.to_i + 60) }
|
20 |
| - let(:worktime) {Time.at(future.to_i + 1)} |
| 24 | + let(:worktime) { Time.at(future.to_i + 1) } |
21 | 25 |
|
22 |
| - it "should add it to Redis then to the real queue" do |
23 |
| - hash = {:one => 1, "two" => "here", "id" => 12 } |
24 |
| - event_name = "event_name" |
| 26 | + it 'should add it to Redis then to the real queue' do |
| 27 | + hash = { :one => 1, 'two' => 'here', 'id' => 12 } |
| 28 | + event_name = 'event_name' |
25 | 29 | QueueBus.publish_at(future, event_name, hash)
|
26 | 30 |
|
27 |
| - schedule = QueueBus.redis { |redis| redis.zrange("delayed_queue_schedule", 0, 1) } |
| 31 | + schedule = QueueBus.redis { |redis| redis.zrange('delayed_queue_schedule', 0, 1) } |
28 | 32 | expect(schedule).to eq([future.to_i.to_s])
|
29 | 33 |
|
30 | 34 | val = QueueBus.redis { |redis| redis.lpop("delayed:#{future.to_i}") }
|
31 | 35 | hash = JSON.parse(val)
|
32 | 36 |
|
33 |
| - expect(hash["class"]).to eq("QueueBus::Worker") |
34 |
| - expect(hash["args"].size).to eq(1) |
35 |
| - expect(JSON.parse(hash["args"].first)).to eq({"bus_class_proxy"=>"QueueBus::Publisher", "bus_event_type"=>"event_name", "two"=>"here", "one"=>1, "id" => 12}.merge(delayed_attrs)) |
36 |
| - expect(hash["queue"]).to eq("bus_incoming") |
| 37 | + expect(hash['class']).to eq('QueueBus::Worker') |
| 38 | + expect(hash['args'].size).to eq(1) |
| 39 | + expect(JSON.parse(hash['args'].first)).to eq({ 'bus_class_proxy' => 'QueueBus::Publisher', 'bus_event_type' => 'event_name', 'two' => 'here', 'one' => 1, 'id' => 12 }.merge(delayed_attrs)) |
| 40 | + expect(hash['queue']).to eq('bus_incoming') |
37 | 41 |
|
38 |
| - val = QueueBus.redis { |redis| redis.lpop("queue:bus_incoming") } |
| 42 | + val = QueueBus.redis { |redis| redis.lpop('queue:bus_incoming') } |
39 | 43 | expect(val).to eq(nil) # nothing really added
|
40 | 44 |
|
41 | 45 | Timecop.freeze(worktime)
|
42 |
| - QueueBus::Publisher.perform(JSON.parse(hash["args"].first)) |
| 46 | + QueueBus::Publisher.perform(JSON.parse(hash['args'].first)) |
43 | 47 |
|
44 |
| - val = QueueBus.redis { |redis| redis.lpop("queue:bus_incoming") } |
| 48 | + val = QueueBus.redis { |redis| redis.lpop('queue:bus_incoming') } |
45 | 49 | hash = JSON.parse(val)
|
46 |
| - expect(hash["class"]).to eq("QueueBus::Worker") |
47 |
| - expect(hash["args"].size).to eq(1) |
48 |
| - expect(JSON.parse(hash["args"].first)).to eq({"bus_class_proxy"=>"QueueBus::Driver", "bus_event_type"=>"event_name", "two"=>"here", "one"=>1, "id" => 12}.merge(bus_attrs)) |
| 50 | + expect(hash['class']).to eq('QueueBus::Worker') |
| 51 | + expect(hash['args'].size).to eq(1) |
| 52 | + expect(JSON.parse(hash['args'].first)).to eq({ 'bus_class_proxy' => 'QueueBus::Driver', 'bus_event_type' => 'event_name', 'two' => 'here', 'one' => 1, 'id' => 12 }.merge(bus_attrs)) |
49 | 53 | end
|
50 |
| - |
51 | 54 | end
|
0 commit comments