marples 1.0.0 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -0
- data/LICENCE +20 -0
- data/README.md +24 -0
- data/Rakefile +8 -0
- data/lib/marples.rb +0 -1
- data/lib/marples/client.rb +2 -1
- data/lib/marples/model_action_broadcast.rb +9 -4
- data/lib/marples/version.rb +1 -1
- data/marples.gemspec +4 -1
- data/test/support/notifications.rb +29 -0
- data/test/support/rails.rb +5 -0
- data/test/support/widget.rb +3 -0
- data/test/test_model_action_broadcast.rb +78 -0
- metadata +61 -13
data/Gemfile
CHANGED
data/LICENCE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 HM Government
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -75,3 +75,27 @@ just use the model like you normally would:
|
|
75
75
|
s.add_filling "cheese"
|
76
76
|
s.add_filling "ham"
|
77
77
|
s.save!
|
78
|
+
|
79
|
+
|
80
|
+
## Testing
|
81
|
+
|
82
|
+
You probably don't want to provide a broker to your test environment.
|
83
|
+
|
84
|
+
Marples provides `Marples::NullTransport` which you can use in place of your
|
85
|
+
real transport when you don't care what happens to the messages:
|
86
|
+
|
87
|
+
null_transport = Marples::NullTransport.instance
|
88
|
+
Marples::Client.new transport: null_transport, client_name: 'whatever'
|
89
|
+
|
90
|
+
|
91
|
+
## Semantic Versioning
|
92
|
+
|
93
|
+
To give you confidence when deciding which version of Marples to depend on we
|
94
|
+
will be using the Semantic Versioning scheme described at http://semver.org/.
|
95
|
+
|
96
|
+
|
97
|
+
## Licencing information
|
98
|
+
|
99
|
+
It's not adviseable to use code that's not had the terms of its licence made
|
100
|
+
explicit. This project is released under the MIT licence, a copy of which
|
101
|
+
should be distributed with this project in the LICENCE file.
|
data/Rakefile
CHANGED
data/lib/marples.rb
CHANGED
data/lib/marples/client.rb
CHANGED
@@ -7,6 +7,7 @@ module Marples
|
|
7
7
|
|
8
8
|
def initialize *args
|
9
9
|
if args[0].kind_of? Hash
|
10
|
+
options = args.shift
|
10
11
|
self.transport = options[:transport]
|
11
12
|
self.client_name = options[:client_name]
|
12
13
|
self.logger = options[:logger]
|
@@ -18,7 +19,7 @@ module Marples
|
|
18
19
|
"deprecated and will be removed."
|
19
20
|
end
|
20
21
|
raise "You must provide a transport" if transport.nil?
|
21
|
-
self.logger
|
22
|
+
self.logger = NullLogger.instance if logger.nil?
|
22
23
|
end
|
23
24
|
|
24
25
|
def join
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module Marples
|
2
2
|
module ModelActionBroadcast
|
3
|
-
|
3
|
+
TRANSACTION_ACTIONS = :create, :update, :destroy
|
4
|
+
CALLBACKS = TRANSACTION_ACTIONS + [:save, :commit]
|
4
5
|
|
5
6
|
def self.included base
|
6
7
|
base.class_eval do
|
@@ -18,8 +19,12 @@ module Marples
|
|
18
19
|
callback_action = callback.to_s =~ /e$/ ? "#{callback}d" : "#{callback}ed"
|
19
20
|
after_callback = "after_#{callback}"
|
20
21
|
next unless respond_to? after_callback
|
21
|
-
|
22
|
-
|
22
|
+
|
23
|
+
notify = lambda { |record| record.class.marples_client.send callback_action, record }
|
24
|
+
if TRANSACTION_ACTIONS.include?(callback) && respond_to?(:after_commit)
|
25
|
+
after_commit :on => callback, ¬ify
|
26
|
+
else
|
27
|
+
send after_callback, ¬ify
|
23
28
|
end
|
24
29
|
end
|
25
30
|
|
@@ -28,7 +33,7 @@ module Marples
|
|
28
33
|
end
|
29
34
|
|
30
35
|
def self.build_marples_client
|
31
|
-
Marples::Client.new
|
36
|
+
Marples::Client.new transport: marples_transport,
|
32
37
|
client_name: marples_client_name, logger: marples_logger
|
33
38
|
end
|
34
39
|
end
|
data/lib/marples/version.rb
CHANGED
data/marples.gemspec
CHANGED
@@ -17,7 +17,10 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
18
|
s.require_paths = ["lib"]
|
19
19
|
|
20
|
-
s.add_runtime_dependency "pethau", ">= 0.0.2"
|
21
20
|
s.add_runtime_dependency "null_logger"
|
22
21
|
s.add_runtime_dependency "activesupport"
|
22
|
+
s.add_runtime_dependency 'i18n'
|
23
|
+
s.add_development_dependency 'rake'
|
24
|
+
s.add_development_dependency 'activerecord'
|
25
|
+
s.add_development_dependency 'activerecord-nulldb-adapter'
|
23
26
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class FakeTransport
|
2
|
+
include Singleton
|
3
|
+
|
4
|
+
attr_reader :notifications
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
flush
|
8
|
+
end
|
9
|
+
|
10
|
+
def flush
|
11
|
+
self.notifications = []
|
12
|
+
end
|
13
|
+
|
14
|
+
def publish(destination, message, headers = {})
|
15
|
+
notifications << { destination: destination, message: Hash.from_xml(message), headers: headers }
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
attr_writer :notifications
|
20
|
+
end
|
21
|
+
|
22
|
+
def flush_notifications
|
23
|
+
FakeTransport.instance.flush
|
24
|
+
end
|
25
|
+
|
26
|
+
def latest_notification_with_destination(destination)
|
27
|
+
notifications = FakeTransport.instance.notifications
|
28
|
+
notifications.reverse.detect { |n| n[:destination] == destination }
|
29
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'marples'
|
3
|
+
require 'marples/model_action_broadcast'
|
4
|
+
require 'active_record'
|
5
|
+
|
6
|
+
require 'support/rails'
|
7
|
+
require 'support/notifications'
|
8
|
+
require 'support/widget'
|
9
|
+
|
10
|
+
class TestModelActionBroadcast < Test::Unit::TestCase
|
11
|
+
def setup
|
12
|
+
ActiveRecord::Base.establish_connection :adapter => :nulldb
|
13
|
+
ActiveRecord::Schema.define do
|
14
|
+
create_table :widgets
|
15
|
+
end
|
16
|
+
|
17
|
+
Widget.marples_transport = FakeTransport.instance
|
18
|
+
Widget.marples_client_name = 'widgetotron'
|
19
|
+
|
20
|
+
FakeTransport.instance.flush
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_created_notification_is_sent_on_create
|
24
|
+
assert_nil latest_notification_with_destination '/topic/marples.widgetotron.widgets.created'
|
25
|
+
Widget.create!
|
26
|
+
assert_not_nil latest_notification_with_destination '/topic/marples.widgetotron.widgets.created'
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_updated_notification_is_sent_on_update
|
30
|
+
widget = Widget.create!
|
31
|
+
|
32
|
+
assert_nil latest_notification_with_destination '/topic/marples.widgetotron.widgets.updated'
|
33
|
+
widget.save!
|
34
|
+
assert_not_nil latest_notification_with_destination '/topic/marples.widgetotron.widgets.updated'
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_destroyed_notification_is_sent_on_destroy
|
38
|
+
widget = Widget.create!
|
39
|
+
|
40
|
+
assert_nil latest_notification_with_destination '/topic/marples.widgetotron.widgets.destroyed'
|
41
|
+
widget.destroy
|
42
|
+
assert_not_nil latest_notification_with_destination '/topic/marples.widgetotron.widgets.destroyed'
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_created_notification_is_sent_after_commit
|
46
|
+
Widget.transaction do
|
47
|
+
assert_nil latest_notification_with_destination '/topic/marples.widgetotron.widgets.created'
|
48
|
+
Widget.create!
|
49
|
+
assert_nil latest_notification_with_destination '/topic/marples.widgetotron.widgets.created'
|
50
|
+
end
|
51
|
+
|
52
|
+
assert_not_nil latest_notification_with_destination '/topic/marples.widgetotron.widgets.created'
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_updated_notification_is_sent_after_commit
|
56
|
+
widget = Widget.create!
|
57
|
+
|
58
|
+
Widget.transaction do
|
59
|
+
assert_nil latest_notification_with_destination '/topic/marples.widgetotron.widgets.updated'
|
60
|
+
widget.save!
|
61
|
+
assert_nil latest_notification_with_destination '/topic/marples.widgetotron.widgets.updated'
|
62
|
+
end
|
63
|
+
|
64
|
+
assert_not_nil latest_notification_with_destination '/topic/marples.widgetotron.widgets.updated'
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_destroyed_notification_is_sent_after_commit
|
68
|
+
widget = Widget.create!
|
69
|
+
|
70
|
+
Widget.transaction do
|
71
|
+
assert_nil latest_notification_with_destination '/topic/marples.widgetotron.widgets.destroyed'
|
72
|
+
widget.destroy
|
73
|
+
assert_nil latest_notification_with_destination '/topic/marples.widgetotron.widgets.destroyed'
|
74
|
+
end
|
75
|
+
|
76
|
+
assert_not_nil latest_notification_with_destination '/topic/marples.widgetotron.widgets.destroyed'
|
77
|
+
end
|
78
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: marples
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,22 +10,22 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2011-11-
|
13
|
+
date: 2011-11-25 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
17
|
-
requirement: &
|
16
|
+
name: null_logger
|
17
|
+
requirement: &70212070634820 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 0
|
22
|
+
version: '0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70212070634820
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
|
-
name:
|
28
|
-
requirement: &
|
27
|
+
name: activesupport
|
28
|
+
requirement: &70212070633860 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70212070633860
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
|
-
name:
|
39
|
-
requirement: &
|
38
|
+
name: i18n
|
39
|
+
requirement: &70212070632780 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,7 +44,40 @@ dependencies:
|
|
44
44
|
version: '0'
|
45
45
|
type: :runtime
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *70212070632780
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: rake
|
50
|
+
requirement: &70212070631880 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
type: :development
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *70212070631880
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: activerecord
|
61
|
+
requirement: &70212070630920 !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
type: :development
|
68
|
+
prerelease: false
|
69
|
+
version_requirements: *70212070630920
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: activerecord-nulldb-adapter
|
72
|
+
requirement: &70212070629780 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: *70212070629780
|
48
81
|
description: Message destination arbiter
|
49
82
|
email:
|
50
83
|
- craig@barkingiguana.com
|
@@ -55,6 +88,7 @@ extra_rdoc_files: []
|
|
55
88
|
files:
|
56
89
|
- .gitignore
|
57
90
|
- Gemfile
|
91
|
+
- LICENCE
|
58
92
|
- README.md
|
59
93
|
- Rakefile
|
60
94
|
- lib/marples.rb
|
@@ -63,6 +97,10 @@ files:
|
|
63
97
|
- lib/marples/null_transport.rb
|
64
98
|
- lib/marples/version.rb
|
65
99
|
- marples.gemspec
|
100
|
+
- test/support/notifications.rb
|
101
|
+
- test/support/rails.rb
|
102
|
+
- test/support/widget.rb
|
103
|
+
- test/test_model_action_broadcast.rb
|
66
104
|
homepage: ''
|
67
105
|
licenses: []
|
68
106
|
post_install_message:
|
@@ -75,16 +113,26 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
75
113
|
- - ! '>='
|
76
114
|
- !ruby/object:Gem::Version
|
77
115
|
version: '0'
|
116
|
+
segments:
|
117
|
+
- 0
|
118
|
+
hash: 2905283016913556502
|
78
119
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
120
|
none: false
|
80
121
|
requirements:
|
81
122
|
- - ! '>='
|
82
123
|
- !ruby/object:Gem::Version
|
83
124
|
version: '0'
|
125
|
+
segments:
|
126
|
+
- 0
|
127
|
+
hash: 2905283016913556502
|
84
128
|
requirements: []
|
85
129
|
rubyforge_project: marples
|
86
130
|
rubygems_version: 1.8.10
|
87
131
|
signing_key:
|
88
132
|
specification_version: 3
|
89
133
|
summary: Message destination arbiter
|
90
|
-
test_files:
|
134
|
+
test_files:
|
135
|
+
- test/support/notifications.rb
|
136
|
+
- test/support/rails.rb
|
137
|
+
- test/support/widget.rb
|
138
|
+
- test/test_model_action_broadcast.rb
|