queue-bus 0.6.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +21 -0
  3. data/.rubocop.yml +35 -0
  4. data/CHANGELOG.md +38 -0
  5. data/Gemfile +4 -2
  6. data/README.mdown +16 -0
  7. data/Rakefile +2 -0
  8. data/lib/queue-bus.rb +15 -13
  9. data/lib/queue_bus/adapters/base.rb +4 -2
  10. data/lib/queue_bus/adapters/data.rb +12 -11
  11. data/lib/queue_bus/application.rb +13 -15
  12. data/lib/queue_bus/config.rb +64 -66
  13. data/lib/queue_bus/dispatch.rb +14 -12
  14. data/lib/queue_bus/dispatchers.rb +12 -5
  15. data/lib/queue_bus/driver.rb +15 -10
  16. data/lib/queue_bus/heartbeat.rb +32 -30
  17. data/lib/queue_bus/local.rb +9 -9
  18. data/lib/queue_bus/matcher.rb +36 -27
  19. data/lib/queue_bus/publisher.rb +7 -5
  20. data/lib/queue_bus/publishing.rb +31 -24
  21. data/lib/queue_bus/rider.rb +26 -22
  22. data/lib/queue_bus/subscriber.rb +20 -14
  23. data/lib/queue_bus/subscription.rb +25 -15
  24. data/lib/queue_bus/subscription_list.rb +30 -12
  25. data/lib/queue_bus/task_manager.rb +18 -16
  26. data/lib/queue_bus/tasks.rb +27 -11
  27. data/lib/queue_bus/util.rb +11 -8
  28. data/lib/queue_bus/version.rb +3 -1
  29. data/lib/queue_bus/worker.rb +3 -2
  30. data/queue-bus.gemspec +19 -17
  31. data/spec/adapter/publish_at_spec.rb +28 -25
  32. data/spec/adapter/support.rb +7 -1
  33. data/spec/adapter_spec.rb +4 -2
  34. data/spec/application_spec.rb +97 -97
  35. data/spec/config_spec.rb +116 -40
  36. data/spec/dispatch_spec.rb +48 -51
  37. data/spec/driver_spec.rb +60 -58
  38. data/spec/heartbeat_spec.rb +26 -24
  39. data/spec/integration_spec.rb +41 -40
  40. data/spec/matcher_spec.rb +104 -102
  41. data/spec/publish_spec.rb +46 -46
  42. data/spec/publisher_spec.rb +3 -1
  43. data/spec/rider_spec.rb +16 -14
  44. data/spec/spec_helper.rb +12 -7
  45. data/spec/subscriber_spec.rb +227 -227
  46. data/spec/subscription_list_spec.rb +31 -31
  47. data/spec/subscription_spec.rb +37 -36
  48. data/spec/worker_spec.rb +17 -15
  49. metadata +21 -6
@@ -1,42 +1,44 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module QueueBus
4
6
  describe Heartbeat do
5
7
  def now_attributes
6
8
  {
7
- "epoch_seconds" => (Time.now.to_i / 60) * 60, # rounded
8
- "epoch_minutes" => Time.now.to_i / 60,
9
- "epoch_hours" => Time.now.to_i / (60*60),
10
- "epoch_days" => Time.now.to_i / (60*60*24),
11
- "minute" => Time.now.min,
12
- "hour" => Time.now.hour,
13
- "day" => Time.now.day,
14
- "month" => Time.now.month,
15
- "year" => Time.now.year,
16
- "yday" => Time.now.yday,
17
- "wday" => Time.now.wday
9
+ 'epoch_seconds' => (Time.now.to_i / 60) * 60, # rounded
10
+ 'epoch_minutes' => Time.now.to_i / 60,
11
+ 'epoch_hours' => Time.now.to_i / (60 * 60),
12
+ 'epoch_days' => Time.now.to_i / (60 * 60 * 24),
13
+ 'minute' => Time.now.min,
14
+ 'hour' => Time.now.hour,
15
+ 'day' => Time.now.day,
16
+ 'month' => Time.now.month,
17
+ 'year' => Time.now.year,
18
+ 'yday' => Time.now.yday,
19
+ 'wday' => Time.now.wday
18
20
  }
19
21
  end
20
-
21
- it "should publish the current time once" do
22
- Timecop.freeze "12/12/2013 12:01:19" do
23
- expect(QueueBus).to receive(:publish).with("heartbeat_minutes", now_attributes)
22
+
23
+ it 'should publish the current time once' do
24
+ Timecop.freeze '12/12/2013 12:01:19' do
25
+ expect(QueueBus).to receive(:publish).with('heartbeat_minutes', now_attributes)
24
26
  Heartbeat.perform
25
27
  end
26
-
27
- Timecop.freeze "12/12/2013 12:01:40" do
28
+
29
+ Timecop.freeze '12/12/2013 12:01:40' do
28
30
  Heartbeat.perform
29
31
  end
30
32
  end
31
-
32
- it "should publish a minute later" do
33
- Timecop.freeze "12/12/2013 12:01:19" do
34
- expect(QueueBus).to receive(:publish).with("heartbeat_minutes", now_attributes)
33
+
34
+ it 'should publish a minute later' do
35
+ Timecop.freeze '12/12/2013 12:01:19' do
36
+ expect(QueueBus).to receive(:publish).with('heartbeat_minutes', now_attributes)
35
37
  Heartbeat.perform
36
38
  end
37
-
38
- Timecop.freeze "12/12/2013 12:02:01" do
39
- expect(QueueBus).to receive(:publish).with("heartbeat_minutes", now_attributes)
39
+
40
+ Timecop.freeze '12/12/2013 12:02:01' do
41
+ expect(QueueBus).to receive(:publish).with('heartbeat_minutes', now_attributes)
40
42
  Heartbeat.perform
41
43
  end
42
44
  end
@@ -1,53 +1,54 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module QueueBus
4
- describe "Integration" do
5
- it "should round trip attributes" do
6
- write1 = Subscription.new("default", "key1", "MyClass1", {"bus_event_type" => "event_one"})
7
- write2 = Subscription.new("else_ok", "key2", "MyClass2", {"bus_event_type" => /^[ab]here/}) #regex
8
-
9
- expect(write1.matches?("bus_event_type" => "event_one")).to eq(true)
10
- expect(write1.matches?("bus_event_type" => "event_one1")).to eq(false)
11
- expect(write1.matches?("bus_event_type" => "aevent_one")).to eq(false)
12
-
13
- expect(write2.matches?("bus_event_type" => "ahere")).to eq(true)
14
- expect(write2.matches?("bus_event_type" => "bhere")).to eq(true)
15
- expect(write2.matches?("bus_event_type" => "qhere")).to eq(false)
16
- expect(write2.matches?("bus_event_type" => "abhere")).to eq(false)
17
- expect(write2.matches?("bus_event_type" => "[ab]here")).to eq(false)
18
-
6
+ describe 'Integration' do
7
+ it 'should round trip attributes' do
8
+ write1 = Subscription.new('default', 'key1', 'MyClass1', 'bus_event_type' => 'event_one')
9
+ write2 = Subscription.new('else_ok', 'key2', 'MyClass2', 'bus_event_type' => /^[ab]here/) # regex
10
+
11
+ expect(write1.matches?('bus_event_type' => 'event_one')).to eq(true)
12
+ expect(write1.matches?('bus_event_type' => 'event_one1')).to eq(false)
13
+ expect(write1.matches?('bus_event_type' => 'aevent_one')).to eq(false)
14
+
15
+ expect(write2.matches?('bus_event_type' => 'ahere')).to eq(true)
16
+ expect(write2.matches?('bus_event_type' => 'bhere')).to eq(true)
17
+ expect(write2.matches?('bus_event_type' => 'qhere')).to eq(false)
18
+ expect(write2.matches?('bus_event_type' => 'abhere')).to eq(false)
19
+ expect(write2.matches?('bus_event_type' => '[ab]here')).to eq(false)
20
+
19
21
  write = SubscriptionList.new
20
22
  write.add(write1)
21
23
  write.add(write2)
22
-
23
- app = Application.new("test")
24
+
25
+ app = Application.new('test')
24
26
  app.subscribe(write)
25
-
26
- reset_test_adapter # reset to make sure we read from redis
27
- app = Application.new("test")
27
+
28
+ reset_test_adapter # reset to make sure we read from redis
29
+ app = Application.new('test')
28
30
  read = app.send(:subscriptions)
29
-
31
+
30
32
  expect(read.size).to eq(2)
31
- read1 = read.key("key1")
32
- read2 = read.key("key2")
33
+ read1 = read.key('key1')
34
+ read2 = read.key('key2')
33
35
  expect(read1).not_to be_nil
34
36
  expect(read2).not_to be_nil
35
-
36
- expect(read1.queue_name).to eq("default")
37
- expect(read1.class_name).to eq("MyClass1")
38
- expect(read2.queue_name).to eq("else_ok")
39
- expect(read2.class_name).to eq("MyClass2")
40
-
41
- expect(read1.matches?("bus_event_type" => "event_one")).to eq(true)
42
- expect(read1.matches?("bus_event_type" => "event_one1")).to eq(false)
43
- expect(read1.matches?("bus_event_type" => "aevent_one")).to eq(false)
44
-
45
- expect(read2.matches?("bus_event_type" => "ahere")).to eq(true)
46
- expect(read2.matches?("bus_event_type" => "bhere")).to eq(true)
47
- expect(read2.matches?("bus_event_type" => "qhere")).to eq(false)
48
- expect(read2.matches?("bus_event_type" => "abhere")).to eq(false)
49
- expect(read2.matches?("bus_event_type" => "[ab]here")).to eq(false)
50
-
37
+
38
+ expect(read1.queue_name).to eq('default')
39
+ expect(read1.class_name).to eq('MyClass1')
40
+ expect(read2.queue_name).to eq('else_ok')
41
+ expect(read2.class_name).to eq('MyClass2')
42
+
43
+ expect(read1.matches?('bus_event_type' => 'event_one')).to eq(true)
44
+ expect(read1.matches?('bus_event_type' => 'event_one1')).to eq(false)
45
+ expect(read1.matches?('bus_event_type' => 'aevent_one')).to eq(false)
46
+
47
+ expect(read2.matches?('bus_event_type' => 'ahere')).to eq(true)
48
+ expect(read2.matches?('bus_event_type' => 'bhere')).to eq(true)
49
+ expect(read2.matches?('bus_event_type' => 'qhere')).to eq(false)
50
+ expect(read2.matches?('bus_event_type' => 'abhere')).to eq(false)
51
+ expect(read2.matches?('bus_event_type' => '[ab]here')).to eq(false)
51
52
  end
52
53
  end
53
- end
54
+ end
@@ -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