restforce-db 1.2.3 → 1.2.4
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 +4 -4
- data/lib/restforce/db/associations/base.rb +5 -2
- data/lib/restforce/db/associations/belongs_to.rb +20 -5
- data/lib/restforce/db/version.rb +1 -1
- data/test/cassettes/Restforce_DB_Associations_BelongsTo/with_an_inverse_mapping/_build/with_an_unrelated_association_mapping/proceeds_without_raising_an_error.yml +271 -0
- data/test/lib/restforce/db/associations/belongs_to_test.rb +12 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 917ef8bd6976aa2326f55c577f57a29ba7569487
|
4
|
+
data.tar.gz: 595a0501e51ac8f258137446db9d14a22b1b266d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb1d74b767dcf8d6a831f7504ab1de8a3234a592402fb008edc2e7880d186df5a4080e7da7cf30752217917ddb769071fe589cbe5f8746cc07abdb3dac45b8f6
|
7
|
+
data.tar.gz: 07002a8559cc853ec102b547d1790240144f3943ed9ccce636455edae230fe624f521757d0710b6766fbceeeec6a096b93be73c520cf46664cf10228e4cbd0c4
|
@@ -61,10 +61,13 @@ module Restforce
|
|
61
61
|
# mapping - A Restforce::DB::Mapping.
|
62
62
|
# database_record - An instance of an ActiveRecord::Base subclass.
|
63
63
|
#
|
64
|
-
# Returns a String.
|
64
|
+
# Returns a String or nil.
|
65
65
|
def lookup_field(mapping, database_record)
|
66
66
|
inverse = inverse_association_name(target_reflection(database_record))
|
67
|
-
mapping.associations.detect { |a| a.name == inverse }
|
67
|
+
association = mapping.associations.detect { |a| a.name == inverse }
|
68
|
+
return unless association
|
69
|
+
|
70
|
+
association.lookup
|
68
71
|
end
|
69
72
|
|
70
73
|
# Internal: Get the class of the inverse ActiveRecord association.
|
@@ -18,12 +18,12 @@ module Restforce
|
|
18
18
|
# Returns an Array of constructed association records.
|
19
19
|
def build(database_record, salesforce_record)
|
20
20
|
lookups = {}
|
21
|
+
attributes = {}
|
21
22
|
instances = []
|
22
23
|
|
23
|
-
|
24
|
-
lookup_id = salesforce_record[
|
24
|
+
for_mappings(database_record) do |mapping, lookup|
|
25
|
+
lookup_id = salesforce_record[lookup]
|
25
26
|
lookups[mapping.lookup_column] = lookup_id
|
26
|
-
|
27
27
|
instance = mapping.salesforce_record_type.find(lookup_id)
|
28
28
|
|
29
29
|
# If any of the mappings are invalid, short-circuit the creation of
|
@@ -31,8 +31,8 @@ module Restforce
|
|
31
31
|
return [] unless instance
|
32
32
|
|
33
33
|
instances << instance
|
34
|
-
|
35
|
-
|
34
|
+
attrs = mapping.convert(mapping.database_model, instance.attributes)
|
35
|
+
attributes = attributes.merge(attrs)
|
36
36
|
end
|
37
37
|
|
38
38
|
associated = association_scope(database_record).find_by(lookups)
|
@@ -46,6 +46,21 @@ module Restforce
|
|
46
46
|
|
47
47
|
private
|
48
48
|
|
49
|
+
# Internal: Iterate through all relevant mappings for the target
|
50
|
+
# ActiveRecord class.
|
51
|
+
#
|
52
|
+
# database_record - An instance of an ActiveRecord::Base subclass.
|
53
|
+
#
|
54
|
+
# Yields the Restforce::DB::Mapping and the corresponding String lookup.
|
55
|
+
# Returns nothing.
|
56
|
+
def for_mappings(database_record)
|
57
|
+
Registry[target_class(database_record)].each do |mapping|
|
58
|
+
lookup = lookup_field(mapping, database_record)
|
59
|
+
next unless lookup
|
60
|
+
yield mapping, lookup
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
49
64
|
# Internal: Get the Salesforce ID belonging to the associated record
|
50
65
|
# for a supplied instance. Must be implemented per-association.
|
51
66
|
#
|
data/lib/restforce/db/version.rb
CHANGED
@@ -0,0 +1,271 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://<host>/services/oauth2/token
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: grant_type=password&client_id=<client_id>&client_secret=<client_secret>&username=<username>&password=<password><security_token>
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Faraday v0.9.1
|
12
|
+
Content-Type:
|
13
|
+
- application/x-www-form-urlencoded
|
14
|
+
Accept-Encoding:
|
15
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
16
|
+
Accept:
|
17
|
+
- "*/*"
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 200
|
21
|
+
message: OK
|
22
|
+
headers:
|
23
|
+
Date:
|
24
|
+
- Thu, 23 Apr 2015 03:13:37 GMT
|
25
|
+
Set-Cookie:
|
26
|
+
- BrowserId=pJidk7gYQ3GCVEMb1Z-p0g;Path=/;Domain=.salesforce.com;Expires=Mon,
|
27
|
+
22-Jun-2015 03:13:37 GMT
|
28
|
+
Expires:
|
29
|
+
- Thu, 01 Jan 1970 00:00:00 GMT
|
30
|
+
Pragma:
|
31
|
+
- no-cache
|
32
|
+
Cache-Control:
|
33
|
+
- no-cache, no-store
|
34
|
+
Content-Type:
|
35
|
+
- application/json;charset=UTF-8
|
36
|
+
Transfer-Encoding:
|
37
|
+
- chunked
|
38
|
+
body:
|
39
|
+
encoding: ASCII-8BIT
|
40
|
+
string: '{"id":"https://login.salesforce.com/id/00D1a000000H3O9EAK/0051a000000UGT8AAO","issued_at":"1429758817565","token_type":"Bearer","instance_url":"https://<host>","signature":"ETRbdU1qbtTF4bZuRhnk3OFfLRmxZRMXihMo3PgUaCc=","access_token":"00D1a000000H3O9!AQ4AQI3jppS_aXZi3eoU3Ztk8o91RYAqZvR2D51oCqu62M0uC1FFl0QlLq8SSc7KMviWaMD3qj3R.OxDi5v6FJ24v5LjiUBH"}'
|
41
|
+
http_version:
|
42
|
+
recorded_at: Thu, 23 Apr 2015 03:13:37 GMT
|
43
|
+
- request:
|
44
|
+
method: post
|
45
|
+
uri: https://<host>/services/data/v26.0/sobjects/Contact
|
46
|
+
body:
|
47
|
+
encoding: UTF-8
|
48
|
+
string: '{"Email":"somebody@example.com","LastName":"Somebody"}'
|
49
|
+
headers:
|
50
|
+
User-Agent:
|
51
|
+
- Faraday v0.9.1
|
52
|
+
Content-Type:
|
53
|
+
- application/json
|
54
|
+
Authorization:
|
55
|
+
- OAuth 00D1a000000H3O9!AQ4AQI3jppS_aXZi3eoU3Ztk8o91RYAqZvR2D51oCqu62M0uC1FFl0QlLq8SSc7KMviWaMD3qj3R.OxDi5v6FJ24v5LjiUBH
|
56
|
+
Accept-Encoding:
|
57
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
58
|
+
Accept:
|
59
|
+
- "*/*"
|
60
|
+
response:
|
61
|
+
status:
|
62
|
+
code: 201
|
63
|
+
message: Created
|
64
|
+
headers:
|
65
|
+
Date:
|
66
|
+
- Thu, 23 Apr 2015 03:13:38 GMT
|
67
|
+
Set-Cookie:
|
68
|
+
- BrowserId=5Nut_wCxQuKIC63Zx74A7A;Path=/;Domain=.salesforce.com;Expires=Mon,
|
69
|
+
22-Jun-2015 03:13:38 GMT
|
70
|
+
Expires:
|
71
|
+
- Thu, 01 Jan 1970 00:00:00 GMT
|
72
|
+
Sforce-Limit-Info:
|
73
|
+
- api-usage=1/15000
|
74
|
+
Location:
|
75
|
+
- "/services/data/v26.0/sobjects/Contact/0031a000002eu2wAAA"
|
76
|
+
Content-Type:
|
77
|
+
- application/json;charset=UTF-8
|
78
|
+
Transfer-Encoding:
|
79
|
+
- chunked
|
80
|
+
body:
|
81
|
+
encoding: ASCII-8BIT
|
82
|
+
string: '{"id":"0031a000002eu2wAAA","success":true,"errors":[]}'
|
83
|
+
http_version:
|
84
|
+
recorded_at: Thu, 23 Apr 2015 03:13:39 GMT
|
85
|
+
- request:
|
86
|
+
method: post
|
87
|
+
uri: https://<host>/services/data/v26.0/sobjects/CustomObject__c
|
88
|
+
body:
|
89
|
+
encoding: UTF-8
|
90
|
+
string: '{"Friend__c":"0031a000002eu2wAAA"}'
|
91
|
+
headers:
|
92
|
+
User-Agent:
|
93
|
+
- Faraday v0.9.1
|
94
|
+
Content-Type:
|
95
|
+
- application/json
|
96
|
+
Authorization:
|
97
|
+
- OAuth 00D1a000000H3O9!AQ4AQI3jppS_aXZi3eoU3Ztk8o91RYAqZvR2D51oCqu62M0uC1FFl0QlLq8SSc7KMviWaMD3qj3R.OxDi5v6FJ24v5LjiUBH
|
98
|
+
Accept-Encoding:
|
99
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
100
|
+
Accept:
|
101
|
+
- "*/*"
|
102
|
+
response:
|
103
|
+
status:
|
104
|
+
code: 201
|
105
|
+
message: Created
|
106
|
+
headers:
|
107
|
+
Date:
|
108
|
+
- Thu, 23 Apr 2015 03:13:40 GMT
|
109
|
+
Set-Cookie:
|
110
|
+
- BrowserId=GQLMiMKEQ42kgZCYY5_Guw;Path=/;Domain=.salesforce.com;Expires=Mon,
|
111
|
+
22-Jun-2015 03:13:40 GMT
|
112
|
+
Expires:
|
113
|
+
- Thu, 01 Jan 1970 00:00:00 GMT
|
114
|
+
Sforce-Limit-Info:
|
115
|
+
- api-usage=1/15000
|
116
|
+
Location:
|
117
|
+
- "/services/data/v26.0/sobjects/CustomObject__c/a001a000001QkMJAA0"
|
118
|
+
Content-Type:
|
119
|
+
- application/json;charset=UTF-8
|
120
|
+
Transfer-Encoding:
|
121
|
+
- chunked
|
122
|
+
body:
|
123
|
+
encoding: ASCII-8BIT
|
124
|
+
string: '{"id":"a001a000001QkMJAA0","success":true,"errors":[]}'
|
125
|
+
http_version:
|
126
|
+
recorded_at: Thu, 23 Apr 2015 03:13:40 GMT
|
127
|
+
- request:
|
128
|
+
method: get
|
129
|
+
uri: https://<host>/services/data/v26.0/query?q=select%20Id,%20SystemModstamp,%20Name,%20Example_Field__c,%20Friend__c%20from%20CustomObject__c%20where%20Id%20=%20%27a001a000001QkMJAA0%27
|
130
|
+
body:
|
131
|
+
encoding: US-ASCII
|
132
|
+
string: ''
|
133
|
+
headers:
|
134
|
+
User-Agent:
|
135
|
+
- Faraday v0.9.1
|
136
|
+
Authorization:
|
137
|
+
- OAuth 00D1a000000H3O9!AQ4AQI3jppS_aXZi3eoU3Ztk8o91RYAqZvR2D51oCqu62M0uC1FFl0QlLq8SSc7KMviWaMD3qj3R.OxDi5v6FJ24v5LjiUBH
|
138
|
+
Accept-Encoding:
|
139
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
140
|
+
Accept:
|
141
|
+
- "*/*"
|
142
|
+
response:
|
143
|
+
status:
|
144
|
+
code: 200
|
145
|
+
message: OK
|
146
|
+
headers:
|
147
|
+
Date:
|
148
|
+
- Thu, 23 Apr 2015 03:13:41 GMT
|
149
|
+
Set-Cookie:
|
150
|
+
- BrowserId=XUQn0DWrTke9Ylns2VGOoQ;Path=/;Domain=.salesforce.com;Expires=Mon,
|
151
|
+
22-Jun-2015 03:13:41 GMT
|
152
|
+
Expires:
|
153
|
+
- Thu, 01 Jan 1970 00:00:00 GMT
|
154
|
+
Sforce-Limit-Info:
|
155
|
+
- api-usage=1/15000
|
156
|
+
Content-Type:
|
157
|
+
- application/json;charset=UTF-8
|
158
|
+
Transfer-Encoding:
|
159
|
+
- chunked
|
160
|
+
body:
|
161
|
+
encoding: ASCII-8BIT
|
162
|
+
string: '{"totalSize":1,"done":true,"records":[{"attributes":{"type":"CustomObject__c","url":"/services/data/v26.0/sobjects/CustomObject__c/a001a000001QkMJAA0"},"Id":"a001a000001QkMJAA0","SystemModstamp":"2015-04-23T03:13:40.000+0000","Name":"a001a000001QkMJ","Example_Field__c":null,"Friend__c":"0031a000002eu2wAAA"}]}'
|
163
|
+
http_version:
|
164
|
+
recorded_at: Thu, 23 Apr 2015 03:13:41 GMT
|
165
|
+
- request:
|
166
|
+
method: get
|
167
|
+
uri: https://<host>/services/data/v26.0/query?q=select%20Id,%20SystemModstamp,%20Email%20from%20Contact%20where%20Id%20=%20%270031a000002eu2wAAA%27
|
168
|
+
body:
|
169
|
+
encoding: US-ASCII
|
170
|
+
string: ''
|
171
|
+
headers:
|
172
|
+
User-Agent:
|
173
|
+
- Faraday v0.9.1
|
174
|
+
Authorization:
|
175
|
+
- OAuth 00D1a000000H3O9!AQ4AQI3jppS_aXZi3eoU3Ztk8o91RYAqZvR2D51oCqu62M0uC1FFl0QlLq8SSc7KMviWaMD3qj3R.OxDi5v6FJ24v5LjiUBH
|
176
|
+
Accept-Encoding:
|
177
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
178
|
+
Accept:
|
179
|
+
- "*/*"
|
180
|
+
response:
|
181
|
+
status:
|
182
|
+
code: 200
|
183
|
+
message: OK
|
184
|
+
headers:
|
185
|
+
Date:
|
186
|
+
- Thu, 23 Apr 2015 03:13:42 GMT
|
187
|
+
Set-Cookie:
|
188
|
+
- BrowserId=3Vfxi4vKSCqE0GyreWo3XA;Path=/;Domain=.salesforce.com;Expires=Mon,
|
189
|
+
22-Jun-2015 03:13:42 GMT
|
190
|
+
Expires:
|
191
|
+
- Thu, 01 Jan 1970 00:00:00 GMT
|
192
|
+
Sforce-Limit-Info:
|
193
|
+
- api-usage=1/15000
|
194
|
+
Content-Type:
|
195
|
+
- application/json;charset=UTF-8
|
196
|
+
Transfer-Encoding:
|
197
|
+
- chunked
|
198
|
+
body:
|
199
|
+
encoding: ASCII-8BIT
|
200
|
+
string: '{"totalSize":1,"done":true,"records":[{"attributes":{"type":"Contact","url":"/services/data/v26.0/sobjects/Contact/0031a000002eu2wAAA"},"Id":"0031a000002eu2wAAA","SystemModstamp":"2015-04-23T03:13:38.000+0000","Email":"somebody@example.com"}]}'
|
201
|
+
http_version:
|
202
|
+
recorded_at: Thu, 23 Apr 2015 03:13:42 GMT
|
203
|
+
- request:
|
204
|
+
method: delete
|
205
|
+
uri: https://<host>/services/data/v26.0/sobjects/Contact/0031a000002eu2wAAA
|
206
|
+
body:
|
207
|
+
encoding: US-ASCII
|
208
|
+
string: ''
|
209
|
+
headers:
|
210
|
+
User-Agent:
|
211
|
+
- Faraday v0.9.1
|
212
|
+
Authorization:
|
213
|
+
- OAuth 00D1a000000H3O9!AQ4AQI3jppS_aXZi3eoU3Ztk8o91RYAqZvR2D51oCqu62M0uC1FFl0QlLq8SSc7KMviWaMD3qj3R.OxDi5v6FJ24v5LjiUBH
|
214
|
+
Accept-Encoding:
|
215
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
216
|
+
Accept:
|
217
|
+
- "*/*"
|
218
|
+
response:
|
219
|
+
status:
|
220
|
+
code: 204
|
221
|
+
message: No Content
|
222
|
+
headers:
|
223
|
+
Date:
|
224
|
+
- Thu, 23 Apr 2015 03:13:43 GMT
|
225
|
+
Set-Cookie:
|
226
|
+
- BrowserId=8tDMUoSmSIqzGT4fCP8feg;Path=/;Domain=.salesforce.com;Expires=Mon,
|
227
|
+
22-Jun-2015 03:13:43 GMT
|
228
|
+
Expires:
|
229
|
+
- Thu, 01 Jan 1970 00:00:00 GMT
|
230
|
+
Sforce-Limit-Info:
|
231
|
+
- api-usage=1/15000
|
232
|
+
body:
|
233
|
+
encoding: UTF-8
|
234
|
+
string: ''
|
235
|
+
http_version:
|
236
|
+
recorded_at: Thu, 23 Apr 2015 03:13:43 GMT
|
237
|
+
- request:
|
238
|
+
method: delete
|
239
|
+
uri: https://<host>/services/data/v26.0/sobjects/CustomObject__c/a001a000001QkMJAA0
|
240
|
+
body:
|
241
|
+
encoding: US-ASCII
|
242
|
+
string: ''
|
243
|
+
headers:
|
244
|
+
User-Agent:
|
245
|
+
- Faraday v0.9.1
|
246
|
+
Authorization:
|
247
|
+
- OAuth 00D1a000000H3O9!AQ4AQI3jppS_aXZi3eoU3Ztk8o91RYAqZvR2D51oCqu62M0uC1FFl0QlLq8SSc7KMviWaMD3qj3R.OxDi5v6FJ24v5LjiUBH
|
248
|
+
Accept-Encoding:
|
249
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
250
|
+
Accept:
|
251
|
+
- "*/*"
|
252
|
+
response:
|
253
|
+
status:
|
254
|
+
code: 204
|
255
|
+
message: No Content
|
256
|
+
headers:
|
257
|
+
Date:
|
258
|
+
- Thu, 23 Apr 2015 03:13:44 GMT
|
259
|
+
Set-Cookie:
|
260
|
+
- BrowserId=ONVEXduoQtKJxklXKfwf9A;Path=/;Domain=.salesforce.com;Expires=Mon,
|
261
|
+
22-Jun-2015 03:13:44 GMT
|
262
|
+
Expires:
|
263
|
+
- Thu, 01 Jan 1970 00:00:00 GMT
|
264
|
+
Sforce-Limit-Info:
|
265
|
+
- api-usage=2/15000
|
266
|
+
body:
|
267
|
+
encoding: UTF-8
|
268
|
+
string: ''
|
269
|
+
http_version:
|
270
|
+
recorded_at: Thu, 23 Apr 2015 03:13:44 GMT
|
271
|
+
recorded_with: VCR 2.9.3
|
@@ -86,6 +86,18 @@ describe Restforce::DB::Associations::BelongsTo do
|
|
86
86
|
expect(associated).to_be :empty?
|
87
87
|
end
|
88
88
|
end
|
89
|
+
|
90
|
+
describe "with an unrelated association mapping" do
|
91
|
+
let(:extraneous_mapping) { Restforce::DB::Mapping.new(User, "Account") }
|
92
|
+
|
93
|
+
before do
|
94
|
+
Restforce::DB::Registry << extraneous_mapping
|
95
|
+
end
|
96
|
+
|
97
|
+
it "proceeds without raising an error" do
|
98
|
+
expect(associated).to_not_be :empty?
|
99
|
+
end
|
100
|
+
end
|
89
101
|
end
|
90
102
|
end
|
91
103
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restforce-db
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Horner
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -242,6 +242,7 @@ files:
|
|
242
242
|
- test/cassettes/Restforce_DB/accessing_Salesforce/uses_the_configured_credentials.yml
|
243
243
|
- test/cassettes/Restforce_DB_Associations_BelongsTo/with_an_inverse_mapping/_build/returns_an_associated_record_populated_with_the_Salesforce_attributes.yml
|
244
244
|
- test/cassettes/Restforce_DB_Associations_BelongsTo/with_an_inverse_mapping/_build/when_no_salesforce_record_is_found_for_the_association/proceeds_without_constructing_any_records.yml
|
245
|
+
- test/cassettes/Restforce_DB_Associations_BelongsTo/with_an_inverse_mapping/_build/with_an_unrelated_association_mapping/proceeds_without_raising_an_error.yml
|
245
246
|
- test/cassettes/Restforce_DB_Associations_BelongsTo/with_an_inverse_mapping/_synced_for_/when_a_matching_associated_record_has_been_synchronized/returns_true.yml
|
246
247
|
- test/cassettes/Restforce_DB_Associations_BelongsTo/with_an_inverse_mapping/_synced_for_/when_no_matching_associated_record_has_been_synchronized/returns_false.yml
|
247
248
|
- test/cassettes/Restforce_DB_Associations_HasMany/with_an_inverse_mapping/_build/builds_a_number_of_associated_records_from_the_data_in_Salesforce.yml
|