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.
- checksums.yaml +4 -4
- data/README.md +79 -35
- data/lib/global_registry_bindings/entity/entity_type_methods.rb +35 -33
- data/lib/global_registry_bindings/entity/mdm_methods.rb +9 -19
- data/lib/global_registry_bindings/entity/push_entity_methods.rb +31 -38
- data/lib/global_registry_bindings/entity/push_relationship_methods.rb +61 -47
- data/lib/global_registry_bindings/entity/relationship_type_methods.rb +48 -37
- data/lib/global_registry_bindings/exceptions.rb +1 -0
- data/lib/global_registry_bindings/global_registry_bindings.rb +129 -46
- data/lib/global_registry_bindings/{entity/delete_entity_methods.rb → model/delete_entity.rb} +5 -5
- data/lib/global_registry_bindings/model/entity.rb +64 -0
- data/lib/global_registry_bindings/model/pull_mdm.rb +23 -0
- data/lib/global_registry_bindings/model/push_entity.rb +21 -0
- data/lib/global_registry_bindings/model/push_relationship.rb +79 -0
- data/lib/global_registry_bindings/model/relationship.rb +68 -0
- data/lib/global_registry_bindings/options.rb +26 -59
- data/lib/global_registry_bindings/options/entity_class_options.rb +34 -0
- data/lib/global_registry_bindings/options/entity_instance_options.rb +90 -0
- data/lib/global_registry_bindings/options/entity_options_parser.rb +76 -0
- data/lib/global_registry_bindings/options/relationship_class_options.rb +37 -0
- data/lib/global_registry_bindings/options/relationship_instance_options.rb +131 -0
- data/lib/global_registry_bindings/options/relationship_options_parser.rb +98 -0
- data/lib/global_registry_bindings/railtie.rb +2 -1
- data/lib/global_registry_bindings/version.rb +1 -1
- data/lib/global_registry_bindings/worker.rb +25 -0
- data/lib/global_registry_bindings/workers/{delete_gr_entity_worker.rb → delete_entity_worker.rb} +1 -6
- data/lib/global_registry_bindings/workers/pull_mdm_id_worker.rb +12 -13
- data/lib/global_registry_bindings/workers/push_entity_worker.rb +24 -0
- data/lib/global_registry_bindings/workers/push_relationship_worker.rb +17 -7
- data/spec/acceptance/global_registry_bindings_spec.rb +50 -40
- data/spec/factories/factories.rb +24 -0
- data/spec/fixtures/get_entity_types_area.json +44 -0
- data/spec/fixtures/post_entities_community.json +8 -0
- data/spec/fixtures/post_relationship_types_fancy_org_area.json +16 -0
- data/spec/fixtures/put_entities_community_relationship.json +16 -0
- data/spec/fixtures/put_entities_fancy_org_area_relationship.json +8 -0
- data/spec/fixtures/put_entities_fancy_org_relationship.json +17 -0
- data/spec/fixtures/put_entities_person_country_relationship.json +23 -0
- data/spec/fixtures/put_entities_relationship_400.json +3 -0
- data/spec/fixtures/put_relationship_types_fields_fancy_org_area.json +25 -0
- data/spec/helpers/sidekiq_helpers.rb +14 -0
- data/spec/internal/app/models/address.rb +7 -2
- data/spec/internal/app/models/area.rb +7 -0
- data/spec/internal/app/models/assignment.rb +5 -4
- data/spec/internal/app/models/community.rb +19 -0
- data/spec/internal/app/models/country.rb +8 -0
- data/spec/internal/app/models/namespaced/person.rb +48 -2
- data/spec/internal/app/models/organization.rb +26 -3
- data/spec/internal/db/schema.rb +28 -0
- data/spec/internal/log/test.log +71023 -0
- data/spec/models/address_spec.rb +6 -204
- data/spec/models/assignment_spec.rb +40 -186
- data/spec/models/organization_spec.rb +106 -92
- data/spec/models/person_spec.rb +158 -214
- data/spec/models/user_edited_person_spec.rb +2 -2
- data/spec/spec_helper.rb +5 -6
- data/spec/workers/delete_gr_entity_worker_spec.rb +4 -4
- data/spec/workers/pull_mdm_id_worker_spec.rb +94 -32
- data/spec/workers/push_entity_worker_spec.rb +476 -0
- data/spec/workers/push_relationship_worker_spec.rb +344 -15
- metadata +45 -10
- data/lib/global_registry_bindings/entity/entity_methods.rb +0 -62
- data/lib/global_registry_bindings/options/class_options.rb +0 -62
- data/lib/global_registry_bindings/options/instance_options.rb +0 -63
- data/lib/global_registry_bindings/workers/push_gr_entity_worker.rb +0 -22
- data/spec/workers/push_gr_entity_worker_spec.rb +0 -27
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ostruct'
|
4
|
+
|
5
|
+
module GlobalRegistry #:nodoc:
|
6
|
+
module Bindings #:nodoc:
|
7
|
+
module Options
|
8
|
+
class RelationshipClassOptions
|
9
|
+
delegate :id_column,
|
10
|
+
:type,
|
11
|
+
:push_on,
|
12
|
+
:client_integration_id,
|
13
|
+
:primary_association,
|
14
|
+
:primary_association_class,
|
15
|
+
:primary_association_foreign_key,
|
16
|
+
:primary_relationship_name,
|
17
|
+
:related_association,
|
18
|
+
:related_association_class,
|
19
|
+
:related_association_foreign_key,
|
20
|
+
:related_association_type,
|
21
|
+
:related_relationship_name,
|
22
|
+
:related_global_registry_id,
|
23
|
+
:exclude_fields,
|
24
|
+
:extra_fields, to: :@options
|
25
|
+
|
26
|
+
def initialize(type, model_class)
|
27
|
+
@model_class = model_class
|
28
|
+
@options = OpenStruct.new model_class._global_registry_bindings_options[:relationships][type]
|
29
|
+
end
|
30
|
+
|
31
|
+
def ensure_relationship_type?
|
32
|
+
@options.ensure_relationship_type.present?
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GlobalRegistry #:nodoc:
|
4
|
+
module Bindings #:nodoc:
|
5
|
+
module Options
|
6
|
+
class RelationshipInstanceOptions
|
7
|
+
delegate :id_column,
|
8
|
+
:push_on,
|
9
|
+
:primary_association,
|
10
|
+
:primary_association_class,
|
11
|
+
:primary_association_foreign_key,
|
12
|
+
:related_association,
|
13
|
+
:related_association_class,
|
14
|
+
:related_association_foreign_key,
|
15
|
+
to: :@class_options
|
16
|
+
|
17
|
+
def initialize(type, model)
|
18
|
+
@model = model
|
19
|
+
@class_options = model.class.global_registry_relationship(type)
|
20
|
+
end
|
21
|
+
|
22
|
+
def id_value
|
23
|
+
@model.send id_column
|
24
|
+
end
|
25
|
+
|
26
|
+
def id_value=(value)
|
27
|
+
@model.send "#{id_column}=", value
|
28
|
+
end
|
29
|
+
|
30
|
+
def id_value?
|
31
|
+
@model.send "#{id_column}?"
|
32
|
+
end
|
33
|
+
|
34
|
+
def type
|
35
|
+
t = @class_options.type
|
36
|
+
t.is_a?(Proc) ? t.call(@model) : t
|
37
|
+
end
|
38
|
+
|
39
|
+
def client_integration_id
|
40
|
+
option = @class_options.client_integration_id
|
41
|
+
case option
|
42
|
+
when Proc
|
43
|
+
option.call(@model)
|
44
|
+
when Symbol
|
45
|
+
@model.send(option, type)
|
46
|
+
end
|
47
|
+
rescue ArgumentError
|
48
|
+
@model.send(option)
|
49
|
+
end
|
50
|
+
|
51
|
+
def primary
|
52
|
+
return @model.send(primary_association) if primary_association.present?
|
53
|
+
@model
|
54
|
+
end
|
55
|
+
|
56
|
+
def primary_class
|
57
|
+
primary_association_class || primary.class
|
58
|
+
end
|
59
|
+
|
60
|
+
def primary_type
|
61
|
+
primary&.global_registry_entity&.type
|
62
|
+
end
|
63
|
+
|
64
|
+
def primary_id_value
|
65
|
+
primary&.global_registry_entity&.id_value
|
66
|
+
end
|
67
|
+
|
68
|
+
def primary_class_is_self?
|
69
|
+
primary_class == @model.class
|
70
|
+
end
|
71
|
+
|
72
|
+
def primary_relationship_name
|
73
|
+
@class_options.primary_relationship_name || primary_type
|
74
|
+
end
|
75
|
+
|
76
|
+
def related
|
77
|
+
@model.send(related_association) if related_association.present?
|
78
|
+
end
|
79
|
+
|
80
|
+
def related_type
|
81
|
+
@class_options.related_association_type || related&.global_registry_entity&.type
|
82
|
+
end
|
83
|
+
|
84
|
+
def related_id_value
|
85
|
+
option = @class_options.related_global_registry_id
|
86
|
+
case option
|
87
|
+
when Proc
|
88
|
+
option.call(@model, type)
|
89
|
+
when Symbol
|
90
|
+
@model.send(option, type)
|
91
|
+
else
|
92
|
+
related&.global_registry_entity&.id_value
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def related_relationship_name
|
97
|
+
@class_options.related_relationship_name || related_type
|
98
|
+
end
|
99
|
+
|
100
|
+
def exclude_fields
|
101
|
+
option = @class_options.exclude_fields
|
102
|
+
case option
|
103
|
+
when Proc
|
104
|
+
option.call(type, @model)
|
105
|
+
when Symbol
|
106
|
+
@model.send(option, type)
|
107
|
+
else
|
108
|
+
option
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def extra_fields
|
113
|
+
option = @class_options.extra_fields
|
114
|
+
case option
|
115
|
+
when Proc
|
116
|
+
option.call(type, @model)
|
117
|
+
when Symbol
|
118
|
+
@model.send(option, type)
|
119
|
+
else
|
120
|
+
option
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def ensure_relationship_type?
|
125
|
+
return false if @class_options.related_global_registry_id.present?
|
126
|
+
@class_options.ensure_relationship_type?
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GlobalRegistry #:nodoc:
|
4
|
+
module Bindings #:nodoc:
|
5
|
+
module Options
|
6
|
+
class RelationshipOptionsParser
|
7
|
+
def initialize(model_class)
|
8
|
+
@model_class = model_class
|
9
|
+
end
|
10
|
+
|
11
|
+
def defaults
|
12
|
+
{
|
13
|
+
id_column: :global_registry_id,
|
14
|
+
type: @model_class.name.demodulize.underscore.to_sym,
|
15
|
+
client_integration_id: :id,
|
16
|
+
primary_association: nil,
|
17
|
+
primary_association_class: nil,
|
18
|
+
primary_relationship_name: nil,
|
19
|
+
related_association: nil, related_association_type: nil,
|
20
|
+
related_association_class: nil,
|
21
|
+
related_relationship_name: nil,
|
22
|
+
related_global_registry_id: nil,
|
23
|
+
exclude_fields: %i[id created_at updated_at],
|
24
|
+
extra_fields: {}, ensure_relationship_type: true
|
25
|
+
}.freeze
|
26
|
+
end
|
27
|
+
|
28
|
+
def parse(options_hash = {})
|
29
|
+
merge_defaults(options_hash)
|
30
|
+
update_association_classes
|
31
|
+
update_foreign_keys
|
32
|
+
update_excludes
|
33
|
+
@options
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def merge_defaults(options_hash = {})
|
39
|
+
@options = defaults.merge(options_hash) do |key, oldval, newval|
|
40
|
+
if key == :exclude_fields
|
41
|
+
case newval
|
42
|
+
when Proc, Symbol
|
43
|
+
newval
|
44
|
+
else
|
45
|
+
oldval.concat Array.wrap(newval)
|
46
|
+
end
|
47
|
+
else
|
48
|
+
newval
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def update_association_classes
|
54
|
+
unless @options[:primary_association_class]
|
55
|
+
@options[:primary_association_class] = if @options[:primary_association]
|
56
|
+
association_class @options[:primary_association]
|
57
|
+
else
|
58
|
+
@model_class
|
59
|
+
end
|
60
|
+
end
|
61
|
+
unless @options[:related_association_class] # rubocop:disable Style/GuardClause
|
62
|
+
@options[:related_association_class] = association_class @options[:related_association]
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def update_foreign_keys
|
67
|
+
unless @options[:primary_association_foreign_key]
|
68
|
+
@options[:primary_association_foreign_key] = association_foreign_key @options[:primary_association]
|
69
|
+
end
|
70
|
+
unless @options[:related_association_foreign_key] # rubocop:disable Style/GuardClause
|
71
|
+
@options[:related_association_foreign_key] = association_foreign_key @options[:related_association]
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def update_excludes
|
76
|
+
return unless @options[:exclude_fields].is_a? Array
|
77
|
+
@options[:exclude_fields] << @options[:id_column]
|
78
|
+
@options[:exclude_fields] << @options[:mdm_id_column] if @options[:mdm_id_column].present?
|
79
|
+
|
80
|
+
if @options[:primary_association_foreign_key]
|
81
|
+
@options[:exclude_fields] << @options[:primary_association_foreign_key]
|
82
|
+
end
|
83
|
+
if @options[:related_association_foreign_key] # rubocop:disable Style/GuardClause
|
84
|
+
@options[:exclude_fields] << @options[:related_association_foreign_key]
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def association_foreign_key(name)
|
89
|
+
@model_class.reflect_on_association(name)&.foreign_key&.to_sym
|
90
|
+
end
|
91
|
+
|
92
|
+
def association_class(name)
|
93
|
+
@model_class.reflect_on_association(name)&.klass
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -11,7 +11,8 @@ module GlobalRegistry #:nodoc:
|
|
11
11
|
'GlobalRegistry::Bindings::RecordMissingGlobalRegistryId' => 'ignore',
|
12
12
|
'GlobalRegistry::Bindings::EntityMissingMdmId' => 'ignore',
|
13
13
|
'GlobalRegistry::Bindings::RelatedEntityMissingGlobalRegistryId' => 'ignore',
|
14
|
-
'GlobalRegistry::Bindings::ParentEntityMissingGlobalRegistryId' => 'ignore'
|
14
|
+
'GlobalRegistry::Bindings::ParentEntityMissingGlobalRegistryId' => 'ignore',
|
15
|
+
'GlobalRegistry::Bindings::RelatedEntityExistsWithCID' => 'ignore'
|
15
16
|
)
|
16
17
|
end
|
17
18
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'sidekiq'
|
4
|
+
require 'sidekiq-unique-jobs'
|
5
|
+
|
6
|
+
module GlobalRegistry #:nodoc:
|
7
|
+
module Bindings #:nodoc:
|
8
|
+
class Worker
|
9
|
+
include Sidekiq::Worker
|
10
|
+
|
11
|
+
attr_accessor :model
|
12
|
+
delegate :global_registry_entity, to: :model
|
13
|
+
delegate :global_registry_relationship, to: :model
|
14
|
+
|
15
|
+
def initialize(model = nil)
|
16
|
+
self.model = model
|
17
|
+
end
|
18
|
+
|
19
|
+
def perform(model_class, id)
|
20
|
+
klass = model_class.is_a?(String) ? model_class.constantize : model_class
|
21
|
+
self.model = klass.find(id)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/global_registry_bindings/workers/{delete_gr_entity_worker.rb → delete_entity_worker.rb}
RENAMED
@@ -1,14 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'sidekiq'
|
4
|
-
require 'sidekiq-unique-jobs'
|
5
|
-
require 'global_registry'
|
6
|
-
|
7
3
|
module GlobalRegistry #:nodoc:
|
8
4
|
module Bindings #:nodoc:
|
9
5
|
module Workers #:nodoc:
|
10
|
-
class
|
11
|
-
include Sidekiq::Worker
|
6
|
+
class DeleteEntityWorker < ::GlobalRegistry::Bindings::Worker
|
12
7
|
sidekiq_options unique: :until_executed
|
13
8
|
|
14
9
|
def perform(global_registry_id)
|
@@ -1,17 +1,23 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
4
|
-
require 'sidekiq-unique-jobs'
|
3
|
+
require 'global_registry_bindings/entity/mdm_methods'
|
5
4
|
|
6
5
|
module GlobalRegistry #:nodoc:
|
7
6
|
module Bindings #:nodoc:
|
8
7
|
module Workers #:nodoc:
|
9
|
-
|
10
|
-
|
8
|
+
def self.mdm_worker_class(model_class)
|
9
|
+
klass = Class.new(PullMdmIdWorker) do
|
10
|
+
sidekiq_options unique: :until_timeout, unique_expiration: model_class.global_registry_entity.mdm_timeout
|
11
|
+
end
|
12
|
+
const_set model_class.global_registry_entity.mdm_worker_class_name, klass
|
13
|
+
end
|
14
|
+
|
15
|
+
class PullMdmIdWorker < ::GlobalRegistry::Bindings::Worker
|
16
|
+
include GlobalRegistry::Bindings::Entity::MdmMethods
|
11
17
|
|
12
18
|
def perform(model_class, id)
|
13
|
-
|
14
|
-
|
19
|
+
super model_class, id
|
20
|
+
pull_mdm_id_from_global_registry
|
15
21
|
rescue ActiveRecord::RecordNotFound
|
16
22
|
# If the record was deleted after the job was created, swallow it
|
17
23
|
return
|
@@ -19,13 +25,6 @@ module GlobalRegistry #:nodoc:
|
|
19
25
|
Rails.logger.info "GR entity for #{self.class.name} #{id} does not exist; will _not_ retry"
|
20
26
|
end
|
21
27
|
end
|
22
|
-
|
23
|
-
def self.mdm_worker_class(model_class)
|
24
|
-
klass = Class.new(PullMdmIdWorker) do
|
25
|
-
sidekiq_options unique: :until_timeout, unique_expiration: model_class.global_registry.mdm_timeout
|
26
|
-
end
|
27
|
-
const_set model_class.global_registry.mdm_worker_class_name, klass
|
28
|
-
end
|
29
28
|
end
|
30
29
|
end
|
31
30
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'global_registry_bindings/worker'
|
4
|
+
require 'global_registry_bindings/entity/entity_type_methods'
|
5
|
+
require 'global_registry_bindings/entity/push_entity_methods'
|
6
|
+
|
7
|
+
module GlobalRegistry #:nodoc:
|
8
|
+
module Bindings #:nodoc:
|
9
|
+
module Workers #:nodoc:
|
10
|
+
class PushEntityWorker < GlobalRegistry::Bindings::Worker
|
11
|
+
include GlobalRegistry::Bindings::Entity::EntityTypeMethods
|
12
|
+
include GlobalRegistry::Bindings::Entity::PushEntityMethods
|
13
|
+
sidekiq_options unique: :until_and_while_executing
|
14
|
+
|
15
|
+
def perform(model_class, id)
|
16
|
+
super model_class, id
|
17
|
+
push_entity_to_global_registry
|
18
|
+
rescue ActiveRecord::RecordNotFound # rubocop:disable Lint/HandleExceptions
|
19
|
+
# If the record was deleted after the job was created, swallow it
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -1,18 +1,28 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
4
|
-
require '
|
3
|
+
require 'global_registry_bindings/worker'
|
4
|
+
require 'global_registry_bindings/entity/relationship_type_methods'
|
5
|
+
require 'global_registry_bindings/entity/push_relationship_methods'
|
5
6
|
|
6
7
|
module GlobalRegistry #:nodoc:
|
7
8
|
module Bindings #:nodoc:
|
8
9
|
module Workers #:nodoc:
|
9
|
-
class PushRelationshipWorker
|
10
|
-
include
|
10
|
+
class PushRelationshipWorker < GlobalRegistry::Bindings::Worker
|
11
|
+
include GlobalRegistry::Bindings::Entity::RelationshipTypeMethods
|
12
|
+
include GlobalRegistry::Bindings::Entity::PushRelationshipMethods
|
11
13
|
sidekiq_options unique: :until_and_while_executing
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
-
|
15
|
+
attr_accessor :type
|
16
|
+
|
17
|
+
def initialize(model = nil, type = nil)
|
18
|
+
super model
|
19
|
+
self.type = type
|
20
|
+
end
|
21
|
+
|
22
|
+
def perform(model_class, id, type)
|
23
|
+
super model_class, id
|
24
|
+
self.type = type
|
25
|
+
push_relationship_to_global_registry
|
16
26
|
rescue ActiveRecord::RecordNotFound # rubocop:disable Lint/HandleExceptions
|
17
27
|
# If the record was deleted after the job was created, swallow it
|
18
28
|
end
|
@@ -11,64 +11,74 @@ RSpec.describe 'GlobalRegistry::Bindings' do
|
|
11
11
|
|
12
12
|
describe 'Options' do
|
13
13
|
it 'should have default values for all options' do
|
14
|
-
expect(Default.
|
15
|
-
expect(Default.
|
16
|
-
expect(Default.
|
17
|
-
expect(Default.
|
18
|
-
.to contain_exactly(:create, :update, :
|
19
|
-
expect(Default.
|
20
|
-
expect(Default.
|
21
|
-
expect(Default.
|
14
|
+
expect(Default.global_registry_entity.id_column).to be :global_registry_id
|
15
|
+
expect(Default.global_registry_entity.mdm_id_column).to be nil
|
16
|
+
expect(Default.global_registry_entity.parent_association).to be nil
|
17
|
+
expect(Default.global_registry_entity.push_on)
|
18
|
+
.to contain_exactly(:create, :update, :destroy)
|
19
|
+
expect(Default.global_registry_entity.mdm_timeout).to eq 1.minute
|
20
|
+
expect(Default.global_registry_entity.type).to be :default
|
21
|
+
expect(Default.global_registry_entity.exclude_fields)
|
22
22
|
.to contain_exactly(:global_registry_id, :id, :created_at, :updated_at)
|
23
|
-
expect(Default.
|
23
|
+
expect(Default.global_registry_entity.extra_fields).to be_a(Hash).and be_empty
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'should parse and set mdm options' do
|
27
|
-
expect(Namespaced::Person.
|
28
|
-
expect(Namespaced::Person.
|
29
|
-
expect(Namespaced::Person.
|
30
|
-
expect(Namespaced::Person.
|
31
|
-
expect(Namespaced::Person.
|
32
|
-
.to contain_exactly(:
|
33
|
-
|
27
|
+
expect(Namespaced::Person.global_registry_entity.id_column).to be :global_registry_id
|
28
|
+
expect(Namespaced::Person.global_registry_entity.mdm_id_column).to be :global_registry_mdm_id
|
29
|
+
expect(Namespaced::Person.global_registry_entity.mdm_timeout).to eq 24.hours
|
30
|
+
expect(Namespaced::Person.global_registry_entity.type).to be :person
|
31
|
+
expect(Namespaced::Person.global_registry_entity.exclude_fields)
|
32
|
+
.to contain_exactly(:country_of_residence_gr_id, :country_of_residence_id, :country_of_service_gr_id,
|
33
|
+
:country_of_service_id, :created_at, :global_registry_id, :global_registry_mdm_id,
|
34
|
+
:guid, :id, :updated_at)
|
35
|
+
expect(Namespaced::Person.global_registry_entity.extra_fields).to be_a(Hash).and be_empty
|
34
36
|
expect(GlobalRegistry::Bindings::Workers::PullNamespacedPersonMdmIdWorker.get_sidekiq_options)
|
35
37
|
.to include('unique' => :until_timeout, 'unique_expiration' => 24.hours)
|
36
38
|
end
|
37
39
|
|
38
40
|
it 'should parse and set exclude and extra fields options' do
|
39
|
-
|
40
|
-
expect(Address.
|
41
|
-
expect(Address.
|
42
|
-
expect(Address.
|
43
|
-
expect(Address.
|
41
|
+
address = build(:address)
|
42
|
+
expect(Address.global_registry_entity.id_column).to be :global_registry_id
|
43
|
+
expect(Address.global_registry_entity.mdm_id_column).to be nil
|
44
|
+
expect(Address.global_registry_entity.type).to be :address
|
45
|
+
expect(Address.global_registry_entity.parent_association).to be :person
|
46
|
+
expect(Address.global_registry_entity.exclude_fields).to be_a Proc
|
47
|
+
expect(address.global_registry_entity.exclude_fields)
|
44
48
|
.to contain_exactly(:global_registry_id, :id, :created_at, :updated_at, :person_id, :address1)
|
45
|
-
expect(Address.
|
49
|
+
expect(Address.global_registry_entity.extra_fields).to be_a Symbol
|
50
|
+
expect(address.global_registry_entity.extra_fields)
|
46
51
|
.to include(line1: :string, postal_code: :string)
|
47
52
|
end
|
48
53
|
|
49
54
|
it 'should parse and set push_on fields' do
|
50
|
-
|
51
|
-
expect(Organization.
|
52
|
-
expect(Organization.
|
53
|
-
expect(Organization.
|
54
|
-
expect(
|
55
|
-
expect(Organization.
|
56
|
-
|
57
|
-
expect(Organization.
|
55
|
+
org = build(:organization)
|
56
|
+
expect(Organization.global_registry_entity.id_column).to be :gr_id
|
57
|
+
expect(Organization.global_registry_entity.mdm_id_column).to be nil
|
58
|
+
expect(Organization.global_registry_entity.type).to be_a Proc
|
59
|
+
expect(org.global_registry_entity.type).to be :fancy_org
|
60
|
+
expect(Organization.global_registry_entity.parent_association).to be :parent
|
61
|
+
expect(Organization.global_registry_entity.push_on).to be_an(Array).and eq(%i[create destroy])
|
62
|
+
expect(Organization.global_registry_entity.exclude_fields).to be_a Symbol
|
63
|
+
expect(org.global_registry_entity.exclude_fields)
|
64
|
+
.to contain_exactly(:gr_id, :id, :created_at, :updated_at, :parent_id, :area_id, :global_registry_area_id)
|
65
|
+
expect(Organization.global_registry_entity.extra_fields).to be_a Proc
|
66
|
+
expect(org.global_registry_entity.extra_fields).to be_a(Hash).and be_empty
|
58
67
|
end
|
59
68
|
|
60
69
|
it 'should parse and set relationship fields' do
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
expect(Assignment.
|
65
|
-
expect(Assignment.
|
66
|
-
expect(Assignment.
|
67
|
-
expect(Assignment.
|
68
|
-
expect(
|
69
|
-
expect(
|
70
|
+
person = build(:person)
|
71
|
+
org = build(:organization)
|
72
|
+
assignment = build(:assignment, person: person, organization: org)
|
73
|
+
expect(Assignment.global_registry_relationship(:assignment).id_column).to be :global_registry_id
|
74
|
+
expect(Assignment.global_registry_relationship(:assignment).type).to be :assignment
|
75
|
+
expect(Assignment.global_registry_relationship(:assignment).primary_association).to be :person
|
76
|
+
expect(Assignment.global_registry_relationship(:assignment).related_association).to be :organization
|
77
|
+
expect(assignment.global_registry_relationship(:assignment).primary_relationship_name).to be :person
|
78
|
+
expect(assignment.global_registry_relationship(:assignment).related_relationship_name).to be :fancy_org
|
79
|
+
expect(assignment.global_registry_relationship(:assignment).exclude_fields)
|
70
80
|
.to contain_exactly(:global_registry_id, :id, :created_at, :updated_at, :person_id, :organization_id)
|
71
|
-
expect(
|
81
|
+
expect(assignment.global_registry_relationship(:assignment).extra_fields).to be_a(Hash).and be_empty
|
72
82
|
end
|
73
83
|
end
|
74
84
|
end
|