maestrano-connector-rails 0.2.20 → 0.3.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.
@@ -1,70 +1,74 @@
1
1
  module Maestrano::Connector::Rails::Concerns::SubEntityBase
2
2
  extend ActiveSupport::Concern
3
3
 
4
- def external?
5
- raise "Not implemented"
6
- end
4
+ module ClassMethods
5
+ def external?
6
+ raise "Not implemented"
7
+ end
7
8
 
8
- def entity_name
9
- raise "Not implemented"
10
- end
9
+ def entity_name
10
+ raise "Not implemented"
11
+ end
11
12
 
12
- def map_to(name, entity, organization)
13
- raise "Not implemented"
14
- end
13
+ def external_entity_name
14
+ if external?
15
+ entity_name
16
+ else
17
+ raise "Forbidden call: cannot call external_entity_name for a connec entity"
18
+ end
19
+ end
15
20
 
16
- def external_entity_name
17
- if external?
18
- entity_name
19
- else
20
- raise "Forbidden call: cannot call external_entity_name for a connec entity"
21
+ def connec_entity_name
22
+ if external?
23
+ raise "Forbidden call: cannot call connec_entity_name for an external entity"
24
+ else
25
+ entity_name
26
+ end
21
27
  end
22
- end
23
28
 
24
- def connec_entity_name
25
- if external?
26
- raise "Forbidden call: cannot call connec_entity_name for an external entity"
27
- else
28
- entity_name
29
+ def names_hash
30
+ if external?
31
+ {external_entity: entity_name.downcase}
32
+ else
33
+ {connec_entity: entity_name.downcase}
34
+ end
29
35
  end
30
- end
31
36
 
32
- def names_hash
33
- if external?
34
- {external_entity: entity_name.downcase}
35
- else
36
- {connec_entity: entity_name.downcase}
37
+ def create_idmap_from_external_entity(entity, connec_entity_name, organization)
38
+ if external?
39
+ h = names_hash.merge({
40
+ external_id: id_from_external_entity_hash(entity),
41
+ name: object_name_from_external_entity_hash(entity),
42
+ connec_entity: connec_entity_name.downcase,
43
+ organization_id: organization.id
44
+ })
45
+ Maestrano::Connector::Rails::IdMap.create(h)
46
+ else
47
+ raise 'Forbidden call: cannot call create_idmap_from_external_entity for a connec entity'
48
+ end
37
49
  end
38
- end
39
50
 
40
- def create_idmap_from_external_entity(entity, connec_entity_name, organization)
41
- if external?
42
- h = names_hash.merge({
43
- external_id: get_id_from_external_entity_hash(entity),
44
- name: object_name_from_external_entity_hash(entity),
45
- connec_entity: connec_entity_name.downcase,
46
- organization_id: organization.id
47
- })
48
- Maestrano::Connector::Rails::IdMap.create(h)
49
- else
50
- raise 'Forbidden call: cannot call create_idmap_from_external_entity for a connec entity'
51
+ def create_idmap_from_connec_entity(entity, external_entity_name, organization)
52
+ if external?
53
+ raise 'Forbidden call: cannot call create_idmap_from_connec_entity for an external entity'
54
+ else
55
+ h = names_hash.merge({
56
+ connec_id: entity['id'],
57
+ name: object_name_from_connec_entity_hash(entity),
58
+ external_entity: external_entity_name.downcase,
59
+ organization_id: organization.id
60
+ })
61
+ Maestrano::Connector::Rails::IdMap.create(h)
62
+ end
51
63
  end
52
64
  end
53
65
 
54
- def create_idmap_from_connec_entity(entity, external_entity_name, organization)
55
- if external?
56
- raise 'Forbidden call: cannot call create_idmap_from_connec_entity for an external entity'
57
- else
58
- h = names_hash.merge({
59
- connec_id: entity['id'],
60
- name: object_name_from_connec_entity_hash(entity),
61
- external_entity: external_entity_name.downcase,
62
- organization_id: organization.id
63
- })
64
- Maestrano::Connector::Rails::IdMap.create(h)
65
- end
66
+
67
+ def map_to(name, entity, organization)
68
+ raise "Not implemented"
66
69
  end
67
70
 
71
+
68
72
  def map_external_entity_with_idmap(external_entity, connec_entity_name, idmap, organization)
69
73
  {entity: map_to(connec_entity_name, external_entity, organization), idmap: idmap}
70
74
  end
@@ -3,11 +3,11 @@
3
3
  # See README for explanation
4
4
  # class Entities::SubEntities::Contact < Maestrano::Connector::Rails::SubEntityBase
5
5
 
6
- # def external?
6
+ # def self.external?
7
7
  # true
8
8
  # end
9
9
 
10
- # def entity_name
10
+ # def self.entity_name
11
11
  # 'contact'
12
12
  # end
13
13
 
@@ -20,11 +20,11 @@
20
20
  # end
21
21
  # end
22
22
 
23
- # def object_name_from_connec_entity_hash(entity)
23
+ # def self.object_name_from_connec_entity_hash(entity)
24
24
  # "#{entity['first_name']} #{entity['last_name']}"
25
25
  # end
26
26
 
27
- # def object_name_from_external_entity_hash(entity)
27
+ # def self.object_name_from_external_entity_hash(entity)
28
28
  # "#{entity['FirstName']} #{entity['LastName']}"
29
29
  # end
30
30
  # end
@@ -2,13 +2,13 @@
2
2
  # This file is provided as an example and should be removed
3
3
  # See README for explanation
4
4
  # class Entities::ContactAndLead < Maestrano::Connector::Rails::ComplexEntity
5
- # def connec_entities_names
5
+ # def self.connec_entities_names
6
6
  # %w(person)
7
7
  # end
8
8
 
9
- # def external_entities_names
9
+ # def self.external_entities_names
10
10
  # %w(contact lead)
11
- # end
11
+ # endCont
12
12
 
13
13
  # # input : {
14
14
  # # connec_entity_names[0]: [unmapped_connec_entitiy1, unmapped_connec_entitiy2],
@@ -3,11 +3,11 @@
3
3
  # See README for explanation
4
4
  # class Entities::SubEntities::Lead < Maestrano::Connector::Rails::SubEntityBase
5
5
 
6
- # def external?
6
+ # def self.external?
7
7
  # true
8
8
  # end
9
9
 
10
- # def entity_name
10
+ # def self.entity_name
11
11
  # 'lead'
12
12
  # end
13
13
 
@@ -20,11 +20,11 @@
20
20
  # end
21
21
  # end
22
22
 
23
- # def object_name_from_connec_entity_hash(entity)
23
+ # def self.object_name_from_connec_entity_hash(entity)
24
24
  # "#{entity['first_name']} #{entity['last_name']}"
25
25
  # end
26
26
 
27
- # def object_name_from_external_entity_hash(entity)
27
+ # def self.object_name_from_external_entity_hash(entity)
28
28
  # "#{entity['FirstName']} #{entity['LastName']}"
29
29
  # end
30
30
  # end
@@ -2,11 +2,11 @@
2
2
  # This file is provided as an example and should be removed
3
3
  # See README for explanation
4
4
  # class Enities::SubEntities::Person < Maestrano::Connector::Rails::SubEntityBase
5
- # def external?
5
+ # def self.external?
6
6
  # false
7
7
  # end
8
8
 
9
- # def entity_name
9
+ # def self.entity_name
10
10
  # 'person'
11
11
  # end
12
12
 
@@ -21,11 +21,11 @@
21
21
  # end
22
22
  # end
23
23
 
24
- # def object_name_from_connec_entity_hash(entity)
24
+ # def self.object_name_from_connec_entity_hash(entity)
25
25
  # "#{entity['first_name']} #{entity['last_name']}"
26
26
  # end
27
27
 
28
- # def object_name_from_external_entity_hash(entity)
28
+ # def self.object_name_from_external_entity_hash(entity)
29
29
  # "#{entity['FirstName']} #{entity['LastName']}"
30
30
  # end
31
31
  # end
@@ -33,13 +33,13 @@ class Maestrano::Connector::Rails::Entity
33
33
  # This method updates the entity with the given id in the external app
34
34
  end
35
35
 
36
- def get_id_from_external_entity_hash(entity)
36
+ def self.id_from_external_entity_hash(entity)
37
37
  # TODO
38
38
  # This method return the id from an external_entity_hash
39
39
  # e.g entity['id']
40
40
  end
41
41
 
42
- def get_last_update_date_from_external_entity_hash(entity)
42
+ def self.last_update_date_from_external_entity_hash(entity)
43
43
  # TODO
44
44
  # This method return the last update date from an external_entity_hash
45
45
  # e.g entity['last_update']
@@ -4,23 +4,23 @@
4
4
  # with its associated mapper
5
5
 
6
6
  # class Entities::ExampleEntity < Maestrano::Connector::Rails::Entity
7
- # def connec_entity_name
7
+ # def self.connec_entity_name
8
8
  # 'ExampleEntity'
9
9
  # end
10
10
 
11
- # def external_entity_name
11
+ # def self.external_entity_name
12
12
  # 'Contact'
13
13
  # end
14
14
 
15
- # def mapper_class
15
+ # def self.mapper_class
16
16
  # ExampleEntityMapper
17
17
  # end
18
18
 
19
- # def object_name_from_connec_entity_hash(entity)
19
+ # def self.object_name_from_connec_entity_hash(entity)
20
20
  # "#{entity['first_name']} #{entity['last_name']}"
21
21
  # end
22
22
 
23
- # def object_name_from_external_entity_hash(entity)
23
+ # def self.object_name_from_external_entity_hash(entity)
24
24
  # "#{entity['FirstName']} #{entity['LastName']}"
25
25
  # end
26
26
 
@@ -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 0.2.20 ruby lib
5
+ # stub: maestrano-connector-rails 0.3.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "maestrano-connector-rails"
9
- s.version = "0.2.20"
9
+ s.version = "0.3.0"
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-03-11"
14
+ s.date = "2016-03-18"
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"]
@@ -71,7 +71,6 @@ Gem::Specification.new do |s|
71
71
  "lib/generators/connector/templates/complex_entity_example/lead.rb",
72
72
  "lib/generators/connector/templates/complex_entity_example/lead_mapper.rb",
73
73
  "lib/generators/connector/templates/complex_entity_example/person.rb",
74
- "lib/generators/connector/templates/contact_and_lead.rb",
75
74
  "lib/generators/connector/templates/entity.rb",
76
75
  "lib/generators/connector/templates/example_entity.rb",
77
76
  "lib/generators/connector/templates/external.rb",
@@ -49,7 +49,7 @@ describe Maestrano::ConnecController, type: :controller do
49
49
  before {
50
50
  allow(Maestrano::Connector::Rails::Entity).to receive(:entities_list).and_return(%w(contact_and_lead))
51
51
  class Entities::ContactAndLead < Maestrano::Connector::Rails::ComplexEntity
52
- def connec_entities_names
52
+ def self.connec_entities_names
53
53
  %w(Lead)
54
54
  end
55
55
  end
@@ -65,7 +65,7 @@ describe Maestrano::ConnecController, type: :controller do
65
65
 
66
66
  context 'when syncing' do
67
67
  before {
68
- allow_any_instance_of(Entities::ContactAndLead).to receive(:external_entities_names).and_return(%w())
68
+ allow(Entities::ContactAndLead).to receive(:external_entities_names).and_return(%w())
69
69
  }
70
70
  let!(:organization) { create(:organization, uid: group_id, oauth_uid: 'lala', sync_enabled: true, synchronized_entities: {contact_and_lead: true}) }
71
71
 
@@ -83,7 +83,7 @@ describe Maestrano::ConnecController, type: :controller do
83
83
  before {
84
84
  allow(Maestrano::Connector::Rails::Entity).to receive(:entities_list).and_return(%w(person))
85
85
  class Entities::Person < Maestrano::Connector::Rails::Entity
86
- def connec_entity_name
86
+ def self.connec_entity_name
87
87
  'People'
88
88
  end
89
89
  end
@@ -11,18 +11,18 @@ describe Maestrano::Connector::Rails::PushToConnecJob do
11
11
  end
12
12
  end
13
13
  allow_any_instance_of(Entities::Entity1).to receive(:push_entities_to_connec)
14
- allow_any_instance_of(Entities::Entity1).to receive(:external_entity_name).and_return('ext_entity1')
14
+ allow(Entities::Entity1).to receive(:external_entity_name).and_return('ext_entity1')
15
15
  class Entities::Entity2 < Maestrano::Connector::Rails::ComplexEntity
16
16
  end
17
17
  allow_any_instance_of(Entities::Entity2).to receive(:consolidate_and_map_data).and_return({})
18
18
  allow_any_instance_of(Entities::Entity2).to receive(:push_entities_to_connec)
19
- allow_any_instance_of(Entities::Entity2).to receive(:connec_entities_names).and_return(%w())
20
- allow_any_instance_of(Entities::Entity2).to receive(:external_entities_names).and_return(%w(Subs ll))
19
+ allow(Entities::Entity2).to receive(:connec_entities_names).and_return(%w())
20
+ allow(Entities::Entity2).to receive(:external_entities_names).and_return(%w(Subs ll))
21
21
  module Entities::SubEntities end;
22
22
  class Entities::SubEntities::Sub < Maestrano::Connector::Rails::SubEntityBase
23
23
  end
24
24
  allow(Maestrano::Connector::Rails::Entity).to receive(:entities_list).and_return([entity_name1, entity_name2])
25
- allow_any_instance_of(Maestrano::Connector::Rails::Entity).to receive(:get_id_from_external_entity_hash).and_return('11')
25
+ allow(Maestrano::Connector::Rails::Entity).to receive(:id_from_external_entity_hash).and_return('11')
26
26
  }
27
27
  let(:entity11) { {first_name: 'John'} }
28
28
  let(:entity12) { {first_name: 'Jane'} }
@@ -57,12 +57,14 @@ describe Maestrano::Connector::Rails::SynchronizationJob do
57
57
 
58
58
  subject { Maestrano::Connector::Rails::SynchronizationJob.new }
59
59
 
60
- it 'calls the five methods' do
60
+ it 'calls the seven methods' do
61
+ expect_any_instance_of(Entities::Person).to receive(:before_sync)
61
62
  expect_any_instance_of(Entities::Person).to receive(:get_connec_entities)
62
63
  expect_any_instance_of(Entities::Person).to receive(:get_external_entities)
63
64
  expect_any_instance_of(Entities::Person).to receive(:consolidate_and_map_data).and_return({})
64
65
  expect_any_instance_of(Entities::Person).to receive(:push_entities_to_external)
65
66
  expect_any_instance_of(Entities::Person).to receive(:push_entities_to_connec)
67
+ expect_any_instance_of(Entities::Person).to receive(:after_sync)
66
68
  subject.sync_entity('person', organization, nil, nil, nil, {})
67
69
  end
68
70
  end
@@ -2,13 +2,15 @@ require 'spec_helper'
2
2
 
3
3
  describe Maestrano::Connector::Rails::ComplexEntity do
4
4
 
5
- #Connec specific methods
6
- describe 'connec specific methods' do
5
+ subject { Maestrano::Connector::Rails::ComplexEntity.new }
6
+
7
+ #Complex specific methods
8
+ describe 'complex specific methods' do
7
9
  describe 'connec_entities_names' do
8
- it { expect{ subject.connec_entities_names }.to raise_error('Not implemented') }
10
+ it { expect{ subject.class.connec_entities_names }.to raise_error('Not implemented') }
9
11
  end
10
12
  describe 'external_entities_names' do
11
- it { expect{ subject.external_entities_names }.to raise_error('Not implemented') }
13
+ it { expect{ subject.class.external_entities_names }.to raise_error('Not implemented') }
12
14
  end
13
15
  describe 'connec_model_to_external_model' do
14
16
  it { expect{ subject.connec_model_to_external_model({}) }.to raise_error('Not implemented') }
@@ -19,7 +21,6 @@ describe Maestrano::Connector::Rails::ComplexEntity do
19
21
  end
20
22
 
21
23
  describe 'general methods' do
22
- subject { Maestrano::Connector::Rails::ComplexEntity.new }
23
24
 
24
25
  describe 'map_to_external_with_idmap' do
25
26
  let(:organization) { create(:organization) }
@@ -31,10 +32,10 @@ describe Maestrano::Connector::Rails::ComplexEntity do
31
32
  let(:sub_instance) { Maestrano::Connector::Rails::SubEntityBase.new }
32
33
  let(:human_name) { 'ET' }
33
34
  before {
34
- allow(sub_instance).to receive(:external?).and_return(false)
35
- allow(sub_instance).to receive(:entity_name).and_return(connec_name)
35
+ allow(sub_instance.class).to receive(:external?).and_return(false)
36
+ allow(sub_instance.class).to receive(:entity_name).and_return(connec_name)
36
37
  allow(sub_instance).to receive(:map_to).and_return(mapped_entity)
37
- allow(sub_instance).to receive(:object_name_from_connec_entity_hash).and_return(human_name)
38
+ allow(sub_instance.class).to receive(:object_name_from_connec_entity_hash).and_return(human_name)
38
39
  }
39
40
 
40
41
  context 'when entity has no idmap' do
@@ -188,20 +189,20 @@ describe Maestrano::Connector::Rails::ComplexEntity do
188
189
  before{
189
190
  allow(subject).to receive(:external_model_to_connec_model).and_return(external_hash)
190
191
  allow(subject).to receive(:connec_model_to_external_model).and_return(connec_hash)
191
- allow_any_instance_of(Entities::SubEntities::ScE1).to receive(:external?).and_return(true)
192
- allow_any_instance_of(Entities::SubEntities::ScE1).to receive(:entity_name).and_return('sc_e1')
193
- allow_any_instance_of(Entities::SubEntities::ScE1).to receive(:get_id_from_external_entity_hash).with(entity1).and_return(id1)
194
- allow_any_instance_of(Entities::SubEntities::ScE1).to receive(:get_last_update_date_from_external_entity_hash).and_return(1.minute.ago)
192
+ allow(Entities::SubEntities::ScE1).to receive(:external?).and_return(true)
193
+ allow(Entities::SubEntities::ScE1).to receive(:entity_name).and_return('sc_e1')
194
+ allow(Entities::SubEntities::ScE1).to receive(:id_from_external_entity_hash).with(entity1).and_return(id1)
195
+ allow(Entities::SubEntities::ScE1).to receive(:last_update_date_from_external_entity_hash).and_return(1.minute.ago)
195
196
  allow_any_instance_of(Entities::SubEntities::ScE1).to receive(:map_to).with('connec1', entity1, organization).and_return(mapped_entity1)
196
- allow_any_instance_of(Entities::SubEntities::ScE2).to receive(:external?).and_return(true)
197
- allow_any_instance_of(Entities::SubEntities::ScE2).to receive(:entity_name).and_return('Sce2')
198
- allow_any_instance_of(Entities::SubEntities::ScE2).to receive(:get_id_from_external_entity_hash).with(entity1).and_return(id1)
199
- allow_any_instance_of(Entities::SubEntities::ScE2).to receive(:get_id_from_external_entity_hash).with(entity2).and_return(id2)
200
- allow_any_instance_of(Entities::SubEntities::ScE2).to receive(:get_last_update_date_from_external_entity_hash).and_return(1.minute.ago)
197
+ allow(Entities::SubEntities::ScE2).to receive(:external?).and_return(true)
198
+ allow(Entities::SubEntities::ScE2).to receive(:entity_name).and_return('Sce2')
199
+ allow(Entities::SubEntities::ScE2).to receive(:id_from_external_entity_hash).with(entity1).and_return(id1)
200
+ allow(Entities::SubEntities::ScE2).to receive(:id_from_external_entity_hash).with(entity2).and_return(id2)
201
+ allow(Entities::SubEntities::ScE2).to receive(:last_update_date_from_external_entity_hash).and_return(1.minute.ago)
201
202
  allow_any_instance_of(Entities::SubEntities::ScE2).to receive(:map_to).with('connec1', entity1, organization).and_return(mapped_entity1)
202
203
  allow_any_instance_of(Entities::SubEntities::ScE2).to receive(:map_to).with('connec2', entity2, organization).and_return(mapped_entity2)
203
- allow_any_instance_of(Entities::SubEntities::ScE1).to receive(:object_name_from_external_entity_hash).and_return(human_name)
204
- allow_any_instance_of(Entities::SubEntities::ScE2).to receive(:object_name_from_external_entity_hash).and_return(human_name)
204
+ allow(Entities::SubEntities::ScE1).to receive(:object_name_from_external_entity_hash).and_return(human_name)
205
+ allow(Entities::SubEntities::ScE2).to receive(:object_name_from_external_entity_hash).and_return(human_name)
205
206
  }
206
207
 
207
208
  context 'when entities have no idmaps' do
@@ -268,9 +269,9 @@ describe Maestrano::Connector::Rails::ComplexEntity do
268
269
  class Entities::SubEntities::Connec2 < Maestrano::Connector::Rails::SubEntityBase
269
270
  end
270
271
  allow_any_instance_of(Entities::SubEntities::Connec1).to receive(:map_to).and_return({'name' => 'Jacob'})
271
- allow_any_instance_of(Entities::SubEntities::Connec1).to receive(:external?).and_return(false)
272
- allow_any_instance_of(Entities::SubEntities::Connec1).to receive(:entity_name).and_return('connec1')
273
- allow_any_instance_of(Entities::SubEntities::Connec1).to receive(:object_name_from_connec_entity_hash).and_return('human name')
272
+ allow(Entities::SubEntities::Connec1).to receive(:external?).and_return(false)
273
+ allow(Entities::SubEntities::Connec1).to receive(:entity_name).and_return('connec1')
274
+ allow(Entities::SubEntities::Connec1).to receive(:object_name_from_connec_entity_hash).and_return('human name')
274
275
  }
275
276
  let(:connec_id1) { '67ttf-5rr4d' }
276
277
  let!(:idmap1) { create(:idmap, organization: organization, external_id: id1, external_entity: 'sc_e1', connec_entity: 'connec1', last_push_to_connec: 1.year.ago, connec_id: connec_id1) }
@@ -384,8 +385,8 @@ describe Maestrano::Connector::Rails::ComplexEntity do
384
385
  let(:idmap) { create(:idmap, organization: organization) }
385
386
  before {
386
387
  [Entities::SubEntities::ScE1, Entities::SubEntities::ScE2].each do |klass|
387
- allow_any_instance_of(klass).to receive(:external?).and_return(true)
388
- allow_any_instance_of(klass).to receive(:entity_name).and_return('n')
388
+ allow(klass).to receive(:external?).and_return(true)
389
+ allow(klass).to receive(:entity_name).and_return('n')
389
390
  end
390
391
  allow(client).to receive(:put).and_return(ActionDispatch::Response.new(200, {}, {people: {}}.to_json, {}))
391
392
  }