queue-bus 0.7.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +21 -0
  3. data/CHANGELOG.md +30 -0
  4. data/Gemfile +4 -2
  5. data/README.mdown +16 -0
  6. data/Rakefile +2 -0
  7. data/lib/queue-bus.rb +15 -12
  8. data/lib/queue_bus/adapters/base.rb +4 -2
  9. data/lib/queue_bus/adapters/data.rb +12 -11
  10. data/lib/queue_bus/application.rb +24 -16
  11. data/lib/queue_bus/config.rb +31 -1
  12. data/lib/queue_bus/dispatch.rb +14 -12
  13. data/lib/queue_bus/dispatchers.rb +12 -5
  14. data/lib/queue_bus/driver.rb +15 -10
  15. data/lib/queue_bus/heartbeat.rb +32 -30
  16. data/lib/queue_bus/local.rb +9 -9
  17. data/lib/queue_bus/matcher.rb +36 -27
  18. data/lib/queue_bus/publisher.rb +7 -5
  19. data/lib/queue_bus/publishing.rb +31 -24
  20. data/lib/queue_bus/rider.rb +26 -22
  21. data/lib/queue_bus/subscriber.rb +20 -14
  22. data/lib/queue_bus/subscription.rb +25 -15
  23. data/lib/queue_bus/subscription_list.rb +30 -12
  24. data/lib/queue_bus/task_manager.rb +25 -16
  25. data/lib/queue_bus/tasks.rb +35 -11
  26. data/lib/queue_bus/util.rb +11 -8
  27. data/lib/queue_bus/version.rb +3 -1
  28. data/lib/queue_bus/worker.rb +3 -2
  29. data/queue-bus.gemspec +19 -18
  30. data/spec/adapter/publish_at_spec.rb +28 -25
  31. data/spec/adapter/support.rb +7 -1
  32. data/spec/adapter_spec.rb +4 -2
  33. data/spec/application_spec.rb +138 -96
  34. data/spec/config_spec.rb +35 -0
  35. data/spec/dispatch_spec.rb +48 -51
  36. data/spec/driver_spec.rb +60 -58
  37. data/spec/heartbeat_spec.rb +26 -24
  38. data/spec/integration_spec.rb +41 -40
  39. data/spec/matcher_spec.rb +104 -102
  40. data/spec/publish_spec.rb +46 -46
  41. data/spec/publisher_spec.rb +3 -1
  42. data/spec/rider_spec.rb +16 -14
  43. data/spec/spec_helper.rb +2 -2
  44. data/spec/subscriber_spec.rb +227 -227
  45. data/spec/subscription_list_spec.rb +57 -31
  46. data/spec/subscription_spec.rb +37 -36
  47. data/spec/worker_spec.rb +17 -15
  48. metadata +8 -8
@@ -1,143 +1,145 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module QueueBus
4
6
  describe Matcher do
5
- it "should already return false on empty filters" do
7
+ it 'should already return false on empty filters' do
6
8
  matcher = Matcher.new({})
7
- expect(matcher.matches?({})).to eq(false)
9
+ expect(matcher.matches?({})).to eq(false)
8
10
  expect(matcher.matches?(nil)).to eq(false)
9
- expect(matcher.matches?("name" => "val")).to eq(false)
11
+ expect(matcher.matches?('name' => 'val')).to eq(false)
10
12
  end
11
13
 
12
- it "should not crash if nil inputs" do
13
- matcher = Matcher.new("name" => "val")
14
+ it 'should not crash if nil inputs' do
15
+ matcher = Matcher.new('name' => 'val')
14
16
  expect(matcher.matches?(nil)).to eq(false)
15
17
  end
16
18
 
17
- it "string filter to/from redis" do
18
- matcher = Matcher.new("name" => "val")
19
- expect(matcher.matches?("name" => "val")).to eq(true)
20
- expect(matcher.matches?("name" => " val")).to eq(false)
21
- expect(matcher.matches?("name" => "zval")).to eq(false)
19
+ it 'string filter to/from redis' do
20
+ matcher = Matcher.new('name' => 'val')
21
+ expect(matcher.matches?('name' => 'val')).to eq(true)
22
+ expect(matcher.matches?('name' => ' val')).to eq(false)
23
+ expect(matcher.matches?('name' => 'zval')).to eq(false)
22
24
  end
23
25
 
24
- it "regex filter" do
25
- matcher = Matcher.new("name" => /^[cb]a+t/)
26
- expect(matcher.matches?("name" => "cat")).to eq(true)
27
- expect(matcher.matches?("name" => "bat")).to eq(true)
28
- expect(matcher.matches?("name" => "caaaaat")).to eq(true)
29
- expect(matcher.matches?("name" => "ct")).to eq(false)
30
- expect(matcher.matches?("name" => "bcat")).to eq(false)
26
+ it 'regex filter' do
27
+ matcher = Matcher.new('name' => /^[cb]a+t/)
28
+ expect(matcher.matches?('name' => 'cat')).to eq(true)
29
+ expect(matcher.matches?('name' => 'bat')).to eq(true)
30
+ expect(matcher.matches?('name' => 'caaaaat')).to eq(true)
31
+ expect(matcher.matches?('name' => 'ct')).to eq(false)
32
+ expect(matcher.matches?('name' => 'bcat')).to eq(false)
31
33
  end
32
34
 
33
- it "present filter" do
34
- matcher = Matcher.new("name" => :present)
35
- expect(matcher.matches?("name" => "")).to eq(false)
36
- expect(matcher.matches?("name" => "cat")).to eq(true)
37
- expect(matcher.matches?("name" => "bear")).to eq(true)
38
- expect(matcher.matches?("other" => "bear")).to eq(false)
35
+ it 'present filter' do
36
+ matcher = Matcher.new('name' => :present)
37
+ expect(matcher.matches?('name' => '')).to eq(false)
38
+ expect(matcher.matches?('name' => 'cat')).to eq(true)
39
+ expect(matcher.matches?('name' => 'bear')).to eq(true)
40
+ expect(matcher.matches?('other' => 'bear')).to eq(false)
39
41
  end
40
42
 
41
- it "blank filter" do
42
- matcher = Matcher.new("name" => :blank)
43
- expect(matcher.matches?("name" => nil)).to eq(true)
44
- expect(matcher.matches?("other" => "bear")).to eq(true)
45
- expect(matcher.matches?("name" => "")).to eq(true)
46
- expect(matcher.matches?("name" => " ")).to eq(true)
47
- expect(matcher.matches?("name" => "bear")).to eq(false)
48
- expect(matcher.matches?("name" => " s ")).to eq(false)
43
+ it 'blank filter' do
44
+ matcher = Matcher.new('name' => :blank)
45
+ expect(matcher.matches?('name' => nil)).to eq(true)
46
+ expect(matcher.matches?('other' => 'bear')).to eq(true)
47
+ expect(matcher.matches?('name' => '')).to eq(true)
48
+ expect(matcher.matches?('name' => ' ')).to eq(true)
49
+ expect(matcher.matches?('name' => 'bear')).to eq(false)
50
+ expect(matcher.matches?('name' => ' s ')).to eq(false)
49
51
  end
50
52
 
51
- it "nil filter" do
52
- matcher = Matcher.new("name" => :nil)
53
- expect(matcher.matches?("name" => nil)).to eq(true)
54
- expect(matcher.matches?("other" => "bear")).to eq(true)
55
- expect(matcher.matches?("name" => "")).to eq(false)
56
- expect(matcher.matches?("name" => " ")).to eq(false)
57
- expect(matcher.matches?("name" => "bear")).to eq(false)
53
+ it 'nil filter' do
54
+ matcher = Matcher.new('name' => :nil)
55
+ expect(matcher.matches?('name' => nil)).to eq(true)
56
+ expect(matcher.matches?('other' => 'bear')).to eq(true)
57
+ expect(matcher.matches?('name' => '')).to eq(false)
58
+ expect(matcher.matches?('name' => ' ')).to eq(false)
59
+ expect(matcher.matches?('name' => 'bear')).to eq(false)
58
60
  end
59
61
 
60
- it "key filter" do
61
- matcher = Matcher.new("name" => :key)
62
- expect(matcher.matches?("name" => nil)).to eq(true)
63
- expect(matcher.matches?("other" => "bear")).to eq(false)
64
- expect(matcher.matches?("name" => "")).to eq(true)
65
- expect(matcher.matches?("name" => " ")).to eq(true)
66
- expect(matcher.matches?("name" => "bear")).to eq(true)
62
+ it 'key filter' do
63
+ matcher = Matcher.new('name' => :key)
64
+ expect(matcher.matches?('name' => nil)).to eq(true)
65
+ expect(matcher.matches?('other' => 'bear')).to eq(false)
66
+ expect(matcher.matches?('name' => '')).to eq(true)
67
+ expect(matcher.matches?('name' => ' ')).to eq(true)
68
+ expect(matcher.matches?('name' => 'bear')).to eq(true)
67
69
  end
68
70
 
69
- it "empty filter" do
70
- matcher = Matcher.new("name" => :empty)
71
- expect(matcher.matches?("name" => nil)).to eq(false)
72
- expect(matcher.matches?("other" => "bear")).to eq(false)
73
- expect(matcher.matches?("name" => "")).to eq(true)
74
- expect(matcher.matches?("name" => " ")).to eq(false)
75
- expect(matcher.matches?("name" => "bear")).to eq(false)
76
- expect(matcher.matches?("name" => " s ")).to eq(false)
71
+ it 'empty filter' do
72
+ matcher = Matcher.new('name' => :empty)
73
+ expect(matcher.matches?('name' => nil)).to eq(false)
74
+ expect(matcher.matches?('other' => 'bear')).to eq(false)
75
+ expect(matcher.matches?('name' => '')).to eq(true)
76
+ expect(matcher.matches?('name' => ' ')).to eq(false)
77
+ expect(matcher.matches?('name' => 'bear')).to eq(false)
78
+ expect(matcher.matches?('name' => ' s ')).to eq(false)
77
79
  end
78
80
 
79
- it "value filter" do
80
- matcher = Matcher.new("name" => :value)
81
- expect(matcher.matches?("name" => nil)).to eq(false)
82
- expect(matcher.matches?("other" => "bear")).to eq(false)
83
- expect(matcher.matches?("name" => "")).to eq(true)
84
- expect(matcher.matches?("name" => " ")).to eq(true)
85
- expect(matcher.matches?("name" => "bear")).to eq(true)
86
- expect(matcher.matches?("name" => " s ")).to eq(true)
81
+ it 'value filter' do
82
+ matcher = Matcher.new('name' => :value)
83
+ expect(matcher.matches?('name' => nil)).to eq(false)
84
+ expect(matcher.matches?('other' => 'bear')).to eq(false)
85
+ expect(matcher.matches?('name' => '')).to eq(true)
86
+ expect(matcher.matches?('name' => ' ')).to eq(true)
87
+ expect(matcher.matches?('name' => 'bear')).to eq(true)
88
+ expect(matcher.matches?('name' => ' s ')).to eq(true)
87
89
  end
88
90
 
89
- it "multiple filters" do
90
- matcher = Matcher.new("name" => /^[cb]a+t/, "state" => "sleeping")
91
- expect(matcher.matches?("state" => "sleeping", "name" => "cat")).to eq(true)
92
- expect(matcher.matches?("state" => "awake", "name" => "cat")).to eq(false)
93
- expect(matcher.matches?("state" => "sleeping", "name" => "bat")).to eq(true)
94
- expect(matcher.matches?("state" => "sleeping", "name" => "bear")).to eq(false)
95
- expect(matcher.matches?("state" => "awake", "name" => "bear")).to eq(false)
91
+ it 'multiple filters' do
92
+ matcher = Matcher.new('name' => /^[cb]a+t/, 'state' => 'sleeping')
93
+ expect(matcher.matches?('state' => 'sleeping', 'name' => 'cat')).to eq(true)
94
+ expect(matcher.matches?('state' => 'awake', 'name' => 'cat')).to eq(false)
95
+ expect(matcher.matches?('state' => 'sleeping', 'name' => 'bat')).to eq(true)
96
+ expect(matcher.matches?('state' => 'sleeping', 'name' => 'bear')).to eq(false)
97
+ expect(matcher.matches?('state' => 'awake', 'name' => 'bear')).to eq(false)
96
98
  end
97
99
 
98
- it "regex should go back and forth into redis" do
99
- matcher = Matcher.new("name" => /^[cb]a+t/)
100
- expect(matcher.matches?("name" => "cat")).to eq(true)
101
- expect(matcher.matches?("name" => "bat")).to eq(true)
102
- expect(matcher.matches?("name" => "caaaaat")).to eq(true)
103
- expect(matcher.matches?("name" => "ct")).to eq(false)
104
- expect(matcher.matches?("name" => "bcat")).to eq(false)
100
+ it 'regex should go back and forth into redis' do
101
+ matcher = Matcher.new('name' => /^[cb]a+t/)
102
+ expect(matcher.matches?('name' => 'cat')).to eq(true)
103
+ expect(matcher.matches?('name' => 'bat')).to eq(true)
104
+ expect(matcher.matches?('name' => 'caaaaat')).to eq(true)
105
+ expect(matcher.matches?('name' => 'ct')).to eq(false)
106
+ expect(matcher.matches?('name' => 'bcat')).to eq(false)
105
107
 
106
- QueueBus.redis { |redis| redis.set("temp1", QueueBus::Util.encode(matcher.to_redis) ) }
107
- redis = QueueBus.redis { |redis| redis.get("temp1") }
108
+ QueueBus.redis { |redis| redis.set('temp1', QueueBus::Util.encode(matcher.to_redis)) }
109
+ redis = QueueBus.redis { |redis| redis.get('temp1') }
108
110
  matcher = Matcher.new(QueueBus::Util.decode(redis))
109
- expect(matcher.matches?("name" => "cat")).to eq(true)
110
- expect(matcher.matches?("name" => "bat")).to eq(true)
111
- expect(matcher.matches?("name" => "caaaaat")).to eq(true)
112
- expect(matcher.matches?("name" => "ct")).to eq(false)
113
- expect(matcher.matches?("name" => "bcat")).to eq(false)
114
-
115
- QueueBus.redis { |redis| redis.set("temp2", QueueBus::Util.encode(matcher.to_redis) ) }
116
- redis = QueueBus.redis { |redis| redis.get("temp2") }
111
+ expect(matcher.matches?('name' => 'cat')).to eq(true)
112
+ expect(matcher.matches?('name' => 'bat')).to eq(true)
113
+ expect(matcher.matches?('name' => 'caaaaat')).to eq(true)
114
+ expect(matcher.matches?('name' => 'ct')).to eq(false)
115
+ expect(matcher.matches?('name' => 'bcat')).to eq(false)
116
+
117
+ QueueBus.redis { |redis| redis.set('temp2', QueueBus::Util.encode(matcher.to_redis)) }
118
+ redis = QueueBus.redis { |redis| redis.get('temp2') }
117
119
  matcher = Matcher.new(QueueBus::Util.decode(redis))
118
- expect(matcher.matches?("name" => "cat")).to eq(true)
119
- expect(matcher.matches?("name" => "bat")).to eq(true)
120
- expect(matcher.matches?("name" => "caaaaat")).to eq(true)
121
- expect(matcher.matches?("name" => "ct")).to eq(false)
122
- expect(matcher.matches?("name" => "bcat")).to eq(false)
120
+ expect(matcher.matches?('name' => 'cat')).to eq(true)
121
+ expect(matcher.matches?('name' => 'bat')).to eq(true)
122
+ expect(matcher.matches?('name' => 'caaaaat')).to eq(true)
123
+ expect(matcher.matches?('name' => 'ct')).to eq(false)
124
+ expect(matcher.matches?('name' => 'bcat')).to eq(false)
123
125
  end
124
126
 
125
- it "special value should go back and forth into redis" do
126
- matcher = Matcher.new("name" => :blank)
127
- expect(matcher.matches?("name" => "cat")).to eq(false)
128
- expect(matcher.matches?("name" => "")).to eq(true)
127
+ it 'special value should go back and forth into redis' do
128
+ matcher = Matcher.new('name' => :blank)
129
+ expect(matcher.matches?('name' => 'cat')).to eq(false)
130
+ expect(matcher.matches?('name' => '')).to eq(true)
129
131
 
130
- QueueBus.redis { |redis| redis.set("temp1", QueueBus::Util.encode(matcher.to_redis) ) }
131
- redis= QueueBus.redis { |redis| redis.get("temp1") }
132
+ QueueBus.redis { |redis| redis.set('temp1', QueueBus::Util.encode(matcher.to_redis)) }
133
+ redis = QueueBus.redis { |redis| redis.get('temp1') }
132
134
  matcher = Matcher.new(QueueBus::Util.decode(redis))
133
- expect(matcher.matches?("name" => "cat")).to eq(false)
134
- expect(matcher.matches?("name" => "")).to eq(true)
135
+ expect(matcher.matches?('name' => 'cat')).to eq(false)
136
+ expect(matcher.matches?('name' => '')).to eq(true)
135
137
 
136
- QueueBus.redis { |redis| redis.set("temp2", QueueBus::Util.encode(matcher.to_redis) ) }
137
- redis= QueueBus.redis { |redis| redis.get("temp2") }
138
+ QueueBus.redis { |redis| redis.set('temp2', QueueBus::Util.encode(matcher.to_redis)) }
139
+ redis = QueueBus.redis { |redis| redis.get('temp2') }
138
140
  matcher = Matcher.new(QueueBus::Util.decode(redis))
139
- expect(matcher.matches?("name" => "cat")).to eq(false)
140
- expect(matcher.matches?("name" => "")).to eq(true)
141
+ expect(matcher.matches?('name' => 'cat')).to eq(false)
142
+ expect(matcher.matches?('name' => '')).to eq(true)
141
143
  end
142
144
  end
143
145
  end
@@ -1,98 +1,98 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
2
 
3
- describe "Publishing an event" do
3
+ require 'spec_helper'
4
4
 
5
+ describe 'Publishing an event' do
5
6
  before(:each) do
6
7
  Timecop.freeze
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(:bus_attrs) { {"bus_class_proxy"=>"QueueBus::Driver",
13
- "bus_published_at" => Time.now.to_i,
14
- "bus_id"=>"#{Time.now.to_i}-idfhlkj",
15
- "bus_app_hostname" => `hostname 2>&1`.strip.sub(/.local/,'')} }
13
+ let(:bus_attrs) do
14
+ { 'bus_class_proxy' => 'QueueBus::Driver',
15
+ 'bus_published_at' => Time.now.to_i,
16
+ 'bus_id' => "#{Time.now.to_i}-idfhlkj",
17
+ 'bus_app_hostname' => `hostname 2>&1`.strip.sub(/.local/, '') }
18
+ end
16
19
 
17
- it "should add it to Redis" do
18
- hash = {:one => 1, "two" => "here", "id" => 12 }
19
- event_name = "event_name"
20
+ it 'should add it to Redis' do
21
+ hash = { :one => 1, 'two' => 'here', 'id' => 12 }
22
+ event_name = 'event_name'
20
23
 
21
- val = QueueBus.redis { |redis| redis.lpop("queue:bus_incoming") }
24
+ val = QueueBus.redis { |redis| redis.lpop('queue:bus_incoming') }
22
25
  expect(val).to eq(nil)
23
26
 
24
27
  QueueBus.publish(event_name, hash)
25
28
 
26
- val = QueueBus.redis { |redis| redis.lpop("queue:bus_incoming") }
29
+ val = QueueBus.redis { |redis| redis.lpop('queue:bus_incoming') }
27
30
  hash = JSON.parse(val)
28
- expect(hash["class"]).to eq("QueueBus::Worker")
29
- expect(hash["args"].size).to eq(1)
30
- expect(JSON.parse(hash["args"].first)).to eq({"bus_event_type" => event_name, "two"=>"here", "one"=>1, "id" => 12}.merge(bus_attrs))
31
-
31
+ expect(hash['class']).to eq('QueueBus::Worker')
32
+ expect(hash['args'].size).to eq(1)
33
+ expect(JSON.parse(hash['args'].first)).to eq({ 'bus_event_type' => event_name, 'two' => 'here', 'one' => 1, 'id' => 12 }.merge(bus_attrs))
32
34
  end
33
35
 
34
- it "should use the id if given" do
35
- hash = {:one => 1, "two" => "here", "bus_id" => "app-given" }
36
- event_name = "event_name"
36
+ it 'should use the id if given' do
37
+ hash = { :one => 1, 'two' => 'here', 'bus_id' => 'app-given' }
38
+ event_name = 'event_name'
37
39
 
38
- val = QueueBus.redis { |redis| redis.lpop("queue:bus_incoming") }
40
+ val = QueueBus.redis { |redis| redis.lpop('queue:bus_incoming') }
39
41
  expect(val).to eq(nil)
40
42
 
41
43
  QueueBus.publish(event_name, hash)
42
44
 
43
- val = QueueBus.redis { |redis| redis.lpop("queue:bus_incoming") }
45
+ val = QueueBus.redis { |redis| redis.lpop('queue:bus_incoming') }
44
46
  hash = JSON.parse(val)
45
- expect(hash["class"]).to eq("QueueBus::Worker")
46
- expect(hash["args"].size).to eq(1)
47
- expect(JSON.parse(hash["args"].first)).to eq({"bus_event_type" => event_name, "two"=>"here", "one"=>1}.merge(bus_attrs).merge("bus_id" => 'app-given'))
47
+ expect(hash['class']).to eq('QueueBus::Worker')
48
+ expect(hash['args'].size).to eq(1)
49
+ expect(JSON.parse(hash['args'].first)).to eq({ 'bus_event_type' => event_name, 'two' => 'here', 'one' => 1 }.merge(bus_attrs).merge('bus_id' => 'app-given'))
48
50
  end
49
51
 
50
- it "should add metadata via callback" do
52
+ it 'should add metadata via callback' do
51
53
  myval = 0
52
54
  QueueBus.before_publish = lambda { |att|
53
- att["mine"] = 4
55
+ att['mine'] = 4
54
56
  myval += 1
55
57
  }
56
58
 
57
- hash = {:one => 1, "two" => "here", "bus_id" => "app-given" }
58
- event_name = "event_name"
59
+ hash = { :one => 1, 'two' => 'here', 'bus_id' => 'app-given' }
60
+ event_name = 'event_name'
59
61
 
60
- val = QueueBus.redis { |redis| redis.lpop("queue:bus_incoming") }
62
+ val = QueueBus.redis { |redis| redis.lpop('queue:bus_incoming') }
61
63
  expect(val).to eq(nil)
62
64
 
63
65
  QueueBus.publish(event_name, hash)
64
66
 
65
-
66
- val = QueueBus.redis { |redis| redis.lpop("queue:bus_incoming") }
67
+ val = QueueBus.redis { |redis| redis.lpop('queue:bus_incoming') }
67
68
  hash = JSON.parse(val)
68
- att = JSON.parse(hash["args"].first)
69
- expect(att["mine"]).to eq(4)
69
+ att = JSON.parse(hash['args'].first)
70
+ expect(att['mine']).to eq(4)
70
71
  expect(myval).to eq(1)
71
72
  end
72
73
 
73
- it "should set the timezone and locale if available" do
74
+ it 'should set the timezone and locale if available' do
74
75
  expect(defined?(I18n)).to be_nil
75
76
  expect(Time.respond_to?(:zone)).to eq(false)
76
77
 
77
- stub_const("I18n", Class.new)
78
- allow(I18n).to receive(:locale).and_return("jp")
78
+ stub_const('I18n', Class.new)
79
+ allow(I18n).to receive(:locale).and_return('jp')
79
80
 
80
- allow(Time).to receive(:zone).and_return(double('zone', :name => "EST"))
81
+ allow(Time).to receive(:zone).and_return(double('zone', name: 'EST'))
81
82
 
82
- hash = {:one => 1, "two" => "here", "bus_id" => "app-given" }
83
- event_name = "event_name"
83
+ hash = { :one => 1, 'two' => 'here', 'bus_id' => 'app-given' }
84
+ event_name = 'event_name'
84
85
 
85
- val = QueueBus.redis { |redis| redis.lpop("queue:bus_incoming") }
86
+ val = QueueBus.redis { |redis| redis.lpop('queue:bus_incoming') }
86
87
  expect(val).to eq(nil)
87
88
 
88
89
  QueueBus.publish(event_name, hash)
89
90
 
90
- val = QueueBus.redis { |redis| redis.lpop("queue:bus_incoming") }
91
+ val = QueueBus.redis { |redis| redis.lpop('queue:bus_incoming') }
91
92
  hash = JSON.parse(val)
92
- expect(hash["class"]).to eq("QueueBus::Worker")
93
- att = JSON.parse(hash["args"].first)
94
- expect(att["bus_locale"]).to eq("jp")
95
- expect(att["bus_timezone"]).to eq("EST")
93
+ expect(hash['class']).to eq('QueueBus::Worker')
94
+ att = JSON.parse(hash['args'].first)
95
+ expect(att['bus_locale']).to eq('jp')
96
+ expect(att['bus_timezone']).to eq('EST')
96
97
  end
97
-
98
98
  end
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module QueueBus
4
6
  describe Publisher do
5
- it "should call publish as expected"
7
+ it 'should call publish as expected'
6
8
  end
7
9
  end
@@ -1,27 +1,29 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module QueueBus
4
6
  describe Rider do
5
- it "should call execute" do
7
+ it 'should call execute' do
6
8
  expect(QueueBus).to receive(:dispatcher_execute)
7
- Rider.perform("bus_rider_app_key" => "app", "bus_rider_sub_key" => "sub", "ok" => true, "bus_event_type" => "event_name")
9
+ Rider.perform('bus_rider_app_key' => 'app', 'bus_rider_sub_key' => 'sub', 'ok' => true, 'bus_event_type' => 'event_name')
8
10
  end
9
11
 
10
- it "should change the value" do
11
- QueueBus.dispatch("r1") do
12
- subscribe "event_name" do |attributes|
12
+ it 'should change the value' do
13
+ QueueBus.dispatch('r1') do
14
+ subscribe 'event_name' do |attributes|
13
15
  Runner1.run(attributes)
14
16
  end
15
17
  end
16
18
  expect(Runner1.value).to eq(0)
17
- Rider.perform("bus_locale" => "en", "bus_timezone" => "PST", "bus_rider_app_key" => "r1", "bus_rider_sub_key" => "event_name", "ok" => true, "bus_event_type" => "event_name")
18
- Rider.perform("bus_rider_app_key" => "other", "bus_rider_sub_key" => "event_name", "ok" => true, "bus_event_type" => "event_name")
19
+ Rider.perform('bus_locale' => 'en', 'bus_timezone' => 'PST', 'bus_rider_app_key' => 'r1', 'bus_rider_sub_key' => 'event_name', 'ok' => true, 'bus_event_type' => 'event_name')
20
+ Rider.perform('bus_rider_app_key' => 'other', 'bus_rider_sub_key' => 'event_name', 'ok' => true, 'bus_event_type' => 'event_name')
19
21
  expect(Runner1.value).to eq(1)
20
22
  end
21
23
 
22
- it "should set the timezone and locale if present" do
23
- QueueBus.dispatch("r1") do
24
- subscribe "event_name" do |attributes|
24
+ it 'should set the timezone and locale if present' do
25
+ QueueBus.dispatch('r1') do
26
+ subscribe 'event_name' do |attributes|
25
27
  Runner1.run(attributes)
26
28
  end
27
29
  end
@@ -29,11 +31,11 @@ module QueueBus
29
31
  expect(defined?(I18n)).to be_nil
30
32
  expect(Time.respond_to?(:zone)).to eq(false)
31
33
 
32
- stub_const("I18n", Class.new)
33
- expect(I18n).to receive(:locale=).with("en")
34
- expect(Time).to receive(:zone=).with("PST")
34
+ stub_const('I18n', Class.new)
35
+ expect(I18n).to receive(:locale=).with('en')
36
+ expect(Time).to receive(:zone=).with('PST')
35
37
 
36
- Rider.perform("bus_locale" => "en", "bus_timezone" => "PST", "bus_rider_app_key" => "r1", "bus_rider_sub_key" => "event_name", "ok" => true, "bus_event_type" => "event_name")
38
+ Rider.perform('bus_locale' => 'en', 'bus_timezone' => 'PST', 'bus_rider_app_key' => 'r1', 'bus_rider_sub_key' => 'event_name', 'ok' => true, 'bus_event_type' => 'event_name')
37
39
  end
38
40
  end
39
41
  end