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
@@ -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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module GlobalRegistry #:nodoc:
4
4
  module Bindings #:nodoc:
5
- VERSION = '0.0.6'
5
+ VERSION = '0.1.0'
6
6
  end
7
7
  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
@@ -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 DeleteGrEntityWorker
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 'sidekiq'
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
- class PullMdmIdWorker
10
- include Sidekiq::Worker
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
- klass = model_class.is_a?(String) ? model_class.constantize : model_class
14
- klass.find(id).send(:pull_mdm_id_from_global_registry)
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 'sidekiq'
4
- require 'sidekiq-unique-jobs'
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 Sidekiq::Worker
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
- def perform(model_class, id)
14
- klass = model_class.is_a?(String) ? model_class.constantize : model_class
15
- klass.find(id).send(:push_relationship_to_global_registry)
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.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)
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.global_registry.extra_fields).to be_a(Hash).and be_empty
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.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
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
- 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)
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.global_registry.extra_fields)
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
- 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
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
- 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
+ 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(Assignment.global_registry.extra_fields).to be_a(Hash).and be_empty
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