maestrano-connector-rails 0.2.17 → 0.2.18

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: fb5c07cb2cd6e41eed0cf6d969bccfaca04bbfd7
4
- data.tar.gz: 597eff9e10f8091d32df3efa8fe3d401686471b1
3
+ metadata.gz: f94f571529c54189a2416028f32c9eaf10f0f496
4
+ data.tar.gz: ec2a9b0396f561cb157aa909f758b66b07d50cd9
5
5
  SHA512:
6
- metadata.gz: 8255bd1676f26950267b98125e88679f3d91d5d127e650fbcfe4bc7d72c55b4d3d5ef3742022b6e2cdd267d5cab9d0fa449ed4197817f94c8ee43400320c4a55
7
- data.tar.gz: 897a96ac9045cb71828ade21e216586f34db7af9bbec6ea7d6c1dca7cdbcbf9666e44a4a5dcb8f1fdb74fcd2fa194fa6f8386125f49b8cc21c73fc4dc372a65c
6
+ metadata.gz: 580f8d9921831198e67a9102ddce992fbe6359b08f0346a32c35af69385ca4f51c6c35a34975b71e7744e74b24fa8d7a03cc4e48ab0e8d31464da2d729091c33
7
+ data.tar.gz: 46749aca76d739411ea64a4187a7fdfdbe2d1c795481306458c338bac8586628a6706cae51132e1c5538de1c6f490ffed6357f2a52057efacb0dd889b7444c50
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.17
1
+ 0.2.18
@@ -68,6 +68,10 @@ module Maestrano::Connector::Rails::Concerns::Entity
68
68
  # Connec! methods
69
69
  # ----------------------------------------------
70
70
  def normalized_connec_entity_name
71
+ normalize_connec_entity_name(connec_entity_name)
72
+ end
73
+
74
+ def normalize_connec_entity_name(connec_entity_name)
71
75
  if singleton?
72
76
  connec_entity_name.downcase
73
77
  else
@@ -133,10 +137,10 @@ module Maestrano::Connector::Rails::Concerns::Entity
133
137
 
134
138
  begin
135
139
  if idmap.connec_id.blank?
136
- connec_entity = create_connec_entity(connec_client, external_entity, connec_entity_name, organization)
140
+ connec_entity = create_connec_entity(connec_client, external_entity, normalize_connec_entity_name(connec_entity_name), organization)
137
141
  idmap.update_attributes(connec_id: connec_entity['id'], connec_entity: connec_entity_name.downcase, last_push_to_connec: Time.now, message: nil)
138
142
  else
139
- connec_entity = update_connec_entity(connec_client, external_entity, idmap.connec_id, connec_entity_name, organization)
143
+ connec_entity = update_connec_entity(connec_client, external_entity, idmap.connec_id, normalize_connec_entity_name(connec_entity_name), organization)
140
144
  idmap.update_attributes(last_push_to_connec: Time.now, message: nil)
141
145
  end
142
146
  rescue => e
@@ -148,18 +152,18 @@ module Maestrano::Connector::Rails::Concerns::Entity
148
152
 
149
153
  def create_connec_entity(connec_client, mapped_external_entity, connec_entity_name, organization)
150
154
  Maestrano::Connector::Rails::ConnectorLogger.log('info', organization, "Sending create #{connec_entity_name}: #{mapped_external_entity} to Connec!")
151
- response = connec_client.post("/#{normalized_connec_entity_name}", { "#{normalized_connec_entity_name}".to_sym => mapped_external_entity })
155
+ response = connec_client.post("/#{connec_entity_name}", { "#{connec_entity_name}".to_sym => mapped_external_entity })
152
156
  response = JSON.parse(response.body)
153
157
  raise "Connec!: #{response['errors']['title']}" if response['errors'] && response['errors']['title']
154
- response["#{normalized_connec_entity_name}"]
158
+ response["#{connec_entity_name}"]
155
159
  end
156
160
 
157
161
  def update_connec_entity(connec_client, mapped_external_entity, connec_id, connec_entity_name, organization)
158
162
  Maestrano::Connector::Rails::ConnectorLogger.log('info', organization, "Sending update #{connec_entity_name}: #{mapped_external_entity} to Connec!")
159
- response = connec_client.put("/#{normalized_connec_entity_name}/#{connec_id}", { "#{normalized_connec_entity_name}".to_sym => mapped_external_entity })
163
+ response = connec_client.put("/#{connec_entity_name}/#{connec_id}", { "#{connec_entity_name}".to_sym => mapped_external_entity })
160
164
  response = JSON.parse(response.body)
161
165
  raise "Connec!: #{response['errors']['title']}" if response['errors'] && response['errors']['title']
162
- response["#{normalized_connec_entity_name}"]
166
+ response["#{connec_entity_name}"]
163
167
  end
164
168
 
165
169
  def map_to_external_with_idmap(entity, organization)
@@ -17,13 +17,13 @@ module Maestrano::Connector::Rails
17
17
  if external?
18
18
  entity_name
19
19
  else
20
- raise "Forbidden call"
20
+ raise "Forbidden call: cannot call external_entity_name for a connec entity"
21
21
  end
22
22
  end
23
23
 
24
24
  def connec_entity_name
25
25
  if external?
26
- raise "Forbidden call"
26
+ raise "Forbidden call: cannot call connec_entity_name for an external entity"
27
27
  else
28
28
  entity_name
29
29
  end
@@ -47,13 +47,13 @@ module Maestrano::Connector::Rails
47
47
  })
48
48
  Maestrano::Connector::Rails::IdMap.create(h)
49
49
  else
50
- raise 'Forbidden call'
50
+ raise 'Forbidden call: cannot call create_idmap_from_external_entity for a connec entity'
51
51
  end
52
52
  end
53
53
 
54
54
  def create_idmap_from_connec_entity(entity, external_entity_name, organization)
55
55
  if external?
56
- raise 'Forbidden call'
56
+ raise 'Forbidden call: cannot call create_idmap_from_connec_entity for an external entity'
57
57
  else
58
58
  h = names_hash.merge({
59
59
  connec_id: entity['id'],
@@ -2,11 +2,11 @@
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.17 ruby lib
5
+ # stub: maestrano-connector-rails 0.2.18 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "maestrano-connector-rails"
9
- s.version = "0.2.17"
9
+ s.version = "0.2.18"
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"]
@@ -364,7 +364,8 @@ describe Maestrano::Connector::Rails::ComplexEntity do
364
364
  end
365
365
 
366
366
  describe 'push_entities_to_connec' do
367
- let(:mapped_entity_with_idmap) { {entity: {}, idmap: nil} }
367
+ let(:idmap) { nil }
368
+ let(:mapped_entity_with_idmap) { {entity: {}, idmap: idmap} }
368
369
  let(:external_hash) {
369
370
  {
370
371
  'sc_e1' => {'connec1' => [mapped_entity_with_idmap]},
@@ -377,6 +378,24 @@ describe Maestrano::Connector::Rails::ComplexEntity do
377
378
  expect_any_instance_of(Entities::SubEntities::ScE2).to receive(:push_entities_to_connec_to).twice
378
379
  subject.push_entities_to_connec(nil, external_hash, nil)
379
380
  end
381
+
382
+ describe 'full call' do
383
+ let(:organization) { create(:organization) }
384
+ let!(:client) { Maestrano::Connec::Client.new(organization.uid) }
385
+ let(:idmap) { create(:idmap, organization: organization) }
386
+ before {
387
+ [Entities::SubEntities::ScE1, Entities::SubEntities::ScE2].each do |klass|
388
+ allow_any_instance_of(klass).to receive(:external?).and_return(true)
389
+ allow_any_instance_of(klass).to receive(:entity_name).and_return('n')
390
+ end
391
+ allow(client).to receive(:put).and_return(ActionDispatch::Response.new(200, {}, {people: {}}.to_json, {}))
392
+ }
393
+ it 'is successful' do
394
+ subject.push_entities_to_connec(client, external_hash, organization)
395
+ idmap.reload
396
+ expect(idmap.message).to be nil
397
+ end
398
+ end
380
399
  end
381
400
 
382
401
 
@@ -200,8 +200,8 @@ describe Maestrano::Connector::Rails::Entity do
200
200
  allow(subject).to receive(:create_connec_entity).and_return({'id' => id})
201
201
  allow(subject).to receive(:external_entity_name).and_return(external_name)
202
202
 
203
- expect(subject).to receive(:create_connec_entity).with(client, entity2, connec_name, organization)
204
- expect(subject).to receive(:update_connec_entity).with(client, entity1, idmap1.connec_id, connec_name, organization)
203
+ expect(subject).to receive(:create_connec_entity).with(client, entity2, connec_name.downcase.pluralize, organization)
204
+ expect(subject).to receive(:update_connec_entity).with(client, entity1, idmap1.connec_id, connec_name.downcase.pluralize, organization)
205
205
  old_push_date = idmap1.last_push_to_connec
206
206
 
207
207
  subject.push_entities_to_connec_to(client, entities_with_idmaps, connec_name, organization)
@@ -224,11 +224,11 @@ describe Maestrano::Connector::Rails::Entity do
224
224
 
225
225
  it 'sends a post to connec' do
226
226
  expect(client).to receive(:post).with("/#{connec_name.downcase.pluralize}", {"#{connec_name.downcase.pluralize}".to_sym => entity})
227
- subject.create_connec_entity(client, entity, connec_name, organization)
227
+ subject.create_connec_entity(client, entity, connec_name.downcase.pluralize, organization)
228
228
  end
229
229
 
230
230
  it 'returns the created entity' do
231
- expect(subject.create_connec_entity(client, entity, connec_name, organization)).to eql(JSON.parse(entity.to_json))
231
+ expect(subject.create_connec_entity(client, entity, connec_name.downcase.pluralize, organization)).to eql(JSON.parse(entity.to_json))
232
232
  end
233
233
  end
234
234
 
@@ -242,7 +242,7 @@ describe Maestrano::Connector::Rails::Entity do
242
242
 
243
243
  it 'sends a put to connec' do
244
244
  expect(client).to receive(:put).with("/#{connec_name.downcase.pluralize}/#{id}", {"#{connec_name.downcase.pluralize}".to_sym => entity})
245
- subject.update_connec_entity(client, entity, id, connec_name, organization)
245
+ subject.update_connec_entity(client, entity, id, connec_name.downcase.pluralize, organization)
246
246
  end
247
247
  end
248
248
 
@@ -28,7 +28,10 @@ describe Maestrano::Connector::Rails::SubEntityBase do
28
28
  end
29
29
 
30
30
  context 'when entity is not external' do
31
- it { expect{ subject.external_entity_name }.to raise_error('Not implemented') }
31
+ before {
32
+ allow_any_instance_of(Maestrano::Connector::Rails::SubEntityBase).to receive(:external?).and_return(false)
33
+ }
34
+ it { expect{ subject.external_entity_name }.to raise_error('Forbidden call: cannot call external_entity_name for a connec entity') }
32
35
  end
33
36
  end
34
37
 
@@ -45,7 +48,10 @@ describe Maestrano::Connector::Rails::SubEntityBase do
45
48
  end
46
49
 
47
50
  context 'when entity is external' do
48
- it { expect{ subject.connec_entity_name }.to raise_error('Not implemented') }
51
+ before {
52
+ allow_any_instance_of(Maestrano::Connector::Rails::SubEntityBase).to receive(:external?).and_return(true)
53
+ }
54
+ it { expect{ subject.connec_entity_name }.to raise_error('Forbidden call: cannot call connec_entity_name for an external entity') }
49
55
  end
50
56
  end
51
57
 
@@ -83,7 +89,7 @@ describe Maestrano::Connector::Rails::SubEntityBase do
83
89
  end
84
90
  context 'when not external' do
85
91
  let(:bool) { false }
86
- it { expect{ subject.create_idmap_from_external_entity({}, '', organization) }.to raise_error('Forbidden call') }
92
+ it { expect{ subject.create_idmap_from_external_entity({}, '', organization) }.to raise_error('Forbidden call: cannot call create_idmap_from_external_entity for a connec entity') }
87
93
  end
88
94
  end
89
95
 
@@ -97,7 +103,7 @@ describe Maestrano::Connector::Rails::SubEntityBase do
97
103
  }
98
104
 
99
105
  context 'when external' do
100
- it { expect{ subject.create_idmap_from_connec_entity({}, '', organization) }.to raise_error('Forbidden call') }
106
+ it { expect{ subject.create_idmap_from_connec_entity({}, '', organization) }.to raise_error('Forbidden call: cannot call create_idmap_from_connec_entity for an external entity') }
101
107
  end
102
108
  context 'when not external' do
103
109
  let(:bool) { false }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maestrano-connector-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.17
4
+ version: 0.2.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pierre Berard