global-registry-bindings 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -4
- data/lib/global_registry_bindings/entity/push_relationship_methods.rb +53 -29
- data/lib/global_registry_bindings/entity/relationship_type_methods.rb +17 -8
- data/lib/global_registry_bindings/global_registry_bindings.rb +21 -14
- data/lib/global_registry_bindings/model/entity.rb +13 -9
- data/lib/global_registry_bindings/model/push_relationship.rb +6 -0
- data/lib/global_registry_bindings/model/relationship.rb +12 -10
- data/lib/global_registry_bindings/options/entity_class_options.rb +4 -0
- data/lib/global_registry_bindings/options/entity_instance_options.rb +1 -0
- data/lib/global_registry_bindings/options/entity_options_parser.rb +1 -0
- data/lib/global_registry_bindings/options/relationship_class_options.rb +9 -0
- data/lib/global_registry_bindings/options/relationship_instance_options.rb +16 -6
- data/lib/global_registry_bindings/options/relationship_options_parser.rb +5 -5
- data/lib/global_registry_bindings/version.rb +1 -1
- data/lib/global_registry_bindings/workers/push_relationship_worker.rb +2 -2
- data/spec/acceptance/global_registry_bindings_spec.rb +11 -9
- data/spec/factories/factories.rb +2 -0
- data/spec/fixtures/get_entity_types_fancy_org_assignment.json +35 -0
- data/spec/fixtures/post_relationship_types_assigned_by.json +16 -0
- data/spec/fixtures/put_entities_fancy_org_assignment_assigned_by.json +20 -0
- data/spec/internal/app/models/area.rb +2 -1
- data/spec/internal/app/models/assignment.rb +12 -2
- data/spec/internal/app/models/community.rb +2 -1
- data/spec/internal/app/models/namespaced/person.rb +6 -2
- data/spec/internal/app/models/organization.rb +3 -1
- data/spec/internal/db/schema.rb +2 -0
- data/spec/internal/log/test.log +28818 -0
- data/spec/workers/push_relationship_worker_spec.rb +133 -33
- metadata +10 -4
@@ -34,7 +34,7 @@ RSpec.describe GlobalRegistry::Bindings::Workers::PushRelationshipWorker do
|
|
34
34
|
|
35
35
|
describe '#push_relationship_to_global_registry' do
|
36
36
|
describe Assignment do
|
37
|
-
let(:worker) { GlobalRegistry::Bindings::Workers::PushRelationshipWorker.new assignment, :
|
37
|
+
let(:worker) { GlobalRegistry::Bindings::Workers::PushRelationshipWorker.new assignment, :fancy_org_assignment }
|
38
38
|
context 'as create' do
|
39
39
|
let(:person) { create(:person, global_registry_id: '22527d88-3cba-11e7-b876-129bd0521531') }
|
40
40
|
let(:organization) { create(:organization, gr_id: 'aebb4170-3f34-11e7-bba6-129bd0521531') }
|
@@ -71,7 +71,12 @@ RSpec.describe GlobalRegistry::Bindings::Workers::PushRelationshipWorker do
|
|
71
71
|
'https://backend.global-registry.org/relationship_types/5d721db8-4248-11e7-90b4-129bd0521531')
|
72
72
|
.with(body: { relationship_type: { fields: [{ name: 'role', field_type: 'string' },
|
73
73
|
{ name: 'hired_at', field_type: 'datetime' }] } })
|
74
|
-
.to_return(body: file_fixture('put_relationship_types_fields.json'), status: 200)
|
74
|
+
.to_return(body: file_fixture('put_relationship_types_fields.json'), status: 200),
|
75
|
+
stub_request(:put,
|
76
|
+
'https://backend.global-registry.org/entity_types/5d70b630-4248-11e7-90b4-129bd0521531')
|
77
|
+
.with(body: { entity_type: { id: '5d70b630-4248-11e7-90b4-129bd0521531',
|
78
|
+
name: 'fancy_org_assignment' } })
|
79
|
+
.to_return(status: 200)]
|
75
80
|
end
|
76
81
|
|
77
82
|
it 'should create \'assignment\' relationship_type and push relationship' do
|
@@ -229,6 +234,74 @@ RSpec.describe GlobalRegistry::Bindings::Workers::PushRelationshipWorker do
|
|
229
234
|
end
|
230
235
|
end
|
231
236
|
|
237
|
+
describe Assignment do
|
238
|
+
let(:worker) { GlobalRegistry::Bindings::Workers::PushRelationshipWorker.new assignment, :assigned_by }
|
239
|
+
|
240
|
+
context 'as create' do
|
241
|
+
let(:person) { create(:person, global_registry_id: '22527d88-3cba-11e7-b876-129bd0521531') }
|
242
|
+
let(:organization) { create(:organization, gr_id: 'aebb4170-3f34-11e7-bba6-129bd0521531') }
|
243
|
+
|
244
|
+
context '\'assigned_by\' relationship_type does not exist' do
|
245
|
+
let(:assignment) do
|
246
|
+
create(:assignment, person: person, organization: organization, assigned_by: person,
|
247
|
+
global_registry_id: '51a014a4-4252-11e7-944f-129bd0521531')
|
248
|
+
end
|
249
|
+
|
250
|
+
let!(:requests) do
|
251
|
+
[stub_request(:get, 'https://backend.global-registry.org/entity_types')
|
252
|
+
.with(query: { 'filters[name]' => 'fancy_org_assignment' })
|
253
|
+
.to_return(body: file_fixture('get_entity_types_fancy_org_assignment.json'), status: 200),
|
254
|
+
stub_request(:get, 'https://backend.global-registry.org/entity_types')
|
255
|
+
.with(query: { 'filters[name]' => 'person', 'filters[parent_id]' => nil })
|
256
|
+
.to_return(body: file_fixture('get_entity_types_person.json'), status: 200),
|
257
|
+
stub_request(:get, 'https://backend.global-registry.org/relationship_types')
|
258
|
+
.with(query: { 'filters[between]' =>
|
259
|
+
'5d70b630-4248-11e7-90b4-129bd0521531,ee13a693-3ce7-4c19-b59a-30c8f137acd8' })
|
260
|
+
.to_return(body: file_fixture('get_relationship_types.json'), status: 200),
|
261
|
+
stub_request(:post, 'https://backend.global-registry.org/relationship_types')
|
262
|
+
.with(body: { relationship_type: { entity_type1_id: '5d70b630-4248-11e7-90b4-129bd0521531',
|
263
|
+
entity_type2_id: 'ee13a693-3ce7-4c19-b59a-30c8f137acd8',
|
264
|
+
relationship1: 'assigned_by', relationship2: 'person' } })
|
265
|
+
.to_return(body: file_fixture('post_relationship_types_assigned_by.json'), status: 200),
|
266
|
+
stub_request(:put,
|
267
|
+
'https://backend.global-registry.org/entity_types/4f5d8150-76c7-11e7-b3f0-129bd0521531')
|
268
|
+
.with(body: { entity_type: { id: '4f5d8150-76c7-11e7-b3f0-129bd0521531',
|
269
|
+
name: 'assigned_by' } })
|
270
|
+
.to_return(status: 200),
|
271
|
+
stub_request(:put, "https://backend.global-registry.org/entities/#{assignment.global_registry_id}")
|
272
|
+
.with(body: { entity: { fancy_org_assignment: { 'person:relationship': {
|
273
|
+
client_integration_id: assignment.id,
|
274
|
+
client_updated_at: '2001-02-03 00:00:00', person: person.global_registry_id
|
275
|
+
} }, client_integration_id: assignment.id } },
|
276
|
+
query: { full_response: 'true', fields: 'person:relationship' })
|
277
|
+
.to_return(body: file_fixture('put_entities_fancy_org_assignment_assigned_by.json'), status: 200)]
|
278
|
+
end
|
279
|
+
|
280
|
+
it 'should create \'assigned_by\' relationship_type and push relationship' do
|
281
|
+
worker.push_relationship_to_global_registry
|
282
|
+
requests.each { |r| expect(r).to have_been_requested.once }
|
283
|
+
expect(assignment.assigned_by_gr_rel_id).to eq '0fd8b8b8-76c9-11e7-b15c-129bd0521531'
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
context 'fancy_org_assignment missing global_registry_id' do
|
288
|
+
let(:assignment) do
|
289
|
+
create(:assignment, person: person, organization: organization, assigned_by: person)
|
290
|
+
end
|
291
|
+
|
292
|
+
it 'should raise an exception' do
|
293
|
+
clear_sidekiq_jobs_and_locks
|
294
|
+
|
295
|
+
expect do
|
296
|
+
worker.push_relationship_to_global_registry
|
297
|
+
end.to raise_error(GlobalRegistry::Bindings::RelatedEntityMissingGlobalRegistryId).and(
|
298
|
+
change(GlobalRegistry::Bindings::Workers::PushRelationshipWorker.jobs, :size).by(2)
|
299
|
+
)
|
300
|
+
end
|
301
|
+
end
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
232
305
|
describe Organization do
|
233
306
|
let(:worker) { GlobalRegistry::Bindings::Workers::PushRelationshipWorker.new organization, :area }
|
234
307
|
context 'as create' do
|
@@ -333,11 +406,11 @@ RSpec.describe GlobalRegistry::Bindings::Workers::PushRelationshipWorker do
|
|
333
406
|
|
334
407
|
describe Community do
|
335
408
|
let(:worker) { GlobalRegistry::Bindings::Workers::PushRelationshipWorker.new community, :infobase_ministry }
|
336
|
-
let(:community) do
|
337
|
-
create(:community, global_registry_id: '6133f6fe-c63a-425a-bb46-68917c689723', infobase_id: 2345)
|
338
|
-
end
|
339
409
|
|
340
410
|
context '\'ministry\' entity_type does not exist' do
|
411
|
+
let(:community) do
|
412
|
+
create(:community, global_registry_id: '6133f6fe-c63a-425a-bb46-68917c689723', infobase_id: 2345)
|
413
|
+
end
|
341
414
|
let!(:requests) do
|
342
415
|
[stub_request(:get, 'https://backend.global-registry.org/entity_types')
|
343
416
|
.with(query: { 'filters[name]' => 'ministry' })
|
@@ -355,36 +428,63 @@ RSpec.describe GlobalRegistry::Bindings::Workers::PushRelationshipWorker do
|
|
355
428
|
end
|
356
429
|
end
|
357
430
|
|
358
|
-
context '\'ministry\' entity_type
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
.with(body: { entity: { community: { 'ministry:relationship': {
|
377
|
-
client_integration_id: community.id, client_updated_at: '2001-02-03 00:00:00',
|
378
|
-
ministry: '41f767fd-86f4-42e2-8d24-cbc3f697b794'
|
379
|
-
} }, client_integration_id: community.id } },
|
380
|
-
query: { full_response: 'true', fields: 'ministry:relationship' })
|
381
|
-
.to_return(body: file_fixture('put_entities_community_relationship.json'), status: 200)]
|
431
|
+
context '\'ministry\' entity_type exists' do
|
432
|
+
context 'ministry global_registry_id not found' do
|
433
|
+
let(:community) do
|
434
|
+
create(:community, global_registry_id: '6133f6fe-c63a-425a-bb46-68917c689723',
|
435
|
+
infobase_id: 2345, infobase_gr_id: 'ee40f9ed-d625-405b-8ce6-aec821611ec6')
|
436
|
+
end
|
437
|
+
let!(:requests) do
|
438
|
+
[stub_request(:delete,
|
439
|
+
'https://backend.global-registry.org/entities/ee40f9ed-d625-405b-8ce6-aec821611ec6')
|
440
|
+
.to_return(status: 200)]
|
441
|
+
end
|
442
|
+
|
443
|
+
it 'should delete existing relationship' do
|
444
|
+
allow(community).to receive(:pull_infobase_global_registry_id)
|
445
|
+
worker.push_relationship_to_global_registry
|
446
|
+
requests.each { |r| expect(r).to have_been_requested.once }
|
447
|
+
expect(community.infobase_gr_id).to be nil
|
448
|
+
end
|
382
449
|
end
|
383
450
|
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
451
|
+
context 'ministry global_registry_id exists' do
|
452
|
+
let(:community) do
|
453
|
+
create(:community, global_registry_id: '6133f6fe-c63a-425a-bb46-68917c689723', infobase_id: 2345)
|
454
|
+
end
|
455
|
+
let!(:requests) do
|
456
|
+
[stub_request(:get, 'https://backend.global-registry.org/entity_types')
|
457
|
+
.with(query: { 'filters[name]' => 'ministry' })
|
458
|
+
.to_return(body: file_fixture('get_entity_types_ministry.json'), status: 200),
|
459
|
+
stub_request(:get, 'https://backend.global-registry.org/entity_types')
|
460
|
+
.with(query: { 'filters[name]' => 'community' })
|
461
|
+
.to_return(body: file_fixture('get_entity_types_community.json'), status: 200),
|
462
|
+
stub_request(:get, 'https://backend.global-registry.org/relationship_types')
|
463
|
+
.with(query: { 'filters[between]' =>
|
464
|
+
'3d8a68df-72f3-45f0-848b-4a6322448a6c,f0f0876b-0ebe-4680-9e48-1c3b72523d07' })
|
465
|
+
.to_return(body: file_fixture('get_relationship_types.json'), status: 200),
|
466
|
+
stub_request(:post, 'https://backend.global-registry.org/relationship_types')
|
467
|
+
.with(body: { relationship_type: { entity_type1_id: '3d8a68df-72f3-45f0-848b-4a6322448a6c',
|
468
|
+
entity_type2_id: 'f0f0876b-0ebe-4680-9e48-1c3b72523d07',
|
469
|
+
relationship1: 'community', relationship2: 'ministry' } })
|
470
|
+
.to_return(body: file_fixture('post_relationship_types_community_ministry.json'), status: 200),
|
471
|
+
stub_request(:put, "https://backend.global-registry.org/entities/#{community.global_registry_id}")
|
472
|
+
.with(body: { entity: { community: { 'ministry:relationship': {
|
473
|
+
client_integration_id: community.id, client_updated_at: '2001-02-03 00:00:00',
|
474
|
+
ministry: '41f767fd-86f4-42e2-8d24-cbc3f697b794'
|
475
|
+
} }, client_integration_id: community.id } },
|
476
|
+
query: { full_response: 'true', fields: 'ministry:relationship' })
|
477
|
+
.to_return(body: file_fixture('put_entities_community_relationship.json'), status: 200),
|
478
|
+
stub_request(:put,
|
479
|
+
'https://backend.global-registry.org/entity_types/f854900f-9dcf-473a-be1b-399dda75edae')
|
480
|
+
.with(body: { entity_type: { id: 'f854900f-9dcf-473a-be1b-399dda75edae', name: 'infobase_ministry' } })
|
481
|
+
.to_return(status: 200)]
|
482
|
+
end
|
483
|
+
it 'should push relationship_type and infobase_ministry relationship' do
|
484
|
+
worker.push_relationship_to_global_registry
|
485
|
+
requests.each { |r| expect(r).to have_been_requested.once }
|
486
|
+
expect(community.infobase_gr_id).to eq('ee40f9ed-d625-405b-8ce6-aec821611ec6')
|
487
|
+
end
|
388
488
|
end
|
389
489
|
end
|
390
490
|
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.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Zoetewey
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-07
|
11
|
+
date: 2017-08-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -36,7 +36,7 @@ dependencies:
|
|
36
36
|
requirements:
|
37
37
|
- - "~>"
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: '1.
|
39
|
+
version: '1.4'
|
40
40
|
- - "<"
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: '2'
|
@@ -46,7 +46,7 @@ dependencies:
|
|
46
46
|
requirements:
|
47
47
|
- - "~>"
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version: '1.
|
49
|
+
version: '1.4'
|
50
50
|
- - "<"
|
51
51
|
- !ruby/object:Gem::Version
|
52
52
|
version: '2'
|
@@ -335,6 +335,7 @@ files:
|
|
335
335
|
- spec/fixtures/get_entity_types_area.json
|
336
336
|
- spec/fixtures/get_entity_types_community.json
|
337
337
|
- spec/fixtures/get_entity_types_fancy_org.json
|
338
|
+
- spec/fixtures/get_entity_types_fancy_org_assignment.json
|
338
339
|
- spec/fixtures/get_entity_types_fancy_org_partial.json
|
339
340
|
- spec/fixtures/get_entity_types_ministry.json
|
340
341
|
- spec/fixtures/get_entity_types_person.json
|
@@ -349,12 +350,14 @@ files:
|
|
349
350
|
- spec/fixtures/post_entity_types_address.json
|
350
351
|
- spec/fixtures/post_entity_types_fancy_org.json
|
351
352
|
- spec/fixtures/post_entity_types_person.json
|
353
|
+
- spec/fixtures/post_relationship_types_assigned_by.json
|
352
354
|
- spec/fixtures/post_relationship_types_community_ministry.json
|
353
355
|
- spec/fixtures/post_relationship_types_fancy_org_area.json
|
354
356
|
- spec/fixtures/post_relationship_types_person_fancy_org.json
|
355
357
|
- spec/fixtures/put_entities_address.json
|
356
358
|
- spec/fixtures/put_entities_community_relationship.json
|
357
359
|
- spec/fixtures/put_entities_fancy_org_area_relationship.json
|
360
|
+
- spec/fixtures/put_entities_fancy_org_assignment_assigned_by.json
|
358
361
|
- spec/fixtures/put_entities_fancy_org_relationship.json
|
359
362
|
- spec/fixtures/put_entities_person_country_relationship.json
|
360
363
|
- spec/fixtures/put_entities_person_relationship.json
|
@@ -424,6 +427,7 @@ test_files:
|
|
424
427
|
- spec/fixtures/get_entity_types_area.json
|
425
428
|
- spec/fixtures/get_entity_types_community.json
|
426
429
|
- spec/fixtures/get_entity_types_fancy_org.json
|
430
|
+
- spec/fixtures/get_entity_types_fancy_org_assignment.json
|
427
431
|
- spec/fixtures/get_entity_types_fancy_org_partial.json
|
428
432
|
- spec/fixtures/get_entity_types_ministry.json
|
429
433
|
- spec/fixtures/get_entity_types_person.json
|
@@ -438,12 +442,14 @@ test_files:
|
|
438
442
|
- spec/fixtures/post_entity_types_address.json
|
439
443
|
- spec/fixtures/post_entity_types_fancy_org.json
|
440
444
|
- spec/fixtures/post_entity_types_person.json
|
445
|
+
- spec/fixtures/post_relationship_types_assigned_by.json
|
441
446
|
- spec/fixtures/post_relationship_types_community_ministry.json
|
442
447
|
- spec/fixtures/post_relationship_types_fancy_org_area.json
|
443
448
|
- spec/fixtures/post_relationship_types_person_fancy_org.json
|
444
449
|
- spec/fixtures/put_entities_address.json
|
445
450
|
- spec/fixtures/put_entities_community_relationship.json
|
446
451
|
- spec/fixtures/put_entities_fancy_org_area_relationship.json
|
452
|
+
- spec/fixtures/put_entities_fancy_org_assignment_assigned_by.json
|
447
453
|
- spec/fixtures/put_entities_fancy_org_relationship.json
|
448
454
|
- spec/fixtures/put_entities_person_country_relationship.json
|
449
455
|
- spec/fixtures/put_entities_person_relationship.json
|