journaled 2.4.0 → 4.0.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 +68 -19
- data/Rakefile +7 -1
- data/app/jobs/journaled/application_job.rb +4 -0
- data/app/jobs/journaled/delivery_job.rb +105 -0
- data/app/models/journaled/change.rb +3 -3
- data/app/models/journaled/change_writer.rb +5 -5
- data/app/models/journaled/event.rb +2 -2
- data/app/models/journaled/writer.rb +8 -6
- data/lib/journaled/engine.rb +5 -0
- data/lib/journaled/relation_change_protection.rb +1 -1
- data/lib/journaled/version.rb +1 -1
- data/lib/journaled.rb +23 -5
- data/spec/dummy/config/application.rb +1 -2
- data/spec/dummy/config/database.yml +4 -19
- data/spec/dummy/config/environments/development.rb +0 -13
- data/spec/dummy/config/environments/test.rb +3 -5
- data/spec/dummy/db/schema.rb +3 -16
- data/spec/{models/journaled/delivery_spec.rb → jobs/journaled/delivery_job_spec.rb} +82 -28
- data/spec/lib/journaled_spec.rb +39 -0
- data/spec/models/database_change_protection_spec.rb +19 -25
- data/spec/models/journaled/change_writer_spec.rb +10 -10
- data/spec/models/journaled/event_spec.rb +4 -4
- data/spec/models/journaled/writer_spec.rb +18 -15
- data/spec/rails_helper.rb +1 -2
- data/spec/spec_helper.rb +1 -3
- metadata +31 -74
- data/app/models/journaled/delivery.rb +0 -88
- data/config/routes.rb +0 -2
- data/lib/journaled/enqueue.rb +0 -13
- data/spec/dummy/config/environments/production.rb +0 -78
- data/spec/dummy/config/initializers/assets.rb +0 -8
- data/spec/dummy/db/migrate/20180606205114_create_delayed_jobs.rb +0 -18
- data/spec/support/delayed_job_spec_helper.rb +0 -11
@@ -1,16 +1,11 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
|
-
RSpec.describe Journaled::
|
3
|
+
RSpec.describe Journaled::DeliveryJob do
|
4
4
|
let(:stream_name) { 'test_events' }
|
5
5
|
let(:partition_key) { 'fake_partition_key' }
|
6
6
|
let(:serialized_event) { '{"foo":"bar"}' }
|
7
7
|
let(:kinesis_client) { Aws::Kinesis::Client.new(stub_responses: true) }
|
8
|
-
|
9
|
-
around do |example|
|
10
|
-
with_env(JOURNALED_STREAM_NAME: stream_name) { example.run }
|
11
|
-
end
|
12
|
-
|
13
|
-
subject { described_class.new serialized_event: serialized_event, partition_key: partition_key, app_name: nil }
|
8
|
+
let(:args) { { serialized_event: serialized_event, partition_key: partition_key, stream_name: stream_name } }
|
14
9
|
|
15
10
|
describe '#perform' do
|
16
11
|
let(:return_status_body) { { shard_id: '101', sequence_number: '101123' } }
|
@@ -20,15 +15,21 @@ RSpec.describe Journaled::Delivery do
|
|
20
15
|
allow(Aws::AssumeRoleCredentials).to receive(:new).and_call_original
|
21
16
|
allow(Aws::Kinesis::Client).to receive(:new).and_return kinesis_client
|
22
17
|
kinesis_client.stub_responses(:put_record, return_status_body)
|
18
|
+
allow(kinesis_client).to receive(:put_record).and_call_original
|
23
19
|
|
24
20
|
allow(Journaled).to receive(:enabled?).and_return(true)
|
25
21
|
end
|
26
22
|
|
27
23
|
it 'makes requests to AWS to put the event on the Kinesis with the correct body' do
|
28
|
-
event =
|
24
|
+
event = described_class.perform_now(args)
|
29
25
|
|
30
26
|
expect(event.shard_id).to eq '101'
|
31
27
|
expect(event.sequence_number).to eq '101123'
|
28
|
+
expect(kinesis_client).to have_received(:put_record).with(
|
29
|
+
stream_name: 'test_events',
|
30
|
+
data: '{"foo":"bar"}',
|
31
|
+
partition_key: 'fake_partition_key',
|
32
|
+
)
|
32
33
|
end
|
33
34
|
|
34
35
|
context 'when JOURNALED_IAM_ROLE_ARN is defined' do
|
@@ -59,7 +60,7 @@ RSpec.describe Journaled::Delivery do
|
|
59
60
|
end
|
60
61
|
|
61
62
|
it 'initializes a Kinesis client with assume role credentials' do
|
62
|
-
|
63
|
+
described_class.perform_now(args)
|
63
64
|
|
64
65
|
expect(Aws::AssumeRoleCredentials).to have_received(:new).with(
|
65
66
|
client: aws_sts_client,
|
@@ -69,11 +70,64 @@ RSpec.describe Journaled::Delivery do
|
|
69
70
|
end
|
70
71
|
end
|
71
72
|
|
72
|
-
context 'when the stream name
|
73
|
+
context 'when the stream name is not set' do
|
73
74
|
let(:stream_name) { nil }
|
74
75
|
|
75
76
|
it 'raises an KeyError error' do
|
76
|
-
expect {
|
77
|
+
expect { described_class.perform_now(args) }.to raise_error ArgumentError, 'missing keyword: stream_name'
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
unless Gem::Version.new(Journaled::VERSION) < Gem::Version.new('5.0.0')
|
82
|
+
raise <<~MSG
|
83
|
+
Hey! I see that you're bumping the version to 5.0!
|
84
|
+
|
85
|
+
This is a reminder to:
|
86
|
+
- remove the `app_name` argument (and related logic) from `Journaled::DeliveryJob`,
|
87
|
+
- remove the following app_name test contexts, and
|
88
|
+
- make `stream_name` a required kwarg
|
89
|
+
|
90
|
+
Thanks!
|
91
|
+
MSG
|
92
|
+
end
|
93
|
+
|
94
|
+
context 'when the legacy app_name argument is present but nil' do
|
95
|
+
let(:args) { { serialized_event: serialized_event, partition_key: partition_key, app_name: nil } }
|
96
|
+
|
97
|
+
around do |example|
|
98
|
+
with_env(JOURNALED_STREAM_NAME: 'legacy_stream_name') { example.run }
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'makes requests to AWS to put the event on the Kinesis with the correct body' do
|
102
|
+
event = described_class.perform_now(args)
|
103
|
+
|
104
|
+
expect(event.shard_id).to eq '101'
|
105
|
+
expect(event.sequence_number).to eq '101123'
|
106
|
+
expect(kinesis_client).to have_received(:put_record).with(
|
107
|
+
stream_name: 'legacy_stream_name',
|
108
|
+
data: '{"foo":"bar"}',
|
109
|
+
partition_key: 'fake_partition_key',
|
110
|
+
)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
context 'when the legacy app_name argument is present and has a value' do
|
115
|
+
let(:args) { { serialized_event: serialized_event, partition_key: partition_key, app_name: 'pied_piper' } }
|
116
|
+
|
117
|
+
around do |example|
|
118
|
+
with_env(PIED_PIPER_JOURNALED_STREAM_NAME: 'pied_piper_events') { example.run }
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'makes requests to AWS to put the event on the Kinesis with the correct body' do
|
122
|
+
event = described_class.perform_now(args)
|
123
|
+
|
124
|
+
expect(event.shard_id).to eq '101'
|
125
|
+
expect(event.sequence_number).to eq '101123'
|
126
|
+
expect(kinesis_client).to have_received(:put_record).with(
|
127
|
+
stream_name: 'pied_piper_events',
|
128
|
+
data: '{"foo":"bar"}',
|
129
|
+
partition_key: 'fake_partition_key',
|
130
|
+
)
|
77
131
|
end
|
78
132
|
end
|
79
133
|
|
@@ -83,8 +137,11 @@ RSpec.describe Journaled::Delivery do
|
|
83
137
|
end
|
84
138
|
|
85
139
|
it 'catches the error and re-raises a subclass of NotTrulyExceptionalError and logs about the failure' do
|
86
|
-
|
87
|
-
expect {
|
140
|
+
allow(Rails.logger).to receive(:error)
|
141
|
+
expect { described_class.perform_now(args) }.to raise_error described_class::KinesisTemporaryFailure
|
142
|
+
expect(Rails.logger).to have_received(:error).with(
|
143
|
+
"Kinesis Error - Server Error occurred - Aws::Kinesis::Errors::InternalFailure",
|
144
|
+
).once
|
88
145
|
end
|
89
146
|
end
|
90
147
|
|
@@ -95,7 +152,7 @@ RSpec.describe Journaled::Delivery do
|
|
95
152
|
|
96
153
|
it 'catches the error and re-raises a subclass of NotTrulyExceptionalError and logs about the failure' do
|
97
154
|
allow(Rails.logger).to receive(:error)
|
98
|
-
expect {
|
155
|
+
expect { described_class.perform_now(args) }.to raise_error described_class::KinesisTemporaryFailure
|
99
156
|
expect(Rails.logger).to have_received(:error).with(/\AKinesis Error/).once
|
100
157
|
end
|
101
158
|
end
|
@@ -106,7 +163,7 @@ RSpec.describe Journaled::Delivery do
|
|
106
163
|
end
|
107
164
|
|
108
165
|
it 'raises an error that subclasses Aws::Kinesis::Errors::ServiceError' do
|
109
|
-
expect {
|
166
|
+
expect { described_class.perform_now(args) }.to raise_error Aws::Kinesis::Errors::ServiceError
|
110
167
|
end
|
111
168
|
end
|
112
169
|
|
@@ -116,7 +173,7 @@ RSpec.describe Journaled::Delivery do
|
|
116
173
|
end
|
117
174
|
|
118
175
|
it 'raises an AccessDeniedException error' do
|
119
|
-
expect {
|
176
|
+
expect { described_class.perform_now(args) }.to raise_error Aws::Kinesis::Errors::AccessDeniedException
|
120
177
|
end
|
121
178
|
end
|
122
179
|
|
@@ -126,31 +183,28 @@ RSpec.describe Journaled::Delivery do
|
|
126
183
|
end
|
127
184
|
|
128
185
|
it 'catches the error and re-raises a subclass of NotTrulyExceptionalError and logs about the failure' do
|
129
|
-
|
186
|
+
allow(Rails.logger).to receive(:error)
|
187
|
+
expect { described_class.perform_now(args) }.to raise_error described_class::KinesisTemporaryFailure
|
188
|
+
expect(Rails.logger).to have_received(:error).with(
|
130
189
|
"Kinesis Error - Networking Error occurred - Seahorse::Client::NetworkingError",
|
131
190
|
).once
|
132
|
-
expect { subject.perform }.to raise_error described_class::KinesisTemporaryFailure
|
133
191
|
end
|
134
192
|
end
|
135
193
|
end
|
136
194
|
|
137
|
-
describe "
|
195
|
+
describe ".legacy_computed_stream_name" do
|
138
196
|
context "when app_name is unspecified" do
|
139
|
-
subject { described_class.new serialized_event: serialized_event, partition_key: partition_key, app_name: nil }
|
140
|
-
|
141
197
|
it "is fetched from a prefixed ENV var if specified" do
|
142
198
|
allow(ENV).to receive(:fetch).and_return("expected_stream_name")
|
143
|
-
expect(
|
199
|
+
expect(described_class.legacy_computed_stream_name(app_name: nil)).to eq("expected_stream_name")
|
144
200
|
expect(ENV).to have_received(:fetch).with("JOURNALED_STREAM_NAME")
|
145
201
|
end
|
146
202
|
end
|
147
203
|
|
148
204
|
context "when app_name is specified" do
|
149
|
-
subject { described_class.new serialized_event: serialized_event, partition_key: partition_key, app_name: "my_funky_app_name" }
|
150
|
-
|
151
205
|
it "is fetched from a prefixed ENV var if specified" do
|
152
206
|
allow(ENV).to receive(:fetch).and_return("expected_stream_name")
|
153
|
-
expect(
|
207
|
+
expect(described_class.legacy_computed_stream_name(app_name: "my_funky_app_name")).to eq("expected_stream_name")
|
154
208
|
expect(ENV).to have_received(:fetch).with("MY_FUNKY_APP_NAME_JOURNALED_STREAM_NAME")
|
155
209
|
end
|
156
210
|
end
|
@@ -191,7 +245,7 @@ RSpec.describe Journaled::Delivery do
|
|
191
245
|
end
|
192
246
|
|
193
247
|
it "will set http_open_timeout by default" do
|
194
|
-
expect(subject.kinesis_client_config).to include(http_open_timeout:
|
248
|
+
expect(subject.kinesis_client_config).to include(http_open_timeout: 2)
|
195
249
|
end
|
196
250
|
|
197
251
|
it "will set http_read_timeout by default" do
|
@@ -207,8 +261,8 @@ RSpec.describe Journaled::Delivery do
|
|
207
261
|
|
208
262
|
context "when Journaled.http_open_timeout is specified" do
|
209
263
|
it "will set http_open_timeout by specified value" do
|
210
|
-
allow(Journaled).to receive(:http_open_timeout).and_return(
|
211
|
-
expect(subject.kinesis_client_config).to include(http_open_timeout:
|
264
|
+
allow(Journaled).to receive(:http_open_timeout).and_return(1)
|
265
|
+
expect(subject.kinesis_client_config).to include(http_open_timeout: 1)
|
212
266
|
end
|
213
267
|
end
|
214
268
|
|
data/spec/lib/journaled_spec.rb
CHANGED
@@ -49,4 +49,43 @@ RSpec.describe Journaled do
|
|
49
49
|
expect(described_class.actor_uri).to eq "my actor uri"
|
50
50
|
end
|
51
51
|
end
|
52
|
+
|
53
|
+
describe '.detect_queue_adapter!' do
|
54
|
+
it 'raises an error unless the queue adapter is DB-backed' do
|
55
|
+
expect { described_class.detect_queue_adapter! }.to raise_error <<~MSG
|
56
|
+
Journaled has detected an unsupported ActiveJob queue adapter: `:test`
|
57
|
+
|
58
|
+
Journaled jobs must be enqueued transactionally to your primary database.
|
59
|
+
|
60
|
+
Please install the appropriate gems and set `queue_adapter` to one of the following:
|
61
|
+
- `:delayed`
|
62
|
+
- `:delayed_job`
|
63
|
+
- `:good_job`
|
64
|
+
- `:que`
|
65
|
+
|
66
|
+
Read more at https://github.com/Betterment/journaled
|
67
|
+
MSG
|
68
|
+
end
|
69
|
+
|
70
|
+
context 'when the queue adapter is supported' do
|
71
|
+
before do
|
72
|
+
stub_const("ActiveJob::QueueAdapters::DelayedAdapter", Class.new)
|
73
|
+
ActiveJob::Base.disable_test_adapter
|
74
|
+
ActiveJob::Base.queue_adapter = :delayed
|
75
|
+
end
|
76
|
+
|
77
|
+
around do |example|
|
78
|
+
begin
|
79
|
+
example.run
|
80
|
+
ensure
|
81
|
+
ActiveJob::Base.queue_adapter = :test
|
82
|
+
ActiveJob::Base.enable_test_adapter(ActiveJob::QueueAdapters::TestAdapter.new)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'does not raise an error' do
|
87
|
+
expect { described_class.detect_queue_adapter! }.not_to raise_error
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
52
91
|
end
|
@@ -4,38 +4,42 @@ if Rails::VERSION::MAJOR > 5 || (Rails::VERSION::MAJOR == 5 && Rails::VERSION::M
|
|
4
4
|
# rubocop:disable Rails/SkipsModelValidations
|
5
5
|
RSpec.describe "Raw database change protection" do
|
6
6
|
let(:journaled_class) do
|
7
|
-
Class.new(
|
7
|
+
Class.new(ActiveRecord::Base) do
|
8
8
|
include Journaled::Changes
|
9
9
|
|
10
|
-
|
10
|
+
self.table_name = 'widgets'
|
11
|
+
|
12
|
+
journal_changes_to :name, as: :attempt
|
11
13
|
end
|
12
14
|
end
|
13
15
|
|
14
16
|
let(:journaled_class_with_no_journaled_columns) do
|
15
|
-
Class.new(
|
17
|
+
Class.new(ActiveRecord::Base) do
|
16
18
|
include Journaled::Changes
|
19
|
+
|
20
|
+
self.table_name = 'widgets'
|
17
21
|
end
|
18
22
|
end
|
19
23
|
|
20
24
|
describe "the relation" do
|
21
25
|
describe "#update_all" do
|
22
26
|
it "refuses on journaled columns passed as hash" do
|
23
|
-
expect { journaled_class.update_all(
|
27
|
+
expect { journaled_class.update_all(name: nil) }.to raise_error(/aborted by Journaled/)
|
24
28
|
end
|
25
29
|
|
26
30
|
it "refuses on journaled columns passed as string" do
|
27
|
-
expect { journaled_class.update_all("\"
|
28
|
-
expect { journaled_class.update_all("
|
29
|
-
expect { journaled_class.update_all("
|
30
|
-
expect { journaled_class.update_all("
|
31
|
+
expect { journaled_class.update_all("\"name\" = NULL") }.to raise_error(/aborted by Journaled/)
|
32
|
+
expect { journaled_class.update_all("name = null") }.to raise_error(/aborted by Journaled/)
|
33
|
+
expect { journaled_class.update_all("widgets.name = null") }.to raise_error(/aborted by Journaled/)
|
34
|
+
expect { journaled_class.update_all("other_column = 'name'") }.not_to raise_error
|
31
35
|
end
|
32
36
|
|
33
37
|
it "succeeds on unjournaled columns" do
|
34
|
-
expect { journaled_class.update_all(
|
38
|
+
expect { journaled_class.update_all(other_column: "") }.not_to raise_error
|
35
39
|
end
|
36
40
|
|
37
41
|
it "succeeds when forced on journaled columns" do
|
38
|
-
expect { journaled_class.update_all({
|
42
|
+
expect { journaled_class.update_all({ name: nil }, force: true) }.not_to raise_error
|
39
43
|
end
|
40
44
|
end
|
41
45
|
|
@@ -69,29 +73,19 @@ if Rails::VERSION::MAJOR > 5 || (Rails::VERSION::MAJOR == 5 && Rails::VERSION::M
|
|
69
73
|
end
|
70
74
|
|
71
75
|
describe "an instance" do
|
72
|
-
|
73
|
-
module TestJob
|
74
|
-
def perform
|
75
|
-
"foo"
|
76
|
-
end
|
77
|
-
|
78
|
-
module_function :perform
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
subject { journaled_class.enqueue(job) }
|
76
|
+
subject { journaled_class.create!(name: 'foo') }
|
83
77
|
|
84
78
|
describe "#update_columns" do
|
85
79
|
it "refuses on journaled columns" do
|
86
|
-
expect { subject.update_columns(
|
80
|
+
expect { subject.update_columns(name: nil) }.to raise_error(/aborted by Journaled/)
|
87
81
|
end
|
88
82
|
|
89
83
|
it "succeeds on unjournaled columns" do
|
90
|
-
expect { subject.update_columns(
|
84
|
+
expect { subject.update_columns(other_column: "") }.not_to raise_error
|
91
85
|
end
|
92
86
|
|
93
87
|
it "succeeds when forced on journaled columns" do
|
94
|
-
expect { subject.update_columns({
|
88
|
+
expect { subject.update_columns({ name: nil }, force: true) }.not_to raise_error
|
95
89
|
end
|
96
90
|
end
|
97
91
|
|
@@ -101,7 +95,7 @@ if Rails::VERSION::MAJOR > 5 || (Rails::VERSION::MAJOR == 5 && Rails::VERSION::M
|
|
101
95
|
end
|
102
96
|
|
103
97
|
it "succeeds if no journaled columns exist" do
|
104
|
-
instance = journaled_class_with_no_journaled_columns.
|
98
|
+
instance = journaled_class_with_no_journaled_columns.create!
|
105
99
|
expect { instance.delete }.not_to raise_error
|
106
100
|
end
|
107
101
|
|
@@ -138,30 +138,30 @@ RSpec.describe Journaled::ChangeWriter do
|
|
138
138
|
expect(subject.journaled_change_for("update", {}).logical_operation).to eq("identity_change")
|
139
139
|
end
|
140
140
|
|
141
|
-
it "doesn't set
|
142
|
-
expect(subject.journaled_change_for("update", {}).
|
141
|
+
it "doesn't set journaled_stream_name if model class doesn't respond to it" do
|
142
|
+
expect(subject.journaled_change_for("update", {}).journaled_stream_name).to eq(nil)
|
143
143
|
end
|
144
144
|
|
145
145
|
context "with journaled default app name set" do
|
146
146
|
around do |example|
|
147
|
-
orig_app_name = Journaled.
|
148
|
-
Journaled.
|
147
|
+
orig_app_name = Journaled.default_stream_name
|
148
|
+
Journaled.default_stream_name = "foo"
|
149
149
|
example.run
|
150
|
-
Journaled.
|
150
|
+
Journaled.default_stream_name = orig_app_name
|
151
151
|
end
|
152
152
|
|
153
153
|
it "passes through default" do
|
154
|
-
expect(subject.journaled_change_for("update", {}).
|
154
|
+
expect(subject.journaled_change_for("update", {}).journaled_stream_name).to eq("foo")
|
155
155
|
end
|
156
156
|
end
|
157
157
|
|
158
|
-
context "when model class defines
|
158
|
+
context "when model class defines journaled_stream_name" do
|
159
159
|
before do
|
160
|
-
allow(model_class).to receive(:
|
160
|
+
allow(model_class).to receive(:journaled_stream_name).and_return("my_app_events")
|
161
161
|
end
|
162
162
|
|
163
|
-
it "sets
|
164
|
-
expect(subject.journaled_change_for("update", {}).
|
163
|
+
it "sets journaled_stream_name if model_class responds to it" do
|
164
|
+
expect(subject.journaled_change_for("update", {}).journaled_stream_name).to eq("my_app_events")
|
165
165
|
end
|
166
166
|
end
|
167
167
|
end
|
@@ -65,14 +65,14 @@ RSpec.describe Journaled::Event do
|
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
-
describe '#
|
68
|
+
describe '#journaled_stream_name' do
|
69
69
|
it 'returns nil in the base class so it can be set explicitly in apps spanning multiple app domains' do
|
70
|
-
expect(sample_journaled_event.
|
70
|
+
expect(sample_journaled_event.journaled_stream_name).to be_nil
|
71
71
|
end
|
72
72
|
|
73
73
|
it 'returns the journaled default if set' do
|
74
|
-
allow(Journaled).to receive(:
|
75
|
-
expect(sample_journaled_event.
|
74
|
+
allow(Journaled).to receive(:default_stream_name).and_return("my_app_events")
|
75
|
+
expect(sample_journaled_event.journaled_stream_name).to eq("my_app_events")
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
@@ -18,7 +18,7 @@ RSpec.describe Journaled::Writer do
|
|
18
18
|
journaled_schema_name: nil,
|
19
19
|
journaled_attributes: {},
|
20
20
|
journaled_partition_key: '',
|
21
|
-
|
21
|
+
journaled_stream_name: nil,
|
22
22
|
journaled_enqueue_opts: {},
|
23
23
|
)
|
24
24
|
end
|
@@ -34,7 +34,7 @@ RSpec.describe Journaled::Writer do
|
|
34
34
|
journaled_schema_name: :fake_schema_name,
|
35
35
|
journaled_attributes: { foo: :bar },
|
36
36
|
journaled_partition_key: 'fake_partition_key',
|
37
|
-
|
37
|
+
journaled_stream_name: nil,
|
38
38
|
journaled_enqueue_opts: {},
|
39
39
|
)
|
40
40
|
end
|
@@ -75,21 +75,17 @@ RSpec.describe Journaled::Writer do
|
|
75
75
|
journaled_schema_name: :fake_schema_name,
|
76
76
|
journaled_attributes: journaled_event_attributes,
|
77
77
|
journaled_partition_key: 'fake_partition_key',
|
78
|
-
|
78
|
+
journaled_stream_name: 'my_app_events',
|
79
79
|
journaled_enqueue_opts: journaled_enqueue_opts,
|
80
80
|
)
|
81
81
|
end
|
82
82
|
|
83
|
-
around do |example|
|
84
|
-
with_jobs_delayed { example.run }
|
85
|
-
end
|
86
|
-
|
87
83
|
context 'when the journaled event does NOT comply with the base_event schema' do
|
88
84
|
let(:journaled_event_attributes) { { foo: 1 } }
|
89
85
|
|
90
86
|
it 'raises an error and does not enqueue anything' do
|
91
87
|
expect { subject.journal! }.to raise_error JSON::Schema::ValidationError
|
92
|
-
expect(
|
88
|
+
expect(enqueued_jobs.count).to eq 0
|
93
89
|
end
|
94
90
|
end
|
95
91
|
|
@@ -99,7 +95,7 @@ RSpec.describe Journaled::Writer do
|
|
99
95
|
|
100
96
|
it 'raises an error and does not enqueue anything' do
|
101
97
|
expect { subject.journal! }.to raise_error JSON::Schema::ValidationError
|
102
|
-
expect(
|
98
|
+
expect(enqueued_jobs.count).to eq 0
|
103
99
|
end
|
104
100
|
end
|
105
101
|
|
@@ -107,9 +103,8 @@ RSpec.describe Journaled::Writer do
|
|
107
103
|
let(:journaled_event_attributes) { { id: 'FAKE_UUID', event_type: 'fake_event', created_at: Time.zone.now, foo: :bar } }
|
108
104
|
|
109
105
|
it 'creates a delivery with the app name passed through' do
|
110
|
-
|
111
|
-
|
112
|
-
expect(Journaled::Delivery).to have_received(:new).with(hash_including(app_name: 'my_app'))
|
106
|
+
expect { subject.journal! }.to change { enqueued_jobs.count }.from(0).to(1)
|
107
|
+
expect(enqueued_jobs.first[:args].first).to include('stream_name' => 'my_app_events')
|
113
108
|
end
|
114
109
|
|
115
110
|
context 'when there is no job priority specified in the enqueue opts' do
|
@@ -122,7 +117,11 @@ RSpec.describe Journaled::Writer do
|
|
122
117
|
|
123
118
|
it 'defaults to the global default' do
|
124
119
|
expect { subject.journal! }.to change {
|
125
|
-
|
120
|
+
if Rails::VERSION::MAJOR < 6
|
121
|
+
enqueued_jobs.select { |j| j[:job] == Journaled::DeliveryJob }.count
|
122
|
+
else
|
123
|
+
enqueued_jobs.select { |j| j['job_class'] == 'Journaled::DeliveryJob' && j['priority'] == 999 }.count
|
124
|
+
end
|
126
125
|
}.from(0).to(1)
|
127
126
|
end
|
128
127
|
end
|
@@ -130,9 +129,13 @@ RSpec.describe Journaled::Writer do
|
|
130
129
|
context 'when there is a job priority specified in the enqueue opts' do
|
131
130
|
let(:journaled_enqueue_opts) { { priority: 13 } }
|
132
131
|
|
133
|
-
it 'enqueues a Journaled::
|
132
|
+
it 'enqueues a Journaled::DeliveryJob with the given priority' do
|
134
133
|
expect { subject.journal! }.to change {
|
135
|
-
|
134
|
+
if Rails::VERSION::MAJOR < 6
|
135
|
+
enqueued_jobs.select { |j| j[:job] == Journaled::DeliveryJob }.count
|
136
|
+
else
|
137
|
+
enqueued_jobs.select { |j| j['job_class'] == 'Journaled::DeliveryJob' && j['priority'] == 13 }.count
|
138
|
+
end
|
136
139
|
}.from(0).to(1)
|
137
140
|
end
|
138
141
|
end
|
data/spec/rails_helper.rb
CHANGED
@@ -6,7 +6,6 @@ require 'rspec/rails'
|
|
6
6
|
require 'timecop'
|
7
7
|
require 'webmock/rspec'
|
8
8
|
require 'journaled/rspec'
|
9
|
-
require 'pry-rails'
|
10
9
|
|
11
10
|
Dir[Rails.root.join('..', 'support', '**', '*.rb')].each { |f| require f }
|
12
11
|
|
@@ -15,6 +14,6 @@ RSpec.configure do |config|
|
|
15
14
|
|
16
15
|
config.infer_spec_type_from_file_location!
|
17
16
|
|
18
|
-
config.include
|
17
|
+
config.include ActiveJob::TestHelper
|
19
18
|
config.include EnvironmentSpecHelper
|
20
19
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,7 @@
|
|
1
|
-
require 'delayed_job_active_record'
|
2
1
|
rails_env = ENV['RAILS_ENV'] ||= 'test'
|
3
|
-
db_adapter = ENV['DB_ADAPTER'] ||= 'postgresql'
|
4
2
|
require File.expand_path('dummy/config/environment.rb', __dir__)
|
5
3
|
|
6
|
-
Rails.configuration.database_configuration[
|
4
|
+
Rails.configuration.database_configuration[rails_env].tap do |c|
|
7
5
|
ActiveRecord::Tasks::DatabaseTasks.create(c)
|
8
6
|
ActiveRecord::Base.establish_connection(c)
|
9
7
|
load File.expand_path('dummy/db/schema.rb', __dir__)
|