maestrano-connector-rails 0.3.8 → 0.3.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 10545da2fb0a9de8fdd05ee7fced909eee0ba976
4
- data.tar.gz: d5b49147ff797a4a120c66a7d7508f968d03fed5
3
+ metadata.gz: 956cc667094c5815fea98bf9bb0e1908d42db5ad
4
+ data.tar.gz: 464905041d0edd0d867c5ebefd723f295794e157
5
5
  SHA512:
6
- metadata.gz: 9768a574a8b656df7b32893759bcfd6f9564ec1e1e75e29b2fcc7f3313b22f3f07a9c11984e004298746cb7890aec36c3f07d441897667f16888eee7b66b999b
7
- data.tar.gz: 5e064f3e79676cb28125dc3e0accc57f86a1c18cf0f6cae7016fea4c7814c406c4f0e9c7c150d09612c3fd8ede3119aa5c0f80b958e78851d9714465c8738bf9
6
+ metadata.gz: d87af8e7ac898f9423ede627fdf0fc6a2a89ac6fa852d722272dc8f2c8738913a28e0691fbbd24981e4d684b6e372e6fa9ad13ed5946b29c1969d3ae2470edd9
7
+ data.tar.gz: 4e442c16d85668446e535cde5cefec4d1478d92fd88252472b9674384511d4ee5567c8c3c6978c6249b00f74bf1641f4ed756419fa893900715073965c45d6d0
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.8
1
+ 0.3.9
@@ -53,7 +53,7 @@ module Maestrano::Connector::Rails::Concerns::ComplexEntity
53
53
  # General methods
54
54
  # -------------------------------------------------------------
55
55
  def map_to_external_with_idmap(entity, organization, external_entity_name, sub_entity_instance)
56
- idmap = sub_entity_instance.class.find_idmap({connec_id: entity['id'], external_entity: external_entity_name, organization_id: organization.id})
56
+ idmap = sub_entity_instance.class.find_idmap({connec_id: entity['id'], external_entity: external_entity_name.downcase, organization_id: organization.id})
57
57
 
58
58
  if idmap
59
59
  idmap.update(name: sub_entity_instance.class.object_name_from_connec_entity_hash(entity))
@@ -100,7 +100,7 @@ module Maestrano::Connector::Rails::Concerns::ComplexEntity
100
100
  sub_entity_instance = "Entities::SubEntities::#{external_entity_name.titleize.split.join}".constantize.new
101
101
 
102
102
  entities.map!{|entity|
103
- idmap = sub_entity_instance.class.find_idmap(external_id: sub_entity_instance.class.id_from_external_entity_hash(entity), connec_entity: connec_entity_name, organization_id: organization.id)
103
+ idmap = sub_entity_instance.class.find_idmap(external_id: sub_entity_instance.class.id_from_external_entity_hash(entity), connec_entity: connec_entity_name.downcase, organization_id: organization.id)
104
104
 
105
105
  # No idmap: creating one, nothing else to do
106
106
  if idmap
@@ -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.3.8 ruby lib
5
+ # stub: maestrano-connector-rails 0.3.9 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "maestrano-connector-rails"
9
- s.version = "0.3.8"
9
+ s.version = "0.3.9"
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-31"
14
+ s.date = "2016-04-01"
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"]
@@ -27,8 +27,8 @@ describe Maestrano::Connector::Rails::ComplexEntity do
27
27
  let(:id) { '322j-bbfg4' }
28
28
  let(:entity) { {'id' => id, 'name' => 'John', 'updated_at' => 2.day.ago} }
29
29
  let(:mapped_entity) { {'first_name' => 'John'} }
30
- let(:connec_name) { 'connec_name' }
31
- let(:external_name) { 'external_name' }
30
+ let(:connec_name) { 'Connec_name' }
31
+ let(:external_name) { 'External_name' }
32
32
  let(:sub_instance) { Maestrano::Connector::Rails::SubEntityBase.new }
33
33
  let(:human_name) { 'ET' }
34
34
  before {
@@ -50,7 +50,7 @@ describe Maestrano::Connector::Rails::ComplexEntity do
50
50
  end
51
51
 
52
52
  context 'when entity has an idmap without last_push_to_external' do
53
- let!(:idmap) { create(:idmap, organization: organization, connec_id: id, connec_entity: connec_name, last_push_to_external: nil, external_entity: external_name) }
53
+ let!(:idmap) { create(:idmap, organization: organization, connec_id: id, connec_entity: connec_name.downcase, last_push_to_external: nil, external_entity: external_name.downcase) }
54
54
 
55
55
  it 'returns the mapped entity with its idmap' do
56
56
  expect(subject.map_to_external_with_idmap(entity, organization, external_name, sub_instance)).to eql({entity: mapped_entity, idmap: idmap})
@@ -58,7 +58,7 @@ describe Maestrano::Connector::Rails::ComplexEntity do
58
58
  end
59
59
 
60
60
  context 'when entity has an idmap with an older last_push_to_external' do
61
- let!(:idmap) { create(:idmap, organization: organization, connec_id: id, connec_entity: connec_name, last_push_to_external: 1.year.ago, external_entity: external_name) }
61
+ let!(:idmap) { create(:idmap, organization: organization, connec_id: id, connec_entity: connec_name.downcase, last_push_to_external: 1.year.ago, external_entity: external_name.downcase) }
62
62
 
63
63
  it 'returns the mapped entity with its idmap' do
64
64
  expect(subject.map_to_external_with_idmap(entity, organization, external_name, sub_instance)).to eql({entity: mapped_entity, idmap: idmap})
@@ -66,7 +66,7 @@ describe Maestrano::Connector::Rails::ComplexEntity do
66
66
  end
67
67
 
68
68
  context 'when entity has an idmap with a more recent last_push_to_external' do
69
- let!(:idmap) { create(:idmap, organization: organization, connec_id: id, connec_entity: connec_name, last_push_to_external: 1.second.ago, external_entity: external_name) }
69
+ let!(:idmap) { create(:idmap, organization: organization, connec_id: id, connec_entity: connec_name.downcase, last_push_to_external: 1.second.ago, external_entity: external_name.downcase) }
70
70
 
71
71
  it 'discards the entity' do
72
72
  expect(subject.map_to_external_with_idmap(entity, organization, external_name, sub_instance)).to be_nil
@@ -74,7 +74,7 @@ describe Maestrano::Connector::Rails::ComplexEntity do
74
74
  end
75
75
 
76
76
  context 'when entity has an idmap with to_external set to false' do
77
- let!(:idmap) { create(:idmap, organization: organization, connec_id: id, connec_entity: connec_name, to_external: false, external_entity: external_name) }
77
+ let!(:idmap) { create(:idmap, organization: organization, connec_id: id, connec_entity: connec_name.downcase, to_external: false, external_entity: external_name.downcase) }
78
78
 
79
79
  it 'discards the entity' do
80
80
  expect(subject.map_to_external_with_idmap(entity, organization, external_name, sub_instance)).to be_nil
@@ -180,8 +180,8 @@ describe Maestrano::Connector::Rails::ComplexEntity do
180
180
  let(:mapped_entity2) { {'net_price' => 45} }
181
181
  let(:external_hash) {
182
182
  {
183
- 'sc_e1' => {'connec1' => [entity1]},
184
- 'ScE2' => {'connec1' => [entity1], 'connec2' => [entity2]}
183
+ 'sc_e1' => {'Connec1' => [entity1]},
184
+ 'ScE2' => {'Connec1' => [entity1], 'connec2' => [entity2]}
185
185
  }
186
186
  }
187
187
  let(:connec_hash) { {} }
@@ -193,13 +193,13 @@ describe Maestrano::Connector::Rails::ComplexEntity do
193
193
  allow(Entities::SubEntities::ScE1).to receive(:entity_name).and_return('sc_e1')
194
194
  allow(Entities::SubEntities::ScE1).to receive(:id_from_external_entity_hash).with(entity1).and_return(id1)
195
195
  allow(Entities::SubEntities::ScE1).to receive(:last_update_date_from_external_entity_hash).and_return(1.minute.ago)
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::ScE1).to receive(:map_to).with('Connec1', entity1, organization).and_return(mapped_entity1)
197
197
  allow(Entities::SubEntities::ScE2).to receive(:external?).and_return(true)
198
198
  allow(Entities::SubEntities::ScE2).to receive(:entity_name).and_return('Sce2')
199
199
  allow(Entities::SubEntities::ScE2).to receive(:id_from_external_entity_hash).with(entity1).and_return(id1)
200
200
  allow(Entities::SubEntities::ScE2).to receive(:id_from_external_entity_hash).with(entity2).and_return(id2)
201
201
  allow(Entities::SubEntities::ScE2).to receive(:last_update_date_from_external_entity_hash).and_return(1.minute.ago)
202
- allow_any_instance_of(Entities::SubEntities::ScE2).to receive(:map_to).with('connec1', entity1, organization).and_return(mapped_entity1)
202
+ allow_any_instance_of(Entities::SubEntities::ScE2).to receive(:map_to).with('Connec1', entity1, organization).and_return(mapped_entity1)
203
203
  allow_any_instance_of(Entities::SubEntities::ScE2).to receive(:map_to).with('connec2', entity2, organization).and_return(mapped_entity2)
204
204
  allow(Entities::SubEntities::ScE1).to receive(:object_name_from_external_entity_hash).and_return(human_name)
205
205
  allow(Entities::SubEntities::ScE2).to receive(:object_name_from_external_entity_hash).and_return(human_name)
@@ -216,9 +216,9 @@ describe Maestrano::Connector::Rails::ComplexEntity do
216
216
  it 'returns the entity with their new idmaps' do
217
217
  mapped_entities = subject.consolidate_and_map_data({}, external_hash, organization, opt)
218
218
  expect(mapped_entities).to eql(external_entities: {
219
- 'sc_e1' => {'connec1' => [{entity: mapped_entity1, idmap: Maestrano::Connector::Rails::IdMap.first}]},
219
+ 'sc_e1' => {'Connec1' => [{entity: mapped_entity1, idmap: Maestrano::Connector::Rails::IdMap.first}]},
220
220
  'ScE2' => {
221
- 'connec1' => [{entity: mapped_entity1, idmap: Maestrano::Connector::Rails::IdMap.all[1]}],
221
+ 'Connec1' => [{entity: mapped_entity1, idmap: Maestrano::Connector::Rails::IdMap.all[1]}],
222
222
  'connec2' => [{entity: mapped_entity2, idmap: Maestrano::Connector::Rails::IdMap.last}],
223
223
  }
224
224
  },
@@ -234,9 +234,9 @@ describe Maestrano::Connector::Rails::ComplexEntity do
234
234
  it 'discards the entities' do
235
235
  mapped_entities = subject.consolidate_and_map_data({}, external_hash, organization, opt)
236
236
  expect(mapped_entities).to eql(external_entities: {
237
- 'sc_e1' => {'connec1' => []},
237
+ 'sc_e1' => {'Connec1' => []},
238
238
  'ScE2' => {
239
- 'connec1' => [],
239
+ 'Connec1' => [],
240
240
  'connec2' => [],
241
241
  }
242
242
  },
@@ -252,9 +252,9 @@ describe Maestrano::Connector::Rails::ComplexEntity do
252
252
  it 'discards the entities' do
253
253
  mapped_entities = subject.consolidate_and_map_data({}, external_hash, organization, opt)
254
254
  expect(mapped_entities).to eql(external_entities: {
255
- 'sc_e1' => {'connec1' => []},
255
+ 'sc_e1' => {'Connec1' => []},
256
256
  'ScE2' => {
257
- 'connec1' => [],
257
+ 'Connec1' => [],
258
258
  'connec2' => [],
259
259
  }
260
260
  },
@@ -270,22 +270,22 @@ describe Maestrano::Connector::Rails::ComplexEntity do
270
270
  end
271
271
  allow_any_instance_of(Entities::SubEntities::Connec1).to receive(:map_to).and_return({'name' => 'Jacob'})
272
272
  allow(Entities::SubEntities::Connec1).to receive(:external?).and_return(false)
273
- allow(Entities::SubEntities::Connec1).to receive(:entity_name).and_return('connec1')
273
+ allow(Entities::SubEntities::Connec1).to receive(:entity_name).and_return('Connec1')
274
274
  allow(Entities::SubEntities::Connec1).to receive(:object_name_from_connec_entity_hash).and_return('human name')
275
275
  }
276
276
  let(:connec_id1) { '67ttf-5rr4d' }
277
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) }
278
278
  let!(:idmap21) { create(:idmap, organization: organization, external_id: id1, external_entity: 'sce2', connec_entity: 'connec1', last_push_to_connec: 1.year.ago) }
279
279
  let!(:idmap22) { create(:idmap, organization: organization, external_id: id2, external_entity: 'sce2', connec_entity: 'connec2', last_push_to_connec: 1.year.ago) }
280
- let(:connec_hash) { {'connec1' => {'sc_e1' => [{'id' => connec_id1, 'first_name' => 'Jacob', 'updated_at' => 1.hour.ago}]}, 'connec2' => {'sc_e1' => [], 'ScE2' => []}} }
280
+ let(:connec_hash) { {'Connec1' => {'sc_e1' => [{'id' => connec_id1, 'first_name' => 'Jacob', 'updated_at' => 1.hour.ago}]}, 'connec2' => {'sc_e1' => [], 'ScE2' => []}} }
281
281
 
282
282
  context 'without conflict' do
283
283
  it 'returns the entity with their idmaps' do
284
- subject.consolidate_and_map_data({'connec1' => []}, {'sc_e1' => []}, organization, opt)
284
+ subject.consolidate_and_map_data({'Connec1' => []}, {'sc_e1' => []}, organization, opt)
285
285
  expect(external_hash).to eql({
286
- 'sc_e1' => {'connec1' => [{entity: mapped_entity1, idmap: idmap1}]},
286
+ 'sc_e1' => {'Connec1' => [{entity: mapped_entity1, idmap: idmap1}]},
287
287
  'ScE2' => {
288
- 'connec1' => [{entity: mapped_entity1, idmap: idmap21}],
288
+ 'Connec1' => [{entity: mapped_entity1, idmap: idmap21}],
289
289
  'connec2' => [{entity: mapped_entity2, idmap: idmap22}],
290
290
  }
291
291
  })
@@ -298,12 +298,12 @@ describe Maestrano::Connector::Rails::ComplexEntity do
298
298
  let(:opt) { {connec_preemption: true} }
299
299
 
300
300
  it 'keeps the connec entities' do
301
- mapped_entities = subject.consolidate_and_map_data({'connec1' => []}, {'sc_e1' => []}, organization, opt)
302
- expect(mapped_entities[:connec_entities]).to eq({'connec1' => {'sc_e1' => [{entity: {'name' => 'Jacob'}, idmap: idmap1}]}, 'connec2' => {'sc_e1' => [], 'ScE2' => []}})
301
+ mapped_entities = subject.consolidate_and_map_data({'Connec1' => []}, {'sc_e1' => []}, organization, opt)
302
+ expect(mapped_entities[:connec_entities]).to eq({'Connec1' => {'sc_e1' => [{entity: {'name' => 'Jacob'}, idmap: idmap1}]}, 'connec2' => {'sc_e1' => [], 'ScE2' => []}})
303
303
  expect(mapped_entities[:external_entities]).to eql({
304
- 'sc_e1' => {'connec1' => []},
304
+ 'sc_e1' => {'Connec1' => []},
305
305
  'ScE2' => {
306
- 'connec1' => [{entity: mapped_entity1, idmap: idmap21}],
306
+ 'Connec1' => [{entity: mapped_entity1, idmap: idmap21}],
307
307
  'connec2' => [{entity: mapped_entity2, idmap: idmap22}],
308
308
  }
309
309
  })
@@ -314,12 +314,12 @@ describe Maestrano::Connector::Rails::ComplexEntity do
314
314
  let(:opt) { {connec_preemption: false} }
315
315
 
316
316
  it 'keeps the external entities' do
317
- mapped_entities = subject.consolidate_and_map_data({'connec1' => []}, {'sc_e1' => []}, organization, opt)
318
- expect(mapped_entities[:connec_entities]).to eq({'connec1' => {'sc_e1' => []}, 'connec2' => {'sc_e1' => [], 'ScE2' => []}})
317
+ mapped_entities = subject.consolidate_and_map_data({'Connec1' => []}, {'sc_e1' => []}, organization, opt)
318
+ expect(mapped_entities[:connec_entities]).to eq({'Connec1' => {'sc_e1' => []}, 'connec2' => {'sc_e1' => [], 'ScE2' => []}})
319
319
  expect(mapped_entities[:external_entities]).to eql({
320
- 'sc_e1' => {'connec1' => [{entity: mapped_entity1, idmap: idmap1}]},
320
+ 'sc_e1' => {'Connec1' => [{entity: mapped_entity1, idmap: idmap1}]},
321
321
  'ScE2' => {
322
- 'connec1' => [{entity: mapped_entity1, idmap: idmap21}],
322
+ 'Connec1' => [{entity: mapped_entity1, idmap: idmap21}],
323
323
  'connec2' => [{entity: mapped_entity2, idmap: idmap22}],
324
324
  }
325
325
  })
@@ -330,12 +330,12 @@ describe Maestrano::Connector::Rails::ComplexEntity do
330
330
  context 'without option' do
331
331
  context 'with a more recently updated external entity' do
332
332
  it 'keeps the external entity' do
333
- mapped_entities = subject.consolidate_and_map_data({'connec1' => []}, {'sc_e1' => []}, organization, opt)
334
- expect(mapped_entities[:connec_entities]).to eq({'connec1' => {'sc_e1' => []}, 'connec2' => {'sc_e1' => [], 'ScE2' => []}})
333
+ mapped_entities = subject.consolidate_and_map_data({'Connec1' => []}, {'sc_e1' => []}, organization, opt)
334
+ expect(mapped_entities[:connec_entities]).to eq({'Connec1' => {'sc_e1' => []}, 'connec2' => {'sc_e1' => [], 'ScE2' => []}})
335
335
  expect(mapped_entities[:external_entities]).to eql({
336
- 'sc_e1' => {'connec1' => [{entity: mapped_entity1, idmap: idmap1}]},
336
+ 'sc_e1' => {'Connec1' => [{entity: mapped_entity1, idmap: idmap1}]},
337
337
  'ScE2' => {
338
- 'connec1' => [{entity: mapped_entity1, idmap: idmap21}],
338
+ 'Connec1' => [{entity: mapped_entity1, idmap: idmap21}],
339
339
  'connec2' => [{entity: mapped_entity2, idmap: idmap22}],
340
340
  }
341
341
  })
@@ -343,15 +343,15 @@ describe Maestrano::Connector::Rails::ComplexEntity do
343
343
  end
344
344
 
345
345
  context 'with a more recently updated connec entity' do
346
- let(:connec_hash) { {'connec1' => {'sc_e1' => [{'id' => connec_id1, 'first_name' => 'Jacob', 'updated_at' => 1.second.ago}]}, 'connec2' => {'sc_e1' => [], 'ScE2' => []}} }
346
+ let(:connec_hash) { {'Connec1' => {'sc_e1' => [{'id' => connec_id1, 'first_name' => 'Jacob', 'updated_at' => 1.second.ago}]}, 'connec2' => {'sc_e1' => [], 'ScE2' => []}} }
347
347
 
348
348
  it 'keeps the connec entities' do
349
- mapped_entities = subject.consolidate_and_map_data({'connec1' => []}, {'sc_e1' => []}, organization, opt)
350
- expect(mapped_entities[:connec_entities]).to eq({'connec1' => {'sc_e1' => [{entity: {'name' => 'Jacob'}, idmap: idmap1}]}, 'connec2' => {'sc_e1' => [], 'ScE2' => []}})
349
+ mapped_entities = subject.consolidate_and_map_data({'Connec1' => []}, {'sc_e1' => []}, organization, opt)
350
+ expect(mapped_entities[:connec_entities]).to eq({'Connec1' => {'sc_e1' => [{entity: {'name' => 'Jacob'}, idmap: idmap1}]}, 'connec2' => {'sc_e1' => [], 'ScE2' => []}})
351
351
  expect(mapped_entities[:external_entities]).to eql({
352
- 'sc_e1' => {'connec1' => []},
352
+ 'sc_e1' => {'Connec1' => []},
353
353
  'ScE2' => {
354
- 'connec1' => [{entity: mapped_entity1, idmap: idmap21}],
354
+ 'Connec1' => [{entity: mapped_entity1, idmap: idmap21}],
355
355
  'connec2' => [{entity: mapped_entity2, idmap: idmap22}],
356
356
  }
357
357
  })
@@ -368,13 +368,13 @@ describe Maestrano::Connector::Rails::ComplexEntity do
368
368
  let(:mapped_entity_with_idmap) { {entity: {}, idmap: idmap} }
369
369
  let(:external_hash) {
370
370
  {
371
- 'sc_e1' => {'connec1' => [mapped_entity_with_idmap]},
372
- 'ScE2' => {'connec1' => [mapped_entity_with_idmap, mapped_entity_with_idmap], 'connec2' => [mapped_entity_with_idmap]}
371
+ 'sc_e1' => {'Connec1' => [mapped_entity_with_idmap]},
372
+ 'ScE2' => {'Connec1' => [mapped_entity_with_idmap, mapped_entity_with_idmap], 'connec2' => [mapped_entity_with_idmap]}
373
373
  }
374
374
  }
375
375
 
376
376
  it 'calls push_entities_to_connec on each sub complex entity' do
377
- expect_any_instance_of(Entities::SubEntities::ScE1).to receive(:push_entities_to_connec_to).once.with(nil, [mapped_entity_with_idmap], 'connec1', nil)
377
+ expect_any_instance_of(Entities::SubEntities::ScE1).to receive(:push_entities_to_connec_to).once.with(nil, [mapped_entity_with_idmap], 'Connec1', nil)
378
378
  expect_any_instance_of(Entities::SubEntities::ScE2).to receive(:push_entities_to_connec_to).twice
379
379
  subject.push_entities_to_connec(nil, external_hash, nil)
380
380
  end
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.3.8
4
+ version: 0.3.9
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-31 00:00:00.000000000 Z
11
+ date: 2016-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: maestrano-rails