dispatch-rider 2.0.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/build.yml +5 -4
  3. data/.rubocop.yml +21 -0
  4. data/.rubocop_todo.yml +17 -300
  5. data/CHANGELOG.md +7 -0
  6. data/Rakefile +2 -1
  7. data/dispatch-rider.gemspec +3 -3
  8. data/lib/dispatch-rider/callbacks/access.rb +2 -0
  9. data/lib/dispatch-rider/callbacks/storage.rb +7 -5
  10. data/lib/dispatch-rider/callbacks/support.rb +2 -0
  11. data/lib/dispatch-rider/callbacks.rb +2 -0
  12. data/lib/dispatch-rider/command.rb +3 -3
  13. data/lib/dispatch-rider/configuration.rb +3 -1
  14. data/lib/dispatch-rider/debug.rb +3 -1
  15. data/lib/dispatch-rider/demultiplexer.rb +17 -19
  16. data/lib/dispatch-rider/dispatcher.rb +2 -0
  17. data/lib/dispatch-rider/error_handlers.rb +3 -1
  18. data/lib/dispatch-rider/errors.rb +2 -0
  19. data/lib/dispatch-rider/handlers/base.rb +12 -10
  20. data/lib/dispatch-rider/handlers/inheritance_tracking.rb +2 -0
  21. data/lib/dispatch-rider/handlers/named_process.rb +2 -0
  22. data/lib/dispatch-rider/handlers.rb +2 -0
  23. data/lib/dispatch-rider/integrations/appsignal.rb +3 -1
  24. data/lib/dispatch-rider/logging/json_formatter.rb +2 -0
  25. data/lib/dispatch-rider/logging/lifecycle_logger.rb +3 -1
  26. data/lib/dispatch-rider/logging/text_formatter.rb +2 -0
  27. data/lib/dispatch-rider/logging/translator/base_translator.rb +3 -1
  28. data/lib/dispatch-rider/logging/translator/complete_translator.rb +2 -0
  29. data/lib/dispatch-rider/logging/translator/error_handler_fail_translator.rb +2 -0
  30. data/lib/dispatch-rider/logging/translator/fail_translator.rb +2 -0
  31. data/lib/dispatch-rider/logging/translator/start_translator.rb +2 -0
  32. data/lib/dispatch-rider/logging/translator/stop_translator.rb +2 -0
  33. data/lib/dispatch-rider/logging/translator/success_translator.rb +2 -0
  34. data/lib/dispatch-rider/logging/translator.rb +2 -0
  35. data/lib/dispatch-rider/logging.rb +2 -0
  36. data/lib/dispatch-rider/message.rb +3 -0
  37. data/lib/dispatch-rider/notification_services/aws_sns.rb +5 -3
  38. data/lib/dispatch-rider/notification_services/base.rb +2 -0
  39. data/lib/dispatch-rider/notification_services/file_system/channel.rb +2 -0
  40. data/lib/dispatch-rider/notification_services/file_system/notifier.rb +2 -0
  41. data/lib/dispatch-rider/notification_services/file_system.rb +3 -1
  42. data/lib/dispatch-rider/notification_services.rb +2 -0
  43. data/lib/dispatch-rider/publisher/base.rb +2 -0
  44. data/lib/dispatch-rider/publisher/configuration/destination.rb +6 -4
  45. data/lib/dispatch-rider/publisher/configuration/notification_service.rb +4 -2
  46. data/lib/dispatch-rider/publisher/configuration.rb +2 -0
  47. data/lib/dispatch-rider/publisher/configuration_reader.rb +3 -1
  48. data/lib/dispatch-rider/publisher/configuration_support.rb +3 -1
  49. data/lib/dispatch-rider/publisher.rb +7 -12
  50. data/lib/dispatch-rider/queue_services/aws_sqs/message_body_extractor.rb +2 -0
  51. data/lib/dispatch-rider/queue_services/aws_sqs/sqs_received_message.rb +6 -4
  52. data/lib/dispatch-rider/queue_services/aws_sqs.rb +5 -2
  53. data/lib/dispatch-rider/queue_services/base.rb +5 -4
  54. data/lib/dispatch-rider/queue_services/file_system/fs_received_message.rb +5 -3
  55. data/lib/dispatch-rider/queue_services/file_system/queue.rb +5 -4
  56. data/lib/dispatch-rider/queue_services/file_system.rb +7 -11
  57. data/lib/dispatch-rider/queue_services/received_message.rb +3 -1
  58. data/lib/dispatch-rider/queue_services/simple.rb +5 -7
  59. data/lib/dispatch-rider/queue_services.rb +2 -0
  60. data/lib/dispatch-rider/registrars/base.rb +5 -5
  61. data/lib/dispatch-rider/registrars/file_system_channel.rb +3 -1
  62. data/lib/dispatch-rider/registrars/handler.rb +3 -1
  63. data/lib/dispatch-rider/registrars/notification_service.rb +2 -0
  64. data/lib/dispatch-rider/registrars/publishing_destination.rb +3 -1
  65. data/lib/dispatch-rider/registrars/queue_service.rb +2 -0
  66. data/lib/dispatch-rider/registrars/sns_channel.rb +3 -1
  67. data/lib/dispatch-rider/registrars.rb +2 -0
  68. data/lib/dispatch-rider/runner.rb +2 -0
  69. data/lib/dispatch-rider/scheduled_job/migration.rb +2 -0
  70. data/lib/dispatch-rider/scheduled_job.rb +3 -3
  71. data/lib/dispatch-rider/subscriber.rb +2 -0
  72. data/lib/dispatch-rider/version.rb +3 -1
  73. data/lib/dispatch-rider.rb +3 -1
  74. data/lib/generators/dispatch_rider/install/install_generator.rb +2 -0
  75. data/lib/generators/dispatch_rider/install/templates/script/dispatch_rider +1 -0
  76. data/lib/generators/dispatch_rider/job/dispatch_job_generator.rb +2 -0
  77. data/spec/factories/messages.rb +4 -1
  78. data/spec/fixtures/handlers/another_test_handler.rb +2 -0
  79. data/spec/fixtures/handlers/test_handler.rb +2 -0
  80. data/spec/integration/logging_spec.rb +2 -0
  81. data/spec/lib/dispatch-rider/airbrake_error_handler_spec.rb +3 -1
  82. data/spec/lib/dispatch-rider/callbacks/access_spec.rb +2 -0
  83. data/spec/lib/dispatch-rider/callbacks/storage_spec.rb +2 -0
  84. data/spec/lib/dispatch-rider/configuration_spec.rb +3 -1
  85. data/spec/lib/dispatch-rider/default_error_handler_spec.rb +2 -0
  86. data/spec/lib/dispatch-rider/demultiplexer_spec.rb +4 -2
  87. data/spec/lib/dispatch-rider/dispatcher_spec.rb +12 -9
  88. data/spec/lib/dispatch-rider/handlers/base_spec.rb +2 -0
  89. data/spec/lib/dispatch-rider/handlers/inheritance_tracking_spec.rb +2 -0
  90. data/spec/lib/dispatch-rider/logging/json_formatter_spec.rb +2 -0
  91. data/spec/lib/dispatch-rider/logging/lifecycle_logger_spec.rb +3 -1
  92. data/spec/lib/dispatch-rider/logging/text_formatter_spec.rb +2 -0
  93. data/spec/lib/dispatch-rider/logging/translator_spec.rb +2 -0
  94. data/spec/lib/dispatch-rider/message_spec.rb +7 -5
  95. data/spec/lib/dispatch-rider/notification_services/aws_sns_spec.rb +2 -0
  96. data/spec/lib/dispatch-rider/notification_services/base_spec.rb +6 -4
  97. data/spec/lib/dispatch-rider/notification_services/file_system/channel_spec.rb +2 -0
  98. data/spec/lib/dispatch-rider/notification_services/file_system/notifier_spec.rb +2 -0
  99. data/spec/lib/dispatch-rider/notification_services/file_system_spec.rb +2 -0
  100. data/spec/lib/dispatch-rider/notification_services_spec.rb +2 -0
  101. data/spec/lib/dispatch-rider/publisher/base_spec.rb +2 -0
  102. data/spec/lib/dispatch-rider/publisher/configuration/destination_spec.rb +2 -0
  103. data/spec/lib/dispatch-rider/publisher/configuration/notification_service_spec.rb +2 -0
  104. data/spec/lib/dispatch-rider/publisher/configuration_reader_spec.rb +15 -4
  105. data/spec/lib/dispatch-rider/publisher/configuration_spec.rb +3 -1
  106. data/spec/lib/dispatch-rider/publisher/configuration_support_spec.rb +4 -2
  107. data/spec/lib/dispatch-rider/publisher_spec.rb +15 -22
  108. data/spec/lib/dispatch-rider/queue_services/aws_sqs_spec.rb +11 -4
  109. data/spec/lib/dispatch-rider/queue_services/base_spec.rb +10 -8
  110. data/spec/lib/dispatch-rider/queue_services/file_system_spec.rb +7 -5
  111. data/spec/lib/dispatch-rider/queue_services/received_message_spec.rb +2 -0
  112. data/spec/lib/dispatch-rider/queue_services/simple_spec.rb +6 -4
  113. data/spec/lib/dispatch-rider/registrars/base_spec.rb +4 -2
  114. data/spec/lib/dispatch-rider/registrars/file_system_channel_spec.rb +2 -0
  115. data/spec/lib/dispatch-rider/registrars/handler_spec.rb +2 -0
  116. data/spec/lib/dispatch-rider/registrars/notification_service_spec.rb +2 -0
  117. data/spec/lib/dispatch-rider/registrars/publishing_destination_spec.rb +2 -0
  118. data/spec/lib/dispatch-rider/registrars/queue_service_spec.rb +2 -0
  119. data/spec/lib/dispatch-rider/registrars/sns_channel_spec.rb +2 -0
  120. data/spec/lib/dispatch-rider/registrars_spec.rb +2 -0
  121. data/spec/lib/dispatch-rider/runner_spec.rb +3 -1
  122. data/spec/lib/dispatch-rider/scheduled_job_spec.rb +2 -0
  123. data/spec/lib/dispatch-rider/subscriber_spec.rb +6 -3
  124. data/spec/lib/dispatch-rider_spec.rb +2 -0
  125. data/spec/spec_helper.rb +2 -1
  126. data/spec/support/crashing_handler.rb +2 -0
  127. data/spec/support/integration_support.rb +2 -0
  128. data/spec/support/null_logger.rb +2 -0
  129. data/spec/support/sample_handler.rb +2 -0
  130. metadata +30 -30
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This is the base class that provides the template for all queue services.
2
4
  # The child classes must implement the following methods to become a concrete class :
3
5
  # assign_storage, insert, raw_head, construct_message_from, delete and size.
@@ -27,12 +29,11 @@ module DispatchRider
27
29
  raise NotImplementedError
28
30
  end
29
31
 
30
-
31
32
  #If you pass a block into pop it will wrap the deletion of the message with it's handling
32
- def pop(&block)
33
+ def pop
33
34
  received = head
34
35
  if received
35
- block.call(received) && delete(received.item)
36
+ yield(received) && delete(received.item)
36
37
  received
37
38
  end
38
39
  end
@@ -41,7 +42,7 @@ module DispatchRider
41
42
  raw_item = raw_head
42
43
  raw_item && received_message_for(raw_item)
43
44
  end
44
-
45
+
45
46
  def received_message_for(raw_item)
46
47
  QueueServices::ReceivedMessage.new(construct_message_from(raw_item), raw_item)
47
48
  end
@@ -1,18 +1,20 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DispatchRider
2
4
  module QueueServices
3
5
  class FileSystem < Base
4
6
  class FsReceivedMessage < ReceivedMessage
5
7
  attr_reader :queue
6
-
8
+
7
9
  def initialize(message, item, queue)
8
10
  @queue = queue
9
11
  super(message, item)
10
12
  end
11
-
13
+
12
14
  def extend_timeout(timeout)
13
15
  #file system doesn't support timeouts on items, so we ignore this.
14
16
  end
15
-
17
+
16
18
  def return_to_queue
17
19
  queue.put_back(item)
18
20
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This is a queue implementation for the queue service based on file systems
2
4
  module DispatchRider
3
5
  module QueueServices
@@ -10,13 +12,14 @@ module DispatchRider
10
12
 
11
13
  def add(item)
12
14
  name_base = "#{@path}/#{Time.now.to_f}"
13
- File.open("#{name_base}.inprogress", "w"){ |f| f.write(item) }
15
+ File.write("#{name_base}.inprogress", item)
14
16
  FileUtils.mv("#{name_base}.inprogress", "#{name_base}.ready")
15
17
  end
16
18
 
17
19
  def pop
18
20
  file_path = next_item(10)
19
21
  return nil unless file_path
22
+
20
23
  file_path_inflight = file_path.gsub(/\.ready$/, '.inflight')
21
24
  FileUtils.mv(file_path, file_path_inflight)
22
25
  File.new(file_path_inflight)
@@ -32,9 +35,7 @@ module DispatchRider
32
35
  File.unlink(item.path)
33
36
  end
34
37
 
35
- def size
36
- file_paths.size
37
- end
38
+ delegate :size, to: :file_paths
38
39
 
39
40
  private
40
41
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This is a rudementary queue service that uses file system instead of
2
4
  # Aws::SQS or SimpleQueue. It addresses SimpleQueue's inability to be used
3
5
  # by only one application instance while avoiding the cost of setting up Aws::SQS.
@@ -8,12 +10,10 @@ module DispatchRider
8
10
  require "dispatch-rider/queue_services/file_system/fs_received_message"
9
11
  class FileSystem < Base
10
12
  def assign_storage(attrs)
11
- begin
12
13
  path = attrs.fetch(:path)
13
14
  Queue.new(path)
14
- rescue IndexError
15
+ rescue IndexError
15
16
  raise RecordInvalid.new(self, ["Path can not be blank"])
16
- end
17
17
  end
18
18
 
19
19
  def insert(item)
@@ -23,7 +23,7 @@ module DispatchRider
23
23
  def raw_head
24
24
  queue.pop
25
25
  end
26
-
26
+
27
27
  def received_message_for(raw_item)
28
28
  FsReceivedMessage.new(construct_message_from(raw_item), raw_item, queue)
29
29
  end
@@ -31,18 +31,14 @@ module DispatchRider
31
31
  def construct_message_from(item)
32
32
  deserialize(item.read)
33
33
  end
34
-
35
- def put_back(item)
36
- queue.put_back(item)
37
- end
34
+
35
+ delegate :put_back, to: :queue
38
36
 
39
37
  def delete(item)
40
38
  queue.remove item
41
39
  end
42
40
 
43
- def size
44
- queue.size
45
- end
41
+ delegate :size, to: :queue
46
42
  end
47
43
  end
48
44
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'delegate'
2
4
 
3
5
  module DispatchRider
@@ -13,7 +15,7 @@ module DispatchRider
13
15
  end
14
16
 
15
17
  def guid
16
- self.body['guid']
18
+ body['guid']
17
19
  end
18
20
 
19
21
  def extend_timeout(time)
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This is a simple implementation of an in memory queue using an array.
2
4
  module DispatchRider
3
5
  module QueueServices
4
6
  class Simple < Base
5
- def assign_storage(attrs)
7
+ def assign_storage(_attrs)
6
8
  []
7
9
  end
8
10
 
@@ -18,13 +20,9 @@ module DispatchRider
18
20
  deserialize(item)
19
21
  end
20
22
 
21
- def delete(item)
22
- queue.delete(item)
23
- end
23
+ delegate :delete, to: :queue
24
24
 
25
- def size
26
- queue.size
27
- end
25
+ delegate :size, to: :queue
28
26
  end
29
27
  end
30
28
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # The namespace that holds the queue services
2
4
  module DispatchRider
3
5
  module QueueServices
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This is the base class for the registrars.
2
4
  # It defines the interface that other registrars inherit.
3
5
  # This is an abstract class.
@@ -28,11 +30,9 @@ module DispatchRider
28
30
  end
29
31
 
30
32
  def fetch(name)
31
- begin
32
- store.fetch(name.to_sym)
33
- rescue IndexError
34
- raise NotRegistered, name
35
- end
33
+ store.fetch(name.to_sym)
34
+ rescue IndexError
35
+ raise NotRegistered, name
36
36
  end
37
37
  end
38
38
  end
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This is the registrar for FileSystem channels, basically storing paths
2
4
 
3
5
  module DispatchRider
4
6
  module Registrars
5
7
  class FileSystemChannel < Base
6
- def value(name, options = {})
8
+ def value(_name, options = {})
7
9
  File.expand_path(options[:path])
8
10
  end
9
11
  end
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This is the registrar for the handlers.
2
4
  module DispatchRider
3
5
  module Registrars
4
6
  class Handler < Base
5
- def value(name, options = {})
7
+ def value(name, _options = {})
6
8
  name.to_s.camelize.constantize
7
9
  end
8
10
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This registrar handles the registration of various notification services.
2
4
  module DispatchRider
3
5
  module Registrars
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'ostruct'
2
4
 
3
5
  module DispatchRider
4
6
  module Registrars
5
7
  class PublishingDestination < Base
6
- def value(name, options = {})
8
+ def value(_name, options = {})
7
9
  ::OpenStruct.new(:service => options[:service], :channel => options[:channel])
8
10
  end
9
11
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This si the registrar for queue services.
2
4
  module DispatchRider
3
5
  module Registrars
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This is the registrar for the Aws SNS channels.
2
4
  module DispatchRider
3
5
  module Registrars
4
6
  class SnsChannel < Base
5
- def value(name, options = {})
7
+ def value(_name, options = {})
6
8
  "arn:aws:sns:#{options[:region]}:#{options[:account]}:#{options[:topic]}"
7
9
  end
8
10
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # The namespace that holds the registrars
2
4
  module DispatchRider
3
5
  module Registrars
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DispatchRider
2
4
  class Runner
3
5
  include Callbacks::Support
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DispatchRider
2
4
  module ScheduledJob::Migration
3
5
  def create_scheduled_jobs_table
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_record"
2
4
 
3
5
  # @note: Later this could be pulled out to its own gem and included depending on what ORM the user
@@ -50,9 +52,7 @@ module DispatchRider
50
52
  destroy # once published
51
53
  end
52
54
 
53
- private
54
-
55
- delegate :publisher, to: :"self.class"
55
+ delegate :publisher, to: :'self.class'
56
56
  end
57
57
  end
58
58
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This class takes care of the subscribing side of the messaging system.
2
4
  module DispatchRider
3
5
  class Subscriber
@@ -1,4 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This file specifies the current version of the gem.
2
4
  module DispatchRider
3
- VERSION = '2.0.0'
5
+ VERSION = '2.2.0'
4
6
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Top level namespace of the gem
2
4
  require "dispatch-rider/version"
3
5
 
@@ -22,7 +24,7 @@ module DispatchRider
22
24
  def configuration
23
25
  @configuration ||= Configuration.new
24
26
  end
25
- alias_method :config, :configuration
27
+ alias config configuration
26
28
 
27
29
  def clear_configuration!
28
30
  @configuration = nil
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DispatchRider
2
4
  class InstallGenerator < ::Rails::Generators::Base
3
5
  source_root File.expand_path("../templates", __FILE__)
@@ -1,4 +1,5 @@
1
1
  #!env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  raise "this script is meant to be ran from inside of a Rails.root" unless File.exist?("config/environment.rb")
4
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class DispatchJob < Rails::Generators::Base
2
4
  class Publisher < Rails::Generators::Base
3
5
  source_root File.expand_path('../templates/publisher', __FILE__)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  FactoryBot.define do
2
4
  factory :message, class: 'DispatchRider::Message' do
3
5
  subject { 'sample_handler' }
@@ -5,7 +7,8 @@ FactoryBot.define do
5
7
  {
6
8
  'key' => 'value',
7
9
  'guid' => DispatchRider::Debug::PUBLISHER_MESSAGE_GUID,
8
- }}
10
+ }
11
+ }
9
12
  initialize_with { DispatchRider::Message.new(attributes) }
10
13
  end
11
14
  end
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class AnotherTestHandler < DispatchRider::Handlers::Base
2
4
  end
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class TestHandler < DispatchRider::Handlers::Base
2
4
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe "Logging" do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  describe DispatchRider::AirbrakeErrorHandler do
@@ -12,7 +14,7 @@ describe DispatchRider::AirbrakeErrorHandler do
12
14
  controller: "DispatchRider",
13
15
  action: "TestMessage",
14
16
  parameters: { subject: "TestMessage", body: "foo" },
15
- cgi_data: anything,
17
+ cgi_data: anything
16
18
  ]
17
19
  expect(Airbrake).to receive(:notify).with(*args)
18
20
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe DispatchRider::Callbacks::Access do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe DispatchRider::Callbacks::Storage do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe DispatchRider::Configuration do
@@ -33,7 +35,7 @@ describe DispatchRider::Configuration do
33
35
  end
34
36
 
35
37
  describe "#handlers" do
36
- before :each do
38
+ before do
37
39
  subject.handler_path = "./spec/fixtures/handlers"
38
40
  end
39
41
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  describe DispatchRider::DefaultErrorHandler do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe DispatchRider::Demultiplexer, nodb: true do
@@ -7,7 +9,7 @@ describe DispatchRider::Demultiplexer, nodb: true do
7
9
  end
8
10
  end
9
11
 
10
- subject(:demultiplexer) { DispatchRider::Demultiplexer.new(queue, dispatcher, error_handler) }
12
+ subject(:demultiplexer) { described_class.new(queue, dispatcher, error_handler) }
11
13
 
12
14
  let(:dispatcher) do
13
15
  dispatcher = DispatchRider::Dispatcher.new
@@ -62,7 +64,7 @@ describe DispatchRider::Demultiplexer, nodb: true do
62
64
  # THIS ALSO TESTS THAT THE JOB IS NOT RUN MULTIPLE TIMES
63
65
  # IF THIS FAILS, BE CAREFUL NOT TO INTRODUCE BUGS
64
66
  it "should call the correct handler" do
65
- expect_any_instance_of(TestHandler).to receive(:process).with(message.body).at_least(1).times
67
+ expect_any_instance_of(TestHandler).to receive(:process).with(message.body).at_least(:once)
66
68
  demultiplexer_thread.run
67
69
  sleep 0.01 # give it a chance to process the job async before killing the demux
68
70
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe DispatchRider::Dispatcher, :nodb => true do
@@ -30,16 +32,17 @@ describe DispatchRider::Dispatcher, :nodb => true do
30
32
  before do
31
33
  allow(DispatchRider.config).to receive(:callbacks) { storage }
32
34
  storage.around(:dispatch_message) do |block, message|
33
- begin
34
- dummy.before
35
- dummy.log(message)
36
- block.call
37
- ensure
38
- dummy.after
39
- end
35
+
36
+ dummy.before
37
+ dummy.log(message)
38
+ block.call
39
+ ensure
40
+ dummy.after
41
+
40
42
  end
41
43
  subject.register('handle_something')
42
44
  end
45
+
43
46
  example do
44
47
  expect(dummy).to receive(:before).once
45
48
  expect(dummy).to receive(:after).once
@@ -51,7 +54,7 @@ describe DispatchRider::Dispatcher, :nodb => true do
51
54
  end
52
55
 
53
56
  context "when the handler provided in the message is present" do
54
- before :each do
57
+ before do
55
58
  subject.register('handle_something')
56
59
  end
57
60
 
@@ -63,7 +66,7 @@ describe DispatchRider::Dispatcher, :nodb => true do
63
66
  context "when the handler returns false" do
64
67
  let(:message_subject) { "handler_that_returns_false" }
65
68
 
66
- before :each do
69
+ before do
67
70
  subject.register('handler_that_returns_false')
68
71
  end
69
72
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe DispatchRider::Handlers::Base do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe DispatchRider::Handlers::InheritanceTracking do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe DispatchRider::Logging::JsonFormatter do
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe DispatchRider::Logging::LifecycleLogger, aggregrate_failures: true do
4
- subject { DispatchRider::Logging::LifecycleLogger }
6
+ subject { described_class }
5
7
 
6
8
  let(:queue) { double :queue }
7
9
  let(:item) { double :item }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe DispatchRider::Logging::TextFormatter do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe DispatchRider::Logging::Translator do
@@ -1,12 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe DispatchRider::Message do
4
- subject(:message) { DispatchRider::Message.new(subject: 'test', body: 'test_handler') }
6
+ subject(:message) { described_class.new(subject: 'test', body: 'test_handler') }
5
7
 
6
8
  describe "#initialize" do
7
9
  context "when all the required attributes are passed" do
8
10
  context "when the attributes hash has keys as strings" do
9
- subject(:message) { DispatchRider::Message.new('subject' => 'test', 'body' => 'test_handler') }
11
+ subject(:message) { described_class.new('subject' => 'test', 'body' => 'test_handler') }
10
12
 
11
13
  it "should initiate a new message" do
12
14
  expect(message.subject).to eq('test')
@@ -24,7 +26,7 @@ describe DispatchRider::Message do
24
26
 
25
27
  context "when all the required attributes are not passed" do
26
28
  it "should raise an exception" do
27
- expect { DispatchRider::Message.new({}) }.to raise_exception(DispatchRider::RecordInvalid)
29
+ expect { described_class.new({}) }.to raise_exception(DispatchRider::RecordInvalid)
28
30
  end
29
31
  end
30
32
  end
@@ -46,13 +48,13 @@ describe DispatchRider::Message do
46
48
  describe "#==" do
47
49
  context "when 2 messages have the same attribute values" do
48
50
  it "should return true" do
49
- expect(message).to eq(DispatchRider::Message.new(subject: 'test', body: 'test_handler'))
51
+ expect(message).to eq(described_class.new(subject: 'test', body: 'test_handler'))
50
52
  end
51
53
  end
52
54
 
53
55
  context "when 2 messages do not have same attribute values" do
54
56
  it "should return false" do
55
- expect(message).not_to eq(DispatchRider::Message.new(subject: 'random_test', body: 'test_handler'))
57
+ expect(message).not_to eq(described_class.new(subject: 'random_test', body: 'test_handler'))
56
58
  end
57
59
  end
58
60
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe DispatchRider::NotificationServices::AwsSns do