cony 1.1.1 → 1.2.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.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cony (1.1.1)
4
+ cony (1.2.0)
5
5
  activesupport (>= 3)
6
6
  bunny (~> 1.1.7)
7
7
 
data/README.md CHANGED
@@ -45,14 +45,14 @@ end
45
45
  ## Message Format
46
46
 
47
47
  The routing key for the messages have a format of
48
- `model_name_with_underscore.mutation.action`.
48
+ `model_name_with_underscore.mutation.event_type`.
49
49
 
50
50
  It will append the id of the model and the detected changes to the payload of the message.
51
51
 
52
52
  ### Create
53
53
 
54
54
  A create for a `Example::Model` model will have a routing key of
55
- `example/model.mutation.create`.
55
+ `example/model.mutation.created`.
56
56
 
57
57
  The sent JSON structure will look like this:
58
58
 
@@ -62,7 +62,9 @@ The sent JSON structure will look like this:
62
62
  "changes": [
63
63
  { "name": { "old": null, "new": "value" } },
64
64
  { "description": { "old": null, "new": "value" } }
65
- ]
65
+ ],
66
+ "event": "created",
67
+ "model": "Example::Model",
66
68
  }
67
69
  ```
68
70
 
@@ -70,7 +72,7 @@ The sent JSON structure will look like this:
70
72
  ### Update
71
73
 
72
74
  An update for a `Example::Model` model will have a routing key of
73
- `example/model.mutation.update`.
75
+ `example/model.mutation.updated`.
74
76
 
75
77
  The sent JSON structure will look like this:
76
78
 
@@ -79,7 +81,9 @@ The sent JSON structure will look like this:
79
81
  "id": 1337,
80
82
  "changes": [
81
83
  { "name": { "old": "old-value", "new": "new-value" } }
82
- ]
84
+ ],
85
+ "event": "updated",
86
+ "model": "Example::Model",
83
87
  }
84
88
  ```
85
89
 
@@ -87,14 +91,16 @@ The sent JSON structure will look like this:
87
91
  ### Destroy
88
92
 
89
93
  A destroy event for a `Example::Model` model will have a routing key of
90
- `example/model.mutation.destroy`.
94
+ `example/model.mutation.destroyed`.
91
95
 
92
96
  The sent JSON structure will look like this:
93
97
 
94
98
  ```json
95
99
  {
96
100
  "id": 1337,
97
- "changes": []
101
+ "changes": [],
102
+ "event": "destroyed",
103
+ "model": "Example::Model",
98
104
  }
99
105
  ```
100
106
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.1
1
+ 1.2.0
@@ -15,15 +15,15 @@ module Cony
15
15
  end
16
16
 
17
17
  def cony_send_create_notify
18
- publish(:create)
18
+ publish(:created)
19
19
  end
20
20
 
21
21
  def cony_send_update_notify
22
- publish(:update)
22
+ publish(:updated)
23
23
  end
24
24
 
25
25
  def cony_send_destroy_notify
26
- publish(:destroy)
26
+ publish(:destroyed)
27
27
  end
28
28
 
29
29
 
@@ -31,7 +31,7 @@ module Cony
31
31
  def publish(type)
32
32
  return if Cony.config.test_mode
33
33
  amqp_connection.publish(
34
- {id: self.id, changes: cony_changes},
34
+ {id: self.id, changes: cony_changes, model: self.class.name, event: type},
35
35
  "#{self.class.name.underscore}.mutation.#{type}")
36
36
  end
37
37
 
@@ -8,6 +8,14 @@ describe Cony::ActiveRecord do
8
8
  let(:id) { 1337 }
9
9
  let(:active_record_changes) { {name: ['old', 'new']} }
10
10
  let(:cony_changes) { [{name: {old: 'old', new: 'new'}}] }
11
+ let(:expected_payload) do
12
+ {
13
+ id: id,
14
+ changes: cony_changes,
15
+ model: 'Anonymaus::Klass',
16
+ event: event,
17
+ }
18
+ end
11
19
 
12
20
  let(:model) do
13
21
  eval <<-EOF
@@ -31,22 +39,25 @@ describe Cony::ActiveRecord do
31
39
  subject { model.new }
32
40
 
33
41
  describe '#cony_send_create_notify' do
42
+ let(:event) { :created }
34
43
  it 'uses the amqp connection to send the notify' do
35
- amqp_connection.should_receive(:publish).with({id: id, changes: cony_changes}, 'anonymaus/klass.mutation.create')
44
+ amqp_connection.should_receive(:publish).with(expected_payload, 'anonymaus/klass.mutation.created')
36
45
  subject.cony_send_create_notify
37
46
  end
38
47
  end
39
48
 
40
49
  describe '#cony_send_update_notify' do
50
+ let(:event) { :updated }
41
51
  it 'uses the amqp connection to send the notify' do
42
- amqp_connection.should_receive(:publish).with({id: id, changes: cony_changes}, 'anonymaus/klass.mutation.update')
52
+ amqp_connection.should_receive(:publish).with(expected_payload, 'anonymaus/klass.mutation.updated')
43
53
  subject.cony_send_update_notify
44
54
  end
45
55
  end
46
56
 
47
57
  describe '#cony_send_destroy_notify' do
58
+ let(:event) { :destroyed }
48
59
  it 'uses the amqp connection to send the notify' do
49
- amqp_connection.should_receive(:publish).with({id: id, changes: cony_changes}, 'anonymaus/klass.mutation.destroy')
60
+ amqp_connection.should_receive(:publish).with(expected_payload, 'anonymaus/klass.mutation.destroyed')
50
61
  subject.cony_send_destroy_notify
51
62
  end
52
63
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cony
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -120,7 +120,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
120
120
  version: '0'
121
121
  segments:
122
122
  - 0
123
- hash: 191826322772385537
123
+ hash: -1375090389651372682
124
124
  required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  none: false
126
126
  requirements:
@@ -129,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
129
  version: '0'
130
130
  segments:
131
131
  - 0
132
- hash: 191826322772385537
132
+ hash: -1375090389651372682
133
133
  requirements: []
134
134
  rubyforge_project:
135
135
  rubygems_version: 1.8.23