maestrano-connector-rails 1.3.5 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/Rakefile +2 -2
- data/VERSION +1 -1
- data/app/models/maestrano/connector/rails/concerns/entity.rb +94 -19
- data/app/models/maestrano/connector/rails/concerns/sub_entity_base.rb +12 -14
- data/lib/generators/connector/templates/example_entity.rb +15 -0
- data/maestrano-connector-rails.gemspec +8 -8
- data/release_notes.md +9 -0
- data/spec/integration/complex_spec.rb +298 -4
- data/spec/integration/connec_to_external_spec.rb +117 -10
- data/spec/models/complex_entity_spec.rb +14 -10
- data/spec/models/entity_spec.rb +87 -72
- data/spec/models/sub_entity_base_spec.rb +33 -21
- metadata +7 -5
@@ -14,10 +14,10 @@ describe Maestrano::Connector::Rails::SubEntityBase do
|
|
14
14
|
|
15
15
|
describe 'external_entity_name' do
|
16
16
|
context 'when entity is external' do
|
17
|
-
before(:each)
|
17
|
+
before(:each) do
|
18
18
|
allow(Maestrano::Connector::Rails::SubEntityBase).to receive(:external?).and_return(true)
|
19
19
|
allow(Maestrano::Connector::Rails::SubEntityBase).to receive(:entity_name).and_return('Name')
|
20
|
-
|
20
|
+
end
|
21
21
|
|
22
22
|
it 'returns the entity_name' do
|
23
23
|
expect(subject.external_entity_name).to eql('Name')
|
@@ -25,19 +25,19 @@ describe Maestrano::Connector::Rails::SubEntityBase do
|
|
25
25
|
end
|
26
26
|
|
27
27
|
context 'when entity is not external' do
|
28
|
-
before
|
28
|
+
before do
|
29
29
|
allow(Maestrano::Connector::Rails::SubEntityBase).to receive(:external?).and_return(false)
|
30
|
-
|
30
|
+
end
|
31
31
|
it { expect{ subject.external_entity_name }.to raise_error('Forbidden call: cannot call external_entity_name for a connec entity') }
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
35
|
describe 'connec_entity_name' do
|
36
36
|
context 'when entity is not external' do
|
37
|
-
before(:each)
|
37
|
+
before(:each) do
|
38
38
|
allow(Maestrano::Connector::Rails::SubEntityBase).to receive(:external?).and_return(false)
|
39
39
|
allow(Maestrano::Connector::Rails::SubEntityBase).to receive(:entity_name).and_return('Name')
|
40
|
-
|
40
|
+
end
|
41
41
|
|
42
42
|
it 'returns the entity_name' do
|
43
43
|
expect(subject.connec_entity_name).to eql('Name')
|
@@ -45,19 +45,19 @@ describe Maestrano::Connector::Rails::SubEntityBase do
|
|
45
45
|
end
|
46
46
|
|
47
47
|
context 'when entity is external' do
|
48
|
-
before
|
48
|
+
before do
|
49
49
|
allow(Maestrano::Connector::Rails::SubEntityBase).to receive(:external?).and_return(true)
|
50
|
-
|
50
|
+
end
|
51
51
|
it { expect{ subject.connec_entity_name }.to raise_error('Forbidden call: cannot call connec_entity_name for an external entity') }
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
55
|
describe 'names_hash' do
|
56
56
|
let(:bool) { true }
|
57
|
-
before
|
57
|
+
before do
|
58
58
|
allow(Maestrano::Connector::Rails::SubEntityBase).to receive(:external?).and_return(bool)
|
59
59
|
allow(Maestrano::Connector::Rails::SubEntityBase).to receive(:entity_name).and_return('Name')
|
60
|
-
|
60
|
+
end
|
61
61
|
|
62
62
|
context 'when external' do
|
63
63
|
it { expect(subject.names_hash).to eql({external_entity: 'name'}) }
|
@@ -79,25 +79,25 @@ describe Maestrano::Connector::Rails::SubEntityBase do
|
|
79
79
|
subject { Maestrano::Connector::Rails::SubEntityBase.new(organization, connec_client, external_client, opts) }
|
80
80
|
|
81
81
|
describe 'map_to' do
|
82
|
-
before
|
82
|
+
before do
|
83
83
|
class AMapper
|
84
84
|
extend HashMapper
|
85
85
|
end
|
86
86
|
allow(subject.class).to receive(:mapper_classes).and_return('Name' => AMapper)
|
87
|
-
|
87
|
+
end
|
88
88
|
|
89
89
|
describe 'failure' do
|
90
90
|
it { expect{ subject.map_to('Not an entity', {}) }.to raise_error(RuntimeError) }
|
91
91
|
end
|
92
92
|
|
93
93
|
context 'when external' do
|
94
|
-
before
|
94
|
+
before do
|
95
95
|
allow(subject.class).to receive(:external?).and_return(true)
|
96
96
|
allow(subject.class).to receive(:id_from_external_entity_hash).and_return('this id')
|
97
|
-
|
97
|
+
end
|
98
98
|
|
99
99
|
it 'calls the mapper denormalize' do
|
100
|
-
expect(AMapper).to receive(:denormalize).and_return({})
|
100
|
+
expect(AMapper).to receive(:denormalize).with({}, subject.instance_values).and_return({})
|
101
101
|
subject.map_to('Name', {})
|
102
102
|
end
|
103
103
|
|
@@ -108,6 +108,12 @@ describe Maestrano::Connector::Rails::SubEntityBase do
|
|
108
108
|
subject.map_to('Name', {})
|
109
109
|
end
|
110
110
|
|
111
|
+
it 'calls the creation_mapper_classes that delegates to the mapper_classes denormalize when passed true as a third argument' do
|
112
|
+
expect(subject.class).to receive(:creation_mapper_classes).and_call_original
|
113
|
+
expect(AMapper).to receive(:denormalize).with({}, subject.instance_values).and_return({})
|
114
|
+
subject.map_to('Name', {}, true)
|
115
|
+
end
|
116
|
+
|
111
117
|
context 'when no refs' do
|
112
118
|
it 'calls for reference folding' do
|
113
119
|
allow(subject.class).to receive(:references).and_return({})
|
@@ -117,10 +123,10 @@ describe Maestrano::Connector::Rails::SubEntityBase do
|
|
117
123
|
end
|
118
124
|
|
119
125
|
context 'when connec_matching_fields' do
|
120
|
-
before
|
126
|
+
before do
|
121
127
|
expect(AMapper).to receive(:denormalize).and_return({opts: {a: 2}})
|
122
128
|
allow(subject.class).to receive(:connec_matching_fields).and_return('matching_fields')
|
123
|
-
|
129
|
+
end
|
124
130
|
|
125
131
|
it 'adds the matching_fields in the entity opts' do
|
126
132
|
expect(subject.map_to('Name', {})).to eql({id: [Maestrano::Connector::Rails::ConnecHelper.id_hash('this id', organization)], opts: {a: 2, matching_fields: 'matching_fields'}}.with_indifferent_access)
|
@@ -129,15 +135,21 @@ describe Maestrano::Connector::Rails::SubEntityBase do
|
|
129
135
|
end
|
130
136
|
|
131
137
|
context 'when not external' do
|
132
|
-
before
|
138
|
+
before do
|
133
139
|
allow(subject.class).to receive(:external?).and_return(false)
|
134
|
-
|
140
|
+
end
|
135
141
|
|
136
142
|
it 'calls the mapper normalize' do
|
137
|
-
expect(AMapper).to receive(:normalize).and_return({})
|
143
|
+
expect(AMapper).to receive(:normalize).with({}, subject.instance_values).and_return({})
|
138
144
|
subject.map_to('Name', {})
|
139
145
|
end
|
146
|
+
|
147
|
+
it 'calls the creation_mapper_classes that delegates to the mapper_classes normalize when passed true as a third argument' do
|
148
|
+
expect(subject.class).to receive(:creation_mapper_classes).and_call_original
|
149
|
+
expect(AMapper).to receive(:normalize).with({}, subject.instance_values).and_return({})
|
150
|
+
subject.map_to('Name', {}, true)
|
151
|
+
end
|
140
152
|
end
|
141
153
|
end
|
142
154
|
end
|
143
|
-
end
|
155
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: maestrano-connector-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
+
- Maestrano
|
7
8
|
- Pierre Berard
|
9
|
+
- Marco Bagnasco
|
8
10
|
autorequire:
|
9
11
|
bindir: bin
|
10
12
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
13
|
+
date: 2016-08-24 00:00:00.000000000 Z
|
12
14
|
dependencies:
|
13
15
|
- !ruby/object:Gem::Dependency
|
14
16
|
name: rails
|
@@ -44,14 +46,14 @@ dependencies:
|
|
44
46
|
requirements:
|
45
47
|
- - ">="
|
46
48
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
49
|
+
version: 0.2.2
|
48
50
|
type: :runtime
|
49
51
|
prerelease: false
|
50
52
|
version_requirements: !ruby/object:Gem::Requirement
|
51
53
|
requirements:
|
52
54
|
- - ">="
|
53
55
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
56
|
+
version: 0.2.2
|
55
57
|
- !ruby/object:Gem::Dependency
|
56
58
|
name: haml-rails
|
57
59
|
requirement: !ruby/object:Gem::Requirement
|
@@ -362,7 +364,7 @@ dependencies:
|
|
362
364
|
version: '0'
|
363
365
|
description: Maestrano is the next generation marketplace for SME applications. See
|
364
366
|
https://maestrano.com for details.
|
365
|
-
email:
|
367
|
+
email: developers@maestrano.com
|
366
368
|
executables:
|
367
369
|
- rails
|
368
370
|
extensions: []
|