global-registry-bindings 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +126 -0
  4. data/lib/global_registry_bindings.rb +8 -0
  5. data/lib/global_registry_bindings/entity/delete_entity_methods.rb +22 -0
  6. data/lib/global_registry_bindings/entity/entity_methods.rb +62 -0
  7. data/lib/global_registry_bindings/entity/entity_type_methods.rb +54 -0
  8. data/lib/global_registry_bindings/entity/mdm_methods.rb +43 -0
  9. data/lib/global_registry_bindings/entity/push_entity_methods.rb +78 -0
  10. data/lib/global_registry_bindings/entity/push_relationship_methods.rb +81 -0
  11. data/lib/global_registry_bindings/entity/relationship_type_methods.rb +59 -0
  12. data/lib/global_registry_bindings/exceptions.rb +9 -0
  13. data/lib/global_registry_bindings/global_registry_bindings.rb +71 -0
  14. data/lib/global_registry_bindings/options.rb +80 -0
  15. data/lib/global_registry_bindings/options/class_options.rb +58 -0
  16. data/lib/global_registry_bindings/options/instance_options.rb +61 -0
  17. data/lib/global_registry_bindings/railtie.rb +19 -0
  18. data/lib/global_registry_bindings/version.rb +7 -0
  19. data/lib/global_registry_bindings/workers/delete_gr_entity_worker.rb +22 -0
  20. data/lib/global_registry_bindings/workers/pull_mdm_id_worker.rb +30 -0
  21. data/lib/global_registry_bindings/workers/push_gr_entity_worker.rb +21 -0
  22. data/lib/global_registry_bindings/workers/push_relationship_worker.rb +21 -0
  23. data/spec/acceptance/global_registry_bindings_spec.rb +74 -0
  24. data/spec/factories/factories.rb +37 -0
  25. data/spec/fixtures/get_entities_person.json +8 -0
  26. data/spec/fixtures/get_entities_person_mdm.json +13 -0
  27. data/spec/fixtures/get_entities_person_relationship.json +32 -0
  28. data/spec/fixtures/get_entity_types.json +9 -0
  29. data/spec/fixtures/get_entity_types_address.json +59 -0
  30. data/spec/fixtures/get_entity_types_address_partial.json +43 -0
  31. data/spec/fixtures/get_entity_types_fancy_org.json +43 -0
  32. data/spec/fixtures/get_entity_types_fancy_org_partial.json +35 -0
  33. data/spec/fixtures/get_entity_types_person.json +42 -0
  34. data/spec/fixtures/get_entity_types_person_partial.json +34 -0
  35. data/spec/fixtures/get_relationship_types.json +9 -0
  36. data/spec/fixtures/get_relationship_types_person_fancy_org.json +41 -0
  37. data/spec/fixtures/get_relationship_types_person_fancy_org_partial.json +33 -0
  38. data/spec/fixtures/post_entities_fancy_org.json +8 -0
  39. data/spec/fixtures/post_entities_fancy_org_parent.json +8 -0
  40. data/spec/fixtures/post_entities_person.json +8 -0
  41. data/spec/fixtures/post_entity_types_address.json +9 -0
  42. data/spec/fixtures/post_entity_types_fancy_org.json +9 -0
  43. data/spec/fixtures/post_entity_types_person.json +9 -0
  44. data/spec/fixtures/post_relationship_types_person_fancy_org.json +16 -0
  45. data/spec/fixtures/put_entities_address.json +20 -0
  46. data/spec/fixtures/put_entities_person_relationship.json +29 -0
  47. data/spec/fixtures/put_entities_relationship.json +8 -0
  48. data/spec/fixtures/put_relationship_types_fields.json +33 -0
  49. data/spec/internal/app/models/address.rb +11 -0
  50. data/spec/internal/app/models/application_record.rb +5 -0
  51. data/spec/internal/app/models/assignment.rb +10 -0
  52. data/spec/internal/app/models/default.rb +6 -0
  53. data/spec/internal/app/models/namespaced/person.rb +18 -0
  54. data/spec/internal/app/models/organization.rb +12 -0
  55. data/spec/internal/config/database.yml +4 -0
  56. data/spec/internal/config/initializers/global_registry.rb +8 -0
  57. data/spec/internal/config/routes.rb +5 -0
  58. data/spec/internal/db/schema.rb +41 -0
  59. data/spec/internal/log/test.log +35717 -0
  60. data/spec/models/address_spec.rb +228 -0
  61. data/spec/models/assignment_spec.rb +200 -0
  62. data/spec/models/organization_spec.rb +127 -0
  63. data/spec/models/person_spec.rb +247 -0
  64. data/spec/spec_helper.rb +55 -0
  65. data/spec/workers/delete_gr_entity_worker_spec.rb +33 -0
  66. data/spec/workers/pull_mdm_id_worker_spec.rb +71 -0
  67. data/spec/workers/push_gr_entity_worker_spec.rb +27 -0
  68. data/spec/workers/push_relationship_worker_spec.rb +27 -0
  69. metadata +458 -0
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'sidekiq'
4
+ require 'sidekiq-unique-jobs'
5
+
6
+ module GlobalRegistry #:nodoc:
7
+ module Bindings #:nodoc:
8
+ module Workers #:nodoc:
9
+ class PushRelationshipWorker
10
+ include Sidekiq::Worker
11
+ sidekiq_options unique: :until_and_while_executing
12
+
13
+ def perform(model_class, id)
14
+ model_class.find(id).send(:push_relationship_to_global_registry)
15
+ rescue ActiveRecord::RecordNotFound # rubocop:disable Lint/HandleExceptions
16
+ # If the record was deleted after the job was created, swallow it
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe 'GlobalRegistry::Bindings' do
6
+ describe 'ActiveRecord::Base extensions' do
7
+ it 'should respond to global_registry_bindings' do
8
+ expect(::ActiveRecord::Base).to respond_to :global_registry_bindings
9
+ end
10
+ end
11
+
12
+ describe 'Options' do
13
+ it 'should have default values for all options' do
14
+ expect(Default.global_registry.id_column).to be :global_registry_id
15
+ expect(Default.global_registry.mdm_id_column).to be nil
16
+ expect(Default.global_registry.parent_association).to be nil
17
+ expect(Default.global_registry.push_on)
18
+ .to contain_exactly(:create, :update, :delete)
19
+ expect(Default.global_registry.mdm_timeout).to eq 1.minute
20
+ expect(Default.global_registry.type).to be :default
21
+ expect(Default.global_registry.exclude_fields)
22
+ .to contain_exactly(:global_registry_id, :id, :created_at, :updated_at)
23
+ expect(Default.global_registry.extra_fields).to be_a(Hash).and be_empty
24
+ end
25
+
26
+ it 'should parse and set mdm options' do
27
+ expect(Namespaced::Person.global_registry.id_column).to be :global_registry_id
28
+ expect(Namespaced::Person.global_registry.mdm_id_column).to be :global_registry_mdm_id
29
+ expect(Namespaced::Person.global_registry.mdm_timeout).to eq 24.hours
30
+ expect(Namespaced::Person.global_registry.type).to be :person
31
+ expect(Namespaced::Person.global_registry.exclude_fields)
32
+ .to contain_exactly(:global_registry_id, :id, :created_at, :updated_at, :global_registry_mdm_id, :guid)
33
+ expect(Namespaced::Person.global_registry.extra_fields).to be_a(Hash).and be_empty
34
+ expect(GlobalRegistry::Bindings::Workers::PullNamespacedPersonMdmIdWorker.get_sidekiq_options)
35
+ .to include('unique' => :until_timeout, 'unique_expiration' => 24.hours)
36
+ end
37
+
38
+ it 'should parse and set exclude and extra fields options' do
39
+ expect(Address.global_registry.id_column).to be :global_registry_id
40
+ expect(Address.global_registry.mdm_id_column).to be nil
41
+ expect(Address.global_registry.type).to be :address
42
+ expect(Address.global_registry.parent_association).to be :person
43
+ expect(Address.global_registry.exclude_fields)
44
+ .to contain_exactly(:global_registry_id, :id, :created_at, :updated_at, :person_id, :address1)
45
+ expect(Address.global_registry.extra_fields)
46
+ .to include(line1: :string, postal_code: :string)
47
+ end
48
+
49
+ it 'should parse and set push_on fields' do
50
+ expect(Organization.global_registry.id_column).to be :gr_id
51
+ expect(Organization.global_registry.mdm_id_column).to be nil
52
+ expect(Organization.global_registry.type).to be :fancy_org
53
+ expect(Organization.global_registry.parent_association).to be :parent
54
+ expect(Organization.global_registry.push_on).to be_an(Array).and eq(%i[create delete])
55
+ expect(Organization.global_registry.exclude_fields)
56
+ .to contain_exactly(:gr_id, :id, :created_at, :updated_at, :parent_id)
57
+ expect(Organization.global_registry.extra_fields).to be_a(Hash).and be_empty
58
+ end
59
+
60
+ it 'should parse and set relationship fields' do
61
+ expect(Assignment.global_registry.id_column).to be :global_registry_id
62
+ expect(Assignment.global_registry.mdm_id_column).to be nil
63
+ expect(Assignment.global_registry.type).to be :assignment
64
+ expect(Assignment.global_registry.parent_association).to be :person
65
+ expect(Assignment.global_registry.related_association).to be :organization
66
+ expect(Assignment.global_registry.parent_relationship_name).to be :person
67
+ expect(Assignment.global_registry.related_relationship_name).to be :fancy_org
68
+ expect(Assignment.global_registry.push_on).to be_an(Array).and eq(%i[create update delete])
69
+ expect(Assignment.global_registry.exclude_fields)
70
+ .to contain_exactly(:global_registry_id, :id, :created_at, :updated_at, :person_id, :organization_id)
71
+ expect(Assignment.global_registry.extra_fields).to be_a(Hash).and be_empty
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'securerandom'
4
+
5
+ FactoryGirl.define do
6
+ factory :person, class: Namespaced::Person do
7
+ first_name 'Tony'
8
+ last_name 'Stark'
9
+ guid '98711710-acb5-4a41-ba51-e0fc56644b53'
10
+ global_registry_id nil
11
+ global_registry_mdm_id nil
12
+ end
13
+
14
+ factory :address do
15
+ address1 '10880 Malibu Point'
16
+ zip '90265'
17
+ primary true
18
+ global_registry_id nil
19
+ person_id nil
20
+ end
21
+
22
+ factory :organization do
23
+ name 'Organization'
24
+ description 'Fancy Organization'
25
+ start_date { Time.zone.today }
26
+ parent_id nil
27
+ gr_id nil
28
+ end
29
+
30
+ factory :assignment do
31
+ role 'leader'
32
+ hired_at { 2.months.ago }
33
+ person_id nil
34
+ organization_id nil
35
+ global_registry_id nil
36
+ end
37
+ end
@@ -0,0 +1,8 @@
1
+ {
2
+ "entity": {
3
+ "person": {
4
+ "id": "22527d88-3cba-11e7-b876-129bd0521531"
5
+ }
6
+ },
7
+ "meta": {}
8
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "entity": {
3
+ "person": {
4
+ "id": "22527d88-3cba-11e7-b876-129bd0521531",
5
+ "master_person:relationship": {
6
+ "master_person": "c81340b2-7e57-4978-b6b9-396f21bb0bb2",
7
+ "relationship_entity_id": "31d8465a-f9ff-11e6-9e00-1228c4aab4b9",
8
+ "client_integration_id": "16a96973-6240-449b-adec-757c7da31b17"
9
+ }
10
+ }
11
+ },
12
+ "meta": {}
13
+ }
@@ -0,0 +1,32 @@
1
+ {
2
+ "entity": {
3
+ "person": {
4
+ "id": "22527d88-3cba-11e7-b876-129bd0521531",
5
+ "first_name": "Tony",
6
+ "last_name": "Stark",
7
+ "authentication": {
8
+ "id": "9484718a-3cbb-11e7-b876-129bd0521531",
9
+ "key_guid": "8ec978ef-0b44-4ba1-ab32-1b6cae8aeb17",
10
+ "parent_id": "22527d88-3cba-11e7-b876-129bd0521531",
11
+ "client_integration_id": "1"
12
+ },
13
+ "address": {
14
+ "id": "0a594356-3f1c-11e7-bba6-129bd0521531",
15
+ "zip": "90265",
16
+ "primary": true,
17
+ "line1": "10880 Malibu Point",
18
+ "postal_code": "90265",
19
+ "parent_id": "22527d88-3cba-11e7-b876-129bd0521531",
20
+ "client_integration_id": "1",
21
+ "client_updated_at": "2001-02-03 00:00:00"
22
+ },
23
+ "fancy_org:relationship": {
24
+ "fancy_org": "aebb4170-3f34-11e7-bba6-129bd0521531",
25
+ "relationship_entity_id": "51a014a4-4252-11e7-944f-129bd0521531",
26
+ "client_integration_id": "1",
27
+ "role": "peon"
28
+ },
29
+ "client_integration_id": "1"
30
+ }
31
+ }
32
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "entity_types": [],
3
+ "meta": {
4
+ "page": 1,
5
+ "next_page": false,
6
+ "from": 1,
7
+ "to": 1
8
+ }
9
+ }
@@ -0,0 +1,59 @@
1
+ {
2
+ "entity_types": [
3
+ {
4
+ "id": "f5331684-3ca8-11e7-b937-129bd0521531",
5
+ "name": "address",
6
+ "data_visibility": "public",
7
+ "fields": [
8
+ {
9
+ "id": "26f131be-3f1b-11e7-925c-129bd0521531",
10
+ "name": "zip",
11
+ "data_visibility": "public",
12
+ "field_type": "string",
13
+ "is_editable": true,
14
+ "unique_value": false
15
+ },
16
+ {
17
+ "id": "2dc5993a-3f1b-11e7-b876-129bd0521531",
18
+ "name": "line1",
19
+ "data_visibility": "public",
20
+ "field_type": "string",
21
+ "is_editable": true,
22
+ "unique_value": false
23
+ },
24
+ {
25
+ "id": "30bec83c-3f1b-11e7-b876-129bd0521531",
26
+ "name": "line2",
27
+ "data_visibility": "public",
28
+ "field_type": "string",
29
+ "is_editable": true,
30
+ "unique_value": false
31
+ },
32
+ {
33
+ "id": "40db6be4-3f1b-11e7-b876-129bd0521531",
34
+ "name": "primary",
35
+ "data_visibility": "public",
36
+ "field_type": "boolean",
37
+ "is_editable": true,
38
+ "unique_value": false
39
+ },
40
+ {
41
+ "id": "48181a92-3f1b-11e7-bba6-129bd0521531",
42
+ "name": "postal_code",
43
+ "data_visibility": "public",
44
+ "field_type": "string",
45
+ "is_editable": true,
46
+ "unique_value": false
47
+ }
48
+ ],
49
+ "is_editable": true,
50
+ "unique_value": false
51
+ }
52
+ ],
53
+ "meta": {
54
+ "page": 1,
55
+ "next_page": false,
56
+ "from": 1,
57
+ "to": 1
58
+ }
59
+ }
@@ -0,0 +1,43 @@
1
+ {
2
+ "entity_types": [
3
+ {
4
+ "id": "f5331684-3ca8-11e7-b937-129bd0521531",
5
+ "name": "address",
6
+ "data_visibility": "public",
7
+ "fields": [
8
+ {
9
+ "id": "26f131be-3f1b-11e7-925c-129bd0521531",
10
+ "name": "zip",
11
+ "data_visibility": "public",
12
+ "field_type": "string",
13
+ "is_editable": true,
14
+ "unique_value": false
15
+ },
16
+ {
17
+ "id": "2dc5993a-3f1b-11e7-b876-129bd0521531",
18
+ "name": "line1",
19
+ "data_visibility": "public",
20
+ "field_type": "string",
21
+ "is_editable": true,
22
+ "unique_value": false
23
+ },
24
+ {
25
+ "id": "48181a92-3f1b-11e7-bba6-129bd0521531",
26
+ "name": "postal_code",
27
+ "data_visibility": "public",
28
+ "field_type": "string",
29
+ "is_editable": true,
30
+ "unique_value": false
31
+ }
32
+ ],
33
+ "is_editable": true,
34
+ "unique_value": false
35
+ }
36
+ ],
37
+ "meta": {
38
+ "page": 1,
39
+ "next_page": false,
40
+ "from": 1,
41
+ "to": 1
42
+ }
43
+ }
@@ -0,0 +1,43 @@
1
+ {
2
+ "entity_types": [
3
+ {
4
+ "id": "025a1128-3f33-11e7-b876-129bd0521531",
5
+ "name": "fancy_org",
6
+ "data_visibility": "public",
7
+ "fields": [
8
+ {
9
+ "id": "692bef3e-3f33-11e7-b937-129bd0521531",
10
+ "name": "name",
11
+ "data_visibility": "public",
12
+ "field_type": "string",
13
+ "is_editable": true,
14
+ "unique_value": false
15
+ },
16
+ {
17
+ "id": "6e504b40-3f33-11e7-b937-129bd0521531",
18
+ "name": "description",
19
+ "data_visibility": "public",
20
+ "field_type": "string",
21
+ "is_editable": true,
22
+ "unique_value": false
23
+ },
24
+ {
25
+ "id": "7311faa2-3f33-11e7-b876-129bd0521531",
26
+ "name": "start_date",
27
+ "data_visibility": "public",
28
+ "field_type": "date",
29
+ "is_editable": true,
30
+ "unique_value": false
31
+ }
32
+ ],
33
+ "is_editable": true,
34
+ "unique_value": false
35
+ }
36
+ ],
37
+ "meta": {
38
+ "page": 1,
39
+ "next_page": false,
40
+ "from": 1,
41
+ "to": 1
42
+ }
43
+ }
@@ -0,0 +1,35 @@
1
+ {
2
+ "entity_types": [
3
+ {
4
+ "id": "025a1128-3f33-11e7-b876-129bd0521531",
5
+ "name": "fancy_org",
6
+ "data_visibility": "public",
7
+ "fields": [
8
+ {
9
+ "id": "692bef3e-3f33-11e7-b937-129bd0521531",
10
+ "name": "name",
11
+ "data_visibility": "public",
12
+ "field_type": "string",
13
+ "is_editable": true,
14
+ "unique_value": false
15
+ },
16
+ {
17
+ "id": "7311faa2-3f33-11e7-b876-129bd0521531",
18
+ "name": "start_date",
19
+ "data_visibility": "public",
20
+ "field_type": "date",
21
+ "is_editable": true,
22
+ "unique_value": false
23
+ }
24
+ ],
25
+ "is_editable": true,
26
+ "unique_value": false
27
+ }
28
+ ],
29
+ "meta": {
30
+ "page": 1,
31
+ "next_page": false,
32
+ "from": 1,
33
+ "to": 1
34
+ }
35
+ }
@@ -0,0 +1,42 @@
1
+ {
2
+ "entity_types": [
3
+ {
4
+ "id": "ee13a693-3ce7-4c19-b59a-30c8f137acd8",
5
+ "name": "person",
6
+ "data_visibility": "public",
7
+ "fields": [
8
+ {
9
+ "id": "67256bfa-3b34-11e7-b876-129bd0521531",
10
+ "name": "first_name",
11
+ "data_visibility": "public",
12
+ "field_type": "string",
13
+ "is_editable": true,
14
+ "unique_value": false
15
+ },
16
+ {
17
+ "id": "6b82f97e-3b34-11e7-bba6-129bd0521531",
18
+ "name": "last_name",
19
+ "data_visibility": "public",
20
+ "field_type": "string",
21
+ "is_editable": true,
22
+ "unique_value": false
23
+ },
24
+ {
25
+ "id": "f5331684-3ca8-11e7-b937-129bd0521531",
26
+ "name": "address",
27
+ "data_visibility": "public",
28
+ "is_editable": true,
29
+ "unique_value": false
30
+ }
31
+ ],
32
+ "is_editable": true,
33
+ "unique_value": false
34
+ }
35
+ ],
36
+ "meta": {
37
+ "page": 1,
38
+ "next_page": false,
39
+ "from": 1,
40
+ "to": 1
41
+ }
42
+ }
@@ -0,0 +1,34 @@
1
+ {
2
+ "entity_types": [
3
+ {
4
+ "id": "ee13a693-3ce7-4c19-b59a-30c8f137acd8",
5
+ "name": "person",
6
+ "data_visibility": "public",
7
+ "fields": [
8
+ {
9
+ "id": "6b82f97e-3b34-11e7-bba6-129bd0521531",
10
+ "name": "last_name",
11
+ "data_visibility": "public",
12
+ "field_type": "string",
13
+ "is_editable": true,
14
+ "unique_value": false
15
+ },
16
+ {
17
+ "id": "f5331684-3ca8-11e7-b937-129bd0521531",
18
+ "name": "address",
19
+ "data_visibility": "public",
20
+ "is_editable": true,
21
+ "unique_value": false
22
+ }
23
+ ],
24
+ "is_editable": true,
25
+ "unique_value": false
26
+ }
27
+ ],
28
+ "meta": {
29
+ "page": 1,
30
+ "next_page": false,
31
+ "from": 1,
32
+ "to": 1
33
+ }
34
+ }