rabbit_feed 2.4.4 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +81 -0
  4. data/README.md +39 -5
  5. data/Rakefile +3 -19
  6. data/bin/rabbit_feed +0 -1
  7. data/example/non_rails_app/Gemfile.lock +29 -32
  8. data/example/non_rails_app/Rakefile +1 -1
  9. data/example/non_rails_app/bin/benchmark +3 -3
  10. data/example/non_rails_app/lib/non_rails_app/event_handler.rb +1 -1
  11. data/example/non_rails_app/spec/lib/non_rails_app/event_handler_spec.rb +3 -4
  12. data/example/non_rails_app/spec/lib/non_rails_app/event_routing_spec.rb +3 -3
  13. data/example/rails_app/Gemfile +4 -16
  14. data/example/rails_app/Gemfile.lock +131 -137
  15. data/example/rails_app/app/assets/javascripts/application.js +0 -1
  16. data/example/rails_app/app/controllers/application_controller.rb +0 -3
  17. data/example/rails_app/app/controllers/beavers_controller.rb +14 -15
  18. data/example/rails_app/bin/rails +1 -1
  19. data/example/rails_app/config/environments/development.rb +1 -1
  20. data/example/rails_app/config/environments/test.rb +2 -2
  21. data/example/rails_app/config/initializers/cookies_serializer.rb +1 -1
  22. data/example/rails_app/config/unicorn.rb +1 -1
  23. data/example/rails_app/config.ru +1 -1
  24. data/example/rails_app/db/schema.rb +5 -7
  25. data/example/rails_app/lib/event_handler.rb +1 -1
  26. data/example/rails_app/spec/controllers/beavers_controller_spec.rb +9 -10
  27. data/example/rails_app/spec/event_routing_spec.rb +1 -2
  28. data/example/rails_app/test/controllers/beavers_controller_test.rb +12 -12
  29. data/lib/dsl.rb +4 -4
  30. data/lib/rabbit_feed/client.rb +17 -23
  31. data/lib/rabbit_feed/configuration.rb +10 -9
  32. data/lib/rabbit_feed/connection.rb +3 -3
  33. data/lib/rabbit_feed/console_consumer.rb +22 -24
  34. data/lib/rabbit_feed/consumer.rb +2 -2
  35. data/lib/rabbit_feed/consumer_connection.rb +21 -22
  36. data/lib/rabbit_feed/event.rb +8 -28
  37. data/lib/rabbit_feed/event_definitions.rb +14 -15
  38. data/lib/rabbit_feed/event_routing.rb +26 -27
  39. data/lib/rabbit_feed/json_log_formatter.rb +1 -1
  40. data/lib/rabbit_feed/producer.rb +13 -13
  41. data/lib/rabbit_feed/producer_connection.rb +8 -9
  42. data/lib/rabbit_feed/testing_support/rspec_matchers/publish_event.rb +52 -89
  43. data/lib/rabbit_feed/testing_support/test_rabbit_feed_consumer.rb +1 -2
  44. data/lib/rabbit_feed/testing_support/testing_helpers.rb +0 -1
  45. data/lib/rabbit_feed/testing_support.rb +5 -6
  46. data/lib/rabbit_feed/version.rb +1 -1
  47. data/lib/rabbit_feed.rb +12 -13
  48. data/rabbit_feed.gemspec +16 -14
  49. data/run_benchmark +4 -3
  50. data/run_example +1 -1
  51. data/spec/features/step_definitions/connectivity_steps.rb +6 -9
  52. data/spec/lib/rabbit_feed/client_spec.rb +8 -9
  53. data/spec/lib/rabbit_feed/configuration_spec.rb +20 -23
  54. data/spec/lib/rabbit_feed/console_consumer_spec.rb +11 -13
  55. data/spec/lib/rabbit_feed/consumer_connection_spec.rb +26 -28
  56. data/spec/lib/rabbit_feed/event_definitions_spec.rb +31 -31
  57. data/spec/lib/rabbit_feed/event_routing_spec.rb +35 -62
  58. data/spec/lib/rabbit_feed/event_spec.rb +40 -87
  59. data/spec/lib/rabbit_feed/producer_connection_spec.rb +11 -7
  60. data/spec/lib/rabbit_feed/producer_spec.rb +16 -19
  61. data/spec/lib/rabbit_feed/testing_support/rspec_matchers/publish_event_spec.rb +82 -87
  62. data/spec/lib/rabbit_feed/testing_support/testing_helper_spec.rb +2 -2
  63. data/spec/spec_helper.rb +4 -10
  64. metadata +67 -45
  65. data/example/rails_app/README.rdoc +0 -28
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5cfc4d957f4cce3aac5cf77870241ec8f60d5495
4
- data.tar.gz: b6047ba2d39c634ae3c8d3cbc3b09a1f2849f3ab
3
+ metadata.gz: 341e94f0f96334c74f5f14a9bd394cb076602342
4
+ data.tar.gz: d6a2b2fea2255493db135aec552d48493d2e35fd
5
5
  SHA512:
6
- metadata.gz: 8dafb9b1caf08fc1025fa1f366585a7eab7844e224d1e935c6a7cbf9c2d068cfe490e7964cac24cdcc4011aa797368998b4e0fccd63ca976ac3053c5f190496e
7
- data.tar.gz: 6a740b0c0fdf17fb64516faf622bb77b7b2d30a5f765c5901d6efb14b7d9ef5022e311b1d4c0343c7b439552ca6c99a676cc7b125dcb1b4ad760b4bda92bc23e
6
+ metadata.gz: 7975aa142d54f3c36880776842680d6b7c1b07c0d3a3973d2622149b2801d303b1b4d99bd26245483827fef0dad1470cdb081984e23dff57d43d03352c9c1f34
7
+ data.tar.gz: 396188946a955bd285ea5146e33652f171501e5f54a349431917df947a3e9e87c386ffb6c158a9b3993c460ae5c79c882424787c88ad3b732821600a1559f4f3
data/.gitignore CHANGED
@@ -10,3 +10,4 @@ pkg
10
10
  .idea/
11
11
  *.gem
12
12
  Gemfile.lock
13
+ coverage/
data/.rubocop.yml ADDED
@@ -0,0 +1,81 @@
1
+ Lint/HandleExceptions:
2
+ Exclude:
3
+ - 'example/non_rails_app/bin/benchmark'
4
+ - 'lib/rabbit_feed/testing_support/rspec_matchers/publish_event.rb'
5
+ - 'spec/features/step_definitions/connectivity_steps.rb'
6
+ - 'spec/lib/rabbit_feed/consumer_connection_spec.rb'
7
+ - 'spec/lib/rabbit_feed/producer_connection_spec.rb'
8
+
9
+ Style/RescueModifier:
10
+ Exclude:
11
+ - 'lib/rabbit_feed/testing_support/rspec_matchers/publish_event.rb'
12
+
13
+ Metrics/AbcSize:
14
+ Exclude:
15
+ - 'lib/rabbit_feed/client.rb'
16
+ - 'lib/rabbit_feed/configuration.rb'
17
+ - 'lib/rabbit_feed/consumer_connection.rb'
18
+ - 'lib/rabbit_feed/producer.rb'
19
+ - 'lib/rabbit_feed/testing_support/rspec_matchers/publish_event.rb'
20
+
21
+ Metrics/BlockLength:
22
+ Enabled: false
23
+
24
+ Metrics/ClassLength:
25
+ Exclude:
26
+ - 'lib/rabbit_feed/client.rb'
27
+
28
+ Metrics/CyclomaticComplexity:
29
+ Exclude:
30
+ - 'lib/rabbit_feed/configuration.rb'
31
+ - 'lib/rabbit_feed.rb'
32
+ - 'lib/rabbit_feed/testing_support/rspec_matchers/publish_event.rb'
33
+
34
+ Metrics/LineLength:
35
+ Enabled: false
36
+
37
+ Metrics/MethodLength:
38
+ Max: 20
39
+ Exclude:
40
+ - 'lib/rabbit_feed/client.rb'
41
+
42
+ Metrics/ModuleLength:
43
+ Enabled: false
44
+
45
+ Metrics/PerceivedComplexity:
46
+ Exclude:
47
+ - 'lib/rabbit_feed/configuration.rb'
48
+ - 'lib/rabbit_feed.rb'
49
+ - 'lib/rabbit_feed/testing_support/rspec_matchers/publish_event.rb'
50
+
51
+ Style/Documentation:
52
+ Enabled: false
53
+
54
+ Style/DoubleNegation:
55
+ Enabled: false
56
+
57
+ Style/ClassAndModuleChildren:
58
+ Exclude:
59
+ - 'example/rails_app/test/test_helper.rb'
60
+ - 'spec/features/step_definitions/connectivity_steps.rb'
61
+ - 'spec/lib/rabbit_feed/consumer_connection_spec.rb'
62
+ - 'spec/lib/rabbit_feed/producer_connection_spec.rb'
63
+
64
+ Style/FirstParameterIndentation:
65
+ Exclude:
66
+ - 'spec/lib/rabbit_feed/console_consumer_spec.rb'
67
+
68
+ Style/MethodName:
69
+ Exclude:
70
+ - 'lib/dsl.rb'
71
+
72
+ Style/ModuleFunction:
73
+ EnforcedStyle: 'extend_self'
74
+
75
+ Style/MultilineBlockChain:
76
+ Exclude:
77
+ - 'spec/lib/rabbit_feed/testing_support/rspec_matchers/publish_event_spec.rb'
78
+
79
+ Style/SymbolProc:
80
+ Exclude:
81
+ - 'spec/lib/rabbit_feed/event_routing_spec.rb'
data/README.md CHANGED
@@ -151,7 +151,7 @@ RSpec.configure do |config|
151
151
  end
152
152
  ```
153
153
 
154
- The expectation looks like this:
154
+ Validating an event was published by event name:
155
155
 
156
156
  ```ruby
157
157
  require 'spec_helper'
@@ -162,19 +162,53 @@ describe BeaversController do
162
162
  it 'publishes a create event' do
163
163
  expect{
164
164
  post :create, beaver: { name: 'beaver' }
165
- }.to publish_event('user_creates_beaver', { 'beaver_name' => 'beaver' })
165
+ }.to publish_event('user_creates_beaver')
166
166
  end
167
167
  end
168
168
  end
169
169
  ```
170
170
 
171
- You can also pass a block with `do/end` (not `{}`) and do more fine grained matching.
171
+ Validating an event was published by event name and payload:
172
+
173
+ ```ruby
174
+ require 'spec_helper'
175
+
176
+ describe BeaversController do
177
+
178
+ describe 'POST create' do
179
+ it 'publishes a create event' do
180
+ expect{
181
+ post :create, beaver: { name: 'beaver' }
182
+ }.to publish_event('user_creates_beaver', 'beaver_name' => 'beaver')
183
+ end
184
+ end
185
+ end
186
+ ```
187
+
188
+ Validating an event was published by event name and partial payload match:
189
+
190
+ ```ruby
191
+ require 'spec_helper'
192
+
193
+ describe BeaversController do
194
+
195
+ describe 'POST create' do
196
+ it 'publishes a create event' do
197
+ expect{
198
+ post :create, beaver: { name: 'beaver' }
199
+ }.to publish_event('user_creates_beaver').including('beaver_name' => 'beaver')
200
+ end
201
+ end
202
+ end
203
+ ```
204
+
205
+ You can also use the `.asserting` chain, allowing you to provide your own expectation on the event's payload:
172
206
 
173
207
  ```ruby
174
208
  it 'publishes a create event' do
175
209
  expect{
176
210
  post :create, beaver: { name: 'beaver' }
177
- }.to publish_event('user_creates_beaver', nil) do |payload|
211
+ }.to publish_event('user_creates_beaver', nil).asserting do |payload|
178
212
  expect(payload['beaver_name']).to match(/ea/)
179
213
  end
180
214
  end
@@ -228,7 +262,7 @@ describe 'consuming events' do
228
262
 
229
263
  before { define_route }
230
264
 
231
- it 'route to the correct service' do
265
+ it 'routes to the correct service' do
232
266
  rabbit_feed_consumer.consume_event(event)
233
267
  expect(accumulator.size).to eq(1)
234
268
  end
data/Rakefile CHANGED
@@ -1,30 +1,14 @@
1
- require 'bundler/gem_tasks'
2
1
  require 'rspec/core/rake_task'
3
2
 
4
3
  desc 'Default: run specs and features'
5
- task :default => [:all]
4
+ task default: [:all]
6
5
 
7
6
  desc 'Run specs and features'
8
7
  RSpec::Core::RakeTask.new(:all) do |t|
9
- t.pattern = "spec/{**/*_spec.rb,features/**/*.feature}"
8
+ t.pattern = 'spec/{**/*_spec.rb,features/**/*.feature}'
10
9
  end
11
10
 
12
11
  desc 'Run specs'
13
12
  RSpec::Core::RakeTask.new(:spec) do |t|
14
- t.pattern = "spec/**/*_spec.rb"
13
+ t.pattern = 'spec/**/*_spec.rb'
15
14
  end
16
-
17
- def gemspec
18
- @gemspec ||= eval(File.read('rabbit_feed.gemspec'))
19
- end
20
-
21
- desc 'Validate gemspec'
22
- task :validate_gemspec do
23
- gemspec.validate
24
- end
25
-
26
- desc 'Print version'
27
- task :version do
28
- puts gemspec.version
29
- end
30
-
data/bin/rabbit_feed CHANGED
@@ -8,4 +8,3 @@ I18n.enforce_available_locales = true
8
8
 
9
9
  client = RabbitFeed::Client.new
10
10
  client.run
11
-
@@ -1,51 +1,48 @@
1
1
  PATH
2
2
  remote: ../../
3
3
  specs:
4
- rabbit_feed (2.4.4)
5
- activemodel (>= 3.2.0, < 5.0.0)
6
- activesupport (>= 3.2.0, < 5.0.0)
7
- avro (>= 1.5.4, < 1.8.0)
8
- bunny (>= 2.0.0, < 2.1.0)
9
- pidfile
4
+ rabbit_feed (3.0.0)
5
+ activemodel (>= 3.2.0, < 6.0.0)
6
+ activesupport (>= 3.2.0, < 6.0.0)
7
+ avro (>= 1.5.4, < 1.9.0)
8
+ bunny (>= 2.0.0, < 2.7.0)
9
+ pidfile (~> 0.3)
10
10
 
11
11
  GEM
12
12
  remote: https://rubygems.org/
13
13
  specs:
14
- activemodel (4.2.6)
15
- activesupport (= 4.2.6)
16
- builder (~> 3.1)
17
- activesupport (4.2.6)
14
+ activemodel (5.0.1)
15
+ activesupport (= 5.0.1)
16
+ activesupport (5.0.1)
17
+ concurrent-ruby (~> 1.0, >= 1.0.2)
18
18
  i18n (~> 0.7)
19
- json (~> 1.7, >= 1.7.7)
20
19
  minitest (~> 5.1)
21
- thread_safe (~> 0.3, >= 0.3.4)
22
20
  tzinfo (~> 1.1)
23
21
  amq-protocol (2.0.1)
24
- avro (1.7.7)
22
+ avro (1.8.1)
25
23
  multi_json
26
- builder (3.2.2)
27
- bunny (2.0.1)
28
- amq-protocol (>= 1.9.2)
24
+ bunny (2.6.2)
25
+ amq-protocol (>= 2.0.1)
26
+ concurrent-ruby (1.0.4)
29
27
  diff-lcs (1.2.5)
30
28
  i18n (0.7.0)
31
- json (1.8.3)
32
- minitest (5.8.4)
33
- multi_json (1.12.0)
29
+ minitest (5.10.1)
30
+ multi_json (1.12.1)
34
31
  pidfile (0.3.0)
35
- rake (10.4.2)
36
- rspec (3.2.0)
37
- rspec-core (~> 3.2.0)
38
- rspec-expectations (~> 3.2.0)
39
- rspec-mocks (~> 3.2.0)
40
- rspec-core (3.2.0)
41
- rspec-support (~> 3.2.0)
42
- rspec-expectations (3.2.0)
32
+ rake (12.0.0)
33
+ rspec (3.5.0)
34
+ rspec-core (~> 3.5.0)
35
+ rspec-expectations (~> 3.5.0)
36
+ rspec-mocks (~> 3.5.0)
37
+ rspec-core (3.5.4)
38
+ rspec-support (~> 3.5.0)
39
+ rspec-expectations (3.5.0)
43
40
  diff-lcs (>= 1.2.0, < 2.0)
44
- rspec-support (~> 3.2.0)
45
- rspec-mocks (3.2.0)
41
+ rspec-support (~> 3.5.0)
42
+ rspec-mocks (3.5.0)
46
43
  diff-lcs (>= 1.2.0, < 2.0)
47
- rspec-support (~> 3.2.0)
48
- rspec-support (3.2.1)
44
+ rspec-support (~> 3.5.0)
45
+ rspec-support (3.5.0)
49
46
  thread_safe (0.3.5)
50
47
  tzinfo (1.2.2)
51
48
  thread_safe (~> 0.1)
@@ -59,4 +56,4 @@ DEPENDENCIES
59
56
  rspec
60
57
 
61
58
  BUNDLED WITH
62
- 1.11.2
59
+ 1.13.7
@@ -2,4 +2,4 @@ require 'rspec/core/rake_task'
2
2
 
3
3
  RSpec::Core::RakeTask.new(:spec)
4
4
 
5
- task :default => :spec
5
+ task default: :spec
@@ -9,7 +9,7 @@ I18n.enforce_available_locales = true
9
9
 
10
10
  RabbitFeed.environment = 'development'
11
11
 
12
- payload = 'abc'*5000
12
+ payload = 'abc' * 5000
13
13
  number_of_events = 5000
14
14
 
15
15
  EventDefinitions do
@@ -25,14 +25,14 @@ end
25
25
 
26
26
  puts "Publishing #{number_of_events} events..."
27
27
  Benchmark.bm do |x|
28
- x.report { number_of_events.times { RabbitFeed::Producer.publish_event 'test_event', { 'data' => payload } } }
28
+ x.report { number_of_events.times { RabbitFeed::Producer.publish_event 'test_event', 'data' => payload } }
29
29
  end
30
30
 
31
31
  events_consumed = 0
32
32
 
33
33
  EventRouting do
34
34
  accept_from('non_rails_app') do
35
- event('test_event') do |event|
35
+ event('test_event') do |_event|
36
36
  events_consumed += 1
37
37
  Thread.main.raise Interrupt if events_consumed >= number_of_events
38
38
  end
@@ -2,7 +2,7 @@ module NonRailsApp
2
2
  module EventHandler
3
3
  extend self
4
4
 
5
- def handle_event event
5
+ def handle_event(event)
6
6
  puts "NonRailsApp::EventHandler - Consumed event: #{event.name} with payload: #{event.payload}"
7
7
  RabbitFeed::Producer.publish_event 'application_acknowledges_event', ({ 'event_name' => event.name }.merge event.payload)
8
8
  end
@@ -1,11 +1,10 @@
1
1
  module NonRailsApp
2
2
  describe EventHandler do
3
-
4
3
  describe '#handle_event' do
5
4
  it 'publishes an update event' do
6
- expect{
7
- described_class.handle_event RabbitFeed::Event.new({'name' => 'user_updates_beaver', 'application' => 'rails_app'}, {'beaver_name' => 'beaver'})
8
- }.to publish_event('application_acknowledges_event', { 'beaver_name' => 'beaver', 'event_name' => 'user_updates_beaver' })
5
+ expect do
6
+ described_class.handle_event RabbitFeed::Event.new({ 'name' => 'user_updates_beaver', 'application' => 'rails_app' }, 'beaver_name' => 'beaver')
7
+ end.to publish_event('application_acknowledges_event', 'beaver_name' => 'beaver', 'event_name' => 'user_updates_beaver')
9
8
  end
10
9
  end
11
10
  end
@@ -1,11 +1,11 @@
1
1
  module NonRailsApp
2
2
  describe 'Event Routing' do
3
- let(:payload) { {'field' => 'value'} }
4
- let(:metadata) { {'application' => 'rails_app', 'name' => 'user_creates_beaver'} }
3
+ let(:payload) { { 'field' => 'value' } }
4
+ let(:metadata) { { 'application' => 'rails_app', 'name' => 'user_creates_beaver' } }
5
5
  let(:event) { RabbitFeed::Event.new metadata, payload }
6
6
 
7
7
  it 'routes events correctly' do
8
- expect(NonRailsApp::EventHandler).to receive(:handle_event) { |full_event| expect(full_event.payload).to eq(payload)}
8
+ expect(NonRailsApp::EventHandler).to receive(:handle_event) { |full_event| expect(full_event.payload).to eq(payload) }
9
9
  rabbit_feed_consumer.consume_event(event)
10
10
  end
11
11
  end
@@ -1,30 +1,17 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
4
- gem 'rails', '4.2.0'
4
+ gem 'rails', '~> 5.0'
5
5
  # Use sqlite3 as the database for Active Record
6
6
  gem 'sqlite3'
7
7
  # Use SCSS for stylesheets
8
- gem 'sass-rails', '~> 4.0.3'
8
+ gem 'sass-rails'
9
9
  # Use Uglifier as compressor for JavaScript assets
10
10
  gem 'uglifier', '>= 1.3.0'
11
11
  # Use CoffeeScript for .js.coffee assets and views
12
- gem 'coffee-rails', '~> 4.0.0'
13
- # See https://github.com/sstephenson/execjs#readme for more supported runtimes
14
- # gem 'therubyracer', platforms: :ruby
15
-
12
+ gem 'coffee-rails'
16
13
  # Use jquery as the JavaScript library
17
14
  gem 'jquery-rails'
18
- # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
19
- gem 'turbolinks'
20
- # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
21
- gem 'jbuilder', '~> 2.0'
22
- # bundle exec rake doc:rails generates the API under doc/api.
23
- gem 'sdoc', '~> 0.4.0', group: :doc
24
-
25
- # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
26
- gem 'spring', group: :development
27
-
28
15
  # Use unicorn as the app server
29
16
  gem 'unicorn'
30
17
 
@@ -33,4 +20,5 @@ gem 'unicorn'
33
20
 
34
21
  gem 'rabbit_feed', path: '../../'
35
22
 
23
+ gem 'rails-controller-testing', group: :test
36
24
  gem 'rspec-rails', group: :test