maestrano-connector-rails 0.2.19 → 0.2.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 84ed969991a93b3632339f112511a4baa3848ae9
4
- data.tar.gz: 133ac31a7b246b0d5f7f7aa096fdd859ab2b7e19
3
+ metadata.gz: 641c5c4a44a4f83f3c44ed2c5e23a474eba48abb
4
+ data.tar.gz: 9912810a2b3d6986e68ba89d19d5068e12daaade
5
5
  SHA512:
6
- metadata.gz: 14cbd5436d31186f909ce2c66b01b10e027a5b31fb6f932e2387eabb754aa349f170679d523af24327c79e659a4fad5333e4dd51bbf43a74c468ec0f938add90
7
- data.tar.gz: 5befbf8603f56588e5501bc16594266d3a592ac775c27ebc3c39b4647ce26fb409e96b4fd7dbb384f26e00575c8628217cc79c9d52e6b0ed4d189416993497a4
6
+ metadata.gz: 3ad9efcebceb9e3506693ae02d101ee61efdd103d5f04c62ab97b9764c890da72410d9440b8bcc84235beef2bd9431926d3e13cab6e021e524158f8a54a75698
7
+ data.tar.gz: cdd4bc5ac76e057c4b4249c66f18e88c6c4eba76b020e1fe211563c1074f64b0e61a4ed575fe881aff49cfbca1ed69d9bd7c74f07ea467d49c39ced3c87f8a09
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.19
1
+ 0.2.20
@@ -55,11 +55,16 @@ module Maestrano::Connector::Rails::Concerns::ComplexEntity
55
55
  def map_to_external_with_idmap(entity, organization, external_entity_name, sub_entity_instance)
56
56
  idmap = sub_entity_instance.find_idmap({connec_id: entity['id'], external_entity: external_entity_name, organization_id: organization.id})
57
57
 
58
- if idmap && ((!idmap.to_external) || idmap.last_push_to_external && idmap.last_push_to_external > entity['updated_at'])
59
- Maestrano::Connector::Rails::ConnectorLogger.log('info', organization, "Discard Connec! #{sub_entity_instance.entity_name} : #{entity}")
60
- nil
58
+ if idmap
59
+ idmap.update(name: sub_entity_instance.object_name_from_connec_entity_hash(entity))
60
+ if (!idmap.to_external) || idmap.last_push_to_external && idmap.last_push_to_external > entity['updated_at']
61
+ Maestrano::Connector::Rails::ConnectorLogger.log('info', organization, "Discard Connec! #{sub_entity_instance.entity_name} : #{entity}")
62
+ nil
63
+ else
64
+ {entity: sub_entity_instance.map_to(external_entity_name, entity, organization), idmap: idmap}
65
+ end
61
66
  else
62
- {entity: sub_entity_instance.map_to(external_entity_name, entity, organization), idmap: idmap || sub_entity_instance.create_idmap_from_connec_entity(entity, external_entity_name, organization)}
67
+ {entity: sub_entity_instance.map_to(external_entity_name, entity, organization), idmap: sub_entity_instance.create_idmap_from_connec_entity(entity, external_entity_name, organization)}
63
68
  end
64
69
  end
65
70
 
@@ -98,7 +103,9 @@ module Maestrano::Connector::Rails::Concerns::ComplexEntity
98
103
  idmap = sub_entity_instance.find_idmap(external_id: sub_entity_instance.get_id_from_external_entity_hash(entity), connec_entity: connec_entity_name, organization_id: organization.id)
99
104
 
100
105
  # No idmap: creating one, nothing else to do
101
- unless idmap
106
+ if idmap
107
+ idmap.update(name: sub_entity_instance.object_name_from_external_entity_hash(entity))
108
+ else
102
109
  next {entity: sub_entity_instance.map_to(connec_entity_name, entity, organization), idmap: sub_entity_instance.create_idmap_from_external_entity(entity, connec_entity_name, organization)}
103
110
  end
104
111
 
@@ -169,11 +169,16 @@ module Maestrano::Connector::Rails::Concerns::Entity
169
169
  def map_to_external_with_idmap(entity, organization)
170
170
  idmap = find_idmap({connec_id: entity['id'], organization_id: organization.id})
171
171
 
172
- if idmap && ((!idmap.to_external) || (idmap.last_push_to_external && idmap.last_push_to_external > entity['updated_at']))
173
- Maestrano::Connector::Rails::ConnectorLogger.log('info', organization, "Discard Connec! #{connec_entity_name} : #{entity}")
174
- nil
172
+ if idmap
173
+ idmap.update(name: object_name_from_connec_entity_hash(entity))
174
+ if (!idmap.to_external) || (idmap.last_push_to_external && idmap.last_push_to_external > entity['updated_at'])
175
+ Maestrano::Connector::Rails::ConnectorLogger.log('info', organization, "Discard Connec! #{connec_entity_name} : #{entity}")
176
+ nil
177
+ else
178
+ {entity: map_to_external(entity, organization), idmap: idmap}
179
+ end
175
180
  else
176
- {entity: map_to_external(entity, organization), idmap: idmap || create_idmap_from_connec_entity(entity, organization)}
181
+ {entity: map_to_external(entity, organization), idmap: create_idmap_from_connec_entity(entity, organization)}
177
182
  end
178
183
  end
179
184
 
@@ -245,7 +250,9 @@ module Maestrano::Connector::Rails::Concerns::Entity
245
250
  mapped_external_entities = external_entities.map{|entity|
246
251
  idmap = find_idmap({external_id: get_id_from_external_entity_hash(entity), organization_id: organization.id})
247
252
  # No idmap: creating one, nothing else to do
248
- unless idmap
253
+ if idmap
254
+ idmap.update(name: object_name_from_external_entity_hash(entity))
255
+ else
249
256
  next {entity: map_to_connec(entity, organization), idmap: create_idmap_from_external_entity(entity, organization)}
250
257
  end
251
258
 
@@ -283,10 +290,10 @@ module Maestrano::Connector::Rails::Concerns::Entity
283
290
  keep_external = self.class.is_external_more_recent?(connec_entities.first, external_entities.first, self)
284
291
  end
285
292
  if keep_external
286
- idmap.update(external_id: get_id_from_external_entity_hash(external_entities.first))
293
+ idmap.update(external_id: get_id_from_external_entity_hash(external_entities.first), name: object_name_from_external_entity_hash(external_entities.first))
287
294
  return {connec_entities: [], external_entities: [{entity: map_to_connec(external_entities.first, organization), idmap: idmap}]}
288
295
  else
289
- idmap.update(connec_id: connec_entities.first['id'])
296
+ idmap.update(connec_id: connec_entities.first['id'], name: object_name_from_connec_entity_hash(connec_entities.first))
290
297
  return {connec_entities: [{entity: map_to_external(connec_entities.first, organization), idmap: idmap}], external_entities: []}
291
298
  end
292
299
  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 0.2.19 ruby lib
5
+ # stub: maestrano-connector-rails 0.2.20 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "maestrano-connector-rails"
9
- s.version = "0.2.19"
9
+ s.version = "0.2.20"
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-10"
14
+ s.date = "2016-03-11"
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"]
@@ -184,6 +184,7 @@ describe Maestrano::Connector::Rails::ComplexEntity do
184
184
  }
185
185
  }
186
186
  let(:connec_hash) { {} }
187
+ let(:human_name) { 'Jabba' }
187
188
  before{
188
189
  allow(subject).to receive(:external_model_to_connec_model).and_return(external_hash)
189
190
  allow(subject).to receive(:connec_model_to_external_model).and_return(connec_hash)
@@ -199,14 +200,11 @@ describe Maestrano::Connector::Rails::ComplexEntity do
199
200
  allow_any_instance_of(Entities::SubEntities::ScE2).to receive(:get_last_update_date_from_external_entity_hash).and_return(1.minute.ago)
200
201
  allow_any_instance_of(Entities::SubEntities::ScE2).to receive(:map_to).with('connec1', entity1, organization).and_return(mapped_entity1)
201
202
  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)
202
205
  }
203
206
 
204
207
  context 'when entities have no idmaps' do
205
- let(:human_name) { 'Jabba' }
206
- before {
207
- allow_any_instance_of(Entities::SubEntities::ScE1).to receive(:object_name_from_external_entity_hash).and_return(human_name)
208
- allow_any_instance_of(Entities::SubEntities::ScE2).to receive(:object_name_from_external_entity_hash).and_return(human_name)
209
- }
210
208
 
211
209
  it 'creates an idmap for each entity' do
212
210
  expect{
@@ -272,6 +270,7 @@ describe Maestrano::Connector::Rails::ComplexEntity do
272
270
  allow_any_instance_of(Entities::SubEntities::Connec1).to receive(:map_to).and_return({'name' => 'Jacob'})
273
271
  allow_any_instance_of(Entities::SubEntities::Connec1).to receive(:external?).and_return(false)
274
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')
275
274
  }
276
275
  let(:connec_id1) { '67ttf-5rr4d' }
277
276
  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) }
@@ -417,6 +417,8 @@ describe Maestrano::Connector::Rails::Entity do
417
417
  allow(subject).to receive(:singleton?).and_return(true)
418
418
  allow(subject).to receive(:map_to_connec).and_return({map: 'connec'})
419
419
  allow(subject).to receive(:map_to_external).and_return({map: 'external'})
420
+ allow(subject).to receive(:object_name_from_connec_entity_hash).and_return('connec human name')
421
+ allow(subject).to receive(:object_name_from_external_entity_hash).and_return('external human name')
420
422
  }
421
423
 
422
424
  it { expect(subject.consolidate_and_map_data([], [], organization)).to eql({connec_entities: [], external_entities: []}) }
@@ -484,16 +486,14 @@ describe Maestrano::Connector::Rails::Entity do
484
486
  let(:entity) { {id: id, name: 'John', modifiedDate: date} }
485
487
  let(:mapped_entity) { {first_name: 'John'} }
486
488
  let(:entities) { [entity] }
489
+ let(:human_name) { 'alien' }
487
490
 
488
491
  before {
489
492
  allow(subject).to receive(:map_to_connec).and_return(mapped_entity)
493
+ allow(subject).to receive(:object_name_from_external_entity_hash).and_return(human_name)
490
494
  }
491
495
 
492
496
  context 'when entity has no idmap' do
493
- let(:human_name) { 'alien' }
494
- before {
495
- allow(subject).to receive(:object_name_from_external_entity_hash).and_return(human_name)
496
- }
497
497
 
498
498
  it 'creates an idmap and returns the mapped entity with its new idmap' do
499
499
  mapped_entities = subject.consolidate_and_map_data([], entities, organization)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maestrano-connector-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.19
4
+ version: 0.2.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pierre Berard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-10 00:00:00.000000000 Z
11
+ date: 2016-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: maestrano-rails