wisper-activerecord 0.3.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- data/.travis.yml +16 -2
- data/CHANGELOG.md +11 -0
- data/README.md +19 -16
- data/gemfiles/activerecord-5.0 +12 -0
- data/lib/wisper/active_record/publisher.rb +2 -18
- data/lib/wisper/active_record/version.rb +1 -1
- data/spec/wisper/activerecord_spec.rb +0 -42
- data/wisper-activerecord.gemspec +1 -1
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fad745a4966f059933058249bf4d591d34e409fc
|
4
|
+
data.tar.gz: ff536bef647c1446b384739b90f39412edb39e93
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83206ee20a2f334129eabf67766f7598fb841d838875364ffc6b5722e15fff1f54b7f78490da89e9d112942da8dc0dfae226deeafe3e765e9727b1bf1a2a2d79
|
7
|
+
data.tar.gz: 2da651ee69588854c1a809b651e08c63ff7215d1284aade3d6c1dc6dd93d936f3a727a50d442dfaa8aa6f7d02d68aeac6d286e1e186ff43eb35f4c5934ad7b7b
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.4
|
data/.travis.yml
CHANGED
@@ -1,11 +1,25 @@
|
|
1
1
|
language: ruby
|
2
2
|
bundler_args: --without=metrics
|
3
3
|
script: bundle exec rspec spec
|
4
|
+
sudo: false
|
4
5
|
gemfile:
|
5
6
|
- gemfiles/activerecord-3.0
|
6
7
|
- gemfiles/activerecord-4.0
|
8
|
+
- gemfiles/activerecord-5.0
|
7
9
|
rvm:
|
8
|
-
-
|
9
|
-
-
|
10
|
+
- 1.9.3
|
11
|
+
- 2.4.0
|
10
12
|
- jruby
|
11
13
|
- rbx-2
|
14
|
+
matrix:
|
15
|
+
exclude:
|
16
|
+
- rvm: 1.9.3
|
17
|
+
gemfile: gemfiles/activerecord-5.0
|
18
|
+
- rvm: jruby
|
19
|
+
gemfile: gemfiles/activerecord-5.0
|
20
|
+
- rvm: rbx-2
|
21
|
+
gemfile: gemfiles/activerecord-5.0
|
22
|
+
- rvm: 2.4.0
|
23
|
+
gemfile: gemfiles/activerecord-3.0
|
24
|
+
allow_failures:
|
25
|
+
- rvm: rbx-2
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
## unreleased
|
2
|
+
|
3
|
+
## 1.0.0 (19/May/2017)
|
4
|
+
|
5
|
+
Authors: Kris Leech, robwilliams
|
6
|
+
|
7
|
+
* Remove deprecated #commit method (breaking change)
|
8
|
+
* Update to Wisper 2.0 (non-breaking, but we will released a major anyway)
|
9
|
+
* fixed README example
|
10
|
+
* document fixes
|
11
|
+
|
1
12
|
## 0.3.0 (5 Feb 2015)
|
2
13
|
|
3
14
|
* Fixed README (Thomas Brus / thomasbrus)
|
data/README.md
CHANGED
@@ -61,6 +61,7 @@ Please refer to the [Wisper README](https://github.com/krisleech/wisper) for ful
|
|
61
61
|
The events which are automatically broadcast are:
|
62
62
|
|
63
63
|
* `after_create`
|
64
|
+
* `after_update`
|
64
65
|
* `after_destroy`
|
65
66
|
* `create_<model_name>_{successful, failed}`
|
66
67
|
* `update_<model_name>_{successful, failed}`
|
@@ -92,9 +93,9 @@ class MeetingsController < ApplicationController
|
|
92
93
|
|
93
94
|
def create
|
94
95
|
@meeting = Meeting.new(params[:meeting])
|
95
|
-
@meeting.subscribe(Auditor.
|
96
|
-
@meeting.on(:
|
97
|
-
@meeting.on(:
|
96
|
+
@meeting.subscribe(Auditor.new)
|
97
|
+
@meeting.on(:create_meeting_successful) { redirect_to meeting_path }
|
98
|
+
@meeting.on(:create_meeting_failed) { render action: :new }
|
98
99
|
@meeting.save
|
99
100
|
end
|
100
101
|
|
@@ -104,9 +105,9 @@ class MeetingsController < ApplicationController
|
|
104
105
|
|
105
106
|
def update
|
106
107
|
@meeting = Meeting.find(params[:id])
|
107
|
-
@meeting.subscribe(Auditor.
|
108
|
-
@meeting.on(:
|
109
|
-
@meeting.on(:
|
108
|
+
@meeting.subscribe(Auditor.new)
|
109
|
+
@meeting.on(:update_meeting_successful) { redirect_to meeting_path }
|
110
|
+
@meeting.on(:update_meeting_failed) { render :action => :edit }
|
110
111
|
@meeting.update_attributes(params[:meeting])
|
111
112
|
end
|
112
113
|
end
|
@@ -121,13 +122,6 @@ you can still use `if @meeting.save` if you prefer.
|
|
121
122
|
|
122
123
|
```ruby
|
123
124
|
class Auditor
|
124
|
-
include Singleton
|
125
|
-
|
126
|
-
attr_accessor :audit
|
127
|
-
|
128
|
-
def initialize
|
129
|
-
@audit = []
|
130
|
-
end
|
131
125
|
|
132
126
|
def after_create(subject)
|
133
127
|
push_audit_for('create', subject)
|
@@ -142,13 +136,13 @@ class Auditor
|
|
142
136
|
end
|
143
137
|
|
144
138
|
def self.audit
|
145
|
-
|
139
|
+
@audit ||= []
|
146
140
|
end
|
147
141
|
|
148
142
|
private
|
149
143
|
|
150
144
|
def push_audit_for(action, subject)
|
151
|
-
audit.push(audit_for(action, subject))
|
145
|
+
self.class.audit.push(audit_for(action, subject))
|
152
146
|
end
|
153
147
|
|
154
148
|
def audit_for(action, subject)
|
@@ -179,9 +173,18 @@ meeting.save
|
|
179
173
|
Auditor.audit # => [...]
|
180
174
|
```
|
181
175
|
|
176
|
+
## Notes on Testing
|
177
|
+
|
178
|
+
### ActiveRecord <= 4.0
|
179
|
+
|
180
|
+
This gem makes use of ActiveRecord's `after_commit` lifecycle hook to broadcast
|
181
|
+
events, which will create issues when testing with transactional fixtures.
|
182
|
+
Unless you also include the [test_after_commit gem](https://github.com/grosser/test_after_commit)
|
183
|
+
ActiveRecord models will not broadcast any lifecycle events within your tests.
|
184
|
+
|
182
185
|
## Compatibility
|
183
186
|
|
184
|
-
Tested on
|
187
|
+
Tested on CRuby, Rubinius and JRuby for ActiveRecord ~> 3.0, ~> 4.0, and ~> 5.0.
|
185
188
|
|
186
189
|
See the CI [build status](https://travis-ci.org/krisleech/wisper-activerecord) for more information.
|
187
190
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'wisper'
|
2
|
+
|
1
3
|
module Wisper
|
2
4
|
module ActiveRecord
|
3
5
|
module Publisher
|
@@ -14,19 +16,6 @@ module Wisper
|
|
14
16
|
after_rollback :after_rollback_broadcast
|
15
17
|
end
|
16
18
|
|
17
|
-
def commit(_attributes = nil)
|
18
|
-
warn "[DEPRECATED] use save, create, update_attributes as usual"
|
19
|
-
assign_attributes(_attributes) if _attributes.present?
|
20
|
-
save
|
21
|
-
end
|
22
|
-
|
23
|
-
module ClassMethods
|
24
|
-
def commit(_attributes = nil)
|
25
|
-
warn "[DEPRECATED] use save, create, update_attributes as usual"
|
26
|
-
new(_attributes).save
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
19
|
private
|
31
20
|
|
32
21
|
def after_validation_broadcast
|
@@ -54,11 +43,6 @@ module Wisper
|
|
54
43
|
broadcast("#{broadcast_model_name_key}_committed", self)
|
55
44
|
end
|
56
45
|
|
57
|
-
def after_commit_broadcast
|
58
|
-
broadcast(:after_commit, self)
|
59
|
-
broadcast("#{broadcast_model_name_key}_committed", self)
|
60
|
-
end
|
61
|
-
|
62
46
|
def after_rollback_broadcast
|
63
47
|
broadcast(:after_rollback, self)
|
64
48
|
end
|
@@ -9,48 +9,6 @@ describe 'ActiveRecord' do
|
|
9
9
|
expect(Wisper.model).to eq Wisper::ActiveRecord::Publisher
|
10
10
|
end
|
11
11
|
|
12
|
-
describe '.commit' do # DEPRECATED
|
13
|
-
describe 'when creating' do
|
14
|
-
context 'and model is valid' do
|
15
|
-
it 'publishes create_<model_name>_successful event to listener' do
|
16
|
-
expect(listener).to receive(:create_meeting_successful).with(instance_of(model_class))
|
17
|
-
model_class.subscribe(listener)
|
18
|
-
model_class.commit
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
context 'and model is not valid' do
|
23
|
-
it 'publishes create_<model_name>_failed event to listener' do
|
24
|
-
expect(listener).to receive(:create_meeting_failed).with(instance_of(model_class))
|
25
|
-
model_class.subscribe(listener)
|
26
|
-
model_class.commit(title: nil)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe 'when updating' do
|
32
|
-
before { model_class.create! }
|
33
|
-
|
34
|
-
let(:model) { model_class.first }
|
35
|
-
|
36
|
-
context 'and model is valid' do
|
37
|
-
it 'publishes update_<model_name>_successful event to listener' do
|
38
|
-
expect(listener).to receive(:update_meeting_successful).with(instance_of(model_class))
|
39
|
-
model_class.subscribe(listener)
|
40
|
-
model.commit(title: 'foo')
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
context 'and model is not valid' do
|
45
|
-
it 'publishes update_<model_name>_failed event to listener' do
|
46
|
-
expect(listener).to receive(:update_meeting_failed).with(instance_of(model_class))
|
47
|
-
model_class.subscribe(listener)
|
48
|
-
model.commit(title: nil)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
12
|
describe 'create' do
|
55
13
|
it 'publishes an after_create event to listener' do
|
56
14
|
expect(listener).to receive(:after_create).with(instance_of(model_class))
|
data/wisper-activerecord.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wisper-activerecord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kris Leech
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-05-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: wisper
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2.0'
|
20
20
|
type: :runtime
|
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: '
|
26
|
+
version: '2.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activerecord
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -47,6 +47,7 @@ extra_rdoc_files: []
|
|
47
47
|
files:
|
48
48
|
- ".gitignore"
|
49
49
|
- ".rspec"
|
50
|
+
- ".ruby-version"
|
50
51
|
- ".travis.yml"
|
51
52
|
- CHANGELOG.md
|
52
53
|
- Gemfile
|
@@ -55,6 +56,7 @@ files:
|
|
55
56
|
- Rakefile
|
56
57
|
- gemfiles/activerecord-3.0
|
57
58
|
- gemfiles/activerecord-4.0
|
59
|
+
- gemfiles/activerecord-5.0
|
58
60
|
- lib/wisper/active_record.rb
|
59
61
|
- lib/wisper/active_record/publisher.rb
|
60
62
|
- lib/wisper/active_record/version.rb
|
@@ -85,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
87
|
version: '0'
|
86
88
|
requirements: []
|
87
89
|
rubyforge_project:
|
88
|
-
rubygems_version: 2.
|
90
|
+
rubygems_version: 2.6.8
|
89
91
|
signing_key:
|
90
92
|
specification_version: 4
|
91
93
|
summary: Subscribe to changes on ActiveRecord models
|