global-registry-bindings 0.2.0 → 0.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.
@@ -8,7 +8,11 @@ require 'active_record'
8
8
  ActiveRecord::Migration.verbose = false
9
9
 
10
10
  require 'combustion'
11
- Combustion.initialize! :active_record
11
+ Combustion.initialize! :active_record do
12
+ if config.active_record.sqlite3.respond_to?(:represent_boolean_as_integer)
13
+ config.active_record.sqlite3.represent_boolean_as_integer = true
14
+ end
15
+ end
12
16
 
13
17
  require 'rspec/rails'
14
18
  require 'webmock/rspec'
@@ -18,6 +18,17 @@ RSpec.describe GlobalRegistry::Bindings::Workers::PushEntityWorker do
18
18
  end
19
19
  end
20
20
 
21
+ context 'with valid id and fingerprint' do
22
+ it 'should call #push_entity_to_global_registry' do
23
+ expect(Namespaced::Person).to receive(:find).with(person.id).and_return(person)
24
+
25
+ worker = GlobalRegistry::Bindings::Workers::PushEntityWorker.new
26
+ expect(worker).to receive(:push_entity_to_global_registry)
27
+ worker.perform('Namespaced::Person', person.id)
28
+ expect(worker.model).to be person
29
+ end
30
+ end
31
+
21
32
  context 'with invalid id' do
22
33
  it 'should fail silently' do
23
34
  expect(Namespaced::Person).to receive(:find).with(person.id).and_raise(ActiveRecord::RecordNotFound)
@@ -116,8 +127,16 @@ RSpec.describe GlobalRegistry::Bindings::Workers::PushEntityWorker do
116
127
 
117
128
  describe Namespaced::Person do
118
129
  let(:worker) { GlobalRegistry::Bindings::Workers::PushEntityWorker.new person }
130
+ let(:entity_body) do
131
+ { entity: { person: { first_name: 'Tony', last_name: 'Stark',
132
+ client_integration_id: person.id,
133
+ client_updated_at: '2001-02-03 00:00:00',
134
+ authentication: {
135
+ key_guid: '98711710-acb5-4a41-ba51-e0fc56644b53'
136
+ } } } }
137
+ end
119
138
  context 'as create' do
120
- let(:person) { create(:person) }
139
+ let(:person) { create(:person, global_registry_fingerprint: 'abc123') }
121
140
 
122
141
  context '\'person\' entity_type does not exist' do
123
142
  let!(:requests) do
@@ -136,12 +155,7 @@ RSpec.describe GlobalRegistry::Bindings::Workers::PushEntityWorker do
136
155
  field_type: 'string' } })
137
156
  .to_return(status: 200),
138
157
  stub_request(:post, 'https://backend.global-registry.org/entities')
139
- .with(body: { entity: { person: { first_name: 'Tony', last_name: 'Stark',
140
- client_integration_id: person.id,
141
- client_updated_at: '2001-02-03 00:00:00',
142
- authentication: {
143
- key_guid: '98711710-acb5-4a41-ba51-e0fc56644b53'
144
- } } } })
158
+ .with(body: entity_body)
145
159
  .to_return(body: file_fixture('post_entities_person.json'), status: 200)]
146
160
  end
147
161
 
@@ -149,6 +163,7 @@ RSpec.describe GlobalRegistry::Bindings::Workers::PushEntityWorker do
149
163
  worker.push_entity_to_global_registry
150
164
  requests.each { |r| expect(r).to have_been_requested.once }
151
165
  expect(person.global_registry_id).to eq '22527d88-3cba-11e7-b876-129bd0521531'
166
+ expect(person.global_registry_fingerprint).to eq '4c671c203b5dd19cdc1920ba5434cf64'
152
167
  end
153
168
  end
154
169
 
@@ -158,12 +173,7 @@ RSpec.describe GlobalRegistry::Bindings::Workers::PushEntityWorker do
158
173
  .with(query: { 'filters[name]' => 'person', 'filters[parent_id]' => nil })
159
174
  .to_return(body: file_fixture('get_entity_types_person.json'), status: 200),
160
175
  stub_request(:post, 'https://backend.global-registry.org/entities')
161
- .with(body: { entity: { person: { first_name: 'Tony', last_name: 'Stark',
162
- client_integration_id: person.id,
163
- client_updated_at: '2001-02-03 00:00:00',
164
- authentication: {
165
- key_guid: '98711710-acb5-4a41-ba51-e0fc56644b53'
166
- } } } })
176
+ .with(body: entity_body)
167
177
  .to_return(body: file_fixture('post_entities_person.json'), status: 200)]
168
178
  end
169
179
 
@@ -171,6 +181,7 @@ RSpec.describe GlobalRegistry::Bindings::Workers::PushEntityWorker do
171
181
  worker.push_entity_to_global_registry
172
182
  requests.each { |r| expect(r).to have_been_requested.once }
173
183
  expect(person.global_registry_id).to eq '22527d88-3cba-11e7-b876-129bd0521531'
184
+ expect(person.global_registry_fingerprint).to eq '4c671c203b5dd19cdc1920ba5434cf64'
174
185
  end
175
186
  end
176
187
 
@@ -184,12 +195,7 @@ RSpec.describe GlobalRegistry::Bindings::Workers::PushEntityWorker do
184
195
  field_type: 'string' } })
185
196
  .to_return(status: 200),
186
197
  stub_request(:post, 'https://backend.global-registry.org/entities')
187
- .with(body: { entity: { person: { first_name: 'Tony', last_name: 'Stark',
188
- client_integration_id: person.id,
189
- client_updated_at: '2001-02-03 00:00:00',
190
- authentication: {
191
- key_guid: '98711710-acb5-4a41-ba51-e0fc56644b53'
192
- } } } })
198
+ .with(body: entity_body)
193
199
  .to_return(body: file_fixture('post_entities_person.json'), status: 200)]
194
200
  end
195
201
 
@@ -197,6 +203,7 @@ RSpec.describe GlobalRegistry::Bindings::Workers::PushEntityWorker do
197
203
  worker.push_entity_to_global_registry
198
204
  requests.each { |r| expect(r).to have_been_requested.once }
199
205
  expect(person.global_registry_id).to eq '22527d88-3cba-11e7-b876-129bd0521531'
206
+ expect(person.global_registry_fingerprint).to eq '4c671c203b5dd19cdc1920ba5434cf64'
200
207
  end
201
208
  end
202
209
 
@@ -208,22 +215,21 @@ RSpec.describe GlobalRegistry::Bindings::Workers::PushEntityWorker do
208
215
 
209
216
  it 'should skip creating entity_type and push the entity' do
210
217
  request = stub_request(:post, 'https://backend.global-registry.org/entities')
211
- .with(body: { entity: { person: { first_name: 'Tony', last_name: 'Stark',
212
- client_integration_id: person.id,
213
- client_updated_at: '2001-02-03 00:00:00',
214
- authentication: {
215
- key_guid: '98711710-acb5-4a41-ba51-e0fc56644b53'
216
- } } } })
218
+ .with(body: entity_body)
217
219
  .to_return(body: file_fixture('post_entities_person.json'), status: 200)
218
220
  worker.push_entity_to_global_registry
219
221
  expect(request).to have_been_requested.once
220
222
  expect(person.global_registry_id).to eq '22527d88-3cba-11e7-b876-129bd0521531'
223
+ expect(person.global_registry_fingerprint).to eq '4c671c203b5dd19cdc1920ba5434cf64'
221
224
  end
222
225
  end
223
226
  end
224
227
 
225
228
  context 'as an update' do
226
- let(:person) { create(:person, global_registry_id: 'f8d20318-2ff2-4a98-a5eb-e9d840508bf1') }
229
+ let(:person) do
230
+ create(:person, global_registry_id: 'f8d20318-2ff2-4a98-a5eb-e9d840508bf1',
231
+ global_registry_fingerprint: 'abc123')
232
+ end
227
233
  context '\'person\' entity_type is cached' do
228
234
  before :each do
229
235
  person_entity_types = JSON.parse(file_fixture('get_entity_types_person.json').read)
@@ -233,12 +239,7 @@ RSpec.describe GlobalRegistry::Bindings::Workers::PushEntityWorker do
233
239
  it 'should skip creating entity_type and update the entity' do
234
240
  request = stub_request(:put,
235
241
  'https://backend.global-registry.org/entities/f8d20318-2ff2-4a98-a5eb-e9d840508bf1')
236
- .with(body: { entity: { person: { first_name: 'Tony', last_name: 'Stark',
237
- client_integration_id: person.id,
238
- client_updated_at: '2001-02-03 00:00:00',
239
- authentication: {
240
- key_guid: '98711710-acb5-4a41-ba51-e0fc56644b53'
241
- } } } })
242
+ .with(body: entity_body)
242
243
  .to_return(body: file_fixture('post_entities_person.json'), status: 200)
243
244
  worker.push_entity_to_global_registry
244
245
  expect(request).to have_been_requested.once
@@ -248,20 +249,10 @@ RSpec.describe GlobalRegistry::Bindings::Workers::PushEntityWorker do
248
249
  let!(:requests) do
249
250
  [stub_request(:put,
250
251
  'https://backend.global-registry.org/entities/f8d20318-2ff2-4a98-a5eb-e9d840508bf1')
251
- .with(body: { entity: { person: { first_name: 'Tony', last_name: 'Stark',
252
- client_integration_id: person.id,
253
- client_updated_at: '2001-02-03 00:00:00',
254
- authentication: {
255
- key_guid: '98711710-acb5-4a41-ba51-e0fc56644b53'
256
- } } } })
252
+ .with(body: entity_body)
257
253
  .to_return(status: 404),
258
254
  stub_request(:post, 'https://backend.global-registry.org/entities')
259
- .with(body: { entity: { person: { first_name: 'Tony', last_name: 'Stark',
260
- client_integration_id: person.id,
261
- client_updated_at: '2001-02-03 00:00:00',
262
- authentication: {
263
- key_guid: '98711710-acb5-4a41-ba51-e0fc56644b53'
264
- } } } })
255
+ .with(body: entity_body)
265
256
  .to_return(body: file_fixture('post_entities_person.json'), status: 200)]
266
257
  end
267
258
 
@@ -269,6 +260,19 @@ RSpec.describe GlobalRegistry::Bindings::Workers::PushEntityWorker do
269
260
  worker.push_entity_to_global_registry
270
261
  requests.each { |r| expect(r).to have_been_requested.once }
271
262
  expect(person.global_registry_id).to eq '22527d88-3cba-11e7-b876-129bd0521531'
263
+ expect(person.global_registry_fingerprint).to eq '4c671c203b5dd19cdc1920ba5434cf64'
264
+ end
265
+ end
266
+
267
+ context 'fingerprints match' do
268
+ it 'should do nothing' do
269
+ request = stub_request(:put,
270
+ 'https://backend.global-registry.org/entities/f8d20318-2ff2-4a98-a5eb-e9d840508bf1')
271
+ .with(body: entity_body)
272
+ .to_return(body: file_fixture('post_entities_person.json'), status: 200)
273
+ person.global_registry_fingerprint = '4c671c203b5dd19cdc1920ba5434cf64'
274
+ worker.push_entity_to_global_registry
275
+ expect(request).not_to have_been_requested
272
276
  end
273
277
  end
274
278
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: global-registry-bindings
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Zoetewey
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-09 00:00:00.000000000 Z
11
+ date: 2019-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -90,6 +90,26 @@ dependencies:
90
90
  - - "<"
91
91
  - !ruby/object:Gem::Version
92
92
  version: '6'
93
+ - !ruby/object:Gem::Dependency
94
+ name: deepsort
95
+ requirement: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: 0.4.1
100
+ - - "<"
101
+ - !ruby/object:Gem::Version
102
+ version: 1.0.0
103
+ type: :runtime
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: 0.4.1
110
+ - - "<"
111
+ - !ruby/object:Gem::Version
112
+ version: 1.0.0
93
113
  - !ruby/object:Gem::Dependency
94
114
  name: appraisal
95
115
  requirement: !ruby/object:Gem::Requirement
@@ -110,14 +130,14 @@ dependencies:
110
130
  requirements:
111
131
  - - "~>"
112
132
  - !ruby/object:Gem::Version
113
- version: 0.6.0
133
+ version: '1.0'
114
134
  type: :development
115
135
  prerelease: false
116
136
  version_requirements: !ruby/object:Gem::Requirement
117
137
  requirements:
118
138
  - - "~>"
119
139
  - !ruby/object:Gem::Version
120
- version: 0.6.0
140
+ version: '1.0'
121
141
  - !ruby/object:Gem::Dependency
122
142
  name: rails
123
143
  requirement: !ruby/object:Gem::Requirement
@@ -216,20 +236,6 @@ dependencies:
216
236
  - - '='
217
237
  - !ruby/object:Gem::Version
218
238
  version: 0.48.1
219
- - !ruby/object:Gem::Dependency
220
- name: database_cleaner
221
- requirement: !ruby/object:Gem::Requirement
222
- requirements:
223
- - - ">="
224
- - !ruby/object:Gem::Version
225
- version: '0'
226
- type: :development
227
- prerelease: false
228
- version_requirements: !ruby/object:Gem::Requirement
229
- requirements:
230
- - - ">="
231
- - !ruby/object:Gem::Version
232
- version: '0'
233
239
  - !ruby/object:Gem::Dependency
234
240
  name: sqlite3
235
241
  requirement: !ruby/object:Gem::Requirement
@@ -395,6 +401,7 @@ files:
395
401
  - spec/internal/config/initializers/global_registry.rb
396
402
  - spec/internal/config/routes.rb
397
403
  - spec/internal/db/schema.rb
404
+ - spec/internal/db/test.sqlite
398
405
  - spec/internal/log/test.log
399
406
  - spec/models/address_spec.rb
400
407
  - spec/models/assignment_spec.rb
@@ -449,6 +456,7 @@ test_files:
449
456
  - spec/internal/config/database.yml
450
457
  - spec/internal/config/initializers/global_registry.rb
451
458
  - spec/internal/db/schema.rb
459
+ - spec/internal/db/test.sqlite
452
460
  - spec/internal/log/test.log
453
461
  - spec/models/person_spec.rb
454
462
  - spec/models/testing_spec.rb