queue-bus 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +21 -0
  3. data/CHANGELOG.md +9 -0
  4. data/Gemfile +4 -2
  5. data/Rakefile +2 -0
  6. data/lib/queue-bus.rb +15 -12
  7. data/lib/queue_bus/adapters/base.rb +4 -2
  8. data/lib/queue_bus/adapters/data.rb +12 -11
  9. data/lib/queue_bus/application.rb +13 -15
  10. data/lib/queue_bus/dispatch.rb +14 -12
  11. data/lib/queue_bus/dispatchers.rb +12 -5
  12. data/lib/queue_bus/driver.rb +15 -10
  13. data/lib/queue_bus/heartbeat.rb +32 -30
  14. data/lib/queue_bus/local.rb +9 -9
  15. data/lib/queue_bus/matcher.rb +36 -27
  16. data/lib/queue_bus/publisher.rb +7 -5
  17. data/lib/queue_bus/publishing.rb +31 -24
  18. data/lib/queue_bus/rider.rb +26 -22
  19. data/lib/queue_bus/subscriber.rb +20 -14
  20. data/lib/queue_bus/subscription.rb +25 -15
  21. data/lib/queue_bus/subscription_list.rb +30 -12
  22. data/lib/queue_bus/task_manager.rb +18 -16
  23. data/lib/queue_bus/tasks.rb +20 -15
  24. data/lib/queue_bus/util.rb +11 -8
  25. data/lib/queue_bus/version.rb +3 -1
  26. data/lib/queue_bus/worker.rb +3 -2
  27. data/queue-bus.gemspec +19 -18
  28. data/spec/adapter/publish_at_spec.rb +28 -25
  29. data/spec/adapter/support.rb +7 -1
  30. data/spec/adapter_spec.rb +4 -2
  31. data/spec/application_spec.rb +97 -97
  32. data/spec/dispatch_spec.rb +48 -51
  33. data/spec/driver_spec.rb +60 -58
  34. data/spec/heartbeat_spec.rb +26 -24
  35. data/spec/integration_spec.rb +41 -40
  36. data/spec/matcher_spec.rb +104 -102
  37. data/spec/publish_spec.rb +46 -46
  38. data/spec/publisher_spec.rb +3 -1
  39. data/spec/rider_spec.rb +16 -14
  40. data/spec/spec_helper.rb +2 -2
  41. data/spec/subscriber_spec.rb +227 -227
  42. data/spec/subscription_list_spec.rb +31 -31
  43. data/spec/subscription_spec.rb +37 -36
  44. data/spec/worker_spec.rb +17 -15
  45. metadata +7 -6
@@ -1,92 +1,94 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module QueueBus
4
6
  describe Driver do
5
7
  before(:each) do
6
- Application.new("app1").subscribe(test_list(test_sub("event1"), test_sub("event2"), test_sub("event3")))
7
- Application.new("app2").subscribe(test_list(test_sub("event2","other"), test_sub("event4", "more")))
8
- Application.new("app3").subscribe(test_list(test_sub("event[45]"), test_sub("event5"), test_sub("event6")))
8
+ Application.new('app1').subscribe(test_list(test_sub('event1'), test_sub('event2'), test_sub('event3')))
9
+ Application.new('app2').subscribe(test_list(test_sub('event2', 'other'), test_sub('event4', 'more')))
10
+ Application.new('app3').subscribe(test_list(test_sub('event[45]'), test_sub('event5'), test_sub('event6')))
9
11
  Timecop.freeze
10
12
  end
11
13
  after(:each) do
12
14
  Timecop.return
13
15
  end
14
16
 
15
- let(:bus_attrs) { {"bus_driven_at" => Time.now.to_i, "bus_rider_class_name"=>"::QueueBus::Rider", "bus_class_proxy" => "::QueueBus::Rider"} }
17
+ let(:bus_attrs) { { 'bus_driven_at' => Time.now.to_i, 'bus_rider_class_name' => '::QueueBus::Rider', 'bus_class_proxy' => '::QueueBus::Rider' } }
16
18
 
17
- describe ".subscription_matches" do
18
- it "return empty array when none" do
19
- expect(Driver.subscription_matches("bus_event_type" => "else").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}).to eq([])
20
- expect(Driver.subscription_matches("bus_event_type" => "event").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}).to eq([])
19
+ describe '.subscription_matches' do
20
+ it 'return empty array when none' do
21
+ expect(Driver.subscription_matches('bus_event_type' => 'else').collect { |s| [s.app_key, s.key, s.queue_name, s.class_name] }).to eq([])
22
+ expect(Driver.subscription_matches('bus_event_type' => 'event').collect { |s| [s.app_key, s.key, s.queue_name, s.class_name] }).to eq([])
21
23
  end
22
- it "should return a match" do
23
- expect(Driver.subscription_matches("bus_event_type" => "event1").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}).to match_array([["app1", "event1", "default", "::QueueBus::Rider"]])
24
- expect(Driver.subscription_matches("bus_event_type" => "event6").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}).to match_array([["app3", "event6", "default", "::QueueBus::Rider"]])
24
+ it 'should return a match' do
25
+ expect(Driver.subscription_matches('bus_event_type' => 'event1').collect { |s| [s.app_key, s.key, s.queue_name, s.class_name] }).to match_array([['app1', 'event1', 'default', '::QueueBus::Rider']])
26
+ expect(Driver.subscription_matches('bus_event_type' => 'event6').collect { |s| [s.app_key, s.key, s.queue_name, s.class_name] }).to match_array([['app3', 'event6', 'default', '::QueueBus::Rider']])
25
27
  end
26
- it "should match multiple apps" do
27
- expect(Driver.subscription_matches("bus_event_type" => "event2").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}).to match_array([["app1", "event2", "default", "::QueueBus::Rider"], ["app2", "event2", "other", "::QueueBus::Rider"]])
28
+ it 'should match multiple apps' do
29
+ expect(Driver.subscription_matches('bus_event_type' => 'event2').collect { |s| [s.app_key, s.key, s.queue_name, s.class_name] }).to match_array([['app1', 'event2', 'default', '::QueueBus::Rider'], ['app2', 'event2', 'other', '::QueueBus::Rider']])
28
30
  end
29
- it "should match multiple apps with patterns" do
30
- expect(Driver.subscription_matches("bus_event_type" => "event4").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}).to match_array([["app3", "event[45]", "default", "::QueueBus::Rider"], ["app2", "event4", "more", "::QueueBus::Rider"]])
31
+ it 'should match multiple apps with patterns' do
32
+ expect(Driver.subscription_matches('bus_event_type' => 'event4').collect { |s| [s.app_key, s.key, s.queue_name, s.class_name] }).to match_array([['app3', 'event[45]', 'default', '::QueueBus::Rider'], ['app2', 'event4', 'more', '::QueueBus::Rider']])
31
33
  end
32
- it "should match multiple events in same app" do
33
- expect(Driver.subscription_matches("bus_event_type" => "event5").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}).to match_array([["app3", "event[45]", "default", "::QueueBus::Rider"], ["app3", "event5", "default", "::QueueBus::Rider"]])
34
+ it 'should match multiple events in same app' do
35
+ expect(Driver.subscription_matches('bus_event_type' => 'event5').collect { |s| [s.app_key, s.key, s.queue_name, s.class_name] }).to match_array([['app3', 'event[45]', 'default', '::QueueBus::Rider'], ['app3', 'event5', 'default', '::QueueBus::Rider']])
34
36
  end
35
37
  end
36
38
 
37
- describe ".perform" do
38
- let(:attributes) { {"x" => "y", "bus_class_proxy" => "ResqueBus::Driver"} }
39
+ describe '.perform' do
40
+ let(:attributes) { { 'x' => 'y', 'bus_class_proxy' => 'ResqueBus::Driver' } }
39
41
 
40
42
  before(:each) do
41
- expect(QueueBus.redis { |redis| redis.smembers("queues") }).to eq([])
42
- expect(QueueBus.redis { |redis| redis.lpop("queue:app1_default") }).to be_nil
43
- expect(QueueBus.redis { |redis| redis.lpop("queue:app2_default") }).to be_nil
44
- expect(QueueBus.redis { |redis| redis.lpop("queue:app3_default") }).to be_nil
43
+ expect(QueueBus.redis { |redis| redis.smembers('queues') }).to eq([])
44
+ expect(QueueBus.redis { |redis| redis.lpop('queue:app1_default') }).to be_nil
45
+ expect(QueueBus.redis { |redis| redis.lpop('queue:app2_default') }).to be_nil
46
+ expect(QueueBus.redis { |redis| redis.lpop('queue:app3_default') }).to be_nil
45
47
  end
46
48
 
47
- it "should do nothing when empty" do
48
- Driver.perform(attributes.merge("bus_event_type" => "else"))
49
- expect(QueueBus.redis { |redis| redis.smembers("queues") }).to eq([])
49
+ it 'should do nothing when empty' do
50
+ Driver.perform(attributes.merge('bus_event_type' => 'else'))
51
+ expect(QueueBus.redis { |redis| redis.smembers('queues') }).to eq([])
50
52
  end
51
53
 
52
- it "should queue up the riders in redis" do
53
- expect(QueueBus.redis { |redis| redis.lpop("queue:app1_default") }).to be_nil
54
- Driver.perform(attributes.merge("bus_event_type" => "event1"))
55
- expect(QueueBus.redis { |redis| redis.smembers("queues") }).to match_array(["default"])
54
+ it 'should queue up the riders in redis' do
55
+ expect(QueueBus.redis { |redis| redis.lpop('queue:app1_default') }).to be_nil
56
+ Driver.perform(attributes.merge('bus_event_type' => 'event1'))
57
+ expect(QueueBus.redis { |redis| redis.smembers('queues') }).to match_array(['default'])
56
58
 
57
- hash = JSON.parse(QueueBus.redis { |redis| redis.lpop("queue:default") })
58
- expect(hash["class"]).to eq("QueueBus::Worker")
59
- expect(hash["args"].size).to eq(1)
60
- expect(JSON.parse(hash["args"].first)).to eq({"bus_rider_app_key"=>"app1", "x" => "y", "bus_event_type" => "event1", "bus_rider_sub_key"=>"event1", "bus_rider_queue" => "default"}.merge(bus_attrs))
59
+ hash = JSON.parse(QueueBus.redis { |redis| redis.lpop('queue:default') })
60
+ expect(hash['class']).to eq('QueueBus::Worker')
61
+ expect(hash['args'].size).to eq(1)
62
+ expect(JSON.parse(hash['args'].first)).to eq({ 'bus_rider_app_key' => 'app1', 'x' => 'y', 'bus_event_type' => 'event1', 'bus_rider_sub_key' => 'event1', 'bus_rider_queue' => 'default' }.merge(bus_attrs))
61
63
  end
62
64
 
63
- it "should queue up to multiple" do
64
- Driver.perform(attributes.merge("bus_event_type" => "event4"))
65
- expect(QueueBus.redis { |redis| redis.smembers("queues") }).to match_array(["default", "more"])
65
+ it 'should queue up to multiple' do
66
+ Driver.perform(attributes.merge('bus_event_type' => 'event4'))
67
+ expect(QueueBus.redis { |redis| redis.smembers('queues') }).to match_array(%w[default more])
66
68
 
67
- hash = JSON.parse(QueueBus.redis { |redis| redis.lpop("queue:more") })
68
- expect(hash["class"]).to eq("QueueBus::Worker")
69
- expect(hash["args"].size).to eq(1)
70
- expect(JSON.parse(hash["args"].first)).to eq({"bus_rider_app_key"=>"app2", "x" => "y", "bus_event_type" => "event4", "bus_rider_sub_key"=>"event4", "bus_rider_queue" => "more"}.merge(bus_attrs))
69
+ hash = JSON.parse(QueueBus.redis { |redis| redis.lpop('queue:more') })
70
+ expect(hash['class']).to eq('QueueBus::Worker')
71
+ expect(hash['args'].size).to eq(1)
72
+ expect(JSON.parse(hash['args'].first)).to eq({ 'bus_rider_app_key' => 'app2', 'x' => 'y', 'bus_event_type' => 'event4', 'bus_rider_sub_key' => 'event4', 'bus_rider_queue' => 'more' }.merge(bus_attrs))
71
73
 
72
- hash = JSON.parse(QueueBus.redis { |redis| redis.lpop("queue:default") })
73
- expect(hash["class"]).to eq("QueueBus::Worker")
74
- expect(hash["args"].size).to eq(1)
75
- expect(JSON.parse(hash["args"].first)).to eq({"bus_rider_app_key"=>"app3", "x" => "y", "bus_event_type" => "event4", "bus_rider_sub_key"=>"event[45]", "bus_rider_queue" => "default"}.merge(bus_attrs))
74
+ hash = JSON.parse(QueueBus.redis { |redis| redis.lpop('queue:default') })
75
+ expect(hash['class']).to eq('QueueBus::Worker')
76
+ expect(hash['args'].size).to eq(1)
77
+ expect(JSON.parse(hash['args'].first)).to eq({ 'bus_rider_app_key' => 'app3', 'x' => 'y', 'bus_event_type' => 'event4', 'bus_rider_sub_key' => 'event[45]', 'bus_rider_queue' => 'default' }.merge(bus_attrs))
76
78
  end
77
79
 
78
- it "should queue up to the same" do
79
- Driver.perform(attributes.merge("bus_event_type" => "event5"))
80
- expect(QueueBus.redis { |redis| redis.smembers("queues") }).to match_array(["default"])
80
+ it 'should queue up to the same' do
81
+ Driver.perform(attributes.merge('bus_event_type' => 'event5'))
82
+ expect(QueueBus.redis { |redis| redis.smembers('queues') }).to match_array(['default'])
81
83
 
82
- expect(QueueBus.redis { |redis| redis.llen("queue:default") }).to eq(2)
84
+ expect(QueueBus.redis { |redis| redis.llen('queue:default') }).to eq(2)
83
85
 
84
- pop1 = JSON.parse(QueueBus.redis { |redis| redis.lpop("queue:default") })
85
- pop2 = JSON.parse(QueueBus.redis { |redis| redis.lpop("queue:default") })
86
+ pop1 = JSON.parse(QueueBus.redis { |redis| redis.lpop('queue:default') })
87
+ pop2 = JSON.parse(QueueBus.redis { |redis| redis.lpop('queue:default') })
86
88
 
87
- pargs1 = JSON.parse(pop1["args"].first)
88
- pargs2 = JSON.parse(pop2["args"].first)
89
- if pargs1["bus_rider_sub_key"] == "event5"
89
+ pargs1 = JSON.parse(pop1['args'].first)
90
+ pargs2 = JSON.parse(pop2['args'].first)
91
+ if pargs1['bus_rider_sub_key'] == 'event5'
90
92
  hash1 = pop1
91
93
  hash2 = pop2
92
94
  args1 = pargs1
@@ -98,11 +100,11 @@ module QueueBus
98
100
  args2 = pargs1
99
101
  end
100
102
 
101
- expect(hash1["class"]).to eq("QueueBus::Worker")
102
- expect(args1).to eq({"bus_rider_app_key"=>"app3", "x" => "y", "bus_event_type" => "event5", "bus_rider_sub_key"=>"event5", "bus_rider_queue" => "default"}.merge(bus_attrs))
103
+ expect(hash1['class']).to eq('QueueBus::Worker')
104
+ expect(args1).to eq({ 'bus_rider_app_key' => 'app3', 'x' => 'y', 'bus_event_type' => 'event5', 'bus_rider_sub_key' => 'event5', 'bus_rider_queue' => 'default' }.merge(bus_attrs))
103
105
 
104
- expect(hash2["class"]).to eq("QueueBus::Worker")
105
- expect(args2).to eq({"bus_rider_app_key"=>"app3", "x" => "y", "bus_event_type" => "event5", "bus_rider_sub_key"=>"event[45]", "bus_rider_queue" => "default"}.merge(bus_attrs))
106
+ expect(hash2['class']).to eq('QueueBus::Worker')
107
+ expect(args2).to eq({ 'bus_rider_app_key' => 'app3', 'x' => 'y', 'bus_event_type' => 'event5', 'bus_rider_sub_key' => 'event[45]', 'bus_rider_queue' => 'default' }.merge(bus_attrs))
106
108
  end
107
109
  end
108
110
  end
@@ -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