maestrano-connector-rails 2.0.2.pre.RC6 → 2.0.2.pre.RC7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +6 -0
  3. data/DEVELOPER.md +1 -4
  4. data/Gemfile +2 -32
  5. data/Rakefile +6 -30
  6. data/app/models/maestrano/connector/rails/concerns/entity.rb +12 -0
  7. data/app/models/maestrano/connector/rails/concerns/sub_entity_base.rb +3 -2
  8. data/app/models/maestrano/connector/rails/id_map.rb +1 -0
  9. data/app/models/maestrano/connector/rails/services/data_consolidator.rb +4 -4
  10. data/db/migrate/20170315032224_add_metadata_to_id_map.rb +5 -0
  11. data/lib/maestrano/connector/rails/version.rb +7 -0
  12. data/lib/maestrano_connector_rails/factories.rb +1 -0
  13. data/maestrano-connector-rails.gemspec +44 -308
  14. metadata +13 -151
  15. data/VERSION +0 -1
  16. data/spec/controllers/connec_controller_spec.rb +0 -179
  17. data/spec/controllers/dependancies_controller_spec.rb +0 -31
  18. data/spec/controllers/group_users_controller_spec.rb +0 -39
  19. data/spec/controllers/groups_controller_spec.rb +0 -36
  20. data/spec/controllers/synchronizations_controller_spec.rb +0 -211
  21. data/spec/controllers/version_controller_spec.rb +0 -17
  22. data/spec/dummy/README.md +0 -1
  23. data/spec/dummy/Rakefile +0 -6
  24. data/spec/dummy/app/assets/images/.keep +0 -0
  25. data/spec/dummy/app/assets/javascripts/application.js +0 -13
  26. data/spec/dummy/app/assets/stylesheets/application.css +0 -15
  27. data/spec/dummy/app/controllers/application_controller.rb +0 -8
  28. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  29. data/spec/dummy/app/helpers/application_helper.rb +0 -2
  30. data/spec/dummy/app/mailers/.keep +0 -0
  31. data/spec/dummy/app/models/.keep +0 -0
  32. data/spec/dummy/app/models/concerns/.keep +0 -0
  33. data/spec/dummy/app/models/entities/.keep +0 -0
  34. data/spec/dummy/app/views/home/index.html.erb +0 -1
  35. data/spec/dummy/app/views/layouts/application.html.erb +0 -14
  36. data/spec/dummy/bin/bundle +0 -3
  37. data/spec/dummy/bin/rails +0 -4
  38. data/spec/dummy/bin/rake +0 -4
  39. data/spec/dummy/bin/setup +0 -29
  40. data/spec/dummy/config.ru +0 -4
  41. data/spec/dummy/config/application.rb +0 -26
  42. data/spec/dummy/config/boot.rb +0 -5
  43. data/spec/dummy/config/database.yml +0 -25
  44. data/spec/dummy/config/environment.rb +0 -5
  45. data/spec/dummy/config/environments/development.rb +0 -41
  46. data/spec/dummy/config/environments/production.rb +0 -79
  47. data/spec/dummy/config/environments/test.rb +0 -39
  48. data/spec/dummy/config/initializers/assets.rb +0 -11
  49. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
  50. data/spec/dummy/config/initializers/cookies_serializer.rb +0 -3
  51. data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
  52. data/spec/dummy/config/initializers/inflections.rb +0 -16
  53. data/spec/dummy/config/initializers/maestrano.rb +0 -2
  54. data/spec/dummy/config/initializers/mime_types.rb +0 -4
  55. data/spec/dummy/config/initializers/session_store.rb +0 -3
  56. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
  57. data/spec/dummy/config/locales/en.yml +0 -23
  58. data/spec/dummy/config/routes.rb +0 -9
  59. data/spec/dummy/config/secrets.yml +0 -22
  60. data/spec/dummy/config/settings.yml +0 -2
  61. data/spec/dummy/config/settings/development.yml +0 -12
  62. data/spec/dummy/config/settings/production.yml +0 -1
  63. data/spec/dummy/config/settings/test.yml +0 -12
  64. data/spec/dummy/config/settings/uat.yml +0 -1
  65. data/spec/dummy/db/schema.rb +0 -102
  66. data/spec/dummy/lib/assets/.keep +0 -0
  67. data/spec/dummy/log/.keep +0 -0
  68. data/spec/dummy/public/404.html +0 -67
  69. data/spec/dummy/public/422.html +0 -67
  70. data/spec/dummy/public/500.html +0 -66
  71. data/spec/dummy/public/favicon.ico +0 -0
  72. data/spec/dummy/tmp/cache/.gitkeep +0 -0
  73. data/spec/integration/complex_id_references_spec.rb +0 -249
  74. data/spec/integration/complex_naming_spec.rb +0 -192
  75. data/spec/integration/complex_spec.rb +0 -578
  76. data/spec/integration/connec_to_external_spec.rb +0 -327
  77. data/spec/integration/external_to_connec_spec.rb +0 -159
  78. data/spec/integration/id_references_spec.rb +0 -584
  79. data/spec/integration/singleton_spec.rb +0 -297
  80. data/spec/jobs/all_synchronizations_job_spec.rb +0 -24
  81. data/spec/jobs/push_to_connec_job_spec.rb +0 -111
  82. data/spec/jobs/push_to_connec_worker_spec.rb +0 -37
  83. data/spec/jobs/synchronization_job_spec.rb +0 -216
  84. data/spec/models/complex_entity_spec.rb +0 -407
  85. data/spec/models/connec_helper_spec.rb +0 -588
  86. data/spec/models/connector_logger_spec.rb +0 -26
  87. data/spec/models/entity_base_spec.rb +0 -20
  88. data/spec/models/entity_spec.rb +0 -1078
  89. data/spec/models/external_spec.rb +0 -27
  90. data/spec/models/id_map_spec.rb +0 -12
  91. data/spec/models/organization_spec.rb +0 -243
  92. data/spec/models/sub_entity_base_spec.rb +0 -155
  93. data/spec/models/synchronization_spec.rb +0 -106
  94. data/spec/models/user_organization_rel_spec.rb +0 -14
  95. data/spec/models/user_spec.rb +0 -15
  96. data/spec/routing/connec_routing_spec.rb +0 -12
  97. data/spec/spec_helper.rb +0 -34
  98. data/template/Procfile +0 -2
  99. data/template/application-sample.yml +0 -13
  100. data/template/database.yml +0 -31
  101. data/template/gitignore +0 -23
  102. data/template/maestrano.rb +0 -2
  103. data/template/maestrano_connector_template.rb +0 -135
  104. data/template/routes.rb +0 -25
  105. data/template/rubocop.yml +0 -55
  106. data/template/settings/development.yml +0 -0
  107. data/template/settings/production.yml +0 -0
  108. data/template/settings/settings.yml +0 -2
  109. data/template/settings/test.yml +0 -0
  110. data/template/settings/uat.yml +0 -0
  111. data/template/sidekiq.rb +0 -9
  112. data/template/sidekiq.yml +0 -4
  113. data/template/spec_helper.rb +0 -24
@@ -1,27 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Maestrano::Connector::Rails::External do
4
- subject { Maestrano::Connector::Rails::External }
5
-
6
- before {
7
- allow(Maestrano::Connector::Rails::External).to receive(:external_name).and_call_original
8
- allow(Maestrano::Connector::Rails::External).to receive(:get_client).and_call_original
9
- allow(Maestrano::Connector::Rails::External).to receive(:entities_list).and_call_original
10
- }
11
-
12
- describe 'external_name' do
13
- it { expect{ subject.external_name }.to raise_error(RuntimeError) }
14
- end
15
-
16
- describe 'get_client' do
17
- it { expect{ subject.get_client(nil) }.to raise_error(RuntimeError) }
18
- end
19
-
20
- describe 'entities_list' do
21
- it { expect{ subject.entities_list }.to raise_error(RuntimeError) }
22
- end
23
-
24
- describe 'create_account_link' do
25
- it { expect{ subject.create_account_link }.to raise_error(RuntimeError) }
26
- end
27
- end
@@ -1,12 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Maestrano::Connector::Rails::IdMap do
4
-
5
- # Indexes
6
- it { should have_db_index([:connec_id, :connec_entity, :organization_id]) }
7
- it { should have_db_index([:external_id, :external_entity, :organization_id]) }
8
- it { should have_db_index([:organization_id]) }
9
-
10
- #Associations
11
- it { should belong_to(:organization) }
12
- end
@@ -1,243 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Maestrano::Connector::Rails::Organization do
4
-
5
- # Attributes
6
- it { should validate_presence_of(:name) }
7
- it { should validate_presence_of(:tenant) }
8
- it { should validate_uniqueness_of(:uid) }
9
- it { should serialize(:synchronized_entities) }
10
-
11
- # Indexes
12
- it { should have_db_index([:uid, :tenant]) }
13
-
14
- # Associations
15
- it { should have_many(:user_organization_rels) }
16
- it { should have_many(:users) }
17
- it { should have_many(:id_maps).dependent(:destroy) }
18
- it { should have_many(:synchronizations).dependent(:destroy) }
19
-
20
- describe 'creation' do
21
- subject { Maestrano::Connector::Rails::Organization.new }
22
-
23
- it 'initializes the synchronized entities' do
24
- entities_list = Maestrano::Connector::Rails::External.entities_list
25
- expect(subject.synchronized_entities).to include(entities_list.first.to_sym)
26
- expect(subject.synchronized_entities).to include(entities_list.last.to_sym)
27
- end
28
-
29
- it 'does not allow organizations with the same oauth UID' do
30
- organization1 = create(:organization, oauth_provider: 'myapp', oauth_uid: 'ABC')
31
- organization2 = build(:organization, oauth_provider: 'myapp', oauth_uid: 'ABC')
32
- expect(organization2).not_to be_valid
33
- end
34
-
35
- it 'allows several organizations without oauth UID' do
36
- organization1 = create(:organization, oauth_provider: 'myapp', oauth_uid: nil)
37
- organization2 = build(:organization, oauth_provider: 'myapp', oauth_uid: nil)
38
- expect(organization2).to be_valid
39
- end
40
- end
41
-
42
- describe "instance methods" do
43
- subject { create(:organization) }
44
-
45
- describe 'add_member' do
46
-
47
- context "when user is not from the same tenant" do
48
- let(:user) { create(:user, tenant: 'zzz') }
49
-
50
- it "does nothing" do
51
- expect{
52
- subject.add_member(user)
53
- }.to change{Maestrano::Connector::Rails::UserOrganizationRel.count}.by(0)
54
- end
55
- end
56
-
57
- context "when user is from the same tenant" do
58
- let(:user) { create(:user) }
59
-
60
- context "when user is already in the organization" do
61
- before { create(:user_organization_rel, user: user, organization: subject) }
62
-
63
- it "does nothing" do
64
- expect{
65
- subject.add_member(user)
66
- }.to change{Maestrano::Connector::Rails::UserOrganizationRel.count}.by(0)
67
- end
68
- end
69
-
70
- context "when user is not in the organization yet" do
71
- it "does nothing" do
72
- expect{
73
- subject.add_member(user)
74
- }.to change{Maestrano::Connector::Rails::UserOrganizationRel.count}.by(1)
75
- end
76
- end
77
- end
78
- end
79
-
80
- describe 'member?' do
81
- let(:user) { create(:user) }
82
-
83
- context "when user is a member of the organization" do
84
- before { create(:user_organization_rel, user: user, organization: subject) }
85
-
86
- it { expect(subject.member?(user)).to be(true) }
87
- end
88
-
89
- context "when user is not a member of the organization" do
90
- it { expect(subject.member?(user)).to be(false) }
91
- end
92
- end
93
-
94
- describe 'remove_member' do
95
- let(:user) { create(:user) }
96
-
97
- context "when user is a member of the organization" do
98
- before { create(:user_organization_rel, user: user, organization: subject) }
99
-
100
- it "deletes the user_organization_rel" do
101
- expect{
102
- subject.remove_member(user)
103
- }.to change{Maestrano::Connector::Rails::UserOrganizationRel.count}.by(-1)
104
- end
105
- end
106
- context "when user is not a member of the organization" do
107
- it "does nothing" do
108
- expect{
109
- subject.remove_member(user)
110
- }.to change{Maestrano::Connector::Rails::UserOrganizationRel.count}.by(0)
111
- end
112
- end
113
- end
114
-
115
- describe 'from_omniauth' do
116
- let(:saml_hash) { {provider: :maestrano, uid: 'cld-1234', info: {org_uid: 'org-abcd', name: 'My Company'}} }
117
- let(:tenant) { 'mytenant' }
118
-
119
- let(:subject) { Maestrano::Connector::Rails::Organization.find_or_create_for_maestrano(saml_hash, tenant) }
120
-
121
- context 'with a new organization' do
122
- it 'creates an organization from SAML parameters' do
123
- expect(subject.name).to eql('My Company')
124
- expect(subject.org_uid).to eql('org-abcd')
125
- expect(subject.tenant).to eql(tenant)
126
- end
127
- end
128
-
129
- context 'with an existing organization' do
130
- let!(:organization) { create(:organization, provider: :maestrano, tenant: tenant, uid: 'cld-1234') }
131
-
132
- it 'find the organization from SAML parameters' do
133
- expect(subject).to eql(organization)
134
- end
135
- end
136
- end
137
-
138
- describe 'last_three_synchronizations_failed?' do
139
- it 'returns true when last three syncs are failed' do
140
- 3.times do
141
- subject.synchronizations.create(status: 'ERROR')
142
- end
143
- expect(subject.last_three_synchronizations_failed?).to be true
144
- end
145
-
146
- it 'returns false when on of the last three sync is success' do
147
- subject.synchronizations.create(status: 'SUCCESS')
148
- 2.times do
149
- subject.synchronizations.create(status: 'ERROR')
150
- end
151
-
152
- expect(subject.last_three_synchronizations_failed?).to be false
153
- end
154
-
155
- it 'returns false when no sync' do
156
- expect(subject.last_three_synchronizations_failed?).to be false
157
- end
158
-
159
- it 'returns false when less than three sync' do
160
- 2.times do
161
- subject.synchronizations.create(status: 'ERROR')
162
- end
163
-
164
- expect(subject.last_three_synchronizations_failed?).to be false
165
- end
166
- end
167
-
168
- describe 'last_successful_synchronization' do
169
- let!(:running_sync) { create(:synchronization, organization: subject, status: 'RUNNING') }
170
- let!(:failed_sync) { create(:synchronization, organization: subject, status: 'ERROR') }
171
- let!(:success_sync) { create(:synchronization, organization: subject, status: 'SUCCESS', updated_at: 1.minute.ago) }
172
- let!(:success_sync2) { create(:synchronization, organization: subject, status: 'SUCCESS', updated_at: 3.hours.ago) }
173
- let!(:partial) { create(:synchronization, organization: subject, status: 'SUCCESS', partial: true) }
174
-
175
- it { expect(subject.last_successful_synchronization).to eql(success_sync) }
176
- end
177
-
178
- describe 'last_synchronization_date' do
179
- let(:date) { 2.days.ago }
180
-
181
- context 'with date_filtering_limit' do
182
- before {
183
- subject.date_filtering_limit = date
184
- }
185
-
186
- it { expect(subject.last_synchronization_date).to eql(date) }
187
- end
188
-
189
- context 'with sync' do
190
- let!(:success_sync) { create(:synchronization, organization: subject, status: 'SUCCESS') }
191
-
192
- it { expect(subject.last_synchronization_date.to_date).to eql(success_sync.updated_at.to_date) }
193
- end
194
-
195
- context 'with both' do
196
- let!(:success_sync) { create(:synchronization, organization: subject, status: 'SUCCESS') }
197
- before {
198
- subject.date_filtering_limit = date
199
- }
200
-
201
- it 'returns the sync date' do
202
- expect(subject.last_synchronization_date.to_date).to eql(success_sync.updated_at.to_date)
203
- end
204
- end
205
-
206
- context 'with none' do
207
- it { expect(subject.last_synchronization_date).to eql(nil) }
208
- end
209
- end
210
-
211
- describe '#reset_synchronized_entities' do
212
- let(:hash1) { {can_push_to_connec: true, can_push_to_external: true} }
213
- let(:hash2) { {can_push_to_connec: false, can_push_to_external: false} }
214
- let(:organization) { create(:organization, synchronized_entities: {entity1: true, entity2: true, tomatoes: false}) }
215
- subject { organization.reset_synchronized_entities }
216
-
217
- it 'keeps only the known entities' do
218
- subject
219
- expect(organization.synchronized_entities).to eql(entity1: hash1, entity2: hash1)
220
- end
221
-
222
- it 'adds missing entities' do
223
- organization.update_attributes(synchronized_entities: {entity1: true, tomatoes: false})
224
-
225
- subject
226
- expect(organization.synchronized_entities).to eql(entity1: hash1, entity2: hash2)
227
- end
228
-
229
- context 'with metadata from mnohub' do
230
- before {
231
- organization.push_disabled = true
232
- organization.pull_disabled = true
233
- }
234
-
235
-
236
- it 'takes into account the metadata' do
237
- subject
238
- expect(organization.synchronized_entities).to eql(entity1: hash2, entity2: hash2)
239
- end
240
- end
241
- end
242
- end
243
- end
@@ -1,155 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Maestrano::Connector::Rails::SubEntityBase do
4
- describe 'class methods' do
5
- subject { Maestrano::Connector::Rails::SubEntityBase }
6
-
7
- describe 'external?' do
8
- it { expect{ subject.external? }.to raise_error('Not implemented') }
9
- end
10
-
11
- describe 'entity_name' do
12
- it { expect{ subject.entity_name }.to raise_error('Not implemented') }
13
- end
14
-
15
- describe 'external_entity_name' do
16
- context 'when entity is external' do
17
- before(:each) do
18
- allow(Maestrano::Connector::Rails::SubEntityBase).to receive(:external?).and_return(true)
19
- allow(Maestrano::Connector::Rails::SubEntityBase).to receive(:entity_name).and_return('Name')
20
- end
21
-
22
- it 'returns the entity_name' do
23
- expect(subject.external_entity_name).to eql('Name')
24
- end
25
- end
26
-
27
- context 'when entity is not external' do
28
- before do
29
- allow(Maestrano::Connector::Rails::SubEntityBase).to receive(:external?).and_return(false)
30
- end
31
- it { expect{ subject.external_entity_name }.to raise_error('Forbidden call: cannot call external_entity_name for a connec entity') }
32
- end
33
- end
34
-
35
- describe 'connec_entity_name' do
36
- context 'when entity is not external' do
37
- before(:each) do
38
- allow(Maestrano::Connector::Rails::SubEntityBase).to receive(:external?).and_return(false)
39
- allow(Maestrano::Connector::Rails::SubEntityBase).to receive(:entity_name).and_return('Name')
40
- end
41
-
42
- it 'returns the entity_name' do
43
- expect(subject.connec_entity_name).to eql('Name')
44
- end
45
- end
46
-
47
- context 'when entity is external' do
48
- before do
49
- allow(Maestrano::Connector::Rails::SubEntityBase).to receive(:external?).and_return(true)
50
- end
51
- it { expect{ subject.connec_entity_name }.to raise_error('Forbidden call: cannot call connec_entity_name for an external entity') }
52
- end
53
- end
54
-
55
- describe 'names_hash' do
56
- let(:bool) { true }
57
- before do
58
- allow(Maestrano::Connector::Rails::SubEntityBase).to receive(:external?).and_return(bool)
59
- allow(Maestrano::Connector::Rails::SubEntityBase).to receive(:entity_name).and_return('Name')
60
- end
61
-
62
- context 'when external' do
63
- it { expect(subject.names_hash).to eql({external_entity: 'name'}) }
64
- end
65
- context 'when not external' do
66
- let(:bool) { false }
67
- it { expect(subject.names_hash).to eql({connec_entity: 'name'}) }
68
- end
69
- end
70
-
71
- it { expect(subject.mapper_classes).to eql({}) }
72
- end
73
-
74
- describe 'instance methods' do
75
- let!(:organization) { create(:organization, uid: 'cld-123') }
76
- let!(:connec_client) { Maestrano::Connec::Client[organization.tenant].new(organization.uid) }
77
- let!(:external_client) { Object.new }
78
- let(:opts) { {} }
79
- subject { Maestrano::Connector::Rails::SubEntityBase.new(organization, connec_client, external_client, opts) }
80
-
81
- describe 'map_to' do
82
- before do
83
- class AMapper
84
- extend HashMapper
85
- end
86
- allow(subject.class).to receive(:mapper_classes).and_return('Name' => AMapper)
87
- end
88
-
89
- describe 'failure' do
90
- it { expect{ subject.map_to('Not an entity', {}) }.to raise_error(RuntimeError) }
91
- end
92
-
93
- context 'when external' do
94
- before do
95
- allow(subject.class).to receive(:external?).and_return(true)
96
- allow(subject.class).to receive(:id_from_external_entity_hash).and_return('this id')
97
- end
98
-
99
- it 'calls the mapper denormalize' do
100
- expect(AMapper).to receive(:denormalize).with({}, subject.instance_values).and_return({})
101
- subject.map_to('Name', {})
102
- end
103
-
104
- it 'calls for reference folding' do
105
- refs = %w(organization_id person_id)
106
- allow(subject.class).to receive(:references).and_return({'Name' => refs})
107
- expect(Maestrano::Connector::Rails::ConnecHelper).to receive(:fold_references).with({id: 'this id'}, refs, organization)
108
- subject.map_to('Name', {})
109
- end
110
-
111
- it 'calls the creation_mapper_classes that delegates to the mapper_classes denormalize when passed true as a third argument' do
112
- expect(subject.class).to receive(:creation_mapper_classes).and_call_original
113
- expect(AMapper).to receive(:denormalize).with({}, subject.instance_values).and_return({})
114
- subject.map_to('Name', {}, true)
115
- end
116
-
117
- context 'when no refs' do
118
- it 'calls for reference folding' do
119
- allow(subject.class).to receive(:references).and_return({})
120
- expect(Maestrano::Connector::Rails::ConnecHelper).to receive(:fold_references).with({id: 'this id'}, [], organization)
121
- subject.map_to('Name', {})
122
- end
123
- end
124
-
125
- context 'when connec_matching_fields' do
126
- before do
127
- expect(AMapper).to receive(:denormalize).and_return({opts: {a: 2}})
128
- allow(subject.class).to receive(:connec_matching_fields).and_return('matching_fields')
129
- end
130
-
131
- it 'adds the matching_fields in the entity opts' do
132
- expect(subject.map_to('Name', {})).to eql({id: [Maestrano::Connector::Rails::ConnecHelper.id_hash('this id', organization)], opts: {a: 2, matching_fields: 'matching_fields'}}.with_indifferent_access)
133
- end
134
- end
135
- end
136
-
137
- context 'when not external' do
138
- before do
139
- allow(subject.class).to receive(:external?).and_return(false)
140
- end
141
-
142
- it 'calls the mapper normalize' do
143
- expect(AMapper).to receive(:normalize).with({}, subject.instance_values).and_return({})
144
- subject.map_to('Name', {})
145
- end
146
-
147
- it 'calls the creation_mapper_classes that delegates to the mapper_classes normalize when passed true as a third argument' do
148
- expect(subject.class).to receive(:creation_mapper_classes).and_call_original
149
- expect(AMapper).to receive(:normalize).with({}, subject.instance_values).and_return({})
150
- subject.map_to('Name', {}, true)
151
- end
152
- end
153
- end
154
- end
155
- end
@@ -1,106 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Maestrano::Connector::Rails::Synchronization do
4
-
5
- # Attributes
6
- it { should validate_presence_of(:status) }
7
-
8
- # Indexes
9
- it { should have_db_index(:organization_id) }
10
-
11
- #Associations
12
- it { should belong_to(:organization) }
13
-
14
- describe 'class methods' do
15
- subject { Maestrano::Connector::Rails::Synchronization }
16
-
17
- describe 'create_running' do
18
- let(:organization) { create(:organization) }
19
-
20
- it 'creates an organization' do
21
- expect{ subject.create_running(organization) }.to change{ Maestrano::Connector::Rails::Synchronization.count }.by(1)
22
- end
23
-
24
- it { expect(subject.create_running(organization).status).to eql('RUNNING') }
25
- end
26
- end
27
-
28
- describe 'instance methods' do
29
- describe 'success?' do
30
- it { expect(Maestrano::Connector::Rails::Synchronization.new(status: 'SUCCESS').success?).to be(true) }
31
- it { expect(Maestrano::Connector::Rails::Synchronization.new(status: 'ERROR').success?).to be(false) }
32
- end
33
-
34
- describe 'error?' do
35
- it { expect(Maestrano::Connector::Rails::Synchronization.new(status: 'ERROR').error?).to be(true) }
36
- it { expect(Maestrano::Connector::Rails::Synchronization.new(status: 'RUNNING').error?).to be(false) }
37
- end
38
-
39
- describe 'running?' do
40
- it { expect(Maestrano::Connector::Rails::Synchronization.new(status: 'RUNNING').running?).to be(true) }
41
- it { expect(Maestrano::Connector::Rails::Synchronization.new(status: 'ERROR').running?).to be(false) }
42
- end
43
-
44
- describe 'set_success' do
45
- let(:sync) { create(:synchronization, status: 'RUNNING') }
46
-
47
- it 'set the synchronization status to success' do
48
- sync.set_success
49
- sync.reload
50
- expect(sync.status).to eql('SUCCESS')
51
- end
52
- end
53
-
54
- describe 'set_error' do
55
- let(:sync) { create(:synchronization, status: 'RUNNING') }
56
-
57
- it 'set the synchronization status to error with the message' do
58
- sync.set_error('msg')
59
- sync.reload
60
- expect(sync.status).to eql('ERROR')
61
- expect(sync.message).to eql('msg')
62
- end
63
- end
64
-
65
- describe 'set_partial' do
66
- let(:sync) { create(:synchronization, partial: false) }
67
-
68
- it 'set the synchronization status to error with the message' do
69
- sync.set_partial
70
- sync.reload
71
- expect(sync.partial).to be(true)
72
- end
73
- end
74
-
75
- describe 'clean_synchronizations on creation' do
76
- let!(:organization) { create(:organization) }
77
-
78
- context 'when less than 100 syncs' do
79
- before {
80
- 2.times do
81
- create(:synchronization, organization: organization)
82
- end
83
- }
84
-
85
- it 'does nothing' do
86
- expect{ organization.synchronizations.create(status: 'RUNNING') }.to change{ organization.synchronizations.count }.by(1)
87
- end
88
- end
89
-
90
- context 'when more than 100 syncs' do
91
- before {
92
- 100.times do
93
- create(:synchronization, organization: organization)
94
- end
95
- }
96
-
97
- it 'destroy the right syncs' do
98
- sync = organization.synchronizations.create(status: 'RUNNING')
99
- expect(Maestrano::Connector::Rails::Synchronization.count).to eql(100)
100
- expect(Maestrano::Connector::Rails::Synchronization.all.map(&:id)).to eql([*2..101])
101
- end
102
-
103
- end
104
- end
105
- end
106
- end