msgr 1.2.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/.editorconfig +8 -0
  3. data/.github/workflows/test.yml +79 -0
  4. data/.rubocop.yml +12 -47
  5. data/Appraisals +23 -0
  6. data/CHANGELOG.md +87 -5
  7. data/Gemfile +9 -15
  8. data/README.md +11 -28
  9. data/Rakefile +10 -6
  10. data/bin/msgr +1 -0
  11. data/gemfiles/rails_5.2.gemfile +15 -0
  12. data/gemfiles/rails_6.0.gemfile +15 -0
  13. data/gemfiles/rails_6.1.gemfile +15 -0
  14. data/gemfiles/rails_7.0.gemfile +15 -0
  15. data/gemfiles/rails_head.gemfile +15 -0
  16. data/lib/msgr/binding.rb +13 -8
  17. data/lib/msgr/channel.rb +7 -10
  18. data/lib/msgr/cli.rb +26 -20
  19. data/lib/msgr/client.rb +27 -25
  20. data/lib/msgr/connection.rb +14 -2
  21. data/lib/msgr/consumer.rb +2 -3
  22. data/lib/msgr/dispatcher.rb +7 -9
  23. data/lib/msgr/logging.rb +2 -0
  24. data/lib/msgr/message.rb +1 -2
  25. data/lib/msgr/railtie.rb +14 -75
  26. data/lib/msgr/route.rb +2 -5
  27. data/lib/msgr/routes.rb +2 -0
  28. data/lib/msgr/tasks/msgr/drain.rake +11 -0
  29. data/lib/msgr/test_pool.rb +1 -3
  30. data/lib/msgr/version.rb +1 -1
  31. data/lib/msgr.rb +2 -3
  32. data/msgr.gemspec +8 -6
  33. data/renovate.json +5 -0
  34. data/scripts/simple_test.rb +3 -4
  35. data/spec/fixtures/{msgr-routes-test-1.rb → msgr_routes_test_1.rb} +0 -0
  36. data/spec/fixtures/msgr_routes_test_drain.rb +5 -0
  37. data/spec/integration/dummy/Rakefile +1 -1
  38. data/spec/{msgr/support/.keep → integration/dummy/app/assets/config/manifest.js} +0 -0
  39. data/spec/integration/dummy/bin/bundle +1 -1
  40. data/spec/integration/dummy/bin/rails +1 -1
  41. data/spec/integration/dummy/config/application.rb +1 -1
  42. data/spec/integration/dummy/config/boot.rb +2 -2
  43. data/spec/integration/dummy/config/environment.rb +1 -1
  44. data/spec/integration/dummy/config/rabbitmq.yml +1 -1
  45. data/spec/integration/msgr/dispatcher_spec.rb +28 -12
  46. data/spec/integration/msgr/railtie_spec.rb +10 -120
  47. data/spec/integration/spec_helper.rb +2 -3
  48. data/spec/integration/{msgr_spec.rb → test_controller_spec.rb} +1 -1
  49. data/spec/unit/msgr/client_spec.rb +83 -0
  50. data/spec/{msgr → unit}/msgr/connection_spec.rb +1 -1
  51. data/spec/{msgr → unit}/msgr/consumer_spec.rb +0 -0
  52. data/spec/unit/msgr/dispatcher_spec.rb +45 -0
  53. data/spec/{msgr → unit}/msgr/route_spec.rb +29 -14
  54. data/spec/{msgr → unit}/msgr/routes_spec.rb +32 -35
  55. data/spec/{msgr → unit}/msgr_spec.rb +26 -18
  56. data/spec/{msgr → unit}/spec_helper.rb +1 -1
  57. data/spec/unit/support/.keep +0 -0
  58. metadata +43 -36
  59. data/.travis.yml +0 -43
  60. data/gemfiles/Gemfile.rails-4-2 +0 -7
  61. data/gemfiles/Gemfile.rails-5-0 +0 -7
  62. data/gemfiles/Gemfile.rails-5-1 +0 -7
  63. data/gemfiles/Gemfile.rails-5-2 +0 -7
  64. data/gemfiles/Gemfile.rails-master +0 -14
  65. data/spec/msgr/msgr/client_spec.rb +0 -60
  66. data/spec/msgr/msgr/dispatcher_spec.rb +0 -44
  67. data/spec/support/setup.rb +0 -29
@@ -3,25 +3,15 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe Msgr::Routes do
6
- let(:routes) { Msgr::Routes.new }
6
+ let(:routes) { described_class.new }
7
7
 
8
8
  describe '#configure' do
9
- let(:block) { proc {} }
10
-
11
- it 'should evaluate given block within instance context' do
12
- expect(routes).to receive(:instance_eval) do |&p|
13
- expect(p).to be block
14
- end
15
-
16
- routes.configure(&block)
17
- end
18
-
19
- it 'should allow to call instance method in gven block' do
20
- expect(routes).to receive(:test_instance_method).with(:abc)
21
-
9
+ it 'allows to configure the instance in given block' do
22
10
  routes.configure do
23
- test_instance_method :abc
11
+ route 'abc', to: 'consumer#action'
24
12
  end
13
+
14
+ expect(routes.routes.first.keys).to eq ['abc']
25
15
  end
26
16
  end
27
17
 
@@ -35,7 +25,7 @@ describe Msgr::Routes do
35
25
 
36
26
  let(:each) { routes.each }
37
27
 
38
- it 'should iterate over configured routes' do
28
+ it 'iterates over configured routes' do
39
29
  expect(each.size).to eq 2
40
30
 
41
31
  expect(each.map(&:keys)).to eq [%w[abc.#], %w[edf.#]]
@@ -45,15 +35,16 @@ describe Msgr::Routes do
45
35
  end
46
36
 
47
37
  describe '#route' do
48
- let(:subject) { -> { routes.route 'routing.key', to: 'test2#index2' } }
38
+ subject(:route) { -> { routes.route 'routing.key', to: 'test2#index2' } }
39
+
49
40
  let(:last_route) { routes.routes.last }
50
41
 
51
- it 'should add a new route' do
52
- expect { subject.call }.to change { routes.routes.size }.from(0).to(1)
42
+ it 'adds a new route' do
43
+ expect { route.call }.to change { routes.routes.size }.from(0).to(1)
53
44
  end
54
45
 
55
- it 'should add given route' do
56
- subject.call
46
+ it 'adds given route' do
47
+ route.call
57
48
 
58
49
  expect(last_route.keys).to eq %w[routing.key]
59
50
  expect(last_route.consumer).to eq 'Test2Consumer'
@@ -61,26 +52,26 @@ describe Msgr::Routes do
61
52
  end
62
53
 
63
54
  context 'with same target' do
64
- let(:subject) do
55
+ subject(:route) do
65
56
  lambda do
66
57
  routes.route 'routing.key', to: 'test#index'
67
58
  routes.route 'another.routing.key', to: 'test#index'
68
59
  end
69
60
  end
70
61
 
71
- it 'should only add one new route' do
72
- expect { subject.call }.to change { routes.routes.size }.from(0).to(1)
62
+ it 'onlies add one new route' do
63
+ expect { route.call }.to change { routes.routes.size }.from(0).to(1)
73
64
  end
74
65
 
75
- it 'should add second binding to first route' do
76
- subject.call
66
+ it 'adds second binding to first route' do
67
+ route.call
77
68
  expect(routes.routes.first.keys).to eq %w[routing.key another.routing.key]
78
69
  end
79
70
  end
80
71
  end
81
72
 
82
73
  describe '#files' do
83
- it 'should allow to add route paths' do
74
+ it 'allows to add route paths' do
84
75
  routes.files << 'abc.rb'
85
76
  routes.files += %w[cde.rb edf.rb]
86
77
 
@@ -89,16 +80,20 @@ describe Msgr::Routes do
89
80
  end
90
81
 
91
82
  describe 'reload' do
92
- before { File.stub(:exist?).and_return(true) }
83
+ before do
84
+ allow(File).to receive(:exist?).and_return(true)
85
+ allow(routes).to receive(:load)
86
+ end
93
87
 
94
- it 'should trigger load for all files' do
95
- expect(routes).to receive(:load).with('cde.rb').ordered
96
- expect(routes).to receive(:load).with('edf.rb').ordered
88
+ it 'triggers load for all files' do
97
89
  routes.files += %w[cde.rb edf.rb]
98
90
  routes.reload
91
+
92
+ expect(routes).to have_received(:load).with('cde.rb').ordered
93
+ expect(routes).to have_received(:load).with('edf.rb').ordered
99
94
  end
100
95
 
101
- it 'should clear old routes before reloading' do
96
+ it 'clears old routes before reloading' do
102
97
  routes.route 'abc', to: 'abc#test'
103
98
  routes.reload
104
99
  expect(routes.each.size).to eq 0
@@ -106,11 +101,13 @@ describe Msgr::Routes do
106
101
  end
107
102
 
108
103
  describe 'load' do
109
- let(:file) { 'spec/fixtures/msgr-routes-test-1.rb' }
104
+ let(:file) { 'spec/fixtures/msgr_routes_test_1.rb' }
110
105
 
111
- it 'should eval given file within routes context' do
112
- expect(routes).to receive(:route).with('abc.#', to: 'test#index')
106
+ it 'evals given file within routes context' do
113
107
  routes.load file
108
+ expect(routes.routes.count).to eq 1
109
+ expect(routes.routes.first.keys).to eq ['abc.#']
110
+ expect(routes.routes.first.name).to eq 'msgr.consumer.TestConsumer.index'
114
111
  end
115
112
  end
116
113
  end
@@ -2,10 +2,8 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- class Receiver
6
- end
5
+ Receiver = Class.new
7
6
 
8
- #
9
7
  class MsgrTestConsumer < Msgr::Consumer
10
8
  def index
11
9
  Receiver.index
@@ -26,7 +24,7 @@ end
26
24
 
27
25
  describe Msgr do
28
26
  let(:queue) { Queue.new }
29
- let(:client) { Msgr::Client.new size: 1, prefix: SecureRandom.hex(2) }
27
+ let(:client) { Msgr::Client.new size: 1, prefix: SecureRandom.hex(2), uri: ENV['AMQP_SERVER'] }
30
28
 
31
29
  before do
32
30
  client.routes.configure do
@@ -36,43 +34,51 @@ describe Msgr do
36
34
  end
37
35
 
38
36
  client.start
37
+
38
+ allow(Receiver).to receive(:index) { queue << :end }
39
+ allow(Receiver).to receive(:batch) {|msg| queue << msg }
40
+
41
+ error_count = 0
42
+ allow(Receiver).to receive(:error) do
43
+ error_count += 1
44
+ raise 'error' if error_count == 1
45
+
46
+ queue << :end
47
+ end
39
48
  end
40
49
 
41
50
  after do
42
51
  client.stop delete: true
43
52
  end
44
53
 
45
- it 'should dispatch published methods to consumer' do
46
- expect(Receiver).to receive(:index) { queue << :end }
47
-
54
+ it 'dispatches published methods to consumer' do
48
55
  client.publish 'Payload', to: 'test.index'
49
56
 
50
57
  Timeout.timeout(4) { queue.pop }
51
- end
52
58
 
53
- it 'should redelivery failed messages' do
54
- expect(Receiver).to receive(:error).ordered.and_raise RuntimeError
55
- expect(Receiver).to receive(:error).ordered { queue << :end }
59
+ expect(Receiver).to have_received(:index).exactly(1).time
60
+ end
56
61
 
62
+ it 'redelivers failed messages' do
57
63
  client.publish 'Payload', to: 'test.error'
58
64
 
59
65
  Timeout.timeout(4) { queue.pop }
60
- end
61
66
 
62
- it 'should receive 2 messages when prefetch is set to 2' do
63
- expect(Receiver).to receive(:batch).twice { |msg| queue << msg }
67
+ expect(Receiver).to have_received(:error).exactly(2).times
68
+ end
64
69
 
70
+ it 'receives 2 messages when prefetch is set to 2' do
65
71
  2.times { client.publish 'Payload', to: 'test.batch' }
66
72
 
67
73
  2.times { Timeout.timeout(4) { queue.pop } }
68
- end
69
74
 
70
- it 'should not bulk ack all unacknowledged messages when acknowledging the last one' do
71
- expect(Receiver).to receive(:batch).exactly(3).times { |msg| queue << msg }
75
+ expect(Receiver).to have_received(:batch).exactly(2).times
76
+ end
72
77
 
78
+ it 'does not bulk ack all unacknowledged messages when acknowledging the last one' do
73
79
  2.times { client.publish 'Payload', to: 'test.batch' }
74
80
 
75
- messages = 2.times.map { Timeout.timeout(4) { queue.pop } }
81
+ messages = Array.new(2) { Timeout.timeout(4) { queue.pop } }
76
82
  messages[1].ack
77
83
  messages[0].nack
78
84
 
@@ -80,5 +86,7 @@ describe Msgr do
80
86
  message = Timeout.timeout(4) { queue.pop }
81
87
  expect(message.payload).to eq(messages[0].payload)
82
88
  expect(message.delivery_info.redelivered).to eq(true)
89
+
90
+ expect(Receiver).to have_received(:batch).exactly(3).times
83
91
  end
84
92
  end
@@ -12,7 +12,7 @@ end
12
12
 
13
13
  require 'msgr'
14
14
 
15
- Dir[File.expand_path('../support/**/*.rb', __FILE__)].each {|f| require f }
15
+ Dir[File.expand_path('support/**/*.rb', __dir__)].sort.each {|f| require f }
16
16
 
17
17
  RSpec.configure do |config|
18
18
  config.order = 'random'
File without changes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: msgr
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Graichen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-27 00:00:00.000000000 Z
11
+ date: 2022-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -60,26 +60,28 @@ dependencies:
60
60
  version: '0'
61
61
  description: 'Msgr: Rails-like Messaging Framework'
62
62
  email:
63
- - jg@altimos.de
63
+ - jgraichen@altimos.de
64
64
  executables:
65
65
  - msgr
66
66
  extensions: []
67
67
  extra_rdoc_files: []
68
68
  files:
69
+ - ".editorconfig"
70
+ - ".github/workflows/test.yml"
69
71
  - ".gitignore"
70
72
  - ".rubocop.yml"
71
- - ".travis.yml"
73
+ - Appraisals
72
74
  - CHANGELOG.md
73
75
  - Gemfile
74
76
  - LICENSE.txt
75
77
  - README.md
76
78
  - Rakefile
77
79
  - bin/msgr
78
- - gemfiles/Gemfile.rails-4-2
79
- - gemfiles/Gemfile.rails-5-0
80
- - gemfiles/Gemfile.rails-5-1
81
- - gemfiles/Gemfile.rails-5-2
82
- - gemfiles/Gemfile.rails-master
80
+ - gemfiles/rails_5.2.gemfile
81
+ - gemfiles/rails_6.0.gemfile
82
+ - gemfiles/rails_6.1.gemfile
83
+ - gemfiles/rails_7.0.gemfile
84
+ - gemfiles/rails_head.gemfile
83
85
  - lib/msgr.rb
84
86
  - lib/msgr/binding.rb
85
87
  - lib/msgr/channel.rb
@@ -94,12 +96,16 @@ files:
94
96
  - lib/msgr/railtie.rb
95
97
  - lib/msgr/route.rb
96
98
  - lib/msgr/routes.rb
99
+ - lib/msgr/tasks/msgr/drain.rake
97
100
  - lib/msgr/test_pool.rb
98
101
  - lib/msgr/version.rb
99
102
  - msgr.gemspec
103
+ - renovate.json
100
104
  - scripts/simple_test.rb
101
- - spec/fixtures/msgr-routes-test-1.rb
105
+ - spec/fixtures/msgr_routes_test_1.rb
106
+ - spec/fixtures/msgr_routes_test_drain.rb
102
107
  - spec/integration/dummy/Rakefile
108
+ - spec/integration/dummy/app/assets/config/manifest.js
103
109
  - spec/integration/dummy/app/consumers/application_consumer.rb
104
110
  - spec/integration/dummy/app/consumers/test_consumer.rb
105
111
  - spec/integration/dummy/app/controllers/application_controller.rb
@@ -125,22 +131,22 @@ files:
125
131
  - spec/integration/dummy/public/favicon.ico
126
132
  - spec/integration/msgr/dispatcher_spec.rb
127
133
  - spec/integration/msgr/railtie_spec.rb
128
- - spec/integration/msgr_spec.rb
129
134
  - spec/integration/spec_helper.rb
130
- - spec/msgr/msgr/client_spec.rb
131
- - spec/msgr/msgr/connection_spec.rb
132
- - spec/msgr/msgr/consumer_spec.rb
133
- - spec/msgr/msgr/dispatcher_spec.rb
134
- - spec/msgr/msgr/route_spec.rb
135
- - spec/msgr/msgr/routes_spec.rb
136
- - spec/msgr/msgr_spec.rb
137
- - spec/msgr/spec_helper.rb
138
- - spec/msgr/support/.keep
139
- - spec/support/setup.rb
135
+ - spec/integration/test_controller_spec.rb
136
+ - spec/unit/msgr/client_spec.rb
137
+ - spec/unit/msgr/connection_spec.rb
138
+ - spec/unit/msgr/consumer_spec.rb
139
+ - spec/unit/msgr/dispatcher_spec.rb
140
+ - spec/unit/msgr/route_spec.rb
141
+ - spec/unit/msgr/routes_spec.rb
142
+ - spec/unit/msgr_spec.rb
143
+ - spec/unit/spec_helper.rb
144
+ - spec/unit/support/.keep
140
145
  homepage: https://github.com/jgraichen/msgr
141
146
  licenses:
142
147
  - MIT
143
- metadata: {}
148
+ metadata:
149
+ rubygems_mfa_required: 'true'
144
150
  post_install_message:
145
151
  rdoc_options: []
146
152
  require_paths:
@@ -149,20 +155,22 @@ required_ruby_version: !ruby/object:Gem::Requirement
149
155
  requirements:
150
156
  - - ">="
151
157
  - !ruby/object:Gem::Version
152
- version: '0'
158
+ version: '2.5'
153
159
  required_rubygems_version: !ruby/object:Gem::Requirement
154
160
  requirements:
155
161
  - - ">="
156
162
  - !ruby/object:Gem::Version
157
163
  version: '0'
158
164
  requirements: []
159
- rubygems_version: 3.0.3
165
+ rubygems_version: 3.1.6
160
166
  signing_key:
161
167
  specification_version: 4
162
168
  summary: 'Msgr: Rails-like Messaging Framework'
163
169
  test_files:
164
- - spec/fixtures/msgr-routes-test-1.rb
170
+ - spec/fixtures/msgr_routes_test_1.rb
171
+ - spec/fixtures/msgr_routes_test_drain.rb
165
172
  - spec/integration/dummy/Rakefile
173
+ - spec/integration/dummy/app/assets/config/manifest.js
166
174
  - spec/integration/dummy/app/consumers/application_consumer.rb
167
175
  - spec/integration/dummy/app/consumers/test_consumer.rb
168
176
  - spec/integration/dummy/app/controllers/application_controller.rb
@@ -188,15 +196,14 @@ test_files:
188
196
  - spec/integration/dummy/public/favicon.ico
189
197
  - spec/integration/msgr/dispatcher_spec.rb
190
198
  - spec/integration/msgr/railtie_spec.rb
191
- - spec/integration/msgr_spec.rb
192
199
  - spec/integration/spec_helper.rb
193
- - spec/msgr/msgr/client_spec.rb
194
- - spec/msgr/msgr/connection_spec.rb
195
- - spec/msgr/msgr/consumer_spec.rb
196
- - spec/msgr/msgr/dispatcher_spec.rb
197
- - spec/msgr/msgr/route_spec.rb
198
- - spec/msgr/msgr/routes_spec.rb
199
- - spec/msgr/msgr_spec.rb
200
- - spec/msgr/spec_helper.rb
201
- - spec/msgr/support/.keep
202
- - spec/support/setup.rb
200
+ - spec/integration/test_controller_spec.rb
201
+ - spec/unit/msgr/client_spec.rb
202
+ - spec/unit/msgr/connection_spec.rb
203
+ - spec/unit/msgr/consumer_spec.rb
204
+ - spec/unit/msgr/dispatcher_spec.rb
205
+ - spec/unit/msgr/route_spec.rb
206
+ - spec/unit/msgr/routes_spec.rb
207
+ - spec/unit/msgr_spec.rb
208
+ - spec/unit/spec_helper.rb
209
+ - spec/unit/support/.keep
data/.travis.yml DELETED
@@ -1,43 +0,0 @@
1
- dist: xenial
2
- language: ruby
3
- rvm:
4
- - 2.6.3
5
- - 2.5.5
6
- - 2.4.6
7
- - 2.3.8
8
- gemfile:
9
- - gemfiles/Gemfile.rails-5-2
10
- - gemfiles/Gemfile.rails-5-1
11
- - gemfiles/Gemfile.rails-5-0
12
- - gemfiles/Gemfile.rails-4-2
13
- - gemfiles/Gemfile.rails-master
14
- before_install:
15
- - sudo apt-get install -qy rabbitmq-server
16
- - echo yes | rvm gemset delete global
17
- - gem install bundler -v'~>1.0'
18
- script:
19
- - bundle exec rake spec:msgr
20
- - bundle exec rake spec:integration
21
- jobs:
22
- allow_failures:
23
- - gemfile: gemfiles/Gemfile.rails-master
24
- exclude:
25
- - rvm: 2.6.3
26
- gemfile: gemfiles/Gemfile.rails-4-2
27
- - rvm: 2.4.6
28
- gemfile: gemfiles/Gemfile.rails-master
29
- - rvm: 2.3.8
30
- gemfile: gemfiles/Gemfile.rails-master
31
- include:
32
- - stage: Beta release
33
- rvm: 2.6.3
34
- script: echo "Deploy to rubygems.org..."
35
- deploy:
36
- provider: rubygems
37
- api_key:
38
- secure: g8icPMdxEmbpBzSRCDmR3uB+1Zhu7tGq3h0cVbGUka2Ni1NiEiQo3LCDzbMp+L7AXH5RhdsG9FTViIAyCy9YENqZ1+jzrQGeADx0KnJZb6F81/SyumeUld0zdkzDbe1aUCJWz2WnEk12aLMPLNPRmDE7wub+od7gJEEv2SsKObo=
39
- gem: msgr
40
- on:
41
- branch: master
42
- repo: jgraichen/msgr
43
-
@@ -1,7 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Load root Gemfile
4
- eval_gemfile '../Gemfile'
5
-
6
- gem 'activesupport', '~> 4.2.0'
7
- gem 'bunny', ENV['BUNNY_VERSION'] if ENV['BUNNY_VERSION']
@@ -1,7 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Load root Gemfile
4
- eval_gemfile '../Gemfile'
5
-
6
- gem 'activesupport', '~> 5.0.0'
7
- gem 'bunny', ENV['BUNNY_VERSION'] if ENV['BUNNY_VERSION']
@@ -1,7 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Load root Gemfile
4
- eval_gemfile '../Gemfile'
5
-
6
- gem 'activesupport', '~> 5.1.0'
7
- gem 'bunny', ENV['BUNNY_VERSION'] if ENV['BUNNY_VERSION']
@@ -1,7 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Load root Gemfile
4
- eval_gemfile '../Gemfile'
5
-
6
- gem 'activesupport', '~> 5.2.0'
7
- gem 'bunny', ENV['BUNNY_VERSION'] if ENV['BUNNY_VERSION']
@@ -1,14 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- NO_RAILS_GEM = true
4
-
5
- # Load root Gemfile
6
- eval_gemfile '../Gemfile'
7
-
8
- gem 'activesupport', git: 'https://github.com/rails/rails'
9
- gem 'bunny', ENV['BUNNY_VERSION'] if ENV['BUNNY_VERSION']
10
-
11
- group :rails do
12
- gem 'rails', '>= 5.2', git: 'https://github.com/rails/rails', require: 'rails'
13
- gem 'sqlite3', '~> 1.4'
14
- end
@@ -1,60 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe Msgr::Client do
6
- subject { described_class.new config }
7
- let(:config) { {} }
8
-
9
- describe '#uri' do
10
- subject { super().uri.to_s }
11
-
12
- context 'with default config' do
13
- it 'uses the default config' do
14
- is_expected.to eq 'amqp://127.0.0.1'
15
- end
16
- end
17
-
18
- context 'with overwritten URI' do
19
- context 'without vhost' do
20
- let(:config) { {uri: 'amqp://rabbit'} }
21
-
22
- it 'does not specify a vhost' do
23
- is_expected.to eq 'amqp://rabbit'
24
- end
25
- end
26
-
27
- context 'with empty vhost' do
28
- let(:config) { {uri: 'amqp://rabbit/'} }
29
-
30
- it 'does not specify a vhost' do
31
- is_expected.to eq 'amqp://rabbit'
32
- end
33
- end
34
-
35
- context 'with explicit vhost' do
36
- let(:config) { {uri: 'amqp://rabbit/some_vhost'} }
37
-
38
- # This behavior is due to legacy parsing in Msgr's config.
39
- # We interpret the entire path (incl. the leading slash)
40
- # as vhost. As per AMQP rules, this means the leading slash
41
- # is part of the vhost, which means it has to be URL encoded.
42
- # This will likely change with the next major release.
43
- it 'uses the entire path as vhost' do
44
- is_expected.to eq 'amqp://rabbit/%2Fsome_vhost'
45
- end
46
- end
47
- end
48
-
49
- context 'with URI and vhost' do
50
- let(:config) { {uri: 'amqp://rabbit/some_vhost', vhost: 'real_vhost'} }
51
-
52
- # This is currently the only way to specify a vhost without
53
- # leading slash (as a vhost in the :uri config would have
54
- # an extra URL encoded leading slash).
55
- it 'uses the explicit vhost' do
56
- is_expected.to eq 'amqp://rabbit/real_vhost'
57
- end
58
- end
59
- end
60
- end
@@ -1,44 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- class MsgrAutoAckConsumer < Msgr::Consumer
6
- self.auto_ack = true
7
-
8
- def index
9
- end
10
- end
11
-
12
- class MsgrManualAckConsumer < Msgr::Consumer
13
- self.auto_ack = false
14
-
15
- def index
16
- end
17
- end
18
-
19
- describe Msgr::Dispatcher do
20
- let(:config) { {} }
21
- let(:args) { [config] }
22
- let(:dispatcher) { Msgr::Dispatcher.new(*args) }
23
- subject { dispatcher }
24
-
25
- describe 'dispatch' do
26
- it 'should ack messages automatically if auto_ack is enabled' do
27
- route_db = double('Route', :consumer => 'MsgrAutoAckConsumer', :action => :index)
28
- msg_db = double('Message', :route => route_db, :acked? => false)
29
- expect(msg_db).to receive(:ack)
30
- expect(msg_db).not_to receive(:nack)
31
-
32
- dispatcher.dispatch(msg_db)
33
- end
34
-
35
- it 'should not ack messages if auto_ack is disabled' do
36
- route_db = double('Route', :consumer => 'MsgrManualAckConsumer', :action => :index)
37
- msg_db = double('Message', :route => route_db, :acked? => false)
38
- expect(msg_db).not_to receive(:ack)
39
- expect(msg_db).not_to receive(:nack)
40
-
41
- dispatcher.dispatch(msg_db)
42
- end
43
- end
44
- end
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'bundler'
4
-
5
- # Somewhere between
6
- # `ruby -w -W2 -S rspec ...`
7
- # and the rspec executable `bundle/setup` is required or
8
- # `Bundler.setup` without groups called. This will let Bundler
9
- # load ALL gems from ALL groups. This results in leaking
10
- # gems only for rails integration tests into msgr testing
11
- # environment.
12
- #
13
- # This file will be required by ruby on the commandline before
14
- # everything else can kick in. The code snippet below will
15
- # patch bundler to just ignore `setup` calls without
16
- # specified groups. All test helper will explicit call
17
- # `Bundler.setup` with required test groups.
18
-
19
- module Bundler
20
- class << self
21
- alias old_setup setup
22
- def setup(*groups)
23
- old_setup(*groups) unless groups.empty?
24
- end
25
- end
26
- end
27
-
28
- # Only load default group
29
- Bundler.setup :default