restforce-db 0.5.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +77 -21
  3. data/lib/restforce/db.rb +6 -0
  4. data/lib/restforce/db/associations/active_record.rb +1 -1
  5. data/lib/restforce/db/attribute_map.rb +5 -1
  6. data/lib/restforce/db/dsl.rb +80 -0
  7. data/lib/restforce/db/initializer.rb +3 -2
  8. data/lib/restforce/db/mapping.rb +20 -77
  9. data/lib/restforce/db/model.rb +7 -4
  10. data/lib/restforce/db/registry.rb +62 -0
  11. data/lib/restforce/db/strategies/always.rb +38 -0
  12. data/lib/restforce/db/strategies/passive.rb +37 -0
  13. data/lib/restforce/db/strategy.rb +25 -0
  14. data/lib/restforce/db/version.rb +1 -1
  15. data/test/cassettes/Restforce_DB_Initializer/_run/given_an_existing_Salesforce_record/{for_a_non-root_mapping → for_a_Passive_strategy}/does_not_create_a_database_record.yml +20 -20
  16. data/test/cassettes/Restforce_DB_Initializer/_run/given_an_existing_Salesforce_record/for_an_Always_strategy/creates_a_matching_database_record.yml +159 -0
  17. data/test/cassettes/Restforce_DB_Initializer/_run/given_an_existing_database_record/{for_a_root_mapping → for_an_Always_strategy}/populates_Salesforce_with_the_new_record.yml +44 -43
  18. data/test/cassettes/{Restforce_DB_Initializer/_run/given_an_existing_Salesforce_record/for_a_root_mapping/creates_a_matching_database_record.yml → Restforce_DB_Strategies_Always/_build_/given_a_Salesforce_record/wants_to_build_a_new_matching_record.yml} +30 -30
  19. data/test/cassettes/Restforce_DB_Strategies_Always/_build_/given_a_Salesforce_record/with_a_corresponding_database_record/does_not_want_to_build_a_new_record.yml +158 -0
  20. data/test/lib/restforce/db/associations/active_record_test.rb +6 -6
  21. data/test/lib/restforce/db/attribute_map_test.rb +5 -1
  22. data/test/lib/restforce/db/dsl_test.rb +80 -0
  23. data/test/lib/restforce/db/initializer_test.rb +8 -8
  24. data/test/lib/restforce/db/mapping_test.rb +7 -17
  25. data/test/lib/restforce/db/model_test.rb +8 -9
  26. data/test/lib/restforce/db/record_types/active_record_test.rb +10 -6
  27. data/test/lib/restforce/db/registry_test.rb +43 -0
  28. data/test/lib/restforce/db/strategies/always_test.rb +38 -0
  29. data/test/lib/restforce/db/strategies/passive_test.rb +17 -0
  30. data/test/lib/restforce/db/strategy_test.rb +19 -0
  31. data/test/support/utilities.rb +7 -9
  32. metadata +17 -5
@@ -21,10 +21,10 @@ http_interactions:
21
21
  message: OK
22
22
  headers:
23
23
  Date:
24
- - Mon, 06 Apr 2015 16:24:41 GMT
24
+ - Wed, 08 Apr 2015 17:25:20 GMT
25
25
  Set-Cookie:
26
- - BrowserId=lVxxhf7fSri3JVI565pIKA;Path=/;Domain=.salesforce.com;Expires=Fri,
27
- 05-Jun-2015 16:24:41 GMT
26
+ - BrowserId=aV1yozgjTVWf7NTdcekyKQ;Path=/;Domain=.salesforce.com;Expires=Sun,
27
+ 07-Jun-2015 17:25:20 GMT
28
28
  Expires:
29
29
  - Thu, 01 Jan 1970 00:00:00 GMT
30
30
  Pragma:
@@ -37,22 +37,22 @@ http_interactions:
37
37
  - chunked
38
38
  body:
39
39
  encoding: ASCII-8BIT
40
- string: '{"id":"https://login.salesforce.com/id/00D1a000000H3O9EAK/0051a000000UGT8AAO","issued_at":"1428337481161","token_type":"Bearer","instance_url":"https://<host>","signature":"qovSt6iFWpcplBSmFRHDaaAYio/Wlu4HTu99Vp6+kzY=","access_token":"00D1a000000H3O9!AQ4AQFhXX0t0My8qCHdrUMfRwg3B5FPFTjOwddPzvTaHu0t9H1xiDVKOSpDxKItHiqnvYyMKqZVwaC5AIJvYk_bzVt8m7Vil"}'
40
+ string: '{"id":"https://login.salesforce.com/id/00D1a000000H3O9EAK/0051a000000UGT8AAO","issued_at":"1428513920164","token_type":"Bearer","instance_url":"https://<host>","signature":"+9Ohy1Rt/hV2LV72iFHN4G0osOsG5BWr/EnsA2it878=","access_token":"00D1a000000H3O9!AQ4AQCyefAUUsnWlCVp8nuCPw5FHOg4Bv_Grcp4GTCMkt22gpGUL_iimYlj.5dHJYoGbAKCuPttEXOKeigHMy9VPNErhVDRe"}'
41
41
  http_version:
42
- recorded_at: Mon, 06 Apr 2015 16:24:41 GMT
42
+ recorded_at: Wed, 08 Apr 2015 17:25:19 GMT
43
43
  - request:
44
44
  method: post
45
45
  uri: https://<host>/services/data/v26.0/sobjects/CustomObject__c
46
46
  body:
47
47
  encoding: UTF-8
48
- string: '{"Name":"Custom object","Example_Field__c":"Some sample text"}'
48
+ string: '{"Name":"Sample object"}'
49
49
  headers:
50
50
  User-Agent:
51
51
  - Faraday v0.9.1
52
52
  Content-Type:
53
53
  - application/json
54
54
  Authorization:
55
- - OAuth 00D1a000000H3O9!AQ4AQFhXX0t0My8qCHdrUMfRwg3B5FPFTjOwddPzvTaHu0t9H1xiDVKOSpDxKItHiqnvYyMKqZVwaC5AIJvYk_bzVt8m7Vil
55
+ - OAuth 00D1a000000H3O9!AQ4AQCyefAUUsnWlCVp8nuCPw5FHOg4Bv_Grcp4GTCMkt22gpGUL_iimYlj.5dHJYoGbAKCuPttEXOKeigHMy9VPNErhVDRe
56
56
  Accept-Encoding:
57
57
  - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
58
58
  Accept:
@@ -63,28 +63,28 @@ http_interactions:
63
63
  message: Created
64
64
  headers:
65
65
  Date:
66
- - Mon, 06 Apr 2015 16:24:42 GMT
66
+ - Wed, 08 Apr 2015 17:25:20 GMT
67
67
  Set-Cookie:
68
- - BrowserId=cL6_Fot-T9yc4mTZnI1ACw;Path=/;Domain=.salesforce.com;Expires=Fri,
69
- 05-Jun-2015 16:24:42 GMT
68
+ - BrowserId=bweRzNnuS5yGi0KPQtNPlw;Path=/;Domain=.salesforce.com;Expires=Sun,
69
+ 07-Jun-2015 17:25:20 GMT
70
70
  Expires:
71
71
  - Thu, 01 Jan 1970 00:00:00 GMT
72
72
  Sforce-Limit-Info:
73
- - api-usage=36/15000
73
+ - api-usage=1/15000
74
74
  Location:
75
- - "/services/data/v26.0/sobjects/CustomObject__c/a001a000001LH2uAAG"
75
+ - "/services/data/v26.0/sobjects/CustomObject__c/a001a000001LMs9AAG"
76
76
  Content-Type:
77
77
  - application/json;charset=UTF-8
78
78
  Transfer-Encoding:
79
79
  - chunked
80
80
  body:
81
81
  encoding: ASCII-8BIT
82
- string: '{"id":"a001a000001LH2uAAG","success":true,"errors":[]}'
82
+ string: '{"id":"a001a000001LMs9AAG","success":true,"errors":[]}'
83
83
  http_version:
84
- recorded_at: Mon, 06 Apr 2015 16:24:42 GMT
84
+ recorded_at: Wed, 08 Apr 2015 17:25:19 GMT
85
85
  - request:
86
86
  method: get
87
- uri: https://<host>/services/data/v26.0/query?q=select%20Id,%20SystemModstamp,%20Name,%20Example_Field__c%20from%20CustomObject__c
87
+ uri: https://<host>/services/data/v26.0/query?q=select%20Id,%20SystemModstamp,%20Name,%20Example_Field__c%20from%20CustomObject__c%20where%20Id%20=%20%27a001a000001LMs9AAG%27
88
88
  body:
89
89
  encoding: US-ASCII
90
90
  string: ''
@@ -92,7 +92,7 @@ http_interactions:
92
92
  User-Agent:
93
93
  - Faraday v0.9.1
94
94
  Authorization:
95
- - OAuth 00D1a000000H3O9!AQ4AQFhXX0t0My8qCHdrUMfRwg3B5FPFTjOwddPzvTaHu0t9H1xiDVKOSpDxKItHiqnvYyMKqZVwaC5AIJvYk_bzVt8m7Vil
95
+ - OAuth 00D1a000000H3O9!AQ4AQCyefAUUsnWlCVp8nuCPw5FHOg4Bv_Grcp4GTCMkt22gpGUL_iimYlj.5dHJYoGbAKCuPttEXOKeigHMy9VPNErhVDRe
96
96
  Accept-Encoding:
97
97
  - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
98
98
  Accept:
@@ -103,27 +103,27 @@ http_interactions:
103
103
  message: OK
104
104
  headers:
105
105
  Date:
106
- - Mon, 06 Apr 2015 16:24:43 GMT
106
+ - Wed, 08 Apr 2015 17:25:20 GMT
107
107
  Set-Cookie:
108
- - BrowserId=BILH41M9Q5a6jzEpUQmMaw;Path=/;Domain=.salesforce.com;Expires=Fri,
109
- 05-Jun-2015 16:24:43 GMT
108
+ - BrowserId=LdEHnhcdRxGe-GXkxf1njw;Path=/;Domain=.salesforce.com;Expires=Sun,
109
+ 07-Jun-2015 17:25:20 GMT
110
110
  Expires:
111
111
  - Thu, 01 Jan 1970 00:00:00 GMT
112
112
  Sforce-Limit-Info:
113
- - api-usage=36/15000
113
+ - api-usage=1/15000
114
114
  Content-Type:
115
115
  - application/json;charset=UTF-8
116
116
  Transfer-Encoding:
117
117
  - chunked
118
118
  body:
119
119
  encoding: ASCII-8BIT
120
- string: '{"totalSize":1,"done":true,"records":[{"attributes":{"type":"CustomObject__c","url":"/services/data/v26.0/sobjects/CustomObject__c/a001a000001LH2uAAG"},"Id":"a001a000001LH2uAAG","SystemModstamp":"2015-04-06T16:24:42.000+0000","Name":"Custom
121
- object","Example_Field__c":"Some sample text"}]}'
120
+ string: '{"totalSize":1,"done":true,"records":[{"attributes":{"type":"CustomObject__c","url":"/services/data/v26.0/sobjects/CustomObject__c/a001a000001LMs9AAG"},"Id":"a001a000001LMs9AAG","SystemModstamp":"2015-04-08T17:25:20.000+0000","Name":"Sample
121
+ object","Example_Field__c":null}]}'
122
122
  http_version:
123
- recorded_at: Mon, 06 Apr 2015 16:24:43 GMT
123
+ recorded_at: Wed, 08 Apr 2015 17:25:19 GMT
124
124
  - request:
125
125
  method: delete
126
- uri: https://<host>/services/data/v26.0/sobjects/CustomObject__c/a001a000001LH2uAAG
126
+ uri: https://<host>/services/data/v26.0/sobjects/CustomObject__c/a001a000001LMs9AAG
127
127
  body:
128
128
  encoding: US-ASCII
129
129
  string: ''
@@ -131,7 +131,7 @@ http_interactions:
131
131
  User-Agent:
132
132
  - Faraday v0.9.1
133
133
  Authorization:
134
- - OAuth 00D1a000000H3O9!AQ4AQFhXX0t0My8qCHdrUMfRwg3B5FPFTjOwddPzvTaHu0t9H1xiDVKOSpDxKItHiqnvYyMKqZVwaC5AIJvYk_bzVt8m7Vil
134
+ - OAuth 00D1a000000H3O9!AQ4AQCyefAUUsnWlCVp8nuCPw5FHOg4Bv_Grcp4GTCMkt22gpGUL_iimYlj.5dHJYoGbAKCuPttEXOKeigHMy9VPNErhVDRe
135
135
  Accept-Encoding:
136
136
  - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
137
137
  Accept:
@@ -142,17 +142,17 @@ http_interactions:
142
142
  message: No Content
143
143
  headers:
144
144
  Date:
145
- - Mon, 06 Apr 2015 16:24:44 GMT
145
+ - Wed, 08 Apr 2015 17:25:20 GMT
146
146
  Set-Cookie:
147
- - BrowserId=xFiEOfdbRdiL5E8KUkTLsg;Path=/;Domain=.salesforce.com;Expires=Fri,
148
- 05-Jun-2015 16:24:44 GMT
147
+ - BrowserId=vEmT_p9fRFiuV4_9cudymw;Path=/;Domain=.salesforce.com;Expires=Sun,
148
+ 07-Jun-2015 17:25:20 GMT
149
149
  Expires:
150
150
  - Thu, 01 Jan 1970 00:00:00 GMT
151
151
  Sforce-Limit-Info:
152
- - api-usage=36/15000
152
+ - api-usage=1/15000
153
153
  body:
154
154
  encoding: UTF-8
155
155
  string: ''
156
156
  http_version:
157
- recorded_at: Mon, 06 Apr 2015 16:24:44 GMT
157
+ recorded_at: Wed, 08 Apr 2015 17:25:19 GMT
158
158
  recorded_with: VCR 2.9.3
@@ -0,0 +1,158 @@
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
+ - Wed, 08 Apr 2015 17:25:17 GMT
25
+ Set-Cookie:
26
+ - BrowserId=lengI2EHTRub2Ko8hohJlQ;Path=/;Domain=.salesforce.com;Expires=Sun,
27
+ 07-Jun-2015 17:25:17 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":"1428513917270","token_type":"Bearer","instance_url":"https://<host>","signature":"EQGJyzSNyv8NhiCakDKNBRYnVOwnkS5/GgopPeymCdM=","access_token":"00D1a000000H3O9!AQ4AQCyefAUUsnWlCVp8nuCPw5FHOg4Bv_Grcp4GTCMkt22gpGUL_iimYlj.5dHJYoGbAKCuPttEXOKeigHMy9VPNErhVDRe"}'
41
+ http_version:
42
+ recorded_at: Wed, 08 Apr 2015 17:25:16 GMT
43
+ - request:
44
+ method: post
45
+ uri: https://<host>/services/data/v26.0/sobjects/CustomObject__c
46
+ body:
47
+ encoding: UTF-8
48
+ string: '{"Name":"Sample object"}'
49
+ headers:
50
+ User-Agent:
51
+ - Faraday v0.9.1
52
+ Content-Type:
53
+ - application/json
54
+ Authorization:
55
+ - OAuth 00D1a000000H3O9!AQ4AQCyefAUUsnWlCVp8nuCPw5FHOg4Bv_Grcp4GTCMkt22gpGUL_iimYlj.5dHJYoGbAKCuPttEXOKeigHMy9VPNErhVDRe
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
+ - Wed, 08 Apr 2015 17:25:17 GMT
67
+ Set-Cookie:
68
+ - BrowserId=zaP7cAcjRAO83Rd04ogCbg;Path=/;Domain=.salesforce.com;Expires=Sun,
69
+ 07-Jun-2015 17:25:17 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/CustomObject__c/a001a000001LMs4AAG"
76
+ Content-Type:
77
+ - application/json;charset=UTF-8
78
+ Transfer-Encoding:
79
+ - chunked
80
+ body:
81
+ encoding: ASCII-8BIT
82
+ string: '{"id":"a001a000001LMs4AAG","success":true,"errors":[]}'
83
+ http_version:
84
+ recorded_at: Wed, 08 Apr 2015 17:25:16 GMT
85
+ - request:
86
+ method: get
87
+ uri: https://<host>/services/data/v26.0/query?q=select%20Id,%20SystemModstamp,%20Name,%20Example_Field__c%20from%20CustomObject__c%20where%20Id%20=%20%27a001a000001LMs4AAG%27
88
+ body:
89
+ encoding: US-ASCII
90
+ string: ''
91
+ headers:
92
+ User-Agent:
93
+ - Faraday v0.9.1
94
+ Authorization:
95
+ - OAuth 00D1a000000H3O9!AQ4AQCyefAUUsnWlCVp8nuCPw5FHOg4Bv_Grcp4GTCMkt22gpGUL_iimYlj.5dHJYoGbAKCuPttEXOKeigHMy9VPNErhVDRe
96
+ Accept-Encoding:
97
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
98
+ Accept:
99
+ - "*/*"
100
+ response:
101
+ status:
102
+ code: 200
103
+ message: OK
104
+ headers:
105
+ Date:
106
+ - Wed, 08 Apr 2015 17:25:17 GMT
107
+ Set-Cookie:
108
+ - BrowserId=WXSf9tl1QHmxrtYD_ZRVmA;Path=/;Domain=.salesforce.com;Expires=Sun,
109
+ 07-Jun-2015 17:25:17 GMT
110
+ Expires:
111
+ - Thu, 01 Jan 1970 00:00:00 GMT
112
+ Sforce-Limit-Info:
113
+ - api-usage=1/15000
114
+ Content-Type:
115
+ - application/json;charset=UTF-8
116
+ Transfer-Encoding:
117
+ - chunked
118
+ body:
119
+ encoding: ASCII-8BIT
120
+ string: '{"totalSize":1,"done":true,"records":[{"attributes":{"type":"CustomObject__c","url":"/services/data/v26.0/sobjects/CustomObject__c/a001a000001LMs4AAG"},"Id":"a001a000001LMs4AAG","SystemModstamp":"2015-04-08T17:25:17.000+0000","Name":"Sample
121
+ object","Example_Field__c":null}]}'
122
+ http_version:
123
+ recorded_at: Wed, 08 Apr 2015 17:25:16 GMT
124
+ - request:
125
+ method: delete
126
+ uri: https://<host>/services/data/v26.0/sobjects/CustomObject__c/a001a000001LMs4AAG
127
+ body:
128
+ encoding: US-ASCII
129
+ string: ''
130
+ headers:
131
+ User-Agent:
132
+ - Faraday v0.9.1
133
+ Authorization:
134
+ - OAuth 00D1a000000H3O9!AQ4AQCyefAUUsnWlCVp8nuCPw5FHOg4Bv_Grcp4GTCMkt22gpGUL_iimYlj.5dHJYoGbAKCuPttEXOKeigHMy9VPNErhVDRe
135
+ Accept-Encoding:
136
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
137
+ Accept:
138
+ - "*/*"
139
+ response:
140
+ status:
141
+ code: 204
142
+ message: No Content
143
+ headers:
144
+ Date:
145
+ - Wed, 08 Apr 2015 17:25:18 GMT
146
+ Set-Cookie:
147
+ - BrowserId=Jr37xurySTWA9GLgtkUEsA;Path=/;Domain=.salesforce.com;Expires=Sun,
148
+ 07-Jun-2015 17:25:18 GMT
149
+ Expires:
150
+ - Thu, 01 Jan 1970 00:00:00 GMT
151
+ Sforce-Limit-Info:
152
+ - api-usage=1/15000
153
+ body:
154
+ encoding: UTF-8
155
+ string: ''
156
+ http_version:
157
+ recorded_at: Wed, 08 Apr 2015 17:25:17 GMT
158
+ recorded_with: VCR 2.9.3
@@ -15,12 +15,12 @@ describe Restforce::DB::Associations::ActiveRecord do
15
15
  let(:associated_record) { association.build(salesforce_record) }
16
16
 
17
17
  before do
18
- mapping = Restforce::DB::Mapping.new(
19
- User,
20
- "Contact",
21
- through: "Friend__c",
22
- fields: { email: "Email" },
23
- )
18
+ mapping = Restforce::DB::Mapping.new(User, "Contact").tap do |m|
19
+ m.through = "Friend__c"
20
+ m.fields = { email: "Email" }
21
+ end
22
+ Restforce::DB::Registry << mapping
23
+
24
24
  salesforce_record_type = mapping.salesforce_record_type
25
25
 
26
26
  # Stub out the `#find` method on the record type
@@ -16,7 +16,11 @@ describe Restforce::DB::AttributeMap do
16
16
  let(:attribute_map) { Restforce::DB::AttributeMap.new(database_model, salesforce_model, fields) }
17
17
 
18
18
  describe "#attributes" do
19
- let(:mapping) { Restforce::DB::Mapping.new(database_model, salesforce_model, fields: fields) }
19
+ let(:mapping) do
20
+ Restforce::DB::Mapping.new(database_model, salesforce_model).tap do |m|
21
+ m.fields = fields
22
+ end
23
+ end
20
24
 
21
25
  it "builds a normalized Hash of database attribute values" do
22
26
  attributes = attribute_map.attributes(database_model) do |attribute|
@@ -0,0 +1,80 @@
1
+ require_relative "../../../test_helper"
2
+
3
+ describe Restforce::DB::DSL do
4
+
5
+ let(:database_model) { CustomObject }
6
+ let(:salesforce_model) { "CustomObject__c" }
7
+ let(:strategy) { :always }
8
+ let(:dsl) { Restforce::DB::DSL.new(database_model, salesforce_model, strategy) }
9
+ let(:mapping) { dsl.mapping }
10
+
11
+ before { dsl }
12
+
13
+ describe "#initialize" do
14
+
15
+ it "registers a mapping for the passed models" do
16
+ expect(Restforce::DB::Registry[database_model]).to_equal [mapping]
17
+ expect(Restforce::DB::Registry[salesforce_model]).to_equal [mapping]
18
+ end
19
+
20
+ describe "when a strategy of :always is specified" do
21
+ let(:strategy) { :always }
22
+
23
+ it "respects the declared strategy" do
24
+ expect(dsl.mapping.strategy).to_be_instance_of(Restforce::DB::Strategies::Always)
25
+ end
26
+ end
27
+
28
+ describe "when a strategy of :passive is specified" do
29
+ let(:strategy) { :passive }
30
+
31
+ it "respects the declared strategy" do
32
+ expect(dsl.mapping.strategy).to_be_instance_of(Restforce::DB::Strategies::Passive)
33
+ end
34
+ end
35
+ end
36
+
37
+ describe "#where" do
38
+ let(:conditions) { %w(some list of query conditions) }
39
+
40
+ before do
41
+ dsl.where(*conditions)
42
+ end
43
+
44
+ it "sets a list of conditions for the mapping" do
45
+ expect(mapping.conditions).to_equal conditions
46
+ end
47
+ end
48
+
49
+ describe "#belongs_to" do
50
+ before do
51
+ dsl.belongs_to :some_association, through: "Some_Field__c"
52
+ end
53
+
54
+ it "adds an association to the created mapping" do
55
+ expect(mapping.associations).to_equal some_association: "Some_Field__c"
56
+ end
57
+ end
58
+
59
+ describe "#has_one" do
60
+ before do
61
+ dsl.has_one :other_association, through: "Other_Field__c"
62
+ end
63
+
64
+ it "sets the `through` attribute for the created mapping" do
65
+ expect(mapping.through).to_equal "Other_Field__c"
66
+ end
67
+ end
68
+
69
+ describe "#maps" do
70
+ let(:fields) { { some: "Fields__c", to: "Sync__c" } }
71
+
72
+ before do
73
+ dsl.maps fields
74
+ end
75
+
76
+ it "sets the fields for the created mapping" do
77
+ expect(mapping.fields).to_equal fields
78
+ end
79
+ end
80
+ end
@@ -26,8 +26,9 @@ describe Restforce::DB::Initializer do
26
26
  salesforce_id
27
27
  end
28
28
 
29
- describe "for a root mapping" do
29
+ describe "for an Always strategy" do
30
30
  before do
31
+ mapping.strategy = Restforce::DB::Strategies::Always.new
31
32
  initializer.run
32
33
  end
33
34
 
@@ -40,10 +41,9 @@ describe Restforce::DB::Initializer do
40
41
  end
41
42
  end
42
43
 
43
- describe "for a non-root mapping" do
44
- let(:through) { "SomeField__c" }
45
-
44
+ describe "for a Passive strategy" do
46
45
  before do
46
+ mapping.strategy = Restforce::DB::Strategies::Passive.new
47
47
  initializer.run
48
48
  end
49
49
 
@@ -61,8 +61,9 @@ describe Restforce::DB::Initializer do
61
61
  database_record
62
62
  end
63
63
 
64
- describe "for a root mapping" do
64
+ describe "for an Always strategy" do
65
65
  before do
66
+ mapping.strategy = Restforce::DB::Strategies::Always.new
66
67
  initializer.run
67
68
  Salesforce.records << [salesforce_model, salesforce_id]
68
69
  end
@@ -75,10 +76,9 @@ describe Restforce::DB::Initializer do
75
76
  end
76
77
  end
77
78
 
78
- describe "for a non-root mapping" do
79
- let(:through) { "SomeField__c" }
80
-
79
+ describe "for a Passive strategy" do
81
80
  before do
81
+ mapping.strategy = Restforce::DB::Strategies::Passive.new
82
82
  initializer.run
83
83
  end
84
84