restforce-db 1.2.9 → 1.2.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/lib/restforce/db/association_cache.rb +4 -1
  3. data/lib/restforce/db/associations/belongs_to.rb +27 -3
  4. data/lib/restforce/db/associations/has_many.rb +3 -3
  5. data/lib/restforce/db/associations/has_one.rb +2 -2
  6. data/lib/restforce/db/associator.rb +104 -0
  7. data/lib/restforce/db/cleaner.rb +3 -15
  8. data/lib/restforce/db/collector.rb +2 -4
  9. data/lib/restforce/db/initializer.rb +10 -10
  10. data/lib/restforce/db/record_types/active_record.rb +6 -7
  11. data/lib/restforce/db/record_types/base.rb +0 -2
  12. data/lib/restforce/db/record_types/salesforce.rb +6 -6
  13. data/lib/restforce/db/runner.rb +8 -8
  14. data/lib/restforce/db/runner_cache.rb +93 -0
  15. data/lib/restforce/db/version.rb +1 -1
  16. data/lib/restforce/db/worker.rb +23 -9
  17. data/lib/restforce/db.rb +2 -0
  18. data/restforce-db.gemspec +3 -3
  19. data/test/cassettes/Restforce_DB_Associations_BelongsTo/with_an_inverse_mapping/_lookups/returns_a_hash_of_the_associated_records_lookup_IDs.yml +195 -0
  20. data/test/cassettes/Restforce_DB_Associations_BelongsTo/with_an_inverse_mapping/_lookups/when_there_is_currently_no_associated_record/returns_a_nil_lookup_value_in_the_hash.yml +119 -0
  21. data/test/cassettes/Restforce_DB_Associator/_run/given_a_BelongsTo_association/given_another_record_for_association/when_the_Salesforce_association_is_out_of_date/updates_the_association_ID_in_Salesforce.yml +421 -0
  22. data/test/cassettes/Restforce_DB_Associator/_run/given_a_BelongsTo_association/given_another_record_for_association/when_the_database_association_is_out_of_date/updates_the_associated_record_in_the_database.yml +459 -0
  23. data/test/cassettes/Restforce_DB_RecordTypes_Salesforce/{_each/loops_through_the_existing_records_in_Salesforce.yml → _all/returns_a_list_of_the_existing_records_in_Salesforce.yml} +0 -0
  24. data/test/lib/restforce/db/accumulator_test.rb +3 -0
  25. data/test/lib/restforce/db/association_cache_test.rb +8 -0
  26. data/test/lib/restforce/db/associations/belongs_to_test.rb +18 -0
  27. data/test/lib/restforce/db/associator_test.rb +82 -0
  28. data/test/lib/restforce/db/configuration_test.rb +3 -0
  29. data/test/lib/restforce/db/dsl_test.rb +2 -0
  30. data/test/lib/restforce/db/record_types/salesforce_test.rb +3 -5
  31. data/test/lib/restforce/db/runner_cache_test.rb +60 -0
  32. data/test/lib/restforce/db/runner_test.rb +3 -0
  33. data/test/lib/restforce/db/strategies/passive_test.rb +3 -0
  34. data/test/lib/restforce/db/strategy_test.rb +2 -0
  35. data/test/lib/restforce/db/tracker_test.rb +3 -0
  36. data/test/support/stub.rb +37 -0
  37. metadata +18 -9
@@ -0,0 +1,459 @@
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
+ - Mon, 04 May 2015 03:15:20 GMT
25
+ Set-Cookie:
26
+ - BrowserId=f8mT0XHDTJiqRCvhSpY_nw;Path=/;Domain=.salesforce.com;Expires=Fri,
27
+ 03-Jul-2015 03:15:20 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":"1430709320615","token_type":"Bearer","instance_url":"https://<host>","signature":"8YDUYsEk+RvjVXfzp8kUPZwqF5ZDV+zfzWC0hZdlceo=","access_token":"00D1a000000H3O9!AQ4AQNDrKHLCuinZBZ4a3F0V9mX6K..kuE6uPghr4hEJlGztbaV7OXvvfrl14zZZxgwsTH9RfcLkE1Wikbn..Xma3Bd5XKSX"}'
41
+ http_version:
42
+ recorded_at: Mon, 04 May 2015 03:15:20 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!AQ4AQNDrKHLCuinZBZ4a3F0V9mX6K..kuE6uPghr4hEJlGztbaV7OXvvfrl14zZZxgwsTH9RfcLkE1Wikbn..Xma3Bd5XKSX
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
+ - Mon, 04 May 2015 03:15:21 GMT
67
+ Set-Cookie:
68
+ - BrowserId=MMuCD0IJRX2swBbsGuPA-g;Path=/;Domain=.salesforce.com;Expires=Fri,
69
+ 03-Jul-2015 03:15:21 GMT
70
+ Expires:
71
+ - Thu, 01 Jan 1970 00:00:00 GMT
72
+ Sforce-Limit-Info:
73
+ - api-usage=70/15000
74
+ Location:
75
+ - "/services/data/v26.0/sobjects/Contact/0031a00000317sJAAQ"
76
+ Content-Type:
77
+ - application/json;charset=UTF-8
78
+ Transfer-Encoding:
79
+ - chunked
80
+ body:
81
+ encoding: ASCII-8BIT
82
+ string: '{"id":"0031a00000317sJAAQ","success":true,"errors":[]}'
83
+ http_version:
84
+ recorded_at: Mon, 04 May 2015 03:15:21 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":"0031a00000317sJAAQ"}'
91
+ headers:
92
+ User-Agent:
93
+ - Faraday v0.9.1
94
+ Content-Type:
95
+ - application/json
96
+ Authorization:
97
+ - OAuth 00D1a000000H3O9!AQ4AQNDrKHLCuinZBZ4a3F0V9mX6K..kuE6uPghr4hEJlGztbaV7OXvvfrl14zZZxgwsTH9RfcLkE1Wikbn..Xma3Bd5XKSX
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
+ - Mon, 04 May 2015 03:15:22 GMT
109
+ Set-Cookie:
110
+ - BrowserId=ZnzL6tDeT_SlR_nk4Ea-mg;Path=/;Domain=.salesforce.com;Expires=Fri,
111
+ 03-Jul-2015 03:15:22 GMT
112
+ Expires:
113
+ - Thu, 01 Jan 1970 00:00:00 GMT
114
+ Sforce-Limit-Info:
115
+ - api-usage=68/15000
116
+ Location:
117
+ - "/services/data/v26.0/sobjects/CustomObject__c/a001a000001U16fAAC"
118
+ Content-Type:
119
+ - application/json;charset=UTF-8
120
+ Transfer-Encoding:
121
+ - chunked
122
+ body:
123
+ encoding: ASCII-8BIT
124
+ string: '{"id":"a001a000001U16fAAC","success":true,"errors":[]}'
125
+ http_version:
126
+ recorded_at: Mon, 04 May 2015 03:15:22 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%27a001a000001U16fAAC%27
130
+ body:
131
+ encoding: US-ASCII
132
+ string: ''
133
+ headers:
134
+ User-Agent:
135
+ - Faraday v0.9.1
136
+ Authorization:
137
+ - OAuth 00D1a000000H3O9!AQ4AQNDrKHLCuinZBZ4a3F0V9mX6K..kuE6uPghr4hEJlGztbaV7OXvvfrl14zZZxgwsTH9RfcLkE1Wikbn..Xma3Bd5XKSX
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
+ - Mon, 04 May 2015 03:15:23 GMT
149
+ Set-Cookie:
150
+ - BrowserId=TDgwznv8TPOZ4mPOR91kcA;Path=/;Domain=.salesforce.com;Expires=Fri,
151
+ 03-Jul-2015 03:15:23 GMT
152
+ Expires:
153
+ - Thu, 01 Jan 1970 00:00:00 GMT
154
+ Sforce-Limit-Info:
155
+ - api-usage=69/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/a001a000001U16fAAC"},"Id":"a001a000001U16fAAC","SystemModstamp":"2015-05-04T03:15:22.000+0000","Name":"a001a000001U16f","Example_Field__c":null,"Friend__c":"0031a00000317sJAAQ"}]}'
163
+ http_version:
164
+ recorded_at: Mon, 04 May 2015 03:15:23 GMT
165
+ - request:
166
+ method: post
167
+ uri: https://<host>/services/data/v26.0/sobjects/Contact
168
+ body:
169
+ encoding: UTF-8
170
+ string: '{"Email":"somebody+else@example.com","LastName":"Somebody"}'
171
+ headers:
172
+ User-Agent:
173
+ - Faraday v0.9.1
174
+ Content-Type:
175
+ - application/json
176
+ Authorization:
177
+ - OAuth 00D1a000000H3O9!AQ4AQNDrKHLCuinZBZ4a3F0V9mX6K..kuE6uPghr4hEJlGztbaV7OXvvfrl14zZZxgwsTH9RfcLkE1Wikbn..Xma3Bd5XKSX
178
+ Accept-Encoding:
179
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
180
+ Accept:
181
+ - "*/*"
182
+ response:
183
+ status:
184
+ code: 201
185
+ message: Created
186
+ headers:
187
+ Date:
188
+ - Mon, 04 May 2015 03:15:24 GMT
189
+ Set-Cookie:
190
+ - BrowserId=o_6Udn33SPC9dPTD-nQMiw;Path=/;Domain=.salesforce.com;Expires=Fri,
191
+ 03-Jul-2015 03:15:24 GMT
192
+ Expires:
193
+ - Thu, 01 Jan 1970 00:00:00 GMT
194
+ Sforce-Limit-Info:
195
+ - api-usage=68/15000
196
+ Location:
197
+ - "/services/data/v26.0/sobjects/Contact/0031a00000317sOAAQ"
198
+ Content-Type:
199
+ - application/json;charset=UTF-8
200
+ Transfer-Encoding:
201
+ - chunked
202
+ body:
203
+ encoding: ASCII-8BIT
204
+ string: '{"id":"0031a00000317sOAAQ","success":true,"errors":[]}'
205
+ http_version:
206
+ recorded_at: Mon, 04 May 2015 03:15:24 GMT
207
+ - request:
208
+ method: patch
209
+ uri: https://<host>/services/data/v26.0/sobjects/CustomObject__c/a001a000001U16fAAC
210
+ body:
211
+ encoding: UTF-8
212
+ string: '{"Friend__c":"0031a00000317sOAAQ"}'
213
+ headers:
214
+ User-Agent:
215
+ - Faraday v0.9.1
216
+ Content-Type:
217
+ - application/json
218
+ Authorization:
219
+ - OAuth 00D1a000000H3O9!AQ4AQNDrKHLCuinZBZ4a3F0V9mX6K..kuE6uPghr4hEJlGztbaV7OXvvfrl14zZZxgwsTH9RfcLkE1Wikbn..Xma3Bd5XKSX
220
+ Accept-Encoding:
221
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
222
+ Accept:
223
+ - "*/*"
224
+ response:
225
+ status:
226
+ code: 204
227
+ message: No Content
228
+ headers:
229
+ Date:
230
+ - Mon, 04 May 2015 03:15:25 GMT
231
+ Set-Cookie:
232
+ - BrowserId=P7z15TEeTMOc2R28NJSBwg;Path=/;Domain=.salesforce.com;Expires=Fri,
233
+ 03-Jul-2015 03:15:25 GMT
234
+ Expires:
235
+ - Thu, 01 Jan 1970 00:00:00 GMT
236
+ Sforce-Limit-Info:
237
+ - api-usage=68/15000
238
+ body:
239
+ encoding: UTF-8
240
+ string: ''
241
+ http_version:
242
+ recorded_at: Mon, 04 May 2015 03:15:25 GMT
243
+ - request:
244
+ method: get
245
+ uri: https://<host>/services/data/v26.0/query?q=select%20Id,%20SystemModstamp,%20Name,%20Example_Field__c,%20Friend__c%20from%20CustomObject__c
246
+ body:
247
+ encoding: US-ASCII
248
+ string: ''
249
+ headers:
250
+ User-Agent:
251
+ - Faraday v0.9.1
252
+ Authorization:
253
+ - OAuth 00D1a000000H3O9!AQ4AQNDrKHLCuinZBZ4a3F0V9mX6K..kuE6uPghr4hEJlGztbaV7OXvvfrl14zZZxgwsTH9RfcLkE1Wikbn..Xma3Bd5XKSX
254
+ Accept-Encoding:
255
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
256
+ Accept:
257
+ - "*/*"
258
+ response:
259
+ status:
260
+ code: 200
261
+ message: OK
262
+ headers:
263
+ Date:
264
+ - Mon, 04 May 2015 03:15:26 GMT
265
+ Set-Cookie:
266
+ - BrowserId=XZnTGUjXTtajVhsmadKB_Q;Path=/;Domain=.salesforce.com;Expires=Fri,
267
+ 03-Jul-2015 03:15:26 GMT
268
+ Expires:
269
+ - Thu, 01 Jan 1970 00:00:00 GMT
270
+ Sforce-Limit-Info:
271
+ - api-usage=69/15000
272
+ Content-Type:
273
+ - application/json;charset=UTF-8
274
+ Transfer-Encoding:
275
+ - chunked
276
+ body:
277
+ encoding: ASCII-8BIT
278
+ string: '{"totalSize":1,"done":true,"records":[{"attributes":{"type":"CustomObject__c","url":"/services/data/v26.0/sobjects/CustomObject__c/a001a000001U16fAAC"},"Id":"a001a000001U16fAAC","SystemModstamp":"2015-05-04T03:15:25.000+0000","Name":"a001a000001U16f","Example_Field__c":null,"Friend__c":"0031a00000317sOAAQ"}]}'
279
+ http_version:
280
+ recorded_at: Mon, 04 May 2015 03:15:26 GMT
281
+ - request:
282
+ method: get
283
+ uri: https://<host>/services/data/v26.0/query?q=select%20Id,%20SystemModstamp,%20Email%20from%20Contact%20where%20Id%20=%20%270031a00000317sOAAQ%27
284
+ body:
285
+ encoding: US-ASCII
286
+ string: ''
287
+ headers:
288
+ User-Agent:
289
+ - Faraday v0.9.1
290
+ Authorization:
291
+ - OAuth 00D1a000000H3O9!AQ4AQNDrKHLCuinZBZ4a3F0V9mX6K..kuE6uPghr4hEJlGztbaV7OXvvfrl14zZZxgwsTH9RfcLkE1Wikbn..Xma3Bd5XKSX
292
+ Accept-Encoding:
293
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
294
+ Accept:
295
+ - "*/*"
296
+ response:
297
+ status:
298
+ code: 200
299
+ message: OK
300
+ headers:
301
+ Date:
302
+ - Mon, 04 May 2015 03:15:27 GMT
303
+ Set-Cookie:
304
+ - BrowserId=G9XG-lj1SRGOENEjmobfJA;Path=/;Domain=.salesforce.com;Expires=Fri,
305
+ 03-Jul-2015 03:15:27 GMT
306
+ Expires:
307
+ - Thu, 01 Jan 1970 00:00:00 GMT
308
+ Sforce-Limit-Info:
309
+ - api-usage=69/15000
310
+ Content-Type:
311
+ - application/json;charset=UTF-8
312
+ Transfer-Encoding:
313
+ - chunked
314
+ body:
315
+ encoding: ASCII-8BIT
316
+ string: '{"totalSize":1,"done":true,"records":[{"attributes":{"type":"Contact","url":"/services/data/v26.0/sobjects/Contact/0031a00000317sOAAQ"},"Id":"0031a00000317sOAAQ","SystemModstamp":"2015-05-04T03:15:24.000+0000","Email":"somebody+else@example.com"}]}'
317
+ http_version:
318
+ recorded_at: Mon, 04 May 2015 03:15:27 GMT
319
+ - request:
320
+ method: get
321
+ 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%27a001a000001U16fAAC%27
322
+ body:
323
+ encoding: US-ASCII
324
+ string: ''
325
+ headers:
326
+ User-Agent:
327
+ - Faraday v0.9.1
328
+ Authorization:
329
+ - OAuth 00D1a000000H3O9!AQ4AQNDrKHLCuinZBZ4a3F0V9mX6K..kuE6uPghr4hEJlGztbaV7OXvvfrl14zZZxgwsTH9RfcLkE1Wikbn..Xma3Bd5XKSX
330
+ Accept-Encoding:
331
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
332
+ Accept:
333
+ - "*/*"
334
+ response:
335
+ status:
336
+ code: 200
337
+ message: OK
338
+ headers:
339
+ Date:
340
+ - Mon, 04 May 2015 03:15:28 GMT
341
+ Set-Cookie:
342
+ - BrowserId=IPfzlBlnQba69A4hz7fdaQ;Path=/;Domain=.salesforce.com;Expires=Fri,
343
+ 03-Jul-2015 03:15:28 GMT
344
+ Expires:
345
+ - Thu, 01 Jan 1970 00:00:00 GMT
346
+ Sforce-Limit-Info:
347
+ - api-usage=68/15000
348
+ Content-Type:
349
+ - application/json;charset=UTF-8
350
+ Transfer-Encoding:
351
+ - chunked
352
+ body:
353
+ encoding: ASCII-8BIT
354
+ string: '{"totalSize":1,"done":true,"records":[{"attributes":{"type":"CustomObject__c","url":"/services/data/v26.0/sobjects/CustomObject__c/a001a000001U16fAAC"},"Id":"a001a000001U16fAAC","SystemModstamp":"2015-05-04T03:15:25.000+0000","Name":"a001a000001U16f","Example_Field__c":null,"Friend__c":"0031a00000317sOAAQ"}]}'
355
+ http_version:
356
+ recorded_at: Mon, 04 May 2015 03:15:28 GMT
357
+ - request:
358
+ method: delete
359
+ uri: https://<host>/services/data/v26.0/sobjects/Contact/0031a00000317sJAAQ
360
+ body:
361
+ encoding: US-ASCII
362
+ string: ''
363
+ headers:
364
+ User-Agent:
365
+ - Faraday v0.9.1
366
+ Authorization:
367
+ - OAuth 00D1a000000H3O9!AQ4AQNDrKHLCuinZBZ4a3F0V9mX6K..kuE6uPghr4hEJlGztbaV7OXvvfrl14zZZxgwsTH9RfcLkE1Wikbn..Xma3Bd5XKSX
368
+ Accept-Encoding:
369
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
370
+ Accept:
371
+ - "*/*"
372
+ response:
373
+ status:
374
+ code: 204
375
+ message: No Content
376
+ headers:
377
+ Date:
378
+ - Mon, 04 May 2015 03:15:29 GMT
379
+ Set-Cookie:
380
+ - BrowserId=CM7k5n2TQ_CFPUIjTEkx0Q;Path=/;Domain=.salesforce.com;Expires=Fri,
381
+ 03-Jul-2015 03:15:29 GMT
382
+ Expires:
383
+ - Thu, 01 Jan 1970 00:00:00 GMT
384
+ Sforce-Limit-Info:
385
+ - api-usage=68/15000
386
+ body:
387
+ encoding: UTF-8
388
+ string: ''
389
+ http_version:
390
+ recorded_at: Mon, 04 May 2015 03:15:29 GMT
391
+ - request:
392
+ method: delete
393
+ uri: https://<host>/services/data/v26.0/sobjects/CustomObject__c/a001a000001U16fAAC
394
+ body:
395
+ encoding: US-ASCII
396
+ string: ''
397
+ headers:
398
+ User-Agent:
399
+ - Faraday v0.9.1
400
+ Authorization:
401
+ - OAuth 00D1a000000H3O9!AQ4AQNDrKHLCuinZBZ4a3F0V9mX6K..kuE6uPghr4hEJlGztbaV7OXvvfrl14zZZxgwsTH9RfcLkE1Wikbn..Xma3Bd5XKSX
402
+ Accept-Encoding:
403
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
404
+ Accept:
405
+ - "*/*"
406
+ response:
407
+ status:
408
+ code: 204
409
+ message: No Content
410
+ headers:
411
+ Date:
412
+ - Mon, 04 May 2015 03:15:30 GMT
413
+ Set-Cookie:
414
+ - BrowserId=dCi5gw0SSlOdFSYPj_9ijA;Path=/;Domain=.salesforce.com;Expires=Fri,
415
+ 03-Jul-2015 03:15:30 GMT
416
+ Expires:
417
+ - Thu, 01 Jan 1970 00:00:00 GMT
418
+ Sforce-Limit-Info:
419
+ - api-usage=68/15000
420
+ body:
421
+ encoding: UTF-8
422
+ string: ''
423
+ http_version:
424
+ recorded_at: Mon, 04 May 2015 03:15:30 GMT
425
+ - request:
426
+ method: delete
427
+ uri: https://<host>/services/data/v26.0/sobjects/Contact/0031a00000317sOAAQ
428
+ body:
429
+ encoding: US-ASCII
430
+ string: ''
431
+ headers:
432
+ User-Agent:
433
+ - Faraday v0.9.1
434
+ Authorization:
435
+ - OAuth 00D1a000000H3O9!AQ4AQNDrKHLCuinZBZ4a3F0V9mX6K..kuE6uPghr4hEJlGztbaV7OXvvfrl14zZZxgwsTH9RfcLkE1Wikbn..Xma3Bd5XKSX
436
+ Accept-Encoding:
437
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
438
+ Accept:
439
+ - "*/*"
440
+ response:
441
+ status:
442
+ code: 204
443
+ message: No Content
444
+ headers:
445
+ Date:
446
+ - Mon, 04 May 2015 03:15:31 GMT
447
+ Set-Cookie:
448
+ - BrowserId=XU3CDz1IR0-rsD2l9dipSg;Path=/;Domain=.salesforce.com;Expires=Fri,
449
+ 03-Jul-2015 03:15:31 GMT
450
+ Expires:
451
+ - Thu, 01 Jan 1970 00:00:00 GMT
452
+ Sforce-Limit-Info:
453
+ - api-usage=70/15000
454
+ body:
455
+ encoding: UTF-8
456
+ string: ''
457
+ http_version:
458
+ recorded_at: Mon, 04 May 2015 03:15:32 GMT
459
+ recorded_with: VCR 2.9.3
@@ -1,6 +1,9 @@
1
1
  require_relative "../../../test_helper"
2
2
 
3
3
  describe Restforce::DB::Accumulator do
4
+
5
+ configure!
6
+
4
7
  let(:accumulator) { Restforce::DB::Accumulator.new }
5
8
 
6
9
  describe "#store" do
@@ -9,6 +9,14 @@ describe Restforce::DB::AssociationCache do
9
9
  let(:lookups) { { salesforce_id: "a001a000001E1vREAL" } }
10
10
  let(:record) { database_model.new(lookups) }
11
11
 
12
+ describe "#initialize" do
13
+ let(:cache) { Restforce::DB::AssociationCache.new(record) }
14
+
15
+ it "caches the passed record when present" do
16
+ expect(cache.cache[database_model]).to_equal [record]
17
+ end
18
+ end
19
+
12
20
  describe "#<<" do
13
21
  before do
14
22
  cache << record
@@ -45,6 +45,24 @@ describe Restforce::DB::Associations::BelongsTo do
45
45
  mapping.associations << association
46
46
  end
47
47
 
48
+ describe "#lookups" do
49
+ let(:user) { inverse_mapping.database_model.create!(salesforce_id: user_salesforce_id) }
50
+ let(:object) { mapping.database_model.create!(salesforce_id: object_salesforce_id, user: user) }
51
+
52
+ it "returns a hash of the associated records' lookup IDs" do
53
+ expect(association.lookups(object)).to_equal("Friend__c" => user_salesforce_id)
54
+ end
55
+
56
+ describe "when there is currently no associated record" do
57
+ let(:object_salesforce_id) { Salesforce.create!(mapping.salesforce_model) }
58
+ let(:object) { mapping.database_model.create!(salesforce_id: object_salesforce_id) }
59
+
60
+ it "returns a nil lookup value in the hash" do
61
+ expect(association.lookups(object)).to_equal("Friend__c" => nil)
62
+ end
63
+ end
64
+ end
65
+
48
66
  describe "#synced_for?" do
49
67
  let(:salesforce_instance) { mapping.salesforce_record_type.find(object_salesforce_id) }
50
68
 
@@ -0,0 +1,82 @@
1
+ require_relative "../../../test_helper"
2
+
3
+ describe Restforce::DB::Associator do
4
+
5
+ configure!
6
+ mappings!
7
+
8
+ let(:associator) { Restforce::DB::Associator.new(mapping) }
9
+
10
+ describe "#run", :vcr do
11
+
12
+ describe "given a BelongsTo association" do
13
+ let(:inverse_mapping) do
14
+ Restforce::DB::Mapping.new(User, "Contact").tap do |map|
15
+ map.fields = { email: "Email" }
16
+ map.associations << Restforce::DB::Associations::HasOne.new(
17
+ :custom_object,
18
+ through: "Friend__c",
19
+ )
20
+ end
21
+ end
22
+ let(:user_salesforce_id) do
23
+ Salesforce.create!(
24
+ inverse_mapping.salesforce_model,
25
+ "Email" => "somebody@example.com",
26
+ "LastName" => "Somebody",
27
+ )
28
+ end
29
+ let(:object_salesforce_id) do
30
+ Salesforce.create!(mapping.salesforce_model, "Friend__c" => user_salesforce_id)
31
+ end
32
+ let(:association) { Restforce::DB::Associations::BelongsTo.new(:user, through: "Friend__c") }
33
+ let(:user) { inverse_mapping.database_model.create!(salesforce_id: user_salesforce_id) }
34
+ let(:object) { mapping.database_model.create!(user: user, salesforce_id: object_salesforce_id) }
35
+
36
+ before do
37
+ Restforce::DB::Registry << mapping
38
+ Restforce::DB::Registry << inverse_mapping
39
+ mapping.associations << association
40
+ end
41
+
42
+ describe "given another record for association" do
43
+ let(:new_user_salesforce_id) do
44
+ Salesforce.create!(
45
+ inverse_mapping.salesforce_model,
46
+ "Email" => "somebody+else@example.com",
47
+ "LastName" => "Somebody",
48
+ )
49
+ end
50
+ let(:new_user) { inverse_mapping.database_model.create!(salesforce_id: new_user_salesforce_id) }
51
+ let(:salesforce_instance) { mapping.salesforce_record_type.find(object_salesforce_id) }
52
+
53
+ describe "when the Salesforce association is out of date" do
54
+ before do
55
+ object.update!(user: new_user)
56
+ end
57
+
58
+ it "updates the association ID in Salesforce" do
59
+ associator.run
60
+ expect(salesforce_instance.record["Friend__c"]).to_equal new_user_salesforce_id
61
+ end
62
+ end
63
+
64
+ describe "when the database association is out of date" do
65
+ before do
66
+ object && new_user
67
+ salesforce_instance.update! "Friend__c" => new_user_salesforce_id
68
+ end
69
+
70
+ it "updates the associated record in the database" do
71
+ # We stub `last_update` to get around issues with VCR's cached
72
+ # timestamp; we need the Salesforce record to be more recent.
73
+ Restforce::DB::Instances::Salesforce.stub_any_instance(:last_update, Time.now) do
74
+ associator.run
75
+ end
76
+ expect(object.reload.user).to_equal new_user
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
@@ -1,6 +1,9 @@
1
1
  require_relative "../../../test_helper"
2
2
 
3
3
  describe Restforce::DB::Configuration do
4
+
5
+ configure!
6
+
4
7
  let(:secrets) { Secrets["client"] }
5
8
  let(:secrets_file) { File.expand_path("../../../../config/secrets.yml", __FILE__) }
6
9
  let(:configuration) { Restforce::DB::Configuration.new }
@@ -2,6 +2,8 @@ require_relative "../../../test_helper"
2
2
 
3
3
  describe Restforce::DB::DSL do
4
4
 
5
+ configure!
6
+
5
7
  let(:database_model) { CustomObject }
6
8
  let(:salesforce_model) { "CustomObject__c" }
7
9
  let(:strategy) { :always }
@@ -62,14 +62,12 @@ describe Restforce::DB::RecordTypes::Salesforce do
62
62
  end
63
63
  end
64
64
 
65
- describe "#each", :vcr do
65
+ describe "#all", :vcr do
66
66
  let(:id) { Salesforce.create!(salesforce_model) }
67
67
  before { id }
68
68
 
69
- # Restforce::DB::RecordType::Salesforce actually implements Enumerable, so
70
- # we're just going with a trivially testable portion of the Enumerable API.
71
- it "loops through the existing records in Salesforce" do
72
- record = record_type.first
69
+ it "returns a list of the existing records in Salesforce" do
70
+ record = record_type.all.first
73
71
  expect(record).to_be_instance_of(Restforce::DB::Instances::Salesforce)
74
72
  expect(record.id).to_equal(id)
75
73
  end
@@ -0,0 +1,60 @@
1
+ require_relative "../../../test_helper"
2
+
3
+ describe Restforce::DB::RunnerCache do
4
+
5
+ configure!
6
+ mappings!
7
+
8
+ let(:cache) { Restforce::DB::RunnerCache.new }
9
+
10
+ describe "#collection" do
11
+ let(:object) { mapping.database_model.create! }
12
+
13
+ before { object }
14
+
15
+ it "invokes the specified collection for the mapping" do
16
+ instances = cache.collection(mapping, :database_record_type)
17
+ expect(instances.first.record).to_equal object
18
+ end
19
+
20
+ describe "on repeated calls for the same mapping" do
21
+ let(:dummy_collection) do
22
+ Object.new.tap do |collection|
23
+
24
+ def collection.values
25
+ [1, 2, 3]
26
+ end
27
+
28
+ def collection.all(*_)
29
+ values
30
+ end
31
+ end
32
+ end
33
+
34
+ before do
35
+ cache.collection(mapping, :database_record_type)
36
+ end
37
+
38
+ it "does not re-invoke the original method call" do
39
+ mapping.stub(:database_record_type, dummy_collection) do
40
+ instances = cache.collection(mapping, :database_record_type)
41
+ expect(instances.first.record).to_equal object
42
+ end
43
+ end
44
+
45
+ describe "when the mapping's conditions have been modified" do
46
+ before do
47
+ mapping.conditions = ["Name != null"]
48
+ end
49
+
50
+ it "caches the mapping separately, and re-invokes the original method call" do
51
+ mapping.stub(:database_record_type, dummy_collection) do
52
+ instances = cache.collection(mapping, :database_record_type)
53
+ expect(instances).to_equal dummy_collection.values
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+
60
+ end