deimos-ruby 1.22 → 1.22.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3f8d5ac90c65bc034c6ddcd9992cdc2244100e0c6ac8f7091e253055094580ad
4
- data.tar.gz: 385c04f21fd913f4c913e851010c8a27915e6cb253643fc334b6a73497c0312f
3
+ metadata.gz: b1819694e6ec5bc9cad69f0a3d7edaad53d4daae80ee0af95312044d503e40d1
4
+ data.tar.gz: 1577ab483b8fc8a16dc614c12156e2161a3ab2d372b45ee7825f30837fdc36e4
5
5
  SHA512:
6
- metadata.gz: 33edfce1a07f88bd039cde29a33b63e59411b50237c8869ab06432e9d2622d8c2c506d7311d163adc4bc5ee05344ee379cb5c2e32d99661568446c77c93abf5e
7
- data.tar.gz: ed6f9cff6af0cd6e391c4f891e46874628cdbe41702d6114925417872231b2961d18b2239b83312f2f4fa45105a8d3d29282693252111eb0271a9e83ed2a98a6
6
+ metadata.gz: 1fc162b425d00a308679662d4a48753dbe1fac0ab252d329ad10622f894301de2e35dcc2ca3c0d9366b516ebbce7e8d008fd37ee1c2526d9f5a5be3188d6380f
7
+ data.tar.gz: b09c3c0a0c7980b9bd2431754001c8b3f18d6a21981dbb7dd5b1336f60a3411e26c5c938b3d55e48039c2306ffac54bc2f95c4beac4700b994fdcf4168900ddc
data/CHANGELOG.md CHANGED
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## UNRELEASED
9
9
 
10
+ # 1.22.1 - 2023-05-01
11
+
12
+ - Fix: Bug introduced with 1.22 when associations are not used
13
+
10
14
  # 1.22 - 2023-05-01
11
15
 
12
16
  - Feature: Added `replace_associations` and changed default behavior for multi-table consuming. No longer relies on Rails direct associations and wonky magic for new vs. existing records.
@@ -183,9 +183,13 @@ module Deimos
183
183
  attrs = attrs.merge(record_key(m.key))
184
184
  next unless attrs
185
185
 
186
+ col = if @klass.column_names.include?(self.class.bulk_import_id_column.to_s)
187
+ self.class.bulk_import_id_column
188
+ end
189
+
186
190
  BatchRecord.new(klass: @klass,
187
191
  attributes: attrs,
188
- bulk_import_column: self.class.bulk_import_id_column)
192
+ bulk_import_column: col)
189
193
  end
190
194
  BatchRecordList.new(records.compact)
191
195
  end
@@ -26,7 +26,6 @@ module Deimos
26
26
  @klass = klass
27
27
  if bulk_import_column
28
28
  self.bulk_import_column = bulk_import_column
29
- validate_import_id!
30
29
  self.bulk_import_id = SecureRandom.uuid
31
30
  attributes[bulk_import_column] = bulk_import_id
32
31
  end
@@ -35,6 +34,7 @@ module Deimos
35
34
  assoc_keys = attributes.keys.select { |k| klass.reflect_on_association(k) }
36
35
  # a hash with just the association keys, removing all actual column information.
37
36
  self.associations = attributes.slice(*assoc_keys)
37
+ validate_import_id! if self.associations.any?
38
38
  end
39
39
 
40
40
  # Checks whether the entities has necessary columns for association saving to work
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Deimos
4
- VERSION = '1.22'
4
+ VERSION = '1.22.1'
5
5
  end
@@ -74,7 +74,9 @@ module ActiveRecordBatchConsumerTest # rubocop:disable Metrics/ModuleLength
74
74
  end
75
75
 
76
76
  prepend_before(:each) do
77
+ consumer_class.config[:bulk_import_id_column] = :bulk_import_id
77
78
  stub_const('MyBatchConsumer', consumer_class)
79
+ stub_const('ConsumerTest::MyBatchConsumer', consumer_class)
78
80
  end
79
81
 
80
82
  # Helper to publish a list of messages and call the consumer
@@ -157,7 +159,6 @@ module ActiveRecordBatchConsumerTest # rubocop:disable Metrics/ModuleLength
157
159
  end
158
160
 
159
161
  it 'should raise error when bulk_import_id is not found' do
160
- stub_const('MyBatchConsumer', consumer_class)
161
162
  expect {
162
163
  publish_batch([{ key: 2,
163
164
  payload: { test_id: 'xyz', some_int: 5, title: 'Widget Title' } }])
@@ -169,6 +170,7 @@ module ActiveRecordBatchConsumerTest # rubocop:disable Metrics/ModuleLength
169
170
  context 'with one-to-one relation in association and custom bulk_import_id' do
170
171
  before(:each) do
171
172
  consumer_class.config[:bulk_import_id_column] = :custom_id
173
+ consumer_class.config[:replace_associations] = false
172
174
  end
173
175
 
174
176
  before(:all) do
@@ -177,7 +179,6 @@ module ActiveRecordBatchConsumerTest # rubocop:disable Metrics/ModuleLength
177
179
  end
178
180
 
179
181
  it 'should save item to widget and associated detail' do
180
- stub_const('MyBatchConsumer', consumer_class)
181
182
  publish_batch([{ key: 2,
182
183
  payload: { test_id: 'xyz', some_int: 5, title: 'Widget Title' } }])
183
184
  expect(Widget.count).to eq(2)
@@ -188,7 +189,6 @@ module ActiveRecordBatchConsumerTest # rubocop:disable Metrics/ModuleLength
188
189
 
189
190
  context 'with one-to-many relationship in association and default bulk_import_id' do
190
191
  before(:each) do
191
- consumer_class.config[:bulk_import_id_column] = :bulk_import_id
192
192
  consumer_class.config[:replace_associations] = false
193
193
  consumer_class.record_attributes_proc = proc do |payload|
194
194
  {
@@ -209,7 +209,7 @@ module ActiveRecordBatchConsumerTest # rubocop:disable Metrics/ModuleLength
209
209
  end
210
210
 
211
211
  it 'should save item to widget and associated details' do
212
- stub_const('MyBatchConsumer', consumer_class)
212
+ consumer_class.config[:replace_associations] = false
213
213
  publish_batch([{ key: 2,
214
214
  payload: { test_id: 'xyz', some_int: 5, title: 'Widget Title' } }])
215
215
  expect(Widget.count).to eq(2)
@@ -229,7 +229,6 @@ module ActiveRecordBatchConsumerTest # rubocop:disable Metrics/ModuleLength
229
229
 
230
230
  context 'with replace_associations on' do
231
231
  before(:each) do
232
- consumer_class.config[:bulk_import_id_column] = :bulk_import_id
233
232
  consumer_class.config[:replace_associations] = true
234
233
  consumer_class.record_attributes_proc = proc do |payload|
235
234
  {
@@ -250,7 +249,6 @@ module ActiveRecordBatchConsumerTest # rubocop:disable Metrics/ModuleLength
250
249
  end
251
250
 
252
251
  it 'should save item to widget and replace associated details' do
253
- stub_const('MyBatchConsumer', consumer_class)
254
252
  publish_batch([{ key: 2,
255
253
  payload: { test_id: 'xyz', some_int: 5, title: 'Widget Title' } }])
256
254
  expect(Widget.count).to eq(2)
@@ -271,12 +269,10 @@ module ActiveRecordBatchConsumerTest # rubocop:disable Metrics/ModuleLength
271
269
 
272
270
  context 'with invalid models' do
273
271
  before(:each) do
274
- consumer_class.config[:bulk_import_id_column] = :bulk_import_id
275
272
  consumer_class.should_consume_proc = proc { |val| val.some_int <= 10 }
276
273
  end
277
274
 
278
275
  it 'should only save valid models' do
279
- stub_const('MyBatchConsumer', consumer_class)
280
276
  publish_batch([{ key: 2,
281
277
  payload: { test_id: 'xyz', some_int: 5, title: 'Widget Title' } },
282
278
  { key: 3,
@@ -32,6 +32,8 @@ module ActiveRecordBatchConsumerTest
32
32
 
33
33
  prepend_before(:each) do
34
34
  stub_const('MyBatchConsumer', consumer_class)
35
+ stub_const('ConsumerTest::MyBatchConsumer', consumer_class)
36
+ consumer_class.config[:bulk_import_id_column] = :bulk_import_id # default
35
37
  end
36
38
 
37
39
  around(:each) do |ex|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deimos-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.22'
4
+ version: 1.22.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Orner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-01 00:00:00.000000000 Z
11
+ date: 2023-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: avro_turf