maestrano-connector-rails 0.3.3 → 0.3.4

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: f35f9299a109e93d0c7028759a390d44dd7bff6c
4
- data.tar.gz: 0e4695072a4fa120a03195bd405f459ff37025f4
3
+ metadata.gz: 5f9df8b9e24a3d6b1616c9bb26b59aa2a09d4de3
4
+ data.tar.gz: 4f3c29cd00285f933969bf2fe808bf88ba908004
5
5
  SHA512:
6
- metadata.gz: fd0dff595ef6a407c615d2aa25f3ceb63a74416fece30e9f7332c00c964f991989ffb184b69537f910a662f941b7919750d4c2f75b8fcfcc47f2f80c0bbf47d9
7
- data.tar.gz: d656df9663e232ec8f6c805353cffe338961d79c200e31ed2526ce8d3c0e6298fb4f9698543c7d8ebd91c2412645410ece0e4560ca57d235e38ca3700679bb6e
6
+ metadata.gz: ce9beb1f11f820f1804b2b35f77cc402ff02e1976d70e5dc4ff49b1bbf25786efb5b0090e16ad59c93d90dfa6d0e0dac80800cfa2375887775b35a9ecd5489c5
7
+ data.tar.gz: 401b8a68a25e374ba92b4b099c00e183f304af587c8952d7dca0bbb61be79586b9bb41a101afc02614dc4751986bec529d323df7df008fe8cb75487e4813afd8
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.3
1
+ 0.3.4
@@ -161,4 +161,12 @@ module Maestrano::Connector::Rails::Concerns::ComplexEntity
161
161
  end
162
162
  end
163
163
  end
164
+
165
+ def before_sync(connec_client, external_client, last_synchronization, organization, opts)
166
+ # Does nothing by default
167
+ end
168
+
169
+ def after_sync(connec_client, external_client, last_synchronization, organization, opts)
170
+ # Does nothing by default
171
+ end
164
172
  end
@@ -115,6 +115,30 @@ module Maestrano::Connector::Rails::Concerns::Entity
115
115
  def references
116
116
  []
117
117
  end
118
+
119
+ def can_read_connec?
120
+ true
121
+ end
122
+
123
+ def can_read_external?
124
+ true
125
+ end
126
+
127
+ def can_write_connec?
128
+ true
129
+ end
130
+
131
+ def can_write_external?
132
+ true
133
+ end
134
+
135
+ def can_update_connec?
136
+ true
137
+ end
138
+
139
+ def can_update_external?
140
+ true
141
+ end
118
142
  end
119
143
 
120
144
  # ----------------------------------------------
@@ -144,6 +168,8 @@ module Maestrano::Connector::Rails::Concerns::Entity
144
168
  # Connec! methods
145
169
  # ----------------------------------------------
146
170
  def get_connec_entities(client, last_synchronization, organization, opts={})
171
+ return [] unless self.class.can_read_connec?
172
+
147
173
  Maestrano::Connector::Rails::ConnectorLogger.log('info', organization, "Fetching Connec! #{self.class.connec_entity_name}")
148
174
 
149
175
  entities = []
@@ -194,6 +220,8 @@ module Maestrano::Connector::Rails::Concerns::Entity
194
220
  end
195
221
 
196
222
  def push_entities_to_connec_to(connec_client, mapped_external_entities_with_idmaps, connec_entity_name, organization)
223
+ return unless self.class.can_write_connec?
224
+
197
225
  Maestrano::Connector::Rails::ConnectorLogger.log('info', organization, "Sending #{Maestrano::Connector::Rails::External.external_name} #{self.class.external_entity_name.pluralize} to Connec! #{connec_entity_name.pluralize}")
198
226
  mapped_external_entities_with_idmaps.each do |mapped_external_entity_with_idmap|
199
227
  external_entity = mapped_external_entity_with_idmap[:entity]
@@ -204,6 +232,7 @@ module Maestrano::Connector::Rails::Concerns::Entity
204
232
  connec_entity = create_connec_entity(connec_client, external_entity, self.class.normalize_connec_entity_name(connec_entity_name), organization)
205
233
  idmap.update_attributes(connec_id: connec_entity['id'], last_push_to_connec: Time.now, message: nil)
206
234
  else
235
+ next unless self.class.can_update_connec?
207
236
  connec_entity = update_connec_entity(connec_client, external_entity, idmap.connec_id, self.class.normalize_connec_entity_name(connec_entity_name), organization)
208
237
  idmap.update_attributes(last_push_to_connec: Time.now, message: nil)
209
238
  end
@@ -224,6 +253,7 @@ module Maestrano::Connector::Rails::Concerns::Entity
224
253
  end
225
254
 
226
255
  def update_connec_entity(connec_client, mapped_external_entity, connec_id, connec_entity_name, organization)
256
+
227
257
  Maestrano::Connector::Rails::ConnectorLogger.log('info', organization, "Sending update #{connec_entity_name}: #{mapped_external_entity} to Connec!")
228
258
  response = connec_client.put("/#{connec_entity_name}/#{connec_id}", { "#{connec_entity_name}".to_sym => mapped_external_entity })
229
259
  response = JSON.parse(response.body)
@@ -251,6 +281,7 @@ module Maestrano::Connector::Rails::Concerns::Entity
251
281
  # External methods
252
282
  # ----------------------------------------------
253
283
  def get_external_entities(client, last_synchronization, organization, opts={})
284
+ return [] unless self.class.can_read_external?
254
285
  Maestrano::Connector::Rails::ConnectorLogger.log('info', organization, "Fetching #{Maestrano::Connector::Rails::External.external_name} #{self.class.external_entity_name.pluralize}")
255
286
  raise "Not implemented"
256
287
  end
@@ -260,6 +291,7 @@ module Maestrano::Connector::Rails::Concerns::Entity
260
291
  end
261
292
 
262
293
  def push_entities_to_external_to(external_client, mapped_connec_entities_with_idmaps, external_entity_name, organization)
294
+ return unless self.class.can_write_external?
263
295
  Maestrano::Connector::Rails::ConnectorLogger.log('info', organization, "Sending Connec! #{self.class.connec_entity_name.pluralize} to #{Maestrano::Connector::Rails::External.external_name} #{external_entity_name.pluralize}")
264
296
  mapped_connec_entities_with_idmaps.each do |mapped_connec_entity_with_idmap|
265
297
  push_entity_to_external(external_client, mapped_connec_entity_with_idmap, external_entity_name, organization)
@@ -275,6 +307,7 @@ module Maestrano::Connector::Rails::Concerns::Entity
275
307
  external_id = create_external_entity(external_client, connec_entity, external_entity_name, organization)
276
308
  idmap.update_attributes(external_id: external_id, last_push_to_external: Time.now, message: nil)
277
309
  else
310
+ return unless self.class.can_update_external?
278
311
  update_external_entity(external_client, connec_entity, idmap.external_id, external_entity_name, organization)
279
312
  idmap.update_attributes(last_push_to_external: Time.now, message: nil)
280
313
  end
@@ -14,21 +14,22 @@ class Maestrano::Connector::Rails::Entity
14
14
 
15
15
  # Return an array of entities from the external app
16
16
  def get_external_entities(client, last_synchronization, organization, opts={})
17
- Maestrano::Connector::Rails::ConnectorLogger.log('info', organization, "Fetching #{@@external_name} #{self.external_entity_name.pluralize}")
17
+ return [] unless self.class.can_read_external?
18
+ Maestrano::Connector::Rails::ConnectorLogger.log('info', organization, "Fetching #{Maestrano::Connector::Rails::External.external_name} #{self.external_entity_name.pluralize}")
18
19
  # TODO
19
20
  # This method should return only entities that have been updated since the last_synchronization
20
21
  # It should also implements an option to do a full synchronization when opts[:full_sync] == true or when there is no last_synchronization
21
- # Maestrano::Connector::Rails::ConnectorLogger.log('info', organization, "Received data: Source=#{@@external_name}, Entity=#{self.external_entity_name}, Response=#{entities}")
22
+ # Maestrano::Connector::Rails::ConnectorLogger.log('info', organization, "Received data: Source=#{Maestrano::Connector::Rails::External.external_name}, Entity=#{self.external_entity_name}, Response=#{entities}")
22
23
  end
23
24
 
24
25
  def create_external_entity(client, mapped_connec_entity, external_entity_name, organization)
25
- Maestrano::Connector::Rails::ConnectorLogger.log('info', organization, "Sending create #{external_entity_name}: #{mapped_connec_entity} to #{@@external_name}")
26
+ Maestrano::Connector::Rails::ConnectorLogger.log('info', organization, "Sending create #{external_entity_name}: #{mapped_connec_entity} to #{Maestrano::Connector::Rails::External.external_name}")
26
27
  # TODO
27
28
  # This method creates the entity in the external app and returns the external id
28
29
  end
29
30
 
30
31
  def update_external_entity(client, mapped_connec_entity, external_id, external_entity_name, organization)
31
- Maestrano::Connector::Rails::ConnectorLogger.log('info', organization, "Sending update #{external_entity_name} (id=#{external_id}): #{mapped_connec_entity} to #{@@external_name}")
32
+ Maestrano::Connector::Rails::ConnectorLogger.log('info', organization, "Sending update #{external_entity_name} (id=#{external_id}): #{mapped_connec_entity} to #{Maestrano::Connector::Rails::External.external_name}")
32
33
  # TODO
33
34
  # This method updates the entity with the given id in the external app
34
35
  end
@@ -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.3.3 ruby lib
5
+ # stub: maestrano-connector-rails 0.3.4 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "maestrano-connector-rails"
9
- s.version = "0.3.3"
9
+ s.version = "0.3.4"
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"]
@@ -153,9 +153,9 @@ Gem::Specification.new do |s|
153
153
  "spec/dummy/public/500.html",
154
154
  "spec/dummy/public/favicon.ico",
155
155
  "spec/factories.rb",
156
- "spec/jobs/all_syncrhonizations_job_spec.rb",
156
+ "spec/jobs/all_synchronizations_job_spec.rb",
157
157
  "spec/jobs/push_to_connec_job_spec.rb",
158
- "spec/jobs/syncrhonization_job_spec.rb",
158
+ "spec/jobs/synchronization_job_spec.rb",
159
159
  "spec/models/complex_entity_spec.rb",
160
160
  "spec/models/connector_logger_spec.rb",
161
161
  "spec/models/entity_spec.rb",
@@ -50,22 +50,42 @@ describe Maestrano::Connector::Rails::SynchronizationJob do
50
50
  end
51
51
 
52
52
  describe 'sync_entity' do
53
- before {
54
- class Entities::Person < Maestrano::Connector::Rails::Entity
53
+ subject { Maestrano::Connector::Rails::SynchronizationJob.new }
54
+
55
+ context 'non complex entity' do
56
+ before {
57
+ class Entities::Person < Maestrano::Connector::Rails::Entity
58
+ end
59
+ }
60
+
61
+ it 'calls the seven methods' do
62
+ expect_any_instance_of(Entities::Person).to receive(:before_sync)
63
+ expect_any_instance_of(Entities::Person).to receive(:get_connec_entities)
64
+ expect_any_instance_of(Entities::Person).to receive(:get_external_entities)
65
+ expect_any_instance_of(Entities::Person).to receive(:consolidate_and_map_data).and_return({})
66
+ expect_any_instance_of(Entities::Person).to receive(:push_entities_to_external)
67
+ expect_any_instance_of(Entities::Person).to receive(:push_entities_to_connec)
68
+ expect_any_instance_of(Entities::Person).to receive(:after_sync)
69
+ subject.sync_entity('person', organization, nil, nil, nil, {})
55
70
  end
56
- }
71
+ end
57
72
 
58
- subject { Maestrano::Connector::Rails::SynchronizationJob.new }
73
+ context 'complex entity' do
74
+ before {
75
+ class Entities::SomeStuff < Maestrano::Connector::Rails::ComplexEntity
76
+ end
77
+ }
59
78
 
60
- it 'calls the seven methods' do
61
- expect_any_instance_of(Entities::Person).to receive(:before_sync)
62
- expect_any_instance_of(Entities::Person).to receive(:get_connec_entities)
63
- expect_any_instance_of(Entities::Person).to receive(:get_external_entities)
64
- expect_any_instance_of(Entities::Person).to receive(:consolidate_and_map_data).and_return({})
65
- expect_any_instance_of(Entities::Person).to receive(:push_entities_to_external)
66
- expect_any_instance_of(Entities::Person).to receive(:push_entities_to_connec)
67
- expect_any_instance_of(Entities::Person).to receive(:after_sync)
68
- subject.sync_entity('person', organization, nil, nil, nil, {})
79
+ it 'calls the seven methods' do
80
+ expect_any_instance_of(Entities::SomeStuff).to receive(:before_sync)
81
+ expect_any_instance_of(Entities::SomeStuff).to receive(:get_connec_entities)
82
+ expect_any_instance_of(Entities::SomeStuff).to receive(:get_external_entities)
83
+ expect_any_instance_of(Entities::SomeStuff).to receive(:consolidate_and_map_data).and_return({})
84
+ expect_any_instance_of(Entities::SomeStuff).to receive(:push_entities_to_external)
85
+ expect_any_instance_of(Entities::SomeStuff).to receive(:push_entities_to_connec)
86
+ expect_any_instance_of(Entities::SomeStuff).to receive(:after_sync)
87
+ subject.sync_entity('some stuff', organization, nil, nil, nil, {})
88
+ end
69
89
  end
70
90
  end
71
91
  end
@@ -186,6 +186,14 @@ describe Maestrano::Connector::Rails::Entity do
186
186
  }
187
187
 
188
188
  describe 'get_connec_entities' do
189
+ describe 'when write only' do
190
+ before {
191
+ allow(subject.class).to receive(:can_read_connec?).and_return(false)
192
+ allow(client).to receive(:get).and_return(ActionDispatch::Response.new(200, {}, {people: [{first_name: 'Lea'}]}.to_json, {}))
193
+ }
194
+
195
+ it { expect(subject.get_connec_entities(client, nil, organization)).to eql([]) }
196
+ end
189
197
 
190
198
  describe 'with response' do
191
199
  context 'for a singleton resource' do
@@ -276,6 +284,29 @@ describe Maestrano::Connector::Rails::Entity do
276
284
  let(:entities_with_idmaps) { [entity_with_idmap1, entity_with_idmap2] }
277
285
  let(:id) { 'ab12-34re' }
278
286
 
287
+ context 'when read only' do
288
+ before {
289
+ allow(subject.class).to receive(:can_write_connec?).and_return(false)
290
+ }
291
+
292
+ it 'does nothing' do
293
+ expect(subject).to_not receive(:create_connec_entity)
294
+ expect(subject).to_not receive(:update_connec_entity)
295
+ subject.push_entities_to_connec_to(client, entities_with_idmaps, connec_name, organization)
296
+ end
297
+ end
298
+
299
+ context 'when create_only' do
300
+ before {
301
+ allow(subject.class).to receive(:can_update_connec?).and_return(false)
302
+ }
303
+ it 'calls create only' do
304
+ expect(subject).to receive(:create_connec_entity).with(client, entity2, connec_name.downcase.pluralize, organization)
305
+ expect(subject).to_not receive(:update_connec_entity)
306
+ subject.push_entities_to_connec_to(client, entities_with_idmaps, connec_name, organization)
307
+ end
308
+ end
309
+
279
310
  it 'create or update the entities and idmaps according to their idmap state' do
280
311
  allow(subject).to receive(:create_connec_entity).and_return({'id' => id})
281
312
  allow(subject).to receive(:external_entity_name).and_return(external_name)
@@ -421,6 +452,14 @@ describe Maestrano::Connector::Rails::Entity do
421
452
  end
422
453
 
423
454
  describe 'push_entities_to_external_to' do
455
+ context 'when read only' do
456
+ it 'does nothing' do
457
+ allow(subject.class).to receive(:can_write_external?).and_return(false)
458
+ expect(subject).to_not receive(:push_entity_to_external)
459
+ subject.push_entities_to_external_to(nil, entities_with_idmaps, external_name, organization)
460
+ end
461
+ end
462
+
424
463
  it 'calls push_entity_to_external for each entity' do
425
464
  allow(subject.class).to receive(:connec_entity_name).and_return(connec_name)
426
465
  expect(subject).to receive(:push_entity_to_external).twice
@@ -430,6 +469,12 @@ describe Maestrano::Connector::Rails::Entity do
430
469
 
431
470
  describe 'push_entity_to_external' do
432
471
  context 'when the entity idmap has an external id' do
472
+ it 'does not calls update if create_only' do
473
+ allow(subject.class).to receive(:can_update_external?).and_return(false)
474
+ expect(subject).to_not receive(:update_external_entity)
475
+ subject.push_entity_to_external(nil, entity_with_idmap1, external_name, organization)
476
+ end
477
+
433
478
  it 'calls update_external_entity' do
434
479
  expect(subject).to receive(:update_external_entity).with(nil, entity1, idmap1.external_id, external_name, organization)
435
480
  subject.push_entity_to_external(nil, entity_with_idmap1, external_name, organization)
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.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pierre Berard
@@ -363,9 +363,9 @@ files:
363
363
  - spec/dummy/public/500.html
364
364
  - spec/dummy/public/favicon.ico
365
365
  - spec/factories.rb
366
- - spec/jobs/all_syncrhonizations_job_spec.rb
366
+ - spec/jobs/all_synchronizations_job_spec.rb
367
367
  - spec/jobs/push_to_connec_job_spec.rb
368
- - spec/jobs/syncrhonization_job_spec.rb
368
+ - spec/jobs/synchronization_job_spec.rb
369
369
  - spec/models/complex_entity_spec.rb
370
370
  - spec/models/connector_logger_spec.rb
371
371
  - spec/models/entity_spec.rb