downstream 1.2.0 → 1.3.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.
- checksums.yaml +4 -4
- data/README.md +14 -0
- data/lib/downstream/pubsub_adapters/abstract_pubsub.rb +2 -0
- data/lib/downstream/pubsub_adapters/stateless/pubsub.rb +3 -4
- data/lib/downstream/pubsub_adapters/stateless/subscriber.rb +14 -1
- data/lib/downstream/rspec/have_enqueued_async_subscriber_for.rb +49 -0
- data/lib/downstream/rspec.rb +1 -0
- data/lib/downstream/subscriber_job.rb +9 -0
- data/lib/downstream/version.rb +1 -1
- data/lib/downstream.rb +1 -1
- metadata +4 -3
- data/lib/downstream/pubsub_adapters/stateless/subscriber_job.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ceb9c34b8c3146b89ff1a6668ebadc7b4306abdf5b113fca512b1d2fb27cb64
|
4
|
+
data.tar.gz: 18986657d7665ecd183224025d72ace1013c6ebc3351792863cacca250ff16e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 880ea8f11ba29203402f975c523ac695af7befd8c5824a38805d4c48deec84123f0331f354296fe741cfd1341ba29a38c1f6273a4cdb0dccafc312536aa72de1
|
7
|
+
data.tar.gz: 06faab1f5d2a5d4be4d5a6e82109c197de85e7306f8b6a11d64d304206bf8fe220a3bd1b74dd61a25cb4cf104f1cffae9d5514aea75c60823c6d687e58fe0ac2
|
data/README.md
CHANGED
@@ -131,6 +131,12 @@ store.subscribe OnProfileCreated::DoThat, async: {queue: :low_priority}
|
|
131
131
|
|
132
132
|
You can test subscribers as normal Ruby objects.
|
133
133
|
|
134
|
+
First, load testing helpers in the `spec_helper.rb`:
|
135
|
+
|
136
|
+
```ruby
|
137
|
+
require "downstream/rspec"
|
138
|
+
```
|
139
|
+
|
134
140
|
To test that a given subscriber exists, you can do the following:
|
135
141
|
|
136
142
|
```ruby
|
@@ -143,6 +149,14 @@ it "is subscribed to some event" do
|
|
143
149
|
|
144
150
|
expect(MySubscriberService).to have_received(:call).with(event)
|
145
151
|
end
|
152
|
+
|
153
|
+
# for asynchronous subscriptions
|
154
|
+
it "is subscribed to some event" do
|
155
|
+
event = MyEvent.new(some: "data")
|
156
|
+
expect { Downstream.publish event }.
|
157
|
+
to have_enqueued_async_subscriber_for(MySubscriberService).
|
158
|
+
with(event)
|
159
|
+
end
|
146
160
|
```
|
147
161
|
|
148
162
|
To test publishing use `have_published_event` matcher:
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "active_support/notifications"
|
2
4
|
require_relative "subscriber"
|
3
5
|
|
@@ -5,10 +7,7 @@ module Downstream
|
|
5
7
|
module Stateless
|
6
8
|
class Pubsub < AbstractPubsub
|
7
9
|
def subscribe(identifier, callable, async: false)
|
8
|
-
|
9
|
-
identifier,
|
10
|
-
Subscriber.new(callable, async: async)
|
11
|
-
)
|
10
|
+
Subscriber.new(callable, async: async).tap { |s| s.subscribe(identifier) }
|
12
11
|
end
|
13
12
|
|
14
13
|
def subscribed(identifier, callable, &block)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Downstream
|
4
4
|
module Stateless
|
@@ -38,8 +38,21 @@ module Downstream
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
+
def subscribe(identifier)
|
42
|
+
@notification_subscriber = ActiveSupport::Notifications.subscribe(
|
43
|
+
identifier,
|
44
|
+
self
|
45
|
+
)
|
46
|
+
end
|
47
|
+
|
48
|
+
def unsubscribe
|
49
|
+
ActiveSupport::Notifications.unsubscribe(notification_subscriber)
|
50
|
+
end
|
51
|
+
|
41
52
|
private
|
42
53
|
|
54
|
+
attr_reader :notification_subscriber
|
55
|
+
|
43
56
|
def async_queue_name
|
44
57
|
return @async_queue_name if defined?(@async_queue_name)
|
45
58
|
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rspec/rails/matchers/active_job"
|
4
|
+
|
5
|
+
module Downstream
|
6
|
+
class HaveEnqueuedAsyncSubscriberFor < RSpec::Rails::Matchers::ActiveJob::HaveEnqueuedJob
|
7
|
+
class EventMatcher
|
8
|
+
include ::RSpec::Matchers::Composable
|
9
|
+
|
10
|
+
attr_reader :event
|
11
|
+
|
12
|
+
def initialize(event)
|
13
|
+
@event = event
|
14
|
+
end
|
15
|
+
|
16
|
+
def matches?(actual)
|
17
|
+
actual == event
|
18
|
+
end
|
19
|
+
|
20
|
+
def description
|
21
|
+
"be #{event.inspect}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
attr_reader :callable
|
26
|
+
|
27
|
+
def initialize(callable)
|
28
|
+
@callable = callable
|
29
|
+
super(SubscriberJob)
|
30
|
+
end
|
31
|
+
|
32
|
+
def with(event)
|
33
|
+
super(EventMatcher.new(event), callable.name)
|
34
|
+
end
|
35
|
+
|
36
|
+
def matches?(proc)
|
37
|
+
raise ArgumentError, "have_enqueued_async_subscriber_for only supports block expectations" unless Proc === proc
|
38
|
+
super
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
RSpec.configure do |config|
|
44
|
+
config.include(Module.new do
|
45
|
+
def have_enqueued_async_subscriber_for(*args)
|
46
|
+
Downstream::HaveEnqueuedAsyncSubscriberFor.new(*args)
|
47
|
+
end
|
48
|
+
end)
|
49
|
+
end
|
data/lib/downstream/rspec.rb
CHANGED
data/lib/downstream/version.rb
CHANGED
data/lib/downstream.rb
CHANGED
@@ -9,7 +9,7 @@ require "after_commit_everywhere"
|
|
9
9
|
require "downstream/config"
|
10
10
|
require "downstream/event"
|
11
11
|
require "downstream/pubsub_adapters/abstract_pubsub"
|
12
|
-
require "downstream/
|
12
|
+
require "downstream/subscriber_job"
|
13
13
|
|
14
14
|
module Downstream
|
15
15
|
class << self
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: downstream
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- merkushin.m.s@gmail.com
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-11-
|
12
|
+
date: 2021-11-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: after_commit_everywhere
|
@@ -194,9 +194,10 @@ files:
|
|
194
194
|
- lib/downstream/pubsub_adapters/abstract_pubsub.rb
|
195
195
|
- lib/downstream/pubsub_adapters/stateless/pubsub.rb
|
196
196
|
- lib/downstream/pubsub_adapters/stateless/subscriber.rb
|
197
|
-
- lib/downstream/pubsub_adapters/stateless/subscriber_job.rb
|
198
197
|
- lib/downstream/rspec.rb
|
198
|
+
- lib/downstream/rspec/have_enqueued_async_subscriber_for.rb
|
199
199
|
- lib/downstream/rspec/have_published_event.rb
|
200
|
+
- lib/downstream/subscriber_job.rb
|
200
201
|
- lib/downstream/version.rb
|
201
202
|
homepage: https://github.com/bibendi/downstream
|
202
203
|
licenses:
|