journaled 3.1.0 → 4.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.
- checksums.yaml +4 -4
- data/README.md +102 -24
- data/Rakefile +10 -24
- data/app/controllers/concerns/journaled/actor.rb +8 -5
- data/app/jobs/journaled/delivery_job.rb +14 -5
- data/app/models/concerns/journaled/changes.rb +5 -5
- data/app/models/journaled/actor_uri_provider.rb +1 -2
- data/app/models/journaled/change.rb +14 -14
- data/app/models/journaled/change_writer.rb +8 -7
- data/app/models/journaled/event.rb +25 -3
- data/app/models/journaled/writer.rb +13 -11
- data/journaled_schemas/tagged_event.json +14 -0
- data/lib/journaled/current.rb +18 -0
- data/lib/journaled/relation_change_protection.rb +11 -10
- data/lib/journaled/version.rb +1 -1
- data/lib/journaled.rb +15 -3
- data/spec/dummy/config.ru +1 -1
- data/spec/jobs/journaled/delivery_job_spec.rb +72 -17
- data/spec/lib/journaled_spec.rb +4 -6
- data/spec/models/concerns/journaled/actor_spec.rb +8 -7
- data/spec/models/journaled/actor_uri_provider_spec.rb +6 -5
- data/spec/models/journaled/change_writer_spec.rb +10 -10
- data/spec/models/journaled/event_spec.rb +82 -6
- data/spec/models/journaled/json_schema_model/validator_spec.rb +6 -6
- data/spec/models/journaled/writer_spec.rb +37 -8
- data/spec/rails_helper.rb +1 -1
- data/spec/spec_helper.rb +4 -0
- metadata +26 -26
- data/app/models/journaled/delivery.rb +0 -88
- data/spec/models/journaled/delivery_spec.rb +0 -222
@@ -5,11 +5,7 @@ RSpec.describe Journaled::DeliveryJob do
|
|
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
|
-
let(:args) { { serialized_event: serialized_event, partition_key: partition_key,
|
9
|
-
|
10
|
-
around do |example|
|
11
|
-
with_env(JOURNALED_STREAM_NAME: stream_name) { example.run }
|
12
|
-
end
|
8
|
+
let(:args) { { serialized_event: serialized_event, partition_key: partition_key, stream_name: stream_name } }
|
13
9
|
|
14
10
|
describe '#perform' do
|
15
11
|
let(:return_status_body) { { shard_id: '101', sequence_number: '101123' } }
|
@@ -19,15 +15,21 @@ RSpec.describe Journaled::DeliveryJob do
|
|
19
15
|
allow(Aws::AssumeRoleCredentials).to receive(:new).and_call_original
|
20
16
|
allow(Aws::Kinesis::Client).to receive(:new).and_return kinesis_client
|
21
17
|
kinesis_client.stub_responses(:put_record, return_status_body)
|
18
|
+
allow(kinesis_client).to receive(:put_record).and_call_original
|
22
19
|
|
23
20
|
allow(Journaled).to receive(:enabled?).and_return(true)
|
24
21
|
end
|
25
22
|
|
26
23
|
it 'makes requests to AWS to put the event on the Kinesis with the correct body' do
|
27
|
-
event = described_class.perform_now(args)
|
24
|
+
event = described_class.perform_now(**args)
|
28
25
|
|
29
26
|
expect(event.shard_id).to eq '101'
|
30
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
|
+
)
|
31
33
|
end
|
32
34
|
|
33
35
|
context 'when JOURNALED_IAM_ROLE_ARN is defined' do
|
@@ -58,7 +60,7 @@ RSpec.describe Journaled::DeliveryJob do
|
|
58
60
|
end
|
59
61
|
|
60
62
|
it 'initializes a Kinesis client with assume role credentials' do
|
61
|
-
described_class.perform_now(args)
|
63
|
+
described_class.perform_now(**args)
|
62
64
|
|
63
65
|
expect(Aws::AssumeRoleCredentials).to have_received(:new).with(
|
64
66
|
client: aws_sts_client,
|
@@ -68,11 +70,64 @@ RSpec.describe Journaled::DeliveryJob do
|
|
68
70
|
end
|
69
71
|
end
|
70
72
|
|
71
|
-
context 'when the stream name
|
73
|
+
context 'when the stream name is not set' do
|
72
74
|
let(:stream_name) { nil }
|
73
75
|
|
74
76
|
it 'raises an KeyError error' do
|
75
|
-
expect { described_class.perform_now(args) }.to raise_error
|
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
|
+
)
|
76
131
|
end
|
77
132
|
end
|
78
133
|
|
@@ -83,7 +138,7 @@ RSpec.describe Journaled::DeliveryJob do
|
|
83
138
|
|
84
139
|
it 'catches the error and re-raises a subclass of NotTrulyExceptionalError and logs about the failure' do
|
85
140
|
allow(Rails.logger).to receive(:error)
|
86
|
-
expect { described_class.perform_now(args) }.to raise_error described_class::KinesisTemporaryFailure
|
141
|
+
expect { described_class.perform_now(**args) }.to raise_error described_class::KinesisTemporaryFailure
|
87
142
|
expect(Rails.logger).to have_received(:error).with(
|
88
143
|
"Kinesis Error - Server Error occurred - Aws::Kinesis::Errors::InternalFailure",
|
89
144
|
).once
|
@@ -97,7 +152,7 @@ RSpec.describe Journaled::DeliveryJob do
|
|
97
152
|
|
98
153
|
it 'catches the error and re-raises a subclass of NotTrulyExceptionalError and logs about the failure' do
|
99
154
|
allow(Rails.logger).to receive(:error)
|
100
|
-
expect { described_class.perform_now(args) }.to raise_error described_class::KinesisTemporaryFailure
|
155
|
+
expect { described_class.perform_now(**args) }.to raise_error described_class::KinesisTemporaryFailure
|
101
156
|
expect(Rails.logger).to have_received(:error).with(/\AKinesis Error/).once
|
102
157
|
end
|
103
158
|
end
|
@@ -108,7 +163,7 @@ RSpec.describe Journaled::DeliveryJob do
|
|
108
163
|
end
|
109
164
|
|
110
165
|
it 'raises an error that subclasses Aws::Kinesis::Errors::ServiceError' do
|
111
|
-
expect { described_class.perform_now(args) }.to raise_error Aws::Kinesis::Errors::ServiceError
|
166
|
+
expect { described_class.perform_now(**args) }.to raise_error Aws::Kinesis::Errors::ServiceError
|
112
167
|
end
|
113
168
|
end
|
114
169
|
|
@@ -118,7 +173,7 @@ RSpec.describe Journaled::DeliveryJob do
|
|
118
173
|
end
|
119
174
|
|
120
175
|
it 'raises an AccessDeniedException error' do
|
121
|
-
expect { described_class.perform_now(args) }.to raise_error Aws::Kinesis::Errors::AccessDeniedException
|
176
|
+
expect { described_class.perform_now(**args) }.to raise_error Aws::Kinesis::Errors::AccessDeniedException
|
122
177
|
end
|
123
178
|
end
|
124
179
|
|
@@ -129,7 +184,7 @@ RSpec.describe Journaled::DeliveryJob do
|
|
129
184
|
|
130
185
|
it 'catches the error and re-raises a subclass of NotTrulyExceptionalError and logs about the failure' do
|
131
186
|
allow(Rails.logger).to receive(:error)
|
132
|
-
expect { described_class.perform_now(args) }.to raise_error described_class::KinesisTemporaryFailure
|
187
|
+
expect { described_class.perform_now(**args) }.to raise_error described_class::KinesisTemporaryFailure
|
133
188
|
expect(Rails.logger).to have_received(:error).with(
|
134
189
|
"Kinesis Error - Networking Error occurred - Seahorse::Client::NetworkingError",
|
135
190
|
).once
|
@@ -137,11 +192,11 @@ RSpec.describe Journaled::DeliveryJob do
|
|
137
192
|
end
|
138
193
|
end
|
139
194
|
|
140
|
-
describe ".
|
195
|
+
describe ".legacy_computed_stream_name" do
|
141
196
|
context "when app_name is unspecified" do
|
142
197
|
it "is fetched from a prefixed ENV var if specified" do
|
143
198
|
allow(ENV).to receive(:fetch).and_return("expected_stream_name")
|
144
|
-
expect(described_class.
|
199
|
+
expect(described_class.legacy_computed_stream_name(app_name: nil)).to eq("expected_stream_name")
|
145
200
|
expect(ENV).to have_received(:fetch).with("JOURNALED_STREAM_NAME")
|
146
201
|
end
|
147
202
|
end
|
@@ -149,7 +204,7 @@ RSpec.describe Journaled::DeliveryJob do
|
|
149
204
|
context "when app_name is specified" do
|
150
205
|
it "is fetched from a prefixed ENV var if specified" do
|
151
206
|
allow(ENV).to receive(:fetch).and_return("expected_stream_name")
|
152
|
-
expect(described_class.
|
207
|
+
expect(described_class.legacy_computed_stream_name(app_name: "my_funky_app_name")).to eq("expected_stream_name")
|
153
208
|
expect(ENV).to have_received(:fetch).with("MY_FUNKY_APP_NAME_JOURNALED_STREAM_NAME")
|
154
209
|
end
|
155
210
|
end
|
data/spec/lib/journaled_spec.rb
CHANGED
@@ -75,12 +75,10 @@ RSpec.describe Journaled do
|
|
75
75
|
end
|
76
76
|
|
77
77
|
around do |example|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
ActiveJob::Base.enable_test_adapter(ActiveJob::QueueAdapters::TestAdapter.new)
|
83
|
-
end
|
78
|
+
example.run
|
79
|
+
ensure
|
80
|
+
ActiveJob::Base.queue_adapter = :test
|
81
|
+
ActiveJob::Base.enable_test_adapter(ActiveJob::QueueAdapters::TestAdapter.new)
|
84
82
|
end
|
85
83
|
|
86
84
|
it 'does not raise an error' do
|
@@ -5,11 +5,10 @@ RSpec.describe Journaled::Actor do
|
|
5
5
|
let(:user) { double("User") }
|
6
6
|
let(:klass) do
|
7
7
|
Class.new do
|
8
|
-
cattr_accessor
|
9
|
-
self.before_actions = []
|
8
|
+
cattr_accessor(:before_actions) { [] }
|
10
9
|
|
11
|
-
def self.before_action(
|
12
|
-
before_actions <<
|
10
|
+
def self.before_action(method_name, _opts)
|
11
|
+
before_actions << method_name
|
13
12
|
end
|
14
13
|
|
15
14
|
include Journaled::Actor
|
@@ -21,7 +20,7 @@ RSpec.describe Journaled::Actor do
|
|
21
20
|
end
|
22
21
|
|
23
22
|
def trigger_before_actions
|
24
|
-
before_actions.each { |
|
23
|
+
before_actions.each { |method_name| send(method_name) }
|
25
24
|
end
|
26
25
|
end
|
27
26
|
end
|
@@ -33,7 +32,8 @@ RSpec.describe Journaled::Actor do
|
|
33
32
|
|
34
33
|
allow(subject).to receive(:current_user).and_return(nil)
|
35
34
|
|
36
|
-
expect(
|
35
|
+
expect(Journaled::Current.journaled_actor_proc.call).to be_nil
|
36
|
+
expect(Journaled::Current.actor).to be_nil
|
37
37
|
end
|
38
38
|
|
39
39
|
it "Stores a thunk returning current_user if it is set when called" do
|
@@ -41,6 +41,7 @@ RSpec.describe Journaled::Actor do
|
|
41
41
|
|
42
42
|
allow(subject).to receive(:current_user).and_return(user)
|
43
43
|
|
44
|
-
expect(
|
44
|
+
expect(Journaled::Current.journaled_actor_proc.call).to eq user
|
45
|
+
expect(Journaled::Current.actor).to eq user
|
45
46
|
end
|
46
47
|
end
|
@@ -2,7 +2,7 @@ require 'rails_helper'
|
|
2
2
|
|
3
3
|
RSpec.describe Journaled::ActorUriProvider do
|
4
4
|
describe "#actor_uri" do
|
5
|
-
let(:
|
5
|
+
let(:current_attributes) { double(:[] => nil) }
|
6
6
|
let(:actor) { double(to_global_id: actor_gid) }
|
7
7
|
let(:actor_gid) { double(to_s: "my_fancy_gid") }
|
8
8
|
let(:program_name) { "/usr/local/bin/puma_or_something" }
|
@@ -17,13 +17,14 @@ RSpec.describe Journaled::ActorUriProvider do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
before do
|
20
|
-
allow(
|
20
|
+
allow(Journaled::Current.instance)
|
21
|
+
.to receive(:attributes).and_return(current_attributes)
|
21
22
|
end
|
22
23
|
|
23
|
-
it "returns the global ID of the entity returned by
|
24
|
-
allow(
|
24
|
+
it "returns the global ID of the entity returned by Current.journaled_actor_proc.call if set" do
|
25
|
+
allow(current_attributes).to receive(:[]).and_return(-> { actor })
|
25
26
|
expect(subject.actor_uri).to eq("my_fancy_gid")
|
26
|
-
expect(
|
27
|
+
expect(current_attributes).to have_received(:[]).with(:journaled_actor_proc)
|
27
28
|
end
|
28
29
|
|
29
30
|
context "when running in rake" do
|
@@ -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 be_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
|
|
@@ -88,8 +88,10 @@ RSpec.describe Journaled::Event do
|
|
88
88
|
|
89
89
|
context 'when no additional attributes have been defined' do
|
90
90
|
it 'returns the base attributes, and memoizes them after the first call' do
|
91
|
-
expect(sample_journaled_event.journaled_attributes)
|
92
|
-
|
91
|
+
expect(sample_journaled_event.journaled_attributes)
|
92
|
+
.to eq id: fake_uuid, created_at: frozen_time, event_type: 'some_class_name'
|
93
|
+
expect(sample_journaled_event.journaled_attributes)
|
94
|
+
.to eq id: fake_uuid, created_at: frozen_time, event_type: 'some_class_name'
|
93
95
|
end
|
94
96
|
end
|
95
97
|
|
@@ -134,6 +136,80 @@ RSpec.describe Journaled::Event do
|
|
134
136
|
)
|
135
137
|
end
|
136
138
|
end
|
139
|
+
|
140
|
+
context 'tagged: true' do
|
141
|
+
before do
|
142
|
+
sample_journaled_event_class.journal_attributes tagged: true
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'adds a "tags" attribute' do
|
146
|
+
expect(sample_journaled_event.journaled_attributes).to include(tags: {})
|
147
|
+
end
|
148
|
+
|
149
|
+
context 'when tags are specified' do
|
150
|
+
around do |example|
|
151
|
+
Journaled.tag!(foo: 'bar')
|
152
|
+
Journaled.tagged(baz: 'bat') { example.run }
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'adds them to the journaled attributes' do
|
156
|
+
expect(sample_journaled_event.journaled_attributes).to include(
|
157
|
+
tags: { foo: 'bar', baz: 'bat' },
|
158
|
+
)
|
159
|
+
end
|
160
|
+
|
161
|
+
context 'when even more tags are nested' do
|
162
|
+
it 'merges them in and then resets them' do
|
163
|
+
Journaled.tagged(oh_no: 'even more tags') do
|
164
|
+
expect(sample_journaled_event.journaled_attributes).to include(
|
165
|
+
tags: { foo: 'bar', baz: 'bat', oh_no: 'even more tags' },
|
166
|
+
)
|
167
|
+
end
|
168
|
+
|
169
|
+
allow(SecureRandom).to receive(:uuid).and_return(fake_uuid).once
|
170
|
+
expect(sample_journaled_event_class.new.journaled_attributes).to include(
|
171
|
+
tags: { foo: 'bar', baz: 'bat' },
|
172
|
+
)
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
context 'when custom event tags are also specified and merged' do
|
177
|
+
let(:sample_journaled_event_class) do
|
178
|
+
Class.new do
|
179
|
+
include Journaled::Event
|
180
|
+
|
181
|
+
def tags
|
182
|
+
super.merge(abc: '123')
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
it 'combines all tags' do
|
188
|
+
expect(sample_journaled_event.journaled_attributes).to include(
|
189
|
+
tags: { foo: 'bar', baz: 'bat', abc: '123' },
|
190
|
+
)
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
context 'when custom event tags are also specified but not merged' do
|
195
|
+
let(:sample_journaled_event_class) do
|
196
|
+
Class.new do
|
197
|
+
include Journaled::Event
|
198
|
+
|
199
|
+
def tags
|
200
|
+
{ bananas: 'are great', but_not_actually: 'the best source of potassium' } # it's true
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
it 'adds them to the journaled attributes' do
|
206
|
+
expect(sample_journaled_event.journaled_attributes).to include(
|
207
|
+
tags: { bananas: 'are great', but_not_actually: 'the best source of potassium' },
|
208
|
+
)
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
137
213
|
end
|
138
214
|
|
139
215
|
describe '#journaled_enqueue_opts, .journaled_enqueue_opts' do
|
@@ -8,7 +8,7 @@ RSpec.describe Journaled::JsonSchemaModel::Validator do
|
|
8
8
|
let(:attributes_to_validate) do
|
9
9
|
{
|
10
10
|
some_string: some_string_value,
|
11
|
-
some_decimal: 0.1
|
11
|
+
some_decimal: BigDecimal('0.1'),
|
12
12
|
some_time: Time.zone.parse('2017-01-20 15:16:17 -05:00'),
|
13
13
|
some_int: some_int_value,
|
14
14
|
some_optional_string: some_optional_string_value,
|
@@ -66,7 +66,7 @@ RSpec.describe Journaled::JsonSchemaModel::Validator do
|
|
66
66
|
context 'when all the required fields are provided' do
|
67
67
|
context 'when all the fields are provided' do
|
68
68
|
it 'is valid' do
|
69
|
-
expect(subject.validate!(json_to_validate)).to
|
69
|
+
expect(subject.validate!(json_to_validate)).to be true
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
@@ -74,7 +74,7 @@ RSpec.describe Journaled::JsonSchemaModel::Validator do
|
|
74
74
|
let(:attributes_to_validate) do
|
75
75
|
{
|
76
76
|
some_string: some_string_value,
|
77
|
-
some_decimal: 0.1
|
77
|
+
some_decimal: BigDecimal('0.1'),
|
78
78
|
some_time: Time.zone.parse('2017-01-20 15:16:17 -05:00'),
|
79
79
|
some_int: some_int_value,
|
80
80
|
some_nullable_field: some_nullable_field,
|
@@ -82,7 +82,7 @@ RSpec.describe Journaled::JsonSchemaModel::Validator do
|
|
82
82
|
end
|
83
83
|
|
84
84
|
it 'is valid' do
|
85
|
-
expect(subject.validate!(json_to_validate)).to
|
85
|
+
expect(subject.validate!(json_to_validate)).to be true
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
@@ -90,7 +90,7 @@ RSpec.describe Journaled::JsonSchemaModel::Validator do
|
|
90
90
|
let(:some_nullable_optional_field) { nil }
|
91
91
|
|
92
92
|
it 'is valid' do
|
93
|
-
expect(subject.validate!(json_to_validate)).to
|
93
|
+
expect(subject.validate!(json_to_validate)).to be true
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
@@ -107,7 +107,7 @@ RSpec.describe Journaled::JsonSchemaModel::Validator do
|
|
107
107
|
let(:attributes_to_validate) do
|
108
108
|
{
|
109
109
|
some_string: some_string_value,
|
110
|
-
some_decimal: 0.1
|
110
|
+
some_decimal: BigDecimal('0.1'),
|
111
111
|
some_time: Time.zone.parse('2017-01-20 15:16:17 -05:00'),
|
112
112
|
}
|
113
113
|
end
|
@@ -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,8 +75,9 @@ 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
|
+
tagged?: false,
|
80
81
|
)
|
81
82
|
end
|
82
83
|
|
@@ -104,7 +105,7 @@ RSpec.describe Journaled::Writer do
|
|
104
105
|
|
105
106
|
it 'creates a delivery with the app name passed through' do
|
106
107
|
expect { subject.journal! }.to change { enqueued_jobs.count }.from(0).to(1)
|
107
|
-
expect(enqueued_jobs.first[:args].first).to include('
|
108
|
+
expect(enqueued_jobs.first[:args].first).to include('stream_name' => 'my_app_events')
|
108
109
|
end
|
109
110
|
|
110
111
|
context 'when there is no job priority specified in the enqueue opts' do
|
@@ -118,9 +119,9 @@ RSpec.describe Journaled::Writer do
|
|
118
119
|
it 'defaults to the global default' do
|
119
120
|
expect { subject.journal! }.to change {
|
120
121
|
if Rails::VERSION::MAJOR < 6
|
121
|
-
enqueued_jobs.
|
122
|
+
enqueued_jobs.count { |j| j[:job] == Journaled::DeliveryJob }
|
122
123
|
else
|
123
|
-
enqueued_jobs.
|
124
|
+
enqueued_jobs.count { |j| j['job_class'] == 'Journaled::DeliveryJob' && j['priority'] == 999 }
|
124
125
|
end
|
125
126
|
}.from(0).to(1)
|
126
127
|
end
|
@@ -132,14 +133,42 @@ RSpec.describe Journaled::Writer do
|
|
132
133
|
it 'enqueues a Journaled::DeliveryJob with the given priority' do
|
133
134
|
expect { subject.journal! }.to change {
|
134
135
|
if Rails::VERSION::MAJOR < 6
|
135
|
-
enqueued_jobs.
|
136
|
+
enqueued_jobs.count { |j| j[:job] == Journaled::DeliveryJob }
|
136
137
|
else
|
137
|
-
enqueued_jobs.
|
138
|
+
enqueued_jobs.count { |j| j['job_class'] == 'Journaled::DeliveryJob' && j['priority'] == 13 }
|
138
139
|
end
|
139
140
|
}.from(0).to(1)
|
140
141
|
end
|
141
142
|
end
|
142
143
|
end
|
143
144
|
end
|
145
|
+
|
146
|
+
context 'when the event is tagged' do
|
147
|
+
before do
|
148
|
+
allow(journaled_event).to receive(:tagged?).and_return(true)
|
149
|
+
end
|
150
|
+
|
151
|
+
context 'and the "tags" attribute is not present' do
|
152
|
+
let(:journaled_event_attributes) do
|
153
|
+
{ id: 'FAKE_UUID', event_type: 'fake_event', created_at: Time.zone.now, foo: 'bar' }
|
154
|
+
end
|
155
|
+
|
156
|
+
it 'raises an error and does not enqueue anything' do
|
157
|
+
expect { subject.journal! }.to raise_error JSON::Schema::ValidationError
|
158
|
+
expect(enqueued_jobs.count).to eq 0
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
context 'and the "tags" attribute is present' do
|
163
|
+
let(:journaled_event_attributes) do
|
164
|
+
{ id: 'FAKE_UUID', event_type: 'fake_event', created_at: Time.zone.now, foo: 'bar', tags: { baz: 'bat' } }
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'creates a delivery with the app name passed through' do
|
168
|
+
expect { subject.journal! }.to change { enqueued_jobs.count }.from(0).to(1)
|
169
|
+
expect(enqueued_jobs.first[:args].first).to include('stream_name' => 'my_app_events')
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
144
173
|
end
|
145
174
|
end
|
data/spec/rails_helper.rb
CHANGED
@@ -7,7 +7,7 @@ require 'timecop'
|
|
7
7
|
require 'webmock/rspec'
|
8
8
|
require 'journaled/rspec'
|
9
9
|
|
10
|
-
Dir[Rails.root.join('
|
10
|
+
Dir[Rails.root.join('../support/**/*.rb')].sort.each { |f| require f }
|
11
11
|
|
12
12
|
RSpec.configure do |config|
|
13
13
|
config.use_transactional_fixtures = true
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
rails_env = ENV['RAILS_ENV'] ||= 'test'
|
2
|
+
require 'uncruft'
|
2
3
|
require File.expand_path('dummy/config/environment.rb', __dir__)
|
3
4
|
|
5
|
+
Rails.application.config.active_record.sqlite3.represent_boolean_as_integer = true if Rails::VERSION::MAJOR < 6
|
6
|
+
Rails.application.config.active_record.legacy_connection_handling = false if Rails::VERSION::MAJOR >= 7
|
7
|
+
|
4
8
|
Rails.configuration.database_configuration[rails_env].tap do |c|
|
5
9
|
ActiveRecord::Tasks::DatabaseTasks.create(c)
|
6
10
|
ActiveRecord::Base.establish_connection(c)
|