maestrano-connector-rails 1.3.4 → 1.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +9 -3
- data/.rubocop_todo.yml +1 -18
- data/VERSION +1 -1
- data/app/jobs/maestrano/connector/rails/synchronization_job.rb +13 -2
- data/app/models/maestrano/connector/rails/concerns/complex_entity.rb +4 -2
- data/app/models/maestrano/connector/rails/concerns/entity.rb +13 -7
- data/app/models/maestrano/connector/rails/exceptions/entity_not_found_error.rb +3 -0
- data/app/models/maestrano/connector/rails/organization.rb +20 -0
- data/lib/generators/connector/complex_entity_generator.rb +2 -2
- data/lib/generators/connector/install_generator.rb +3 -3
- data/lib/generators/connector/templates/complex_entity_example/contact.rb +2 -1
- data/lib/generators/connector/templates/complex_entity_example/contact_and_lead.rb +2 -1
- data/lib/generators/connector/templates/complex_entity_example/contact_mapper.rb +2 -1
- data/lib/generators/connector/templates/complex_entity_example/lead.rb +2 -1
- data/lib/generators/connector/templates/complex_entity_example/lead_mapper.rb +2 -1
- data/lib/generators/connector/templates/complex_entity_example/person.rb +2 -1
- data/lib/generators/connector/templates/entity.rb +1 -0
- data/lib/generators/connector/templates/example_entity.rb +2 -1
- data/lib/generators/connector/templates/example_entity_spec.rb +1 -0
- data/lib/generators/connector/templates/external.rb +2 -1
- data/lib/generators/connector/templates/home_controller.rb +19 -30
- data/lib/generators/connector/templates/home_controller_spec.rb +18 -19
- data/lib/generators/connector/templates/oauth_controller.rb +13 -24
- data/lib/generators/connector/templates/shared_entities_controller.rb +4 -4
- data/lib/generators/connector/templates/shared_entities_controller_spec.rb +5 -5
- data/lib/generators/connector/templates/stylesheets/layout.sass +16 -3
- data/lib/generators/connector/templates/stylesheets/variables.sass +22 -4
- data/lib/generators/connector/templates/synchronizations_controller.rb +4 -4
- data/lib/generators/connector/templates/synchronizations_controller_spec.rb +4 -4
- data/maestrano-connector-rails.gemspec +7 -8
- data/release_notes.md +15 -0
- data/spec/dummy/tmp/cache/.keep +1 -0
- data/spec/factories.rb +7 -8
- data/spec/jobs/synchronization_job_spec.rb +34 -12
- data/spec/models/complex_entity_spec.rb +5 -5
- data/spec/models/entity_spec.rb +18 -12
- data/spec/spec_helper.rb +2 -2
- data/template/{application.yml.sample → application-sample.yml} +0 -0
- data/template/factories.rb +4 -5
- data/template/maestrano.rb +3 -3
- data/template/{maestrano-connector-template.rb → maestrano_connector_template.rb} +27 -25
- data/template/routes.rb +2 -8
- data/template/rubocop.yml +55 -0
- data/template/sidekiq.rb +8 -0
- data/template/spec_helper.rb +4 -3
- metadata +6 -7
- data/spec/dummy/app/controllers/admin_controller.rb +0 -48
- data/spec/dummy/app/controllers/home_controller.rb +0 -17
- data/spec/dummy/app/controllers/oauth_controller.rb +0 -45
@@ -1,44 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
class OauthController < ApplicationController
|
2
|
-
|
3
3
|
# TODO
|
4
4
|
# Routes for this controller are not provided by the gem and
|
5
5
|
# should be set according to your needs
|
6
6
|
|
7
7
|
def request_omniauth
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
redirect_to root_url
|
15
|
-
end
|
8
|
+
return redirect_to root_url unless is_admin
|
9
|
+
|
10
|
+
# TODO
|
11
|
+
# Perform oauth request here. The oauth process should be able to
|
12
|
+
# remember the organization, either by a param in the request or using
|
13
|
+
# a session
|
16
14
|
end
|
17
15
|
|
18
16
|
def create_omniauth
|
19
17
|
org_uid = '' # TODO
|
20
18
|
organization = Maestrano::Connector::Rails::Organization.find_by_uid_and_tenant(org_uid, current_user.tenant)
|
21
19
|
|
22
|
-
|
23
|
-
# TODO
|
24
|
-
# Update organization with oauth params
|
25
|
-
# Should at least set oauth_uid, oauth_token and oauth_provider
|
26
|
-
end
|
20
|
+
return redirect_to root_url unless organization && is_admin?(current_user, organization)
|
27
21
|
|
28
|
-
|
22
|
+
# TODO
|
23
|
+
# Update organization with oauth params
|
24
|
+
# Should at least set oauth_uid, oauth_token and oauth_provider
|
29
25
|
end
|
30
26
|
|
31
27
|
def destroy_omniauth
|
32
28
|
organization = Maestrano::Connector::Rails::Organization.find_by_id(params[:organization_id])
|
33
|
-
|
34
|
-
if organization && is_admin?(current_user, organization)
|
35
|
-
organization.oauth_uid = nil
|
36
|
-
organization.oauth_token = nil
|
37
|
-
organization.refresh_token = nil
|
38
|
-
organization.sync_enabled = false
|
39
|
-
organization.save
|
40
|
-
end
|
29
|
+
organization.clear_omniauth if organization && is_admin?(current_user, organization)
|
41
30
|
|
42
31
|
redirect_to root_url
|
43
32
|
end
|
44
|
-
end
|
33
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
class SharedEntitiesController < ApplicationController
|
2
3
|
def index
|
3
|
-
|
4
|
-
|
5
|
-
end
|
4
|
+
return unless is_admin
|
5
|
+
@idmaps = Maestrano::Connector::Rails::IdMap.where(organization_id: current_organization.id).order(:connec_entity)
|
6
6
|
end
|
7
|
-
end
|
7
|
+
end
|
@@ -1,18 +1,18 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe SharedEntitiesController, :
|
3
|
+
describe SharedEntitiesController, type: :controller do
|
4
4
|
describe 'index' do
|
5
5
|
subject { get :index }
|
6
6
|
|
7
7
|
it { expect(subject).to be_success }
|
8
8
|
|
9
9
|
context 'when user is admin' do
|
10
|
-
let(:organization) {
|
10
|
+
let(:organization) { create(:organization) }
|
11
11
|
let(:idmap) { create(:idmap, organization: organization) }
|
12
|
-
before
|
12
|
+
before do
|
13
13
|
allow_any_instance_of(Maestrano::Connector::Rails::SessionHelper).to receive(:current_organization).and_return(organization)
|
14
14
|
allow_any_instance_of(Maestrano::Connector::Rails::SessionHelper).to receive(:is_admin).and_return(true)
|
15
|
-
|
15
|
+
end
|
16
16
|
|
17
17
|
it 'assigns the idmaps' do
|
18
18
|
subject
|
@@ -20,4 +20,4 @@ describe SharedEntitiesController, :type => :controller do
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
23
|
-
end
|
23
|
+
end
|
@@ -30,15 +30,28 @@ html, body
|
|
30
30
|
margin-left: 20px
|
31
31
|
margin-top: -17px
|
32
32
|
|
33
|
+
.logo
|
34
|
+
width: $logo-width
|
35
|
+
height: $logo-height
|
36
|
+
margin-right: $logo-margin-right
|
37
|
+
margin-left: $logo-margin-left
|
38
|
+
margin-top: $logo-margin-top
|
39
|
+
margin-bottom: $logo-margin-bottom
|
40
|
+
|
33
41
|
&.navbar-inverse
|
34
42
|
font-weight: 300
|
35
43
|
letter-spacing: 1px
|
36
44
|
|
37
45
|
ul.nav.navbar-nav
|
38
|
-
text-transform:
|
46
|
+
text-transform: $navbar-text-transform
|
47
|
+
font-weight: $navbar-font-weight
|
39
48
|
|
40
49
|
a
|
41
|
-
font-size:
|
50
|
+
font-size: $text-size-normal
|
51
|
+
|
52
|
+
&:hover, &:focus
|
53
|
+
color: $navbar-links
|
54
|
+
text-decoration: $navbar-links-decoration
|
42
55
|
|
43
56
|
// Reduce the height of the navbar if on mobile device
|
44
57
|
@media(min-width: 768px)
|
@@ -60,4 +73,4 @@ html, body
|
|
60
73
|
text-align: center
|
61
74
|
|
62
75
|
.align-right
|
63
|
-
text-align: right
|
76
|
+
text-align: right
|
@@ -17,6 +17,8 @@ $text-color: #000
|
|
17
17
|
$navbar-bg-color: #aaa
|
18
18
|
$navbar-text-color: #fff
|
19
19
|
|
20
|
+
$navbar-link-hover: #ffa
|
21
|
+
|
20
22
|
$copyright-color: $navbar-text-color
|
21
23
|
|
22
24
|
$primary-button-color: blue
|
@@ -32,8 +34,19 @@ $todo-step-badge-color: darken($todo-step-border-color, 20%)
|
|
32
34
|
/*-----------------------------------------------------------------------*/
|
33
35
|
/* Text Size */
|
34
36
|
/*-----------------------------------------------------------------------*/
|
35
|
-
$small: 11px
|
36
|
-
$normal: 13px
|
37
|
+
$text-size-small: 11px
|
38
|
+
$text-size-normal: 13px
|
39
|
+
|
40
|
+
/*-----------------------------------------------------------------------*/
|
41
|
+
/* Logo */
|
42
|
+
/*-----------------------------------------------------------------------*/
|
43
|
+
$logo-width: 100px
|
44
|
+
$logo-height: 48px
|
45
|
+
|
46
|
+
$logo-margin-right: 0
|
47
|
+
$logo-margin-left: 10px
|
48
|
+
$logo-margin-top: 0
|
49
|
+
$logo-margin-bottom: 0
|
37
50
|
|
38
51
|
/*-----------------------------------------------------------------------*/
|
39
52
|
/* Nav bar */
|
@@ -46,8 +59,13 @@ $navbar-inverse-border: $navbar-bg-color
|
|
46
59
|
$navbar-desktop-height: 80px
|
47
60
|
$navbar-inverse-link-active-bg: $navbar-inverse-bg
|
48
61
|
|
49
|
-
$navbar-
|
50
|
-
$
|
62
|
+
$navbar-text-transform: uppercase
|
63
|
+
$navbar-font-weight: 300
|
64
|
+
|
65
|
+
$navbar-links-decoration: underline
|
66
|
+
|
67
|
+
$navbar-padding: 10px
|
68
|
+
$footer-height: 50px
|
51
69
|
|
52
70
|
$brand-success: $primary-button-color
|
53
71
|
$brand-primary: $primary-button-color
|
@@ -1,7 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
class SynchronizationsController < ApplicationController
|
2
3
|
def index
|
3
|
-
|
4
|
-
|
5
|
-
end
|
4
|
+
return unless current_organization
|
5
|
+
@synchronizations = Maestrano::Connector::Rails::Synchronization.where(organization_id: current_organization.id).order(updated_at: :desc).limit(40)
|
6
6
|
end
|
7
|
-
end
|
7
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe SynchronizationsController, :
|
3
|
+
describe SynchronizationsController, type: :controller do
|
4
4
|
describe 'index' do
|
5
5
|
subject { get :index }
|
6
6
|
|
@@ -9,9 +9,9 @@ describe SynchronizationsController, :type => :controller do
|
|
9
9
|
context 'when user is logged in' do
|
10
10
|
let(:organization) { create(:organization) }
|
11
11
|
let(:synchronization) { create(:synchronization, organization: organization) }
|
12
|
-
before
|
12
|
+
before do
|
13
13
|
allow_any_instance_of(Maestrano::Connector::Rails::SessionHelper).to receive(:current_organization).and_return(organization)
|
14
|
-
|
14
|
+
end
|
15
15
|
|
16
16
|
it 'assigns the synchronizations' do
|
17
17
|
subject
|
@@ -19,4 +19,4 @@ describe SynchronizationsController, :type => :controller do
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
22
|
-
end
|
22
|
+
end
|
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: maestrano-connector-rails 1.3.
|
5
|
+
# stub: maestrano-connector-rails 1.3.5 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "maestrano-connector-rails"
|
9
|
-
s.version = "1.3.
|
9
|
+
s.version = "1.3.5"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Pierre Berard"]
|
14
|
-
s.date = "2016-08-
|
14
|
+
s.date = "2016-08-19"
|
15
15
|
s.description = "Maestrano is the next generation marketplace for SME applications. See https://maestrano.com for details."
|
16
16
|
s.email = "pierre.berard@maestrano.com"
|
17
17
|
s.executables = ["rails"]
|
@@ -57,6 +57,7 @@ Gem::Specification.new do |s|
|
|
57
57
|
"app/models/maestrano/connector/rails/connector_logger.rb",
|
58
58
|
"app/models/maestrano/connector/rails/entity.rb",
|
59
59
|
"app/models/maestrano/connector/rails/entity_base.rb",
|
60
|
+
"app/models/maestrano/connector/rails/exceptions/entity_not_found_error.rb",
|
60
61
|
"app/models/maestrano/connector/rails/external.rb",
|
61
62
|
"app/models/maestrano/connector/rails/id_map.rb",
|
62
63
|
"app/models/maestrano/connector/rails/organization.rb",
|
@@ -122,11 +123,8 @@ Gem::Specification.new do |s|
|
|
122
123
|
"spec/dummy/app/assets/images/.keep",
|
123
124
|
"spec/dummy/app/assets/javascripts/application.js",
|
124
125
|
"spec/dummy/app/assets/stylesheets/application.css",
|
125
|
-
"spec/dummy/app/controllers/admin_controller.rb",
|
126
126
|
"spec/dummy/app/controllers/application_controller.rb",
|
127
127
|
"spec/dummy/app/controllers/concerns/.keep",
|
128
|
-
"spec/dummy/app/controllers/home_controller.rb",
|
129
|
-
"spec/dummy/app/controllers/oauth_controller.rb",
|
130
128
|
"spec/dummy/app/helpers/application_helper.rb",
|
131
129
|
"spec/dummy/app/mailers/.keep",
|
132
130
|
"spec/dummy/app/models/.keep",
|
@@ -198,13 +196,14 @@ Gem::Specification.new do |s|
|
|
198
196
|
"spec/routing/connec_routing_spec.rb",
|
199
197
|
"spec/spec_helper.rb",
|
200
198
|
"template/Procfile",
|
201
|
-
"template/application.yml
|
199
|
+
"template/application-sample.yml",
|
202
200
|
"template/database.yml",
|
203
201
|
"template/factories.rb",
|
204
202
|
"template/gitignore",
|
205
|
-
"template/maestrano-connector-template.rb",
|
206
203
|
"template/maestrano.rb",
|
204
|
+
"template/maestrano_connector_template.rb",
|
207
205
|
"template/routes.rb",
|
206
|
+
"template/rubocop.yml",
|
208
207
|
"template/settings/development.yml",
|
209
208
|
"template/settings/production.yml",
|
210
209
|
"template/settings/settings.yml",
|
data/release_notes.md
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
## 1.3.4
|
2
|
+
`maestrano.rb` file should be updated with new synchronization paths.
|
3
|
+
|
4
|
+
## Features
|
5
|
+
* `connec_version_lt?` method
|
6
|
+
|
7
|
+
## Fixes
|
8
|
+
* Fixes multi-tenancy of synchronization endpoints
|
9
|
+
* Fixes display of singleton entity
|
10
|
+
|
11
|
+
## 1.3.3
|
12
|
+
|
13
|
+
## Fixes
|
14
|
+
* Fixes `connec_version` method
|
15
|
+
|
1
16
|
## 1.3.2
|
2
17
|
|
3
18
|
### Features
|
data/spec/dummy/tmp/cache/.keep
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
|
data/spec/factories.rb
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
FactoryGirl.define do
|
2
|
-
|
3
2
|
factory :user, class: Maestrano::Connector::Rails::User do
|
4
|
-
email
|
5
|
-
tenant
|
3
|
+
email 'email@example.com'
|
4
|
+
tenant 'default'
|
6
5
|
end
|
7
6
|
|
8
7
|
factory :organization, class: Maestrano::Connector::Rails::Organization do
|
9
|
-
name
|
10
|
-
tenant
|
8
|
+
name 'My company'
|
9
|
+
tenant 'default'
|
11
10
|
sequence(:uid) { |n| "cld-11#{n}" }
|
12
11
|
oauth_uid 'sfuiy765'
|
13
12
|
oauth_provider 'this_app'
|
@@ -21,9 +20,9 @@ FactoryGirl.define do
|
|
21
20
|
factory :idmap, class: Maestrano::Connector::Rails::IdMap do
|
22
21
|
sequence(:connec_id) { |n| "#{n}6798-ada6-te43#{n}" }
|
23
22
|
connec_entity 'person'
|
24
|
-
sequence(:external_id) { |n| "#{n}4567ada66#{n}" }
|
23
|
+
sequence(:external_id) { |n| "#{n}4567ada66#{n}" }
|
25
24
|
external_entity 'contact'
|
26
|
-
last_push_to_external 2.
|
25
|
+
last_push_to_external 2.days.ago
|
27
26
|
last_push_to_connec 1.day.ago
|
28
27
|
association :organization
|
29
28
|
end
|
@@ -33,4 +32,4 @@ FactoryGirl.define do
|
|
33
32
|
status 'SUCCESS'
|
34
33
|
partial false
|
35
34
|
end
|
36
|
-
end
|
35
|
+
end
|
@@ -154,11 +154,15 @@ describe Maestrano::Connector::Rails::SynchronizationJob do
|
|
154
154
|
let(:batch_limit) { 50 }
|
155
155
|
|
156
156
|
context 'non complex entity' do
|
157
|
+
let(:external_entities1) { [] }
|
158
|
+
let(:external_entities2) { [] }
|
159
|
+
let(:connec_entities1) { [] }
|
160
|
+
let(:connec_entities2) { [] }
|
157
161
|
before {
|
158
162
|
class Entities::Person < Maestrano::Connector::Rails::Entity
|
159
163
|
end
|
160
|
-
allow_any_instance_of(Entities::Person).to receive(:get_connec_entities).and_return(
|
161
|
-
allow_any_instance_of(Entities::Person).to receive(:get_external_entities_wrapper).and_return(
|
164
|
+
allow_any_instance_of(Entities::Person).to receive(:get_connec_entities).and_return(connec_entities1, connec_entities2)
|
165
|
+
allow_any_instance_of(Entities::Person).to receive(:get_external_entities_wrapper).and_return(external_entities1, external_entities2)
|
162
166
|
allow_any_instance_of(Entities::Person).to receive(:consolidate_and_map_data).and_return({})
|
163
167
|
allow_any_instance_of(Entities::Person).to receive(:push_entities_to_external)
|
164
168
|
allow_any_instance_of(Entities::Person).to receive(:push_entities_to_connec)
|
@@ -166,20 +170,23 @@ describe Maestrano::Connector::Rails::SynchronizationJob do
|
|
166
170
|
|
167
171
|
context 'with pagination' do
|
168
172
|
context 'with more than 50 entities' do
|
173
|
+
let(:external_entities1) { [*1..50] }
|
174
|
+
let(:external_entities2) { [*51..60] }
|
175
|
+
|
169
176
|
it 'calls perform_sync several time' do
|
170
|
-
allow(subject).to receive(:perform_sync).and_return(batch_limit, 0)
|
171
177
|
expect_any_instance_of(Entities::Person).to receive(:opts_merge!).twice
|
172
|
-
expect(subject).to receive(:perform_sync).twice
|
178
|
+
expect(subject).to receive(:perform_sync).twice.and_call_original
|
173
179
|
|
174
180
|
subject.first_sync_entity('person', organization, nil, nil, nil, {}, true)
|
175
181
|
end
|
176
182
|
end
|
177
183
|
|
178
184
|
context 'with less than 50 entities' do
|
185
|
+
let(:external_entities1) { [*1..40] }
|
186
|
+
|
179
187
|
it 'calls perform_sync once' do
|
180
|
-
allow(subject).to receive(:perform_sync).and_return(batch_limit - 10)
|
181
188
|
expect_any_instance_of(Entities::Person).to receive(:opts_merge!).once.with({__skip: 0})
|
182
|
-
expect(subject).to receive(:perform_sync).once
|
189
|
+
expect(subject).to receive(:perform_sync).once.and_call_original
|
183
190
|
|
184
191
|
subject.first_sync_entity('person', organization, nil, nil, nil, {}, true)
|
185
192
|
end
|
@@ -187,12 +194,27 @@ describe Maestrano::Connector::Rails::SynchronizationJob do
|
|
187
194
|
end
|
188
195
|
|
189
196
|
context 'without pagination' do
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
197
|
+
context 'when more than 50 entities' do
|
198
|
+
let(:external_entities1) { [*1..60] }
|
199
|
+
|
200
|
+
it 'calls perform_sync once' do
|
201
|
+
expect_any_instance_of(Entities::Person).to receive(:opts_merge!).once.with({__skip: 0})
|
202
|
+
expect(subject).to receive(:perform_sync).once.and_call_original
|
203
|
+
|
204
|
+
subject.first_sync_entity('person', organization, nil, nil, nil, {}, true)
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
context 'when exactly 50 entities' do
|
209
|
+
let(:external_entities1) { [*1..50] }
|
210
|
+
let(:external_entities1) { [*1..50] }
|
211
|
+
|
212
|
+
it 'calls perform_sync twice but no infinite loop' do
|
213
|
+
expect_any_instance_of(Entities::Person).to receive(:opts_merge!).twice
|
214
|
+
expect(subject).to receive(:perform_sync).twice.and_call_original
|
215
|
+
|
216
|
+
subject.first_sync_entity('person', organization, nil, nil, nil, {}, true)
|
217
|
+
end
|
196
218
|
end
|
197
219
|
end
|
198
220
|
end
|
@@ -12,14 +12,14 @@ describe Maestrano::Connector::Rails::ComplexEntity do
|
|
12
12
|
it { expect{ subject.external_entities_names }.to raise_error('Not implemented') }
|
13
13
|
end
|
14
14
|
|
15
|
-
describe '
|
16
|
-
it 'returns the biggest array size' do
|
15
|
+
describe 'count_and_first' do
|
16
|
+
it 'returns the biggest array size and the first element of the first non empty array' do
|
17
17
|
entities = {
|
18
|
+
'items' => [],
|
18
19
|
'people' => [*1..27],
|
19
|
-
'organizations' => [*
|
20
|
-
'items' => []
|
20
|
+
'organizations' => [*3..39]
|
21
21
|
}
|
22
|
-
expect(subject.
|
22
|
+
expect(subject.count_and_first(entities)).to eql(count: 37, first: 1)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
data/spec/models/entity_spec.rb
CHANGED
@@ -6,7 +6,7 @@ describe Maestrano::Connector::Rails::Entity do
|
|
6
6
|
subject { Maestrano::Connector::Rails::Entity }
|
7
7
|
|
8
8
|
# IdMap methods
|
9
|
-
describe 'idmaps
|
9
|
+
describe 'idmaps methods' do
|
10
10
|
before {
|
11
11
|
allow(subject).to receive(:connec_entity_name).and_return('Ab')
|
12
12
|
allow(subject).to receive(:external_entity_name).and_return('Ab')
|
@@ -111,9 +111,9 @@ describe Maestrano::Connector::Rails::Entity do
|
|
111
111
|
it { expect(subject.connec_matching_fields).to be_nil }
|
112
112
|
end
|
113
113
|
|
114
|
-
describe '
|
115
|
-
it 'returns the array size' do
|
116
|
-
expect(subject.
|
114
|
+
describe 'count_and_first' do
|
115
|
+
it 'returns the array size and the first element' do
|
116
|
+
expect(subject.count_and_first([*1..27])).to eql(count: 27, first: 1)
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
@@ -452,7 +452,7 @@ describe Maestrano::Connector::Rails::Entity do
|
|
452
452
|
it 'does one call' do
|
453
453
|
expect(connec_client).to receive(:batch).once
|
454
454
|
subject.push_entities_to_connec_to(entities, connec_name)
|
455
|
-
end
|
455
|
+
end
|
456
456
|
end
|
457
457
|
|
458
458
|
context 'when more than 100 entities' do
|
@@ -700,6 +700,12 @@ describe Maestrano::Connector::Rails::Entity do
|
|
700
700
|
subject.push_entity_to_external(entity_with_idmap2, external_name)
|
701
701
|
expect(idmap2.reload.message).to include(msg.truncate(255))
|
702
702
|
end
|
703
|
+
|
704
|
+
it 'can raise a custom exception' do
|
705
|
+
allow(subject).to receive(:update_external_entity).and_raise(Maestrano::Connector::Rails::Exceptions::EntityNotFoundError.new)
|
706
|
+
subject.push_entity_to_external(entity_with_idmap1, external_name)
|
707
|
+
expect(idmap1.reload.message).to include("The external_name record has been deleted in External app.")
|
708
|
+
end
|
703
709
|
end
|
704
710
|
end
|
705
711
|
|
@@ -724,13 +730,13 @@ describe Maestrano::Connector::Rails::Entity do
|
|
724
730
|
allow(subject.class).to receive(:last_update_date_from_external_entity_hash).and_return(date)
|
725
731
|
allow(subject.class).to receive(:creation_date_from_external_entity_hash).and_return(date)
|
726
732
|
}
|
727
|
-
|
733
|
+
|
728
734
|
describe 'consolidate_and_map_data' do
|
729
735
|
context 'singleton' do
|
730
736
|
before {
|
731
737
|
allow(subject.class).to receive(:singleton?).and_return(true)
|
732
738
|
}
|
733
|
-
|
739
|
+
|
734
740
|
it 'returns the consolidate_and_map_singleton method result' do
|
735
741
|
expect(subject).to receive(:consolidate_and_map_singleton).with({}, {}).and_return({result: 1})
|
736
742
|
expect(subject.consolidate_and_map_data({}, {})).to eql({result: 1})
|
@@ -944,8 +950,8 @@ describe Maestrano::Connector::Rails::Entity do
|
|
944
950
|
}
|
945
951
|
|
946
952
|
context 'with connec one more recent' do
|
947
|
-
let(:external_date) { 1.year.ago }
|
948
|
-
let(:date) { 1.day.ago }
|
953
|
+
let(:external_date) { 1.year.ago }
|
954
|
+
let(:date) { 1.day.ago }
|
949
955
|
|
950
956
|
it 'keeps the entity and discards the external one' do
|
951
957
|
expect(subject.consolidate_and_map_connec_entities(entities, external_entities, [], external_name)).to eql([{entity: {mapped: 'entity'}, idmap: Maestrano::Connector::Rails::IdMap.first, id_refs_only_connec_entity: id_refs_only_connec_entity}])
|
@@ -954,8 +960,8 @@ describe Maestrano::Connector::Rails::Entity do
|
|
954
960
|
end
|
955
961
|
|
956
962
|
context 'with external one more recent' do
|
957
|
-
let(:external_date) { 1.month.ago }
|
958
|
-
let(:date) { 1.year.ago }
|
963
|
+
let(:external_date) { 1.month.ago }
|
964
|
+
let(:date) { 1.year.ago }
|
959
965
|
|
960
966
|
it 'discards the entity and keep the external one' do
|
961
967
|
expect(subject.consolidate_and_map_connec_entities(entities, external_entities, [], external_name)).to eql([])
|
@@ -1052,4 +1058,4 @@ describe Maestrano::Connector::Rails::Entity do
|
|
1052
1058
|
|
1053
1059
|
|
1054
1060
|
end
|
1055
|
-
end
|
1061
|
+
end
|