global-registry-bindings 0.0.6 → 0.1.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.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +79 -35
  3. data/lib/global_registry_bindings/entity/entity_type_methods.rb +35 -33
  4. data/lib/global_registry_bindings/entity/mdm_methods.rb +9 -19
  5. data/lib/global_registry_bindings/entity/push_entity_methods.rb +31 -38
  6. data/lib/global_registry_bindings/entity/push_relationship_methods.rb +61 -47
  7. data/lib/global_registry_bindings/entity/relationship_type_methods.rb +48 -37
  8. data/lib/global_registry_bindings/exceptions.rb +1 -0
  9. data/lib/global_registry_bindings/global_registry_bindings.rb +129 -46
  10. data/lib/global_registry_bindings/{entity/delete_entity_methods.rb → model/delete_entity.rb} +5 -5
  11. data/lib/global_registry_bindings/model/entity.rb +64 -0
  12. data/lib/global_registry_bindings/model/pull_mdm.rb +23 -0
  13. data/lib/global_registry_bindings/model/push_entity.rb +21 -0
  14. data/lib/global_registry_bindings/model/push_relationship.rb +79 -0
  15. data/lib/global_registry_bindings/model/relationship.rb +68 -0
  16. data/lib/global_registry_bindings/options.rb +26 -59
  17. data/lib/global_registry_bindings/options/entity_class_options.rb +34 -0
  18. data/lib/global_registry_bindings/options/entity_instance_options.rb +90 -0
  19. data/lib/global_registry_bindings/options/entity_options_parser.rb +76 -0
  20. data/lib/global_registry_bindings/options/relationship_class_options.rb +37 -0
  21. data/lib/global_registry_bindings/options/relationship_instance_options.rb +131 -0
  22. data/lib/global_registry_bindings/options/relationship_options_parser.rb +98 -0
  23. data/lib/global_registry_bindings/railtie.rb +2 -1
  24. data/lib/global_registry_bindings/version.rb +1 -1
  25. data/lib/global_registry_bindings/worker.rb +25 -0
  26. data/lib/global_registry_bindings/workers/{delete_gr_entity_worker.rb → delete_entity_worker.rb} +1 -6
  27. data/lib/global_registry_bindings/workers/pull_mdm_id_worker.rb +12 -13
  28. data/lib/global_registry_bindings/workers/push_entity_worker.rb +24 -0
  29. data/lib/global_registry_bindings/workers/push_relationship_worker.rb +17 -7
  30. data/spec/acceptance/global_registry_bindings_spec.rb +50 -40
  31. data/spec/factories/factories.rb +24 -0
  32. data/spec/fixtures/get_entity_types_area.json +44 -0
  33. data/spec/fixtures/post_entities_community.json +8 -0
  34. data/spec/fixtures/post_relationship_types_fancy_org_area.json +16 -0
  35. data/spec/fixtures/put_entities_community_relationship.json +16 -0
  36. data/spec/fixtures/put_entities_fancy_org_area_relationship.json +8 -0
  37. data/spec/fixtures/put_entities_fancy_org_relationship.json +17 -0
  38. data/spec/fixtures/put_entities_person_country_relationship.json +23 -0
  39. data/spec/fixtures/put_entities_relationship_400.json +3 -0
  40. data/spec/fixtures/put_relationship_types_fields_fancy_org_area.json +25 -0
  41. data/spec/helpers/sidekiq_helpers.rb +14 -0
  42. data/spec/internal/app/models/address.rb +7 -2
  43. data/spec/internal/app/models/area.rb +7 -0
  44. data/spec/internal/app/models/assignment.rb +5 -4
  45. data/spec/internal/app/models/community.rb +19 -0
  46. data/spec/internal/app/models/country.rb +8 -0
  47. data/spec/internal/app/models/namespaced/person.rb +48 -2
  48. data/spec/internal/app/models/organization.rb +26 -3
  49. data/spec/internal/db/schema.rb +28 -0
  50. data/spec/internal/log/test.log +71023 -0
  51. data/spec/models/address_spec.rb +6 -204
  52. data/spec/models/assignment_spec.rb +40 -186
  53. data/spec/models/organization_spec.rb +106 -92
  54. data/spec/models/person_spec.rb +158 -214
  55. data/spec/models/user_edited_person_spec.rb +2 -2
  56. data/spec/spec_helper.rb +5 -6
  57. data/spec/workers/delete_gr_entity_worker_spec.rb +4 -4
  58. data/spec/workers/pull_mdm_id_worker_spec.rb +94 -32
  59. data/spec/workers/push_entity_worker_spec.rb +476 -0
  60. data/spec/workers/push_relationship_worker_spec.rb +344 -15
  61. metadata +45 -10
  62. data/lib/global_registry_bindings/entity/entity_methods.rb +0 -62
  63. data/lib/global_registry_bindings/options/class_options.rb +0 -62
  64. data/lib/global_registry_bindings/options/instance_options.rb +0 -63
  65. data/lib/global_registry_bindings/workers/push_gr_entity_worker.rb +0 -22
  66. data/spec/workers/push_gr_entity_worker_spec.rb +0 -27
@@ -2,227 +2,29 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe 'Address' do
6
- describe ':push_entity_to_global_registry_async' do
5
+ RSpec.describe Address do
6
+ describe '#push_entity_to_global_registry_async' do
7
7
  it 'should enqueue sidekiq job' do
8
8
  address = build(:address)
9
9
  expect do
10
10
  address.push_entity_to_global_registry_async
11
- end.to change(GlobalRegistry::Bindings::Workers::PushGrEntityWorker.jobs, :size).by(1)
11
+ end.to change(GlobalRegistry::Bindings::Workers::PushEntityWorker.jobs, :size).by(1)
12
12
  end
13
13
  end
14
14
 
15
- describe ':delete_entity_from_global_registry_async' do
15
+ describe '#delete_entity_from_global_registry_async' do
16
16
  it 'should enqueue sidekiq job' do
17
17
  address = build(:address, global_registry_id: '22527d88-3cba-11e7-b876-129bd0521531')
18
18
  expect do
19
19
  address.delete_entity_from_global_registry_async
20
- end.to change(GlobalRegistry::Bindings::Workers::DeleteGrEntityWorker.jobs, :size).by(1)
20
+ end.to change(GlobalRegistry::Bindings::Workers::DeleteEntityWorker.jobs, :size).by(1)
21
21
  end
22
22
 
23
23
  it 'should not enqueue sidekiq job when missing global_registry_id' do
24
24
  address = build(:address)
25
25
  expect do
26
26
  address.delete_entity_from_global_registry_async
27
- end.not_to change(GlobalRegistry::Bindings::Workers::DeleteGrEntityWorker.jobs, :size)
28
- end
29
- end
30
-
31
- describe ':push_entity_to_global_registry' do
32
- around { |example| travel_to Time.utc(2001, 2, 3), &example }
33
- context 'create' do
34
- context '\'address\' entity_type does not exist' do
35
- let!(:requests) do
36
- [stub_request(:get, 'https://backend.global-registry.org/entity_types')
37
- .with(query: { 'filters[name]' => 'person', 'filters[parent_id]' => nil })
38
- .to_return(body: file_fixture('get_entity_types_person.json'), status: 200),
39
- stub_request(:get, 'https://backend.global-registry.org/entity_types')
40
- .with(query: { 'filters[name]' => 'address',
41
- 'filters[parent_id]' => 'ee13a693-3ce7-4c19-b59a-30c8f137acd8' })
42
- .to_return(body: file_fixture('get_entity_types.json'), status: 200),
43
- stub_request(:post, 'https://backend.global-registry.org/entity_types')
44
- .with(body: { entity_type: { name: 'address', parent_id: 'ee13a693-3ce7-4c19-b59a-30c8f137acd8',
45
- field_type: 'entity' } })
46
- .to_return(body: file_fixture('post_entity_types_address.json'), status: 200),
47
- stub_request(:post, 'https://backend.global-registry.org/entity_types')
48
- .with(body: { entity_type: { name: 'zip', parent_id: 'f5331684-3ca8-11e7-b937-129bd0521531',
49
- field_type: 'string' } })
50
- .to_return(status: 200),
51
- stub_request(:post, 'https://backend.global-registry.org/entity_types')
52
- .with(body: { entity_type: { name: 'line1', parent_id: 'f5331684-3ca8-11e7-b937-129bd0521531',
53
- field_type: 'string' } })
54
- .to_return(status: 200),
55
- stub_request(:post, 'https://backend.global-registry.org/entity_types')
56
- .with(body: { entity_type: { name: 'line2', parent_id: 'f5331684-3ca8-11e7-b937-129bd0521531',
57
- field_type: 'string' } })
58
- .to_return(status: 200),
59
- stub_request(:post, 'https://backend.global-registry.org/entity_types')
60
- .with(body: { entity_type: { name: 'primary', parent_id: 'f5331684-3ca8-11e7-b937-129bd0521531',
61
- field_type: 'boolean' } })
62
- .to_return(status: 200),
63
- stub_request(:post, 'https://backend.global-registry.org/entity_types')
64
- .with(body: { entity_type: { name: 'postal_code', parent_id: 'f5331684-3ca8-11e7-b937-129bd0521531',
65
- field_type: 'string' } })
66
- .to_return(status: 200)]
67
- end
68
-
69
- context '\'address\' record does not belong to a person' do
70
- let(:address) { create(:address) }
71
-
72
- it 'should create \'address\' entity_type and skip push of entity' do
73
- address.push_entity_to_global_registry
74
- requests.each { |r| expect(r).to have_been_requested.once }
75
- end
76
- end
77
-
78
- context '\'address\' record belongs to a person without global registry id' do
79
- let(:person) { create(:person) }
80
- let(:address) { create(:address, person: person) }
81
- let!(:sub_requests) do
82
- [stub_request(:post, 'https://backend.global-registry.org/entities')
83
- .with(body: { entity: { person: { first_name: 'Tony', last_name: 'Stark',
84
- client_integration_id: person.id,
85
- client_updated_at: '2001-02-03 00:00:00',
86
- authentication: {
87
- key_guid: '98711710-acb5-4a41-ba51-e0fc56644b53'
88
- } } } })
89
- .to_return(body: file_fixture('post_entities_person.json'), status: 200),
90
- stub_request(:put,
91
- 'https://backend.global-registry.org/entities/22527d88-3cba-11e7-b876-129bd0521531')
92
- .with(body: { entity: { person: { client_integration_id: person.id,
93
- address: {
94
- zip: '90265', primary: 'true',
95
- line1: '10880 Malibu Point', postal_code: '90265',
96
- client_integration_id: address.id,
97
- client_updated_at: '2001-02-03 00:00:00'
98
- } } } })
99
- .to_return(body: file_fixture('put_entities_address.json'), status: 200)]
100
- end
101
-
102
- it 'should create \'address\' entity_type and push person and address entities' do
103
- address.push_entity_to_global_registry
104
- (requests + sub_requests).each { |r| expect(r).to have_been_requested.once }
105
- expect(person.global_registry_id).to eq '22527d88-3cba-11e7-b876-129bd0521531'
106
- expect(address.global_registry_id).to eq '0a594356-3f1c-11e7-bba6-129bd0521531'
107
- end
108
- end
109
-
110
- context '\'address\' record belongs to an existing person entity' do
111
- let(:person) { create(:person, global_registry_id: '22527d88-3cba-11e7-b876-129bd0521531') }
112
- let(:address) { create(:address, person: person) }
113
- let!(:sub_requests) do
114
- [stub_request(:put,
115
- 'https://backend.global-registry.org/entities/22527d88-3cba-11e7-b876-129bd0521531')
116
- .with(body: { entity: { person: { client_integration_id: person.id,
117
- address: {
118
- zip: '90265', primary: 'true',
119
- line1: '10880 Malibu Point', postal_code: '90265',
120
- client_integration_id: address.id,
121
- client_updated_at: '2001-02-03 00:00:00'
122
- } } } })
123
- .to_return(body: file_fixture('put_entities_address.json'), status: 200)]
124
- end
125
-
126
- it 'should create \'address\' entity_type and push address entity' do
127
- address.push_entity_to_global_registry
128
- (requests + sub_requests).each { |r| expect(r).to have_been_requested.once }
129
- expect(address.global_registry_id).to eq '0a594356-3f1c-11e7-bba6-129bd0521531'
130
- end
131
- end
132
- end
133
-
134
- context '\'address\' and \'person\' entity_types exist' do
135
- let(:person) { create(:person, global_registry_id: '22527d88-3cba-11e7-b876-129bd0521531') }
136
- let(:address) { create(:address, person: person) }
137
- let!(:requests) do
138
- [stub_request(:get, 'https://backend.global-registry.org/entity_types')
139
- .with(query: { 'filters[name]' => 'person', 'filters[parent_id]' => nil })
140
- .to_return(body: file_fixture('get_entity_types_person.json'), status: 200),
141
- stub_request(:put,
142
- 'https://backend.global-registry.org/entities/22527d88-3cba-11e7-b876-129bd0521531')
143
- .with(body: { entity: { person: { client_integration_id: person.id,
144
- address: {
145
- zip: '90265', primary: 'true',
146
- line1: '10880 Malibu Point', postal_code: '90265',
147
- client_integration_id: address.id,
148
- client_updated_at: '2001-02-03 00:00:00'
149
- } } } })
150
- .to_return(body: file_fixture('put_entities_address.json'), status: 200)]
151
- end
152
-
153
- context '\'address\' entity_type has partial fields' do
154
- let!(:sub_requests) do
155
- [stub_request(:get, 'https://backend.global-registry.org/entity_types')
156
- .with(query: { 'filters[name]' => 'address',
157
- 'filters[parent_id]' => 'ee13a693-3ce7-4c19-b59a-30c8f137acd8' })
158
- .to_return(body: file_fixture('get_entity_types_address_partial.json'), status: 200),
159
- stub_request(:post, 'https://backend.global-registry.org/entity_types')
160
- .with(body: { entity_type: { name: 'line2', parent_id: 'f5331684-3ca8-11e7-b937-129bd0521531',
161
- field_type: 'string' } })
162
- .to_return(status: 200),
163
- stub_request(:post, 'https://backend.global-registry.org/entity_types')
164
- .with(body: { entity_type: { name: 'primary', parent_id: 'f5331684-3ca8-11e7-b937-129bd0521531',
165
- field_type: 'boolean' } })
166
- .to_return(status: 200)]
167
- end
168
-
169
- it 'should add missing fields and push address entity' do
170
- address.push_entity_to_global_registry
171
- (requests + sub_requests).each { |r| expect(r).to have_been_requested.once }
172
- expect(address.global_registry_id).to eq '0a594356-3f1c-11e7-bba6-129bd0521531'
173
- end
174
- end
175
-
176
- context '\'address\' entity_type has all fields' do
177
- let!(:sub_requests) do
178
- [stub_request(:get, 'https://backend.global-registry.org/entity_types')
179
- .with(query: { 'filters[name]' => 'address',
180
- 'filters[parent_id]' => 'ee13a693-3ce7-4c19-b59a-30c8f137acd8' })
181
- .to_return(body: file_fixture('get_entity_types_address.json'), status: 200)]
182
- end
183
-
184
- it 'should push address entity' do
185
- address.push_entity_to_global_registry
186
- (requests + sub_requests).each { |r| expect(r).to have_been_requested.once }
187
- expect(address.global_registry_id).to eq '0a594356-3f1c-11e7-bba6-129bd0521531'
188
- end
189
- end
190
- end
191
-
192
- context 'update' do
193
- before :each do
194
- person_entity_types = JSON.parse(file_fixture('get_entity_types_person.json').read)
195
- Rails.cache.write('GlobalRegistry::Bindings::EntityType::person', person_entity_types['entity_types'].first)
196
- address_entity_types = JSON.parse(file_fixture('get_entity_types_address.json').read)
197
- Rails.cache.write('GlobalRegistry::Bindings::EntityType::address',
198
- address_entity_types['entity_types'].first)
199
- end
200
- let(:person) { create(:person, global_registry_id: '22527d88-3cba-11e7-b876-129bd0521531') }
201
- let(:address) do
202
- create(:address, person: person, global_registry_id: '0a594356-3f1c-11e7-bba6-129bd0521531')
203
- end
204
- let!(:request) do
205
- stub_request(:put,
206
- 'https://backend.global-registry.org/entities/22527d88-3cba-11e7-b876-129bd0521531')
207
- .with(body: { entity: { person: { client_integration_id: person.id,
208
- address: {
209
- zip: '90265', primary: 'false',
210
- line1: '100 Sesame Street', postal_code: '90265',
211
- client_integration_id: address.id,
212
- client_updated_at: '2001-02-03 00:00:00'
213
- } } } })
214
- .to_return(body: file_fixture('put_entities_address.json'), status: 200)
215
- end
216
-
217
- it 'should push address entity' do
218
- address.address1 = '100 Sesame Street'
219
- address.primary = false
220
- expect do
221
- address.push_entity_to_global_registry
222
- end.to_not(change { address.global_registry_id })
223
- expect(request).to have_been_requested.once
224
- end
225
- end
27
+ end.not_to change(GlobalRegistry::Bindings::Workers::DeleteEntityWorker.jobs, :size)
226
28
  end
227
29
  end
228
30
  end
@@ -2,199 +2,53 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe 'Assignment' do
6
- describe ':push_relationship_to_global_registry_async' do
5
+ RSpec.describe Assignment do
6
+ describe 'after_commit on: :create' do
7
7
  it 'should enqueue sidekiq job' do
8
- assignment = build(:assignment)
8
+ person = create(:person)
9
+ organization = create(:organization)
10
+ assignment = build(:assignment, person: person, organization: organization)
11
+ clear_sidekiq_jobs_and_locks
9
12
  expect do
10
- assignment.push_relationship_to_global_registry_async
11
- end.to change(GlobalRegistry::Bindings::Workers::PushRelationshipWorker.jobs, :size).by(1)
13
+ assignment.save
14
+ end.to change(GlobalRegistry::Bindings::Workers::PushEntityWorker.jobs, :size).by(0).and(
15
+ change(GlobalRegistry::Bindings::Workers::PushRelationshipWorker.jobs, :size).by(1).and(
16
+ change(GlobalRegistry::Bindings::Workers::DeleteEntityWorker.jobs, :size).by(0)
17
+ )
18
+ )
12
19
  end
13
20
  end
14
21
 
15
- describe ':push_relationship_to_global_registry' do
16
- context '#create' do
17
- let(:person) { create(:person, global_registry_id: '22527d88-3cba-11e7-b876-129bd0521531') }
18
- let(:organization) { create(:organization, gr_id: 'aebb4170-3f34-11e7-bba6-129bd0521531') }
19
- let(:assignment) { create(:assignment, person: person, organization: organization) }
20
- let!(:requests) do
21
- [stub_request(:get, 'https://backend.global-registry.org/entity_types')
22
- .with(query: { 'filters[name]' => 'person', 'filters[parent_id]' => nil })
23
- .to_return(body: file_fixture('get_entity_types_person.json'), status: 200),
24
- stub_request(:get, 'https://backend.global-registry.org/entity_types')
25
- .with(query: { 'filters[name]' => 'fancy_org', 'filters[parent_id]' => nil })
26
- .to_return(body: file_fixture('get_entity_types_fancy_org.json'), status: 200),
27
- stub_request(:put, "https://backend.global-registry.org/entities/#{person.global_registry_id}")
28
- .with(body: { entity: { person: { 'fancy_org:relationship': {
29
- role: 'leader', hired_at: '2000-12-03 00:00:00',
30
- client_integration_id: assignment.id,
31
- client_updated_at: '2001-02-03 00:00:00', fancy_org: organization.gr_id
32
- } }, client_integration_id: person.id } }, query: { full_response: 'true',
33
- fields: 'fancy_org:relationship' })
34
- .to_return(body: file_fixture('put_entities_person_relationship.json'), status: 200),
35
- stub_request(:put, 'https://backend.global-registry.org/entities/51a014a4-4252-11e7-944f-129bd0521531')
36
- .with(body: { entity: { role: 'leader', hired_at: '2000-12-03 00:00:00',
37
- client_integration_id: assignment.id,
38
- client_updated_at: '2001-02-03 00:00:00' } })
39
- .to_return(body: file_fixture('put_entities_relationship.json'), status: 200)]
40
- end
41
-
42
- context '\'assignment\' relationship_type does not exist' do
43
- around { |example| travel_to Time.utc(2001, 2, 3), &example }
44
- let!(:sub_requests) do
45
- [stub_request(:get, 'https://backend.global-registry.org/relationship_types')
46
- .with(query: { 'filters[between]' =>
47
- 'ee13a693-3ce7-4c19-b59a-30c8f137acd8,025a1128-3f33-11e7-b876-129bd0521531' })
48
- .to_return(body: file_fixture('get_relationship_types.json'), status: 200),
49
- stub_request(:post, 'https://backend.global-registry.org/relationship_types')
50
- .with(body: { relationship_type: { entity_type1_id: 'ee13a693-3ce7-4c19-b59a-30c8f137acd8',
51
- entity_type2_id: '025a1128-3f33-11e7-b876-129bd0521531',
52
- relationship1: 'person', relationship2: 'fancy_org' } })
53
- .to_return(body: file_fixture('post_relationship_types_person_fancy_org.json'), status: 200),
54
- stub_request(:put,
55
- 'https://backend.global-registry.org/relationship_types/5d721db8-4248-11e7-90b4-129bd0521531')
56
- .with(body: { relationship_type: { fields: [{ name: 'role', field_type: 'string' },
57
- { name: 'hired_at', field_type: 'datetime' }] } })
58
- .to_return(body: file_fixture('put_relationship_types_fields.json'), status: 200)]
59
- end
60
-
61
- it 'should create \'assignment\' relationship_type and push relationship' do
62
- assignment.push_relationship_to_global_registry
63
- (requests + sub_requests).each { |r| expect(r).to have_been_requested.once }
64
- expect(assignment.global_registry_id).to eq '51a014a4-4252-11e7-944f-129bd0521531'
65
- end
66
- end
67
-
68
- context '\'assignment\' relationship_type partially exists' do
69
- around { |example| travel_to Time.utc(2001, 2, 3), &example }
70
- let!(:sub_requests) do
71
- [stub_request(:get, 'https://backend.global-registry.org/relationship_types')
72
- .with(query: { 'filters[between]' =>
73
- 'ee13a693-3ce7-4c19-b59a-30c8f137acd8,025a1128-3f33-11e7-b876-129bd0521531' })
74
- .to_return(body: file_fixture('get_relationship_types_person_fancy_org_partial.json'), status: 200),
75
- stub_request(:put,
76
- 'https://backend.global-registry.org/relationship_types/5d721db8-4248-11e7-90b4-129bd0521531')
77
- .with(body: { relationship_type: { fields: [{ name: 'role', field_type: 'string' }] } })
78
- .to_return(body: file_fixture('put_relationship_types_fields.json'), status: 200)]
79
- end
80
-
81
- it 'should add fields to relationship type and push relationship' do
82
- assignment.push_relationship_to_global_registry
83
- (requests + sub_requests).each { |r| expect(r).to have_been_requested.once }
84
- expect(assignment.global_registry_id).to eq '51a014a4-4252-11e7-944f-129bd0521531'
85
- end
86
- end
87
-
88
- context '\'assignment\' relationship_type exists' do
89
- around { |example| travel_to Time.utc(2001, 2, 3), &example }
90
- let!(:sub_requests) do
91
- [stub_request(:get, 'https://backend.global-registry.org/relationship_types')
92
- .with(query: { 'filters[between]' =>
93
- 'ee13a693-3ce7-4c19-b59a-30c8f137acd8,025a1128-3f33-11e7-b876-129bd0521531' })
94
- .to_return(body: file_fixture('get_relationship_types_person_fancy_org.json'), status: 200)]
95
- end
96
-
97
- it 'should add fields to relationship type and push relationship' do
98
- assignment.push_relationship_to_global_registry
99
- (requests + sub_requests).each { |r| expect(r).to have_been_requested.once }
100
- expect(assignment.global_registry_id).to eq '51a014a4-4252-11e7-944f-129bd0521531'
101
- end
102
- end
103
- end
104
-
105
- context '#update' do
106
- let(:person) { create(:person, global_registry_id: '22527d88-3cba-11e7-b876-129bd0521531') }
107
- let(:organization) { create(:organization, gr_id: 'aebb4170-3f34-11e7-bba6-129bd0521531') }
108
- let(:assignment) do
109
- create(:assignment, person: person, organization: organization,
110
- global_registry_id: '51a014a4-4252-11e7-944f-129bd0521531')
111
- end
112
-
113
- context '\'assignment\' relationship_type is cached' do
114
- around { |example| travel_to Time.utc(2001, 2, 3), &example }
115
- before :each do
116
- person_entity_types = JSON.parse(file_fixture('get_entity_types_person.json').read)
117
- organization_entity_types = JSON.parse(file_fixture('get_entity_types_fancy_org.json').read)
118
- assignment_relationship_type = JSON.parse(file_fixture('get_relationship_types_person_fancy_org.json').read)
119
- Rails.cache.write('GlobalRegistry::Bindings::EntityType::person', person_entity_types['entity_types'].first)
120
- Rails.cache.write('GlobalRegistry::Bindings::EntityType::fancy_org',
121
- organization_entity_types['entity_types'].first)
122
- Rails.cache.write('GlobalRegistry::Bindings::RelationshipType::person::fancy_org::person',
123
- assignment_relationship_type['relationship_types'].first)
124
- end
125
-
126
- it 'should push relationship' do
127
- request = stub_request(:put,
128
- 'https://backend.global-registry.org/entities/51a014a4-4252-11e7-944f-129bd0521531')
129
- .with(body: { entity: { role: 'leader', hired_at: '2000-12-03 00:00:00',
130
- client_integration_id: assignment.id,
131
- client_updated_at: '2001-02-03 00:00:00' } })
132
- .to_return(body: file_fixture('put_entities_relationship.json'), status: 200)
133
-
134
- assignment.push_relationship_to_global_registry
135
- expect(request).to have_been_requested.once
136
- expect(assignment.global_registry_id).to eq '51a014a4-4252-11e7-944f-129bd0521531'
137
- end
138
- end
22
+ describe 'after_commit on: :update' do
23
+ it 'should enqueue sidekiq job' do
24
+ person = create(:person)
25
+ organization = create(:organization)
26
+ assignment = create(:assignment, person: person, organization: organization)
27
+ clear_sidekiq_jobs_and_locks
28
+ expect do
29
+ assignment.role = 'boss'
30
+ assignment.save
31
+ end.to change(GlobalRegistry::Bindings::Workers::PushEntityWorker.jobs, :size).by(0).and(
32
+ change(GlobalRegistry::Bindings::Workers::PushRelationshipWorker.jobs, :size).by(1).and(
33
+ change(GlobalRegistry::Bindings::Workers::DeleteEntityWorker.jobs, :size).by(0)
34
+ )
35
+ )
139
36
  end
37
+ end
140
38
 
141
- context 'related entities missing global_registry_id' do
142
- context '\'person\' missing global_registry_id' do
143
- let(:person) { build(:person) }
144
- let(:organization) { build(:organization, gr_id: 'aebb4170-3f34-11e7-bba6-129bd0521531') }
145
- let!(:assignment) { create(:assignment, person: person, organization: organization) }
146
-
147
- it 'should raise an exception' do
148
- # Drop sidekiq-unique-jobs locks
149
- MOCK_REDIS.keys.each do |key|
150
- MOCK_REDIS.del(key)
151
- end
152
-
153
- expect do
154
- assignment.push_relationship_to_global_registry
155
- end.to raise_error(GlobalRegistry::Bindings::RelatedEntityMissingGlobalRegistryId).and(
156
- change(GlobalRegistry::Bindings::Workers::PushGrEntityWorker.jobs, :size).by(1)
157
- )
158
- end
159
- end
160
-
161
- context '\'organization\' missing global_registry_id' do
162
- let(:person) { build(:person, global_registry_id: '22527d88-3cba-11e7-b876-129bd0521531') }
163
- let(:organization) { build(:organization) }
164
- let!(:assignment) { create(:assignment, person: person, organization: organization) }
165
-
166
- it 'should raise an exception' do
167
- # Drop sidekiq-unique-jobs locks
168
- MOCK_REDIS.keys.each do |key|
169
- MOCK_REDIS.del(key)
170
- end
171
-
172
- expect do
173
- assignment.push_relationship_to_global_registry
174
- end.to raise_error(GlobalRegistry::Bindings::RelatedEntityMissingGlobalRegistryId).and(
175
- change(GlobalRegistry::Bindings::Workers::PushGrEntityWorker.jobs, :size).by(1)
176
- )
177
- end
178
- end
179
-
180
- context '\'person\' and \'organization\' missing global_registry_id' do
181
- let(:person) { build(:person) }
182
- let(:organization) { build(:organization) }
183
- let!(:assignment) { create(:assignment, person: person, organization: organization) }
184
-
185
- it 'should raise an exception' do
186
- # Drop sidekiq-unique-jobs locks
187
- MOCK_REDIS.keys.each do |key|
188
- MOCK_REDIS.del(key)
189
- end
190
-
191
- expect do
192
- assignment.push_relationship_to_global_registry
193
- end.to raise_error(GlobalRegistry::Bindings::RelatedEntityMissingGlobalRegistryId).and(
194
- change(GlobalRegistry::Bindings::Workers::PushGrEntityWorker.jobs, :size).by(2)
195
- )
196
- end
197
- end
39
+ describe 'after_commit on: :destroy' do
40
+ it 'should enqueue sidekiq job' do
41
+ person = create(:person)
42
+ organization = create(:organization)
43
+ assignment = create(:assignment, person: person, organization: organization, global_registry_id: 'abc')
44
+ clear_sidekiq_jobs_and_locks
45
+ expect do
46
+ assignment.destroy
47
+ end.to change(GlobalRegistry::Bindings::Workers::PushEntityWorker.jobs, :size).by(0).and(
48
+ change(GlobalRegistry::Bindings::Workers::PushRelationshipWorker.jobs, :size).by(0).and(
49
+ change(GlobalRegistry::Bindings::Workers::DeleteEntityWorker.jobs, :size).by(1)
50
+ )
51
+ )
198
52
  end
199
53
  end
200
54
  end