cony 2.0.1 → 2.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 80141fdaf5f3657833bc6fdd609490f6bf9b5d9c
4
- data.tar.gz: c24bfedd50fa54b6c1fa15c9fc77213e6a6e2ef0
3
+ metadata.gz: 6480837c675265e2e4ac5cc86a154d359dec892e
4
+ data.tar.gz: 4734b66beb8e73e0eb557efe901582234f465d5a
5
5
  SHA512:
6
- metadata.gz: 19d4fe42ab1fa80621d4a9da1ab35e83bf1f63ba27434a04af78f12dc7a65bc128ce99d64d2b543af5888b948a9e66526d48651a842151d60e77039b02fa9799
7
- data.tar.gz: 9a6e82f7a42d806f9f4803235bf7341c2fff8bae3fc477b7b7074deed993066808b0fca7b0ca41f3e3bfe66a3a52d1ff1f1eacf0bc43bc8dd0ee818711c84c73
6
+ metadata.gz: 831f2e33dae98754cbbd6f60f2b20ba5d27cfb3cc74f65b9f1f61391022b1091d5eb615d6c75c4c2b6f93af42117060022d735d4c6fecc96a9e24d41a54548fb
7
+ data.tar.gz: f4bf13ad28799d1622d2048f3f6191b16ffce3e676f01c2328cece654660be777d7e4a87fdb83a553b065c4832b5f3764556424e4877fb62d6136a67954db61c
data/Gemfile.lock CHANGED
@@ -1,35 +1,39 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cony (2.0.0)
4
+ cony (2.2.0)
5
5
  activesupport (>= 3)
6
6
  bunny (~> 2.3)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activesupport (4.2.6)
11
+ activesupport (5.0.0.1)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
12
13
  i18n (~> 0.7)
13
- json (~> 1.7, >= 1.7.7)
14
14
  minitest (~> 5.1)
15
- thread_safe (~> 0.3, >= 0.3.4)
16
15
  tzinfo (~> 1.1)
17
16
  amq-protocol (2.0.1)
18
- bunny (2.3.1)
17
+ bunny (2.5.1)
19
18
  amq-protocol (>= 2.0.1)
19
+ concurrent-ruby (1.0.2)
20
20
  diff-lcs (1.2.5)
21
21
  i18n (0.7.0)
22
- json (1.8.3)
23
- minitest (5.9.0)
24
- rake (10.3.0)
25
- rspec (2.14.1)
26
- rspec-core (~> 2.14.0)
27
- rspec-expectations (~> 2.14.0)
28
- rspec-mocks (~> 2.14.0)
29
- rspec-core (2.14.8)
30
- rspec-expectations (2.14.5)
31
- diff-lcs (>= 1.1.3, < 2.0)
32
- rspec-mocks (2.14.6)
22
+ minitest (5.9.1)
23
+ rake (11.3.0)
24
+ rspec (3.5.0)
25
+ rspec-core (~> 3.5.0)
26
+ rspec-expectations (~> 3.5.0)
27
+ rspec-mocks (~> 3.5.0)
28
+ rspec-core (3.5.4)
29
+ rspec-support (~> 3.5.0)
30
+ rspec-expectations (3.5.0)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.5.0)
33
+ rspec-mocks (3.5.0)
34
+ diff-lcs (>= 1.2.0, < 2.0)
35
+ rspec-support (~> 3.5.0)
36
+ rspec-support (3.5.0)
33
37
  thread_safe (0.3.5)
34
38
  tzinfo (1.2.2)
35
39
  thread_safe (~> 0.1)
@@ -39,5 +43,8 @@ PLATFORMS
39
43
 
40
44
  DEPENDENCIES
41
45
  cony!
42
- rake (~> 10.0)
43
- rspec (~> 2.12)
46
+ rake (~> 11.0)
47
+ rspec (~> 3.0)
48
+
49
+ BUNDLED WITH
50
+ 1.12.5
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.1
1
+ 2.2.1
data/bin/cony-receive CHANGED
@@ -6,11 +6,11 @@ EventMachine.run do
6
6
  AMQP.connect do |connection|
7
7
  channel = AMQP::Channel.new(connection)
8
8
  # topic exchange name can be any string
9
- exchange = channel.topic("cony-test", durable: true)
9
+ exchange = channel.topic('cony-test', durable: true)
10
10
 
11
11
  # Subscribers.
12
- channel.queue("", :exclusive => true) do |queue|
13
- queue.bind(exchange, :routing_key => "#").subscribe do |headers, payload|
12
+ channel.queue('', exclusive: true) do |queue|
13
+ queue.bind(exchange, routing_key: '#').subscribe do |_headers, payload|
14
14
  puts payload.inspect
15
15
  end
16
16
  end
data/cony.gemspec CHANGED
@@ -19,8 +19,8 @@ Gem::Specification.new do |s|
19
19
 
20
20
  s.required_ruby_version = '>= 2.0'
21
21
 
22
- s.add_development_dependency 'rake', '~> 10.0'
23
- s.add_development_dependency 'rspec', '~> 2.12'
22
+ s.add_development_dependency 'rake', '~> 11.0'
23
+ s.add_development_dependency 'rspec', '~> 3.0'
24
24
 
25
25
  s.add_runtime_dependency 'activesupport', '>= 3'
26
26
  s.add_runtime_dependency 'bunny', '~> 2.3'
data/lib/cony.rb CHANGED
@@ -9,6 +9,21 @@ require 'active_support/configurable'
9
9
 
10
10
  require 'cony/active_record'
11
11
 
12
+ ##
13
+ # To configure Cony:
14
+ # <code>
15
+ # Cony.configure do |config|
16
+ # config.amqp = {
17
+ # host: 'localhost',
18
+ # exchange: 'organization.application',
19
+ # ssl: true,
20
+ # user: 'username',
21
+ # pass: 'secret',
22
+ # }
23
+ # config.test_mode = Rails.env.test?
24
+ # # config.durable = false
25
+ # end
26
+ # </code>
12
27
  module Cony
13
28
  include ActiveSupport::Configurable
14
29
 
@@ -18,5 +33,4 @@ module Cony
18
33
  }
19
34
 
20
35
  self.config.merge! defaults.deep_dup
21
-
22
36
  end
@@ -4,8 +4,16 @@ require 'cony'
4
4
  require 'cony/amqp_connection_handler'
5
5
 
6
6
  module Cony
7
+ ##
8
+ # Usage:
9
+ # <code>
10
+ # class FooBar < ActiveRecord::Base
11
+ # include Cony::ActiveRecord
12
+ # # your things here
13
+ # end
14
+ # </code>
15
+ #
7
16
  module ActiveRecord
8
-
9
17
  extend ActiveSupport::Concern
10
18
 
11
19
  included do
@@ -34,13 +42,14 @@ module Cony
34
42
  end
35
43
 
36
44
  private
45
+
37
46
  def cony_amqp_connection
38
47
  @cony_amqp_connection ||= Cony::AMQPConnectionHandler.new(Cony.config.amqp)
39
48
  end
40
49
 
41
50
  def cony_mapped_changes
42
51
  changes.map do |name, change|
43
- {name => {old: change.first, new: change.last}}
52
+ { name => { old: change.first, new: change.last } }
44
53
  end
45
54
  end
46
55
 
@@ -54,12 +63,12 @@ module Cony
54
63
 
55
64
  def cony_changes_destroyed
56
65
  attributes.map do |name, value|
57
- {name => {old: value, new: nil}}
66
+ { name => { old: value, new: nil } }
58
67
  end
59
68
  end
60
69
 
61
70
  def cony_notify_hash
62
- {id: self.id, changes: @cony_notify[:changes], model: self.class.name, event: @cony_notify[:event]}
71
+ { id: self.id, changes: @cony_notify[:changes], model: self.class.name, event: @cony_notify[:event] }
63
72
  end
64
73
 
65
74
  def cony_notify_routing_key
@@ -3,7 +3,6 @@ require 'json'
3
3
 
4
4
  module Cony
5
5
  class AMQPConnectionHandler
6
-
7
6
  def initialize(config)
8
7
  @config = config
9
8
  end
@@ -23,6 +22,5 @@ module Cony
23
22
  Airbrake.notify(error) if defined?(Airbrake)
24
23
  Rails.logger.error("#{error.class}: #{error}") if defined?(Rails)
25
24
  end
26
-
27
25
  end
28
26
  end
@@ -3,12 +3,11 @@ require 'spec_helper'
3
3
  require 'cony/active_record'
4
4
 
5
5
  describe Cony::ActiveRecord do
6
-
7
6
  let(:amqp_connection) { double('Cony::AMQPConnectionHandler') }
8
7
  let(:id) { 1337 }
9
- let(:active_record_changes) { {name: ['old', 'new']} }
10
- let(:active_record_attributes) { {name: 'value'} }
11
- let(:cony_changes) { [{name: {old: 'old', new: 'new'}}] }
8
+ let(:active_record_changes) { { name: %w(old new) } }
9
+ let(:active_record_attributes) { { name: 'value' } }
10
+ let(:cony_changes) { [{ name: { old: 'old', new: 'new' } }] }
12
11
  let(:expected_payload) do
13
12
  {
14
13
  id: id,
@@ -36,7 +35,7 @@ describe Cony::ActiveRecord do
36
35
  end
37
36
 
38
37
  before do
39
- Cony::AMQPConnectionHandler.stub(:new).and_return(amqp_connection)
38
+ allow(Cony::AMQPConnectionHandler).to receive(:new).and_return(amqp_connection)
40
39
  end
41
40
 
42
41
  subject { model.new }
@@ -44,7 +43,7 @@ describe Cony::ActiveRecord do
44
43
  describe '#cony_send_create_notify' do
45
44
  let(:event) { :created }
46
45
  it 'uses the amqp connection to send the notify' do
47
- amqp_connection.should_receive(:publish).with(expected_payload, 'anonymaus/klass.mutation.created')
46
+ expect(amqp_connection).to receive(:publish).with(expected_payload, 'anonymaus/klass.mutation.created')
48
47
  subject.cony_save_create_notify_data
49
48
  subject.cony_publish
50
49
  end
@@ -53,7 +52,7 @@ describe Cony::ActiveRecord do
53
52
  describe '#cony_send_update_notify' do
54
53
  let(:event) { :updated }
55
54
  it 'uses the amqp connection to send the notify' do
56
- amqp_connection.should_receive(:publish).with(expected_payload, 'anonymaus/klass.mutation.updated')
55
+ expect(amqp_connection).to receive(:publish).with(expected_payload, 'anonymaus/klass.mutation.updated')
57
56
  subject.cony_save_update_notify_data
58
57
  subject.cony_publish
59
58
  end
@@ -61,9 +60,9 @@ describe Cony::ActiveRecord do
61
60
 
62
61
  describe '#cony_send_destroy_notify' do
63
62
  let(:event) { :destroyed }
64
- let(:cony_changes) { [{name: {old: 'value', new: nil}}] }
63
+ let(:cony_changes) { [{ name: { old: 'value', new: nil } }] }
65
64
  it 'uses the amqp connection to send the notify' do
66
- amqp_connection.should_receive(:publish).with(expected_payload, 'anonymaus/klass.mutation.destroyed')
65
+ expect(amqp_connection).to receive(:publish).with(expected_payload, 'anonymaus/klass.mutation.destroyed')
67
66
  subject.cony_save_destroy_notify_data
68
67
  subject.cony_publish
69
68
  end
@@ -71,7 +70,7 @@ describe Cony::ActiveRecord do
71
70
 
72
71
  context 'test mode enabled' do
73
72
  before do
74
- Cony.config.stub(:test_mode).and_return(true)
73
+ allow(Cony.config).to receive(:test_mode).and_return(true)
75
74
  end
76
75
  it 'does not send the message' do
77
76
  expect(Cony::AMQPConnectionHandler).to_not receive(:new)
@@ -79,5 +78,4 @@ describe Cony::ActiveRecord do
79
78
  subject.cony_publish
80
79
  end
81
80
  end
82
-
83
81
  end
@@ -4,40 +4,39 @@ require 'ostruct'
4
4
  require 'cony/amqp_connection_handler'
5
5
 
6
6
  describe Cony::AMQPConnectionHandler do
7
-
8
- let(:config) { {exchange: 'bunny-tests'} }
7
+ let(:config) { { exchange: 'bunny-tests' } }
9
8
  let(:handler) { Cony::AMQPConnectionHandler.new(config) }
10
9
  let(:message) { 'Bunnies are connies' }
11
10
  let(:routing_key) { 'bunny.info' }
12
11
  let(:exchange_double) do
13
12
  double('Exchange double').tap do |exc|
14
- exc.stub(:publish)
13
+ allow(exc).to receive(:publish)
15
14
  end
16
15
  end
17
16
  let(:channel_double) do
18
17
  double('Channel double').tap do |channel|
19
- channel.stub(:topic).and_return(exchange_double)
18
+ allow(channel).to receive(:topic).and_return(exchange_double)
20
19
  end
21
20
  end
22
21
  let(:connection_double) do
23
22
  double('Connection double').tap do |conn|
24
- conn.stub(:create_channel).and_return(channel_double)
23
+ allow(conn).to receive(:create_channel).and_return(channel_double)
25
24
  end
26
25
  end
27
26
 
28
27
  subject { handler }
29
28
 
30
29
  before do
31
- Bunny.stub(:run).and_yield(connection_double)
30
+ allow(Bunny).to receive(:run).and_yield(connection_double)
32
31
  end
33
32
 
34
33
  it 'uses bunny to publish a message' do
35
- Bunny.should_receive(:run)
34
+ expect(Bunny).to receive(:run)
36
35
  subject.publish(message, routing_key)
37
36
  end
38
37
 
39
38
  it 'configures the exchange correctly' do
40
- channel_double.should_receive(:topic).with('bunny-tests', durable: false)
39
+ expect(channel_double).to receive(:topic).with('bunny-tests', durable: false)
41
40
  subject.publish(message, routing_key)
42
41
  end
43
42
 
@@ -49,14 +48,14 @@ describe Cony::AMQPConnectionHandler do
49
48
  persistent: false,
50
49
  content_type: 'application/json',
51
50
  }
52
- exchange_double.should_receive(:publish)
53
- .with('"Bunnies are connies"', publish_options)
51
+ expect(exchange_double).to receive(:publish).
52
+ with('"Bunnies are connies"', publish_options)
54
53
  subject.publish(message, routing_key)
55
54
  end
56
55
 
57
56
  describe 'error handling' do
58
57
  before do
59
- Bunny.stub(:run).and_raise('I failed so hard')
58
+ allow(Bunny).to receive(:run).and_raise('I failed so hard')
60
59
  end
61
60
 
62
61
  it 'does not raise an error' do
@@ -68,7 +67,7 @@ describe Cony::AMQPConnectionHandler do
68
67
  stub_const('Rails', OpenStruct.new(logger: double('Railslogger')))
69
68
  end
70
69
  it 'logs an error' do
71
- expect(Rails.logger).to receive(:error).with("RuntimeError: I failed so hard")
70
+ expect(Rails.logger).to receive(:error).with('RuntimeError: I failed so hard')
72
71
  subject.publish(message, routing_key)
73
72
  end
74
73
  end
@@ -83,5 +82,4 @@ describe Cony::AMQPConnectionHandler do
83
82
  end
84
83
  end
85
84
  end
86
-
87
85
  end
data/spec/spec_helper.rb CHANGED
@@ -5,7 +5,6 @@
5
5
  #
6
6
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
7
  RSpec.configure do |config|
8
- config.treat_symbols_as_metadata_keys_with_true_values = true
9
8
  config.run_all_when_everything_filtered = true
10
9
  config.filter_run :focus
11
10
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cony
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - nine.ch Development-Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-05 00:00:00.000000000 Z
11
+ date: 2016-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '10.0'
19
+ version: '11.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '10.0'
26
+ version: '11.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2.12'
33
+ version: '3.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '2.12'
40
+ version: '3.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: activesupport
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  version: '0'
118
118
  requirements: []
119
119
  rubyforge_project:
120
- rubygems_version: 2.6.4
120
+ rubygems_version: 2.5.1
121
121
  signing_key:
122
122
  specification_version: 4
123
123
  summary: Automatically sends notifications via AMQP when a model has been changed.