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.
- checksums.yaml +4 -4
- data/.circleci/config.yml +21 -0
- data/CHANGELOG.md +30 -0
- data/Gemfile +4 -2
- data/README.mdown +16 -0
- data/Rakefile +2 -0
- data/lib/queue-bus.rb +15 -12
- data/lib/queue_bus/adapters/base.rb +4 -2
- data/lib/queue_bus/adapters/data.rb +12 -11
- data/lib/queue_bus/application.rb +24 -16
- data/lib/queue_bus/config.rb +31 -1
- data/lib/queue_bus/dispatch.rb +14 -12
- data/lib/queue_bus/dispatchers.rb +12 -5
- data/lib/queue_bus/driver.rb +15 -10
- data/lib/queue_bus/heartbeat.rb +32 -30
- data/lib/queue_bus/local.rb +9 -9
- data/lib/queue_bus/matcher.rb +36 -27
- data/lib/queue_bus/publisher.rb +7 -5
- data/lib/queue_bus/publishing.rb +31 -24
- data/lib/queue_bus/rider.rb +26 -22
- data/lib/queue_bus/subscriber.rb +20 -14
- data/lib/queue_bus/subscription.rb +25 -15
- data/lib/queue_bus/subscription_list.rb +30 -12
- data/lib/queue_bus/task_manager.rb +25 -16
- data/lib/queue_bus/tasks.rb +35 -11
- data/lib/queue_bus/util.rb +11 -8
- data/lib/queue_bus/version.rb +3 -1
- data/lib/queue_bus/worker.rb +3 -2
- data/queue-bus.gemspec +19 -18
- data/spec/adapter/publish_at_spec.rb +28 -25
- data/spec/adapter/support.rb +7 -1
- data/spec/adapter_spec.rb +4 -2
- data/spec/application_spec.rb +138 -96
- data/spec/config_spec.rb +35 -0
- data/spec/dispatch_spec.rb +48 -51
- data/spec/driver_spec.rb +60 -58
- data/spec/heartbeat_spec.rb +26 -24
- data/spec/integration_spec.rb +41 -40
- data/spec/matcher_spec.rb +104 -102
- data/spec/publish_spec.rb +46 -46
- data/spec/publisher_spec.rb +3 -1
- data/spec/rider_spec.rb +16 -14
- data/spec/spec_helper.rb +2 -2
- data/spec/subscriber_spec.rb +227 -227
- data/spec/subscription_list_spec.rb +57 -31
- data/spec/subscription_spec.rb +37 -36
- data/spec/worker_spec.rb +17 -15
- metadata +8 -8
data/spec/matcher_spec.rb
CHANGED
@@ -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
|
7
|
+
it 'should already return false on empty filters' do
|
6
8
|
matcher = Matcher.new({})
|
7
|
-
expect(matcher.matches?({})).to
|
9
|
+
expect(matcher.matches?({})).to eq(false)
|
8
10
|
expect(matcher.matches?(nil)).to eq(false)
|
9
|
-
expect(matcher.matches?(
|
11
|
+
expect(matcher.matches?('name' => 'val')).to eq(false)
|
10
12
|
end
|
11
13
|
|
12
|
-
it
|
13
|
-
matcher = Matcher.new(
|
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
|
18
|
-
matcher = Matcher.new(
|
19
|
-
expect(matcher.matches?(
|
20
|
-
expect(matcher.matches?(
|
21
|
-
expect(matcher.matches?(
|
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
|
25
|
-
matcher = Matcher.new(
|
26
|
-
expect(matcher.matches?(
|
27
|
-
expect(matcher.matches?(
|
28
|
-
expect(matcher.matches?(
|
29
|
-
expect(matcher.matches?(
|
30
|
-
expect(matcher.matches?(
|
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
|
34
|
-
matcher = Matcher.new(
|
35
|
-
expect(matcher.matches?(
|
36
|
-
expect(matcher.matches?(
|
37
|
-
expect(matcher.matches?(
|
38
|
-
expect(matcher.matches?(
|
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
|
42
|
-
matcher = Matcher.new(
|
43
|
-
expect(matcher.matches?(
|
44
|
-
expect(matcher.matches?(
|
45
|
-
expect(matcher.matches?(
|
46
|
-
expect(matcher.matches?(
|
47
|
-
expect(matcher.matches?(
|
48
|
-
expect(matcher.matches?(
|
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
|
52
|
-
matcher = Matcher.new(
|
53
|
-
expect(matcher.matches?(
|
54
|
-
expect(matcher.matches?(
|
55
|
-
expect(matcher.matches?(
|
56
|
-
expect(matcher.matches?(
|
57
|
-
expect(matcher.matches?(
|
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
|
61
|
-
matcher = Matcher.new(
|
62
|
-
expect(matcher.matches?(
|
63
|
-
expect(matcher.matches?(
|
64
|
-
expect(matcher.matches?(
|
65
|
-
expect(matcher.matches?(
|
66
|
-
expect(matcher.matches?(
|
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
|
70
|
-
matcher = Matcher.new(
|
71
|
-
expect(matcher.matches?(
|
72
|
-
expect(matcher.matches?(
|
73
|
-
expect(matcher.matches?(
|
74
|
-
expect(matcher.matches?(
|
75
|
-
expect(matcher.matches?(
|
76
|
-
expect(matcher.matches?(
|
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
|
80
|
-
matcher = Matcher.new(
|
81
|
-
expect(matcher.matches?(
|
82
|
-
expect(matcher.matches?(
|
83
|
-
expect(matcher.matches?(
|
84
|
-
expect(matcher.matches?(
|
85
|
-
expect(matcher.matches?(
|
86
|
-
expect(matcher.matches?(
|
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
|
90
|
-
matcher = Matcher.new(
|
91
|
-
expect(matcher.matches?(
|
92
|
-
expect(matcher.matches?(
|
93
|
-
expect(matcher.matches?(
|
94
|
-
expect(matcher.matches?(
|
95
|
-
expect(matcher.matches?(
|
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
|
99
|
-
matcher = Matcher.new(
|
100
|
-
expect(matcher.matches?(
|
101
|
-
expect(matcher.matches?(
|
102
|
-
expect(matcher.matches?(
|
103
|
-
expect(matcher.matches?(
|
104
|
-
expect(matcher.matches?(
|
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(
|
107
|
-
redis = QueueBus.redis { |redis| redis.get(
|
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?(
|
110
|
-
expect(matcher.matches?(
|
111
|
-
expect(matcher.matches?(
|
112
|
-
expect(matcher.matches?(
|
113
|
-
expect(matcher.matches?(
|
114
|
-
|
115
|
-
QueueBus.redis { |redis| redis.set(
|
116
|
-
redis = QueueBus.redis { |redis| redis.get(
|
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?(
|
119
|
-
expect(matcher.matches?(
|
120
|
-
expect(matcher.matches?(
|
121
|
-
expect(matcher.matches?(
|
122
|
-
expect(matcher.matches?(
|
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
|
126
|
-
matcher = Matcher.new(
|
127
|
-
expect(matcher.matches?(
|
128
|
-
expect(matcher.matches?(
|
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(
|
131
|
-
redis= QueueBus.redis { |redis| redis.get(
|
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?(
|
134
|
-
expect(matcher.matches?(
|
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(
|
137
|
-
redis= QueueBus.redis { |redis| redis.get(
|
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?(
|
140
|
-
expect(matcher.matches?(
|
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
|
data/spec/publish_spec.rb
CHANGED
@@ -1,98 +1,98 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
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(
|
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)
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
18
|
-
hash = {:one => 1,
|
19
|
-
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(
|
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(
|
29
|
+
val = QueueBus.redis { |redis| redis.lpop('queue:bus_incoming') }
|
27
30
|
hash = JSON.parse(val)
|
28
|
-
expect(hash[
|
29
|
-
expect(hash[
|
30
|
-
expect(JSON.parse(hash[
|
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
|
35
|
-
hash = {:one => 1,
|
36
|
-
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(
|
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(
|
45
|
+
val = QueueBus.redis { |redis| redis.lpop('queue:bus_incoming') }
|
44
46
|
hash = JSON.parse(val)
|
45
|
-
expect(hash[
|
46
|
-
expect(hash[
|
47
|
-
expect(JSON.parse(hash[
|
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
|
52
|
+
it 'should add metadata via callback' do
|
51
53
|
myval = 0
|
52
54
|
QueueBus.before_publish = lambda { |att|
|
53
|
-
att[
|
55
|
+
att['mine'] = 4
|
54
56
|
myval += 1
|
55
57
|
}
|
56
58
|
|
57
|
-
hash = {:one => 1,
|
58
|
-
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(
|
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[
|
69
|
-
expect(att[
|
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
|
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(
|
78
|
-
allow(I18n).to receive(:locale).and_return(
|
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', :
|
81
|
+
allow(Time).to receive(:zone).and_return(double('zone', name: 'EST'))
|
81
82
|
|
82
|
-
hash = {:one => 1,
|
83
|
-
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(
|
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(
|
91
|
+
val = QueueBus.redis { |redis| redis.lpop('queue:bus_incoming') }
|
91
92
|
hash = JSON.parse(val)
|
92
|
-
expect(hash[
|
93
|
-
att = JSON.parse(hash[
|
94
|
-
expect(att[
|
95
|
-
expect(att[
|
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
|
data/spec/publisher_spec.rb
CHANGED
data/spec/rider_spec.rb
CHANGED
@@ -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
|
7
|
+
it 'should call execute' do
|
6
8
|
expect(QueueBus).to receive(:dispatcher_execute)
|
7
|
-
Rider.perform(
|
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
|
11
|
-
QueueBus.dispatch(
|
12
|
-
subscribe
|
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(
|
18
|
-
Rider.perform(
|
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
|
23
|
-
QueueBus.dispatch(
|
24
|
-
subscribe
|
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(
|
33
|
-
expect(I18n).to receive(:locale=).with(
|
34
|
-
expect(Time).to receive(:zone=).with(
|
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(
|
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
|