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,247 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe 'Person' do
6
+ describe ':push_entity_to_global_registry_async' do
7
+ it 'should enqueue sidekiq job' do
8
+ person = build(:person)
9
+ expect do
10
+ person.push_entity_to_global_registry_async
11
+ end.to change(GlobalRegistry::Bindings::Workers::PushGrEntityWorker.jobs, :size).by(1)
12
+ end
13
+ end
14
+
15
+ describe ':delete_entity_from_global_registry_async' do
16
+ it 'should enqueue sidekiq job' do
17
+ person = build(:person, global_registry_id: '22527d88-3cba-11e7-b876-129bd0521531')
18
+ expect do
19
+ person.delete_entity_from_global_registry_async
20
+ end.to change(GlobalRegistry::Bindings::Workers::DeleteGrEntityWorker.jobs, :size).by(1)
21
+ end
22
+
23
+ it 'should not enqueue sidekiq job when missing global_registry_id' do
24
+ person = build(:person)
25
+ expect do
26
+ person.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
+ context 'create' do
33
+ let(:person) { create(:person) }
34
+
35
+ context '\'person\' entity_type does not exist' do
36
+ around { |example| travel_to Time.utc(2001, 2, 3), &example }
37
+ let!(:requests) do
38
+ [stub_request(:get, 'https://backend.global-registry.org/entity_types')
39
+ .with(query: { 'filters[name]' => 'person', 'filters[parent_id]' => nil })
40
+ .to_return(body: file_fixture('get_entity_types.json'), status: 200),
41
+ stub_request(:post, 'https://backend.global-registry.org/entity_types')
42
+ .with(body: { entity_type: { name: 'person', parent_id: nil, field_type: 'entity' } })
43
+ .to_return(body: file_fixture('post_entity_types_person.json'), status: 200),
44
+ stub_request(:post, 'https://backend.global-registry.org/entity_types')
45
+ .with(body: { entity_type: { name: 'first_name', parent_id: 'ee13a693-3ce7-4c19-b59a-30c8f137acd8',
46
+ field_type: 'string' } })
47
+ .to_return(status: 200),
48
+ stub_request(:post, 'https://backend.global-registry.org/entity_types')
49
+ .with(body: { entity_type: { name: 'last_name', parent_id: 'ee13a693-3ce7-4c19-b59a-30c8f137acd8',
50
+ field_type: 'string' } })
51
+ .to_return(status: 200),
52
+ stub_request(:post, 'https://backend.global-registry.org/entities')
53
+ .with(body: { entity: { person: { first_name: 'Tony', last_name: 'Stark',
54
+ client_integration_id: person.id,
55
+ client_updated_at: '2001-02-03 00:00:00',
56
+ authentication: {
57
+ key_guid: '98711710-acb5-4a41-ba51-e0fc56644b53'
58
+ } } } })
59
+ .to_return(body: file_fixture('post_entities_person.json'), status: 200)]
60
+ end
61
+
62
+ it 'should create \'person\' entity_type and push entity' do
63
+ person.push_entity_to_global_registry
64
+ requests.each { |r| expect(r).to have_been_requested.once }
65
+ expect(person.global_registry_id).to eq '22527d88-3cba-11e7-b876-129bd0521531'
66
+ end
67
+ end
68
+
69
+ context '\'person\' entity_type exists' do
70
+ around { |example| travel_to Time.utc(2001, 2, 3), &example }
71
+ let!(:requests) do
72
+ [stub_request(:get, 'https://backend.global-registry.org/entity_types')
73
+ .with(query: { 'filters[name]' => 'person', 'filters[parent_id]' => nil })
74
+ .to_return(body: file_fixture('get_entity_types_person.json'), status: 200),
75
+ stub_request(:post, 'https://backend.global-registry.org/entities')
76
+ .with(body: { entity: { person: { first_name: 'Tony', last_name: 'Stark',
77
+ client_integration_id: person.id,
78
+ client_updated_at: '2001-02-03 00:00:00',
79
+ authentication: {
80
+ key_guid: '98711710-acb5-4a41-ba51-e0fc56644b53'
81
+ } } } })
82
+ .to_return(body: file_fixture('post_entities_person.json'), status: 200)]
83
+ end
84
+
85
+ it 'should skip creating entity_type and push the entity' do
86
+ person.push_entity_to_global_registry
87
+ requests.each { |r| expect(r).to have_been_requested.once }
88
+ expect(person.global_registry_id).to eq '22527d88-3cba-11e7-b876-129bd0521531'
89
+ end
90
+ end
91
+
92
+ context 'partial \'person\' entity_type exists' do
93
+ around { |example| travel_to Time.utc(2001, 2, 3), &example }
94
+ let!(:requests) do
95
+ [stub_request(:get, 'https://backend.global-registry.org/entity_types')
96
+ .with(query: { 'filters[name]' => 'person', 'filters[parent_id]' => nil })
97
+ .to_return(body: file_fixture('get_entity_types_person_partial.json'), status: 200),
98
+ stub_request(:post, 'https://backend.global-registry.org/entity_types')
99
+ .with(body: { entity_type: { name: 'first_name', parent_id: 'ee13a693-3ce7-4c19-b59a-30c8f137acd8',
100
+ field_type: 'string' } })
101
+ .to_return(status: 200),
102
+ stub_request(:post, 'https://backend.global-registry.org/entities')
103
+ .with(body: { entity: { person: { first_name: 'Tony', last_name: 'Stark',
104
+ client_integration_id: person.id,
105
+ client_updated_at: '2001-02-03 00:00:00',
106
+ authentication: {
107
+ key_guid: '98711710-acb5-4a41-ba51-e0fc56644b53'
108
+ } } } })
109
+ .to_return(body: file_fixture('post_entities_person.json'), status: 200)]
110
+ end
111
+
112
+ it 'should skip creating entity_type and push the entity' do
113
+ person.push_entity_to_global_registry
114
+ requests.each { |r| expect(r).to have_been_requested.once }
115
+ expect(person.global_registry_id).to eq '22527d88-3cba-11e7-b876-129bd0521531'
116
+ end
117
+ end
118
+
119
+ context '\'person\' entity_type is cached' do
120
+ around { |example| travel_to Time.utc(2001, 2, 3), &example }
121
+ before :each do
122
+ person_entity_types = JSON.parse(file_fixture('get_entity_types_person.json').read)
123
+ Rails.cache.write('GlobalRegistry::Bindings::EntityType::person', person_entity_types['entity_types'].first)
124
+ end
125
+
126
+ it 'should skip creating entity_type and push the entity' do
127
+ request = stub_request(:post, 'https://backend.global-registry.org/entities')
128
+ .with(body: { entity: { person: { first_name: 'Tony', last_name: 'Stark',
129
+ client_integration_id: person.id,
130
+ client_updated_at: '2001-02-03 00:00:00',
131
+ authentication: {
132
+ key_guid: '98711710-acb5-4a41-ba51-e0fc56644b53'
133
+ } } } })
134
+ .to_return(body: file_fixture('post_entities_person.json'), status: 200)
135
+ person.push_entity_to_global_registry
136
+ expect(request).to have_been_requested.once
137
+ expect(person.global_registry_id).to eq '22527d88-3cba-11e7-b876-129bd0521531'
138
+ end
139
+ end
140
+ end
141
+
142
+ context 'update' do
143
+ let(:person) { create(:person, global_registry_id: 'f8d20318-2ff2-4a98-a5eb-e9d840508bf1') }
144
+ context '\'person\' entity_type is cached' do
145
+ around { |example| travel_to Time.utc(2001, 2, 3), &example }
146
+ before :each do
147
+ person_entity_types = JSON.parse(file_fixture('get_entity_types_person.json').read)
148
+ Rails.cache.write('GlobalRegistry::Bindings::EntityType::person', person_entity_types['entity_types'].first)
149
+ end
150
+
151
+ it 'should skip creating entity_type and update the entity' do
152
+ request = stub_request(:put,
153
+ 'https://backend.global-registry.org/entities/f8d20318-2ff2-4a98-a5eb-e9d840508bf1')
154
+ .with(body: { entity: { person: { first_name: 'Tony', last_name: 'Stark',
155
+ client_integration_id: person.id,
156
+ client_updated_at: '2001-02-03 00:00:00',
157
+ authentication: {
158
+ key_guid: '98711710-acb5-4a41-ba51-e0fc56644b53'
159
+ } } } })
160
+ .to_return(body: file_fixture('post_entities_person.json'), status: 200)
161
+ person.push_entity_to_global_registry
162
+ expect(request).to have_been_requested.once
163
+ end
164
+
165
+ context 'invalid entity id' do
166
+ let!(:requests) do
167
+ [stub_request(:put,
168
+ 'https://backend.global-registry.org/entities/f8d20318-2ff2-4a98-a5eb-e9d840508bf1')
169
+ .with(body: { entity: { person: { first_name: 'Tony', last_name: 'Stark',
170
+ client_integration_id: person.id,
171
+ client_updated_at: '2001-02-03 00:00:00',
172
+ authentication: {
173
+ key_guid: '98711710-acb5-4a41-ba51-e0fc56644b53'
174
+ } } } })
175
+ .to_return(status: 404),
176
+ stub_request(:post, 'https://backend.global-registry.org/entities')
177
+ .with(body: { entity: { person: { first_name: 'Tony', last_name: 'Stark',
178
+ client_integration_id: person.id,
179
+ client_updated_at: '2001-02-03 00:00:00',
180
+ authentication: {
181
+ key_guid: '98711710-acb5-4a41-ba51-e0fc56644b53'
182
+ } } } })
183
+ .to_return(body: file_fixture('post_entities_person.json'), status: 200)]
184
+ end
185
+
186
+ it 'should push entity as create' do
187
+ person.push_entity_to_global_registry
188
+ requests.each { |r| expect(r).to have_been_requested.once }
189
+ expect(person.global_registry_id).to eq '22527d88-3cba-11e7-b876-129bd0521531'
190
+ end
191
+ end
192
+ end
193
+ end
194
+ end
195
+
196
+ describe ':pull_mdm_id_from_global_registry_async' do
197
+ it 'should enqueue sidekiq job' do
198
+ person = build(:person)
199
+ expect do
200
+ person.pull_mdm_id_from_global_registry_async
201
+ end.to change(GlobalRegistry::Bindings::Workers::PullNamespacedPersonMdmIdWorker.jobs, :size).by(1)
202
+ end
203
+ end
204
+
205
+ describe ':pull_mdm_id_from_global_registry' do
206
+ context 'record missing global_registry_id' do
207
+ let(:person) { create(:person) }
208
+
209
+ it 'should raise an exception' do
210
+ expect do
211
+ person.pull_mdm_id_from_global_registry
212
+ end.to raise_error GlobalRegistry::Bindings::RecordMissingGlobalRegistryId
213
+ end
214
+ end
215
+
216
+ context 'entity missing mdm id' do
217
+ let(:person) { create(:person, global_registry_id: '22527d88-3cba-11e7-b876-129bd0521531') }
218
+ let!(:request) do
219
+ stub_request(:get, 'https://backend.global-registry.org/entities/22527d88-3cba-11e7-b876-129bd0521531')
220
+ .with(query: { 'filters[owned_by]' => 'mdm' })
221
+ .to_return(body: file_fixture('get_entities_person.json'), status: 200)
222
+ end
223
+
224
+ it 'should raise an exception' do
225
+ expect do
226
+ person.pull_mdm_id_from_global_registry
227
+ end.to raise_error GlobalRegistry::Bindings::EntityMissingMdmId
228
+ end
229
+ end
230
+
231
+ context 'entity missing mdm id' do
232
+ let(:person) { create(:person, global_registry_id: '22527d88-3cba-11e7-b876-129bd0521531') }
233
+ let!(:request) do
234
+ stub_request(:get, 'https://backend.global-registry.org/entities/22527d88-3cba-11e7-b876-129bd0521531')
235
+ .with(query: { 'filters[owned_by]' => 'mdm' })
236
+ .to_return(body: file_fixture('get_entities_person_mdm.json'), status: 200)
237
+ end
238
+
239
+ it 'should raise an exception' do
240
+ expect do
241
+ person.pull_mdm_id_from_global_registry
242
+ expect(person.global_registry_mdm_id).to eq 'c81340b2-7e57-4978-b6b9-396f21bb0bb2'
243
+ end.not_to raise_error
244
+ end
245
+ end
246
+ end
247
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubygems'
4
+ require 'bundler/setup'
5
+ require 'pry'
6
+
7
+ require 'active_record'
8
+ ActiveRecord::Migration.verbose = false
9
+
10
+ require 'combustion'
11
+ Combustion.initialize! :active_record
12
+
13
+ require 'rspec/rails'
14
+ require 'webmock/rspec'
15
+ require 'factory_girl'
16
+ require 'simplecov'
17
+
18
+ require 'global_registry_bindings'
19
+
20
+ require 'sidekiq/testing'
21
+ require 'sidekiq_unique_jobs/testing'
22
+ Sidekiq::Testing.fake!
23
+
24
+ require 'mock_redis'
25
+ MOCK_REDIS = MockRedis.new
26
+
27
+ ActionController::Base.cache_store = :memory_store
28
+
29
+ RSpec.configure do |config|
30
+ config.use_transactional_fixtures = true
31
+ config.file_fixture_path = 'spec/fixtures'
32
+ config.filter_run focus: true
33
+ config.run_all_when_everything_filtered = true
34
+ config.include ActiveSupport::Testing::TimeHelpers
35
+ config.include FactoryGirl::Syntax::Methods
36
+
37
+ config.before(:suite) do
38
+ FactoryGirl.find_definitions
39
+ end
40
+
41
+ config.before(:each) do
42
+ MOCK_REDIS.keys.each do |key|
43
+ MOCK_REDIS.del(key)
44
+ end
45
+
46
+ SidekiqUniqueJobs.configure do |c|
47
+ c.redis_test_mode = :mock
48
+ end
49
+ allow(Sidekiq).to receive(:redis).and_yield(MOCK_REDIS)
50
+
51
+ Sidekiq::Queues.clear_all
52
+ Sidekiq::Worker.clear_all
53
+ Rails.cache.clear
54
+ end
55
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe 'GlobalRegistry::Bindings::Workers' do
6
+ describe 'DeleteGrEntityWorker' do
7
+ context 'valid global_registry_id' do
8
+ let!(:request) do
9
+ stub_request(:delete, 'https://backend.global-registry.org/entities/22527d88-3cba-11e7-b876-129bd0521531')
10
+ .to_return(status: 200)
11
+ end
12
+
13
+ it 'should delete the entity' do
14
+ worker = GlobalRegistry::Bindings::Workers::DeleteGrEntityWorker.new
15
+ worker.perform('22527d88-3cba-11e7-b876-129bd0521531')
16
+ expect(request).to have_been_requested.once
17
+ end
18
+ end
19
+
20
+ context 'unknown global_registry_id' do
21
+ let!(:request) do
22
+ stub_request(:delete, 'https://backend.global-registry.org/entities/22527d88-3cba-11e7-b876-129bd0521531')
23
+ .to_return(status: 404)
24
+ end
25
+
26
+ it 'should delete the entity' do
27
+ worker = GlobalRegistry::Bindings::Workers::DeleteGrEntityWorker.new
28
+ worker.perform('22527d88-3cba-11e7-b876-129bd0521531')
29
+ expect(request).to have_been_requested.once
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe 'GlobalRegistry::Bindings::Workers' do
6
+ describe 'PullMdmIdWorker' do
7
+ let(:user) { create(:person) }
8
+
9
+ it 'sends :pull_mdm_id_from_global_registry to the model instance' do
10
+ allow(Namespaced::Person).to receive(:pull_mdm_id_from_global_registry)
11
+ expect(Namespaced::Person).to receive(:find).with(user.id).and_return(user)
12
+ expect(user).to receive(:pull_mdm_id_from_global_registry)
13
+
14
+ worker_name = "GlobalRegistry::Bindings::Workers::#{Namespaced::Person.global_registry.mdm_worker_class_name}"
15
+ worker = worker_name.constantize.new
16
+ worker.perform(Namespaced::Person, user.id)
17
+ end
18
+
19
+ it 'fails silently on ActiveRecord::RecordNotFound' do
20
+ allow(Namespaced::Person).to receive(:pull_mdm_id_from_global_registry)
21
+ expect(Namespaced::Person).to receive(:find).with(user.id).and_raise(ActiveRecord::RecordNotFound)
22
+ expect(user).not_to receive(:pull_mdm_id_from_global_registry)
23
+
24
+ worker_name = "GlobalRegistry::Bindings::Workers::#{Namespaced::Person.global_registry.mdm_worker_class_name}"
25
+ worker = worker_name.constantize.new
26
+ worker.perform(Namespaced::Person, user.id)
27
+ end
28
+
29
+ it 'logs a message on RestClient::ResourceNotFound' do
30
+ allow(Namespaced::Person).to receive(:pull_mdm_id_from_global_registry)
31
+ expect(Namespaced::Person).to receive(:find).with(user.id).and_raise(RestClient::ResourceNotFound)
32
+ expect(user).not_to receive(:pull_mdm_id_from_global_registry)
33
+ expect(Rails.logger).to receive(:info).with('GR entity for GlobalRegistry::Bindings::Workers::PullNamespaced' \
34
+ 'PersonMdmIdWorker 1 does not exist; will _not_ retry')
35
+
36
+ worker_name = "GlobalRegistry::Bindings::Workers::#{Namespaced::Person.global_registry.mdm_worker_class_name}"
37
+ worker = worker_name.constantize.new
38
+ worker.perform(Namespaced::Person, user.id)
39
+ end
40
+ end
41
+
42
+ describe 'mdm_worker_class' do
43
+ before do
44
+ module MdmTest
45
+ class Klass
46
+ def self.global_registry
47
+ @gr ||= Object.new
48
+ end
49
+ end
50
+ end
51
+ end
52
+ after do
53
+ MdmTest.send :remove_const, :Klass
54
+ GlobalRegistry::Bindings::Workers.send :remove_const, :PullMdmTestKlassMdmIdWorker
55
+ end
56
+
57
+ it 'generates worker class with mdm timeout set' do
58
+ expect(MdmTest::Klass.global_registry).to(
59
+ receive(:mdm_worker_class_name).and_return('PullMdmTestKlassMdmIdWorker')
60
+ )
61
+ expect(MdmTest::Klass.global_registry).to(
62
+ receive(:mdm_timeout).and_return(33.minutes)
63
+ )
64
+
65
+ GlobalRegistry::Bindings::Workers.mdm_worker_class(MdmTest::Klass)
66
+ expect(GlobalRegistry::Bindings::Workers.const_defined?(:PullMdmTestKlassMdmIdWorker)).to be true
67
+ expect(GlobalRegistry::Bindings::Workers::PullMdmTestKlassMdmIdWorker.get_sidekiq_options)
68
+ .to include('unique' => :until_timeout, 'unique_expiration' => 33.minutes)
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe 'GlobalRegistry::Bindings::Workers' do
6
+ describe 'PushGrEntityWorker' do
7
+ let(:user) { create(:person) }
8
+
9
+ it 'sends :push_entity_to_global_registry to the model instance' do
10
+ allow(Namespaced::Person).to receive(:push_entity_to_global_registry_async)
11
+ expect(Namespaced::Person).to receive(:find).with(user.id).and_return(user)
12
+ expect(user).to receive(:push_entity_to_global_registry)
13
+
14
+ worker = GlobalRegistry::Bindings::Workers::PushGrEntityWorker.new
15
+ worker.perform(Namespaced::Person, user.id)
16
+ end
17
+
18
+ it 'fails silently on ActiveRecord::RecordNotFound' do
19
+ allow(Namespaced::Person).to receive(:push_entity_to_global_registry_async)
20
+ expect(Namespaced::Person).to receive(:find).with(user.id).and_raise(ActiveRecord::RecordNotFound)
21
+ expect(user).not_to receive(:push_entity_to_global_registry)
22
+
23
+ worker = GlobalRegistry::Bindings::Workers::PushGrEntityWorker.new
24
+ worker.perform(Namespaced::Person, user.id)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe 'GlobalRegistry::Bindings::Workers' do
6
+ describe 'PushRelationshipWorker' do
7
+ let(:user) { create(:person) }
8
+
9
+ it 'sends :push_relationship_to_global_registry to the model instance' do
10
+ allow(Namespaced::Person).to receive(:push_relationship_to_global_registry)
11
+ expect(Namespaced::Person).to receive(:find).with(user.id).and_return(user)
12
+ expect(user).to receive(:push_relationship_to_global_registry)
13
+
14
+ worker = GlobalRegistry::Bindings::Workers::PushRelationshipWorker.new
15
+ worker.perform(Namespaced::Person, user.id)
16
+ end
17
+
18
+ it 'fails silently on ActiveRecord::RecordNotFound' do
19
+ allow(Namespaced::Person).to receive(:push_relationship_to_global_registry)
20
+ expect(Namespaced::Person).to receive(:find).with(user.id).and_raise(ActiveRecord::RecordNotFound)
21
+ expect(user).not_to receive(:push_relationship_to_global_registry)
22
+
23
+ worker = GlobalRegistry::Bindings::Workers::PushRelationshipWorker.new
24
+ worker.perform(Namespaced::Person, user.id)
25
+ end
26
+ end
27
+ end