soapforce 0.3.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -1
- data/CHANGELOG.md +6 -0
- data/lib/soapforce.rb +1 -0
- data/lib/soapforce/client.rb +68 -40
- data/lib/soapforce/query_result.rb +40 -11
- data/lib/soapforce/result.rb +36 -0
- data/lib/soapforce/sobject.rb +36 -18
- data/lib/soapforce/version.rb +1 -1
- data/soapforce.gemspec +3 -3
- data/spec/lib/client_spec.rb +141 -120
- data/spec/lib/configuration_spec.rb +2 -2
- data/spec/lib/query_result_spec.rb +31 -19
- data/spec/lib/result_spec.rb +24 -0
- data/spec/lib/sobject_spec.rb +133 -17
- data/spec/support/fixture_helpers.rb +6 -6
- metadata +33 -30
data/lib/soapforce/version.rb
CHANGED
data/soapforce.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_runtime_dependency "savon", ">= 2.3.0", '< 3.0.0'
|
22
22
|
|
23
|
-
spec.add_development_dependency 'rspec', '
|
24
|
-
spec.add_development_dependency 'webmock', '
|
25
|
-
spec.add_development_dependency 'simplecov', '
|
23
|
+
spec.add_development_dependency 'rspec', '>= 2.14.0', '< 4.0.0'
|
24
|
+
spec.add_development_dependency 'webmock', '>= 1.17.0', '< 2.0.0'
|
25
|
+
spec.add_development_dependency 'simplecov', '>= 0.9.0', '< 1.0.0'
|
26
26
|
end
|
data/spec/lib/client_spec.rb
CHANGED
@@ -2,11 +2,12 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Soapforce::Client do
|
4
4
|
let(:endpoint) { 'https://na15.salesforce.com' }
|
5
|
+
let(:subject) { Soapforce::Client.new(tag_style: :snakecase) }
|
5
6
|
|
6
7
|
describe "#operations" do
|
7
8
|
it "should return list of operations from the wsdl" do
|
8
|
-
subject.operations.
|
9
|
-
subject.operations.
|
9
|
+
expect(subject.operations).to be_an(Array)
|
10
|
+
expect(subject.operations).to include(:login, :logout, :query, :create)
|
10
11
|
end
|
11
12
|
end
|
12
13
|
|
@@ -32,8 +33,8 @@ describe Soapforce::Client do
|
|
32
33
|
|
33
34
|
user_info = subject.login(session_id: 'abcde12345', server_url: 'https://na15.salesforce.com')
|
34
35
|
|
35
|
-
user_info[:user_email].
|
36
|
-
user_info[:user_full_name].
|
36
|
+
expect(user_info[:user_email]).to eq "johndoe@email.com"
|
37
|
+
expect(user_info[:user_full_name]).to eq "John Doe"
|
37
38
|
end
|
38
39
|
|
39
40
|
it "should raise arugment error when no parameters are passed" do
|
@@ -45,19 +46,19 @@ describe Soapforce::Client do
|
|
45
46
|
it "should return array of object names" do
|
46
47
|
|
47
48
|
body = "<tns:describeGlobal></tns:describeGlobal>"
|
48
|
-
|
49
|
+
stub_api_request(endpoint, {with_body: body, fixture: 'describe_global_response'})
|
49
50
|
|
50
|
-
subject.list_sobjects.
|
51
|
+
expect(subject.list_sobjects).to eq ['Account', 'AccountContactRole']
|
51
52
|
end
|
52
53
|
end
|
53
54
|
|
54
55
|
describe "org_id" do
|
55
56
|
it "should return organization id" do
|
56
57
|
|
57
|
-
body = "<tns:query><tns:queryString>
|
58
|
-
|
58
|
+
body = "<tns:query><tns:queryString>SELECT Id FROM Organization</tns:queryString></tns:query>"
|
59
|
+
stub_api_request(endpoint, {with_body: body, fixture: 'org_id_response'})
|
59
60
|
|
60
|
-
subject.org_id.
|
61
|
+
expect(subject.org_id).to eq "00DA0000000YpZ4MAK"
|
61
62
|
end
|
62
63
|
end
|
63
64
|
|
@@ -66,7 +67,7 @@ describe Soapforce::Client do
|
|
66
67
|
it "supports single sobject name" do
|
67
68
|
|
68
69
|
body = "<tns:describeSObject><tns:sObjectType>Opportunity</tns:sObjectType></tns:describeSObject>"
|
69
|
-
|
70
|
+
stub_api_request(endpoint, {with_body: body, fixture: 'describe_s_object_response'})
|
70
71
|
|
71
72
|
subject.describe("Opportunity")
|
72
73
|
|
@@ -77,7 +78,7 @@ describe Soapforce::Client do
|
|
77
78
|
it "supports array of sobject names" do
|
78
79
|
|
79
80
|
body = "<tns:describeSObjects><tns:sObjectType>Account</tns:sObjectType><tns:sObjectType>Opportunity</tns:sObjectType></tns:describeSObjects>"
|
80
|
-
|
81
|
+
stub_api_request(endpoint, {with_body: body, fixture: 'describe_s_objects_response'})
|
81
82
|
|
82
83
|
subject.describe(["Account", "Opportunity"])
|
83
84
|
end
|
@@ -88,7 +89,7 @@ describe Soapforce::Client do
|
|
88
89
|
it "gets layouts for an sobject type" do
|
89
90
|
|
90
91
|
body = %Q{<tns:describeLayout><tns:sObjectType>Account</tns:sObjectType><tns:recordTypeIds xsi:nil="true"/></tns:describeLayout>}
|
91
|
-
|
92
|
+
stub_api_request(endpoint, {with_body: body, fixture: 'describe_layout_response'})
|
92
93
|
|
93
94
|
subject.describe_layout("Account")
|
94
95
|
|
@@ -99,7 +100,7 @@ describe Soapforce::Client do
|
|
99
100
|
it "get the details for a specific layout" do
|
100
101
|
|
101
102
|
body = %Q{<tns:describeLayout><tns:sObjectType>Account</tns:sObjectType><tns:recordTypeIds>012000000000000AAA</tns:recordTypeIds></tns:describeLayout>}
|
102
|
-
|
103
|
+
stub_api_request(endpoint, {with_body: body, fixture: 'describe_layout_response'})
|
103
104
|
|
104
105
|
subject.describe_layout('Account', '012000000000000AAA')
|
105
106
|
end
|
@@ -108,42 +109,43 @@ describe Soapforce::Client do
|
|
108
109
|
describe "#retrieve" do
|
109
110
|
|
110
111
|
it "should retrieve object by id" do
|
111
|
-
fields =
|
112
|
+
fields = fields_hash
|
113
|
+
|
112
114
|
# retrieve calls describe to get the list of available fields.
|
113
|
-
subject.
|
115
|
+
expect(subject).to receive(:describe).with("Opportunity").and_return(fields)
|
114
116
|
|
115
117
|
body = "<tns:retrieve><tns:fieldList>Id,Name,Description,StageName</tns:fieldList><tns:sObjectType>Opportunity</tns:sObjectType><tns:ids>006A000000LbkT5IAJ</tns:ids></tns:retrieve>"
|
116
|
-
|
118
|
+
stub_api_request(endpoint, {with_body: body, fixture: 'retrieve_response'})
|
117
119
|
|
118
120
|
sobject = subject.retrieve("Opportunity", "006A000000LbkT5IAJ")
|
119
121
|
|
120
|
-
sobject.
|
121
|
-
sobject.type.
|
122
|
-
sobject.Id.
|
123
|
-
sobject.Name.
|
124
|
-
sobject.Description.
|
125
|
-
sobject.StageName.
|
122
|
+
expect(sobject).to be_instance_of(Soapforce::SObject)
|
123
|
+
expect(sobject.type).to eq "Opportunity"
|
124
|
+
expect(sobject.Id).to eq "006A000000LbkT5IAJ"
|
125
|
+
expect(sobject.Name).to eq "SOAPForce Opportunity"
|
126
|
+
expect(sobject.Description).to be_nil
|
127
|
+
expect(sobject.StageName).to eq "Prospecting"
|
126
128
|
end
|
127
129
|
end
|
128
130
|
|
129
131
|
describe "#find" do
|
130
132
|
it "should retrieve object by id" do
|
133
|
+
fields = fields_hash
|
131
134
|
|
132
|
-
fields = {:fields => [{:name => "Id"},{:name => "Name"},{:name => "Description"},{:name => "StageName"}]}
|
133
135
|
# retrieve calls describe to get the list of available fields.
|
134
|
-
subject.
|
136
|
+
expect(subject).to receive(:describe).with("Opportunity").and_return(fields)
|
135
137
|
|
136
138
|
body = "<tns:retrieve><tns:fieldList>Id,Name,Description,StageName</tns:fieldList><tns:sObjectType>Opportunity</tns:sObjectType><tns:ids>006A000000LbkT5IAJ</tns:ids></tns:retrieve>"
|
137
|
-
|
139
|
+
stub_api_request(endpoint, {with_body: body, fixture: 'retrieve_response'})
|
138
140
|
|
139
141
|
sobject = subject.find("Opportunity", "006A000000LbkT5IAJ")
|
140
142
|
|
141
|
-
sobject.
|
142
|
-
sobject.type.
|
143
|
-
sobject.Id.
|
144
|
-
sobject.Name.
|
145
|
-
sobject.Description.
|
146
|
-
sobject.StageName.
|
143
|
+
expect(sobject).to be_instance_of(Soapforce::SObject)
|
144
|
+
expect(sobject.type).to eq "Opportunity"
|
145
|
+
expect(sobject.Id).to eq "006A000000LbkT5IAJ"
|
146
|
+
expect(sobject.Name).to eq "SOAPForce Opportunity"
|
147
|
+
expect(sobject.Description).to be_nil
|
148
|
+
expect(sobject.StageName).to eq "Prospecting"
|
147
149
|
end
|
148
150
|
|
149
151
|
end
|
@@ -151,23 +153,29 @@ describe Soapforce::Client do
|
|
151
153
|
describe "#find_by_field" do
|
152
154
|
|
153
155
|
it "should retrieve object by string field" do
|
154
|
-
fields =
|
156
|
+
fields = fields_hash
|
157
|
+
|
155
158
|
# retrieve calls describe to get the list of available fields.
|
156
|
-
subject.
|
159
|
+
expect(subject).to receive(:describe).exactly(2).with("Opportunity").and_return(fields)
|
157
160
|
|
158
|
-
body = "<tns:query><tns:queryString>
|
159
|
-
|
161
|
+
body = "<tns:query><tns:queryString>SELECT Id, Name, Description, StageName FROM Opportunity WHERE StageName = 'Prospecting'</tns:queryString></tns:query>"
|
162
|
+
stub_api_request(endpoint, {with_body: body, fixture: 'query_response'})
|
160
163
|
|
161
164
|
subject.find_by_field("Opportunity", "Prospecting", "StageName")
|
162
165
|
end
|
163
166
|
|
164
167
|
it "should retrieve object by number field" do
|
165
|
-
|
168
|
+
if subject.tag_style == :raw
|
169
|
+
fields = {"fields" => [{"name" => "Id"},{"name" => "Name"},{"name" => "Description"},{"name" => "Amount", "type" => "double"}]}
|
170
|
+
else
|
171
|
+
fields = {:fields => [{:name => "Id"},{:name => "Name"},{:name => "Description"},{:name => "Amount", :type => "double"}]}
|
172
|
+
end
|
173
|
+
|
166
174
|
# retrieve calls describe to get the list of available fields.
|
167
|
-
subject.
|
175
|
+
expect(subject).to receive(:describe).exactly(2).with("Opportunity").and_return(fields)
|
168
176
|
|
169
|
-
body = "<tns:query><tns:queryString>
|
170
|
-
|
177
|
+
body = "<tns:query><tns:queryString>SELECT Id, Name, Description, Amount FROM Opportunity WHERE Amount = 0.0</tns:queryString></tns:query>"
|
178
|
+
stub_api_request(endpoint, {with_body: body, fixture: 'query_response'})
|
171
179
|
|
172
180
|
subject.find_by_field("Opportunity", 0.0, "Amount")
|
173
181
|
end
|
@@ -176,45 +184,45 @@ describe Soapforce::Client do
|
|
176
184
|
|
177
185
|
describe "#find_where" do
|
178
186
|
|
179
|
-
let(:fields) {
|
180
|
-
let(:body) { "<tns:query><tns:queryString>
|
187
|
+
let(:fields) { fields_hash }
|
188
|
+
let(:body) { "<tns:query><tns:queryString>SELECT Id, Name, Description, StageName FROM Opportunity WHERE Id = '006A000000LbkT5IAJ' AND Amount = 0.0</tns:queryString></tns:query>" }
|
181
189
|
|
182
190
|
after(:each) do
|
183
|
-
@result.
|
184
|
-
@result.size.
|
185
|
-
@result.first.Name
|
186
|
-
@result.last.Name
|
191
|
+
expect(@result).to be_instance_of(Soapforce::QueryResult)
|
192
|
+
expect(@result.size).to eq 2
|
193
|
+
expect(@result.first.Name).to eq "Opportunity 1"
|
194
|
+
expect(@result.last.Name).to eq "Opportunity 2"
|
187
195
|
end
|
188
196
|
|
189
197
|
it "should retrieve records from hash conditions" do
|
190
|
-
|
198
|
+
stub_api_request(endpoint, {with_body: body, fixture: 'query_response'})
|
191
199
|
# retrieve calls describe to get the list of available fields.
|
192
|
-
subject.
|
200
|
+
expect(subject).to receive(:describe).with("Opportunity").and_return(fields)
|
193
201
|
|
194
202
|
@result = subject.find_where("Opportunity", {Id: "006A000000LbkT5IAJ", Amount: 0.0})
|
195
203
|
end
|
196
204
|
|
197
205
|
it "should retrieve records from hash condition using IN clause" do
|
198
|
-
body = "<tns:query><tns:queryString>
|
199
|
-
|
206
|
+
body = "<tns:query><tns:queryString>SELECT Id, Name, Description, StageName FROM Opportunity WHERE Id IN ('006A000000LbkT5IAJ', '006A000000AbkTcIAQ')</tns:queryString></tns:query>"
|
207
|
+
stub_api_request(endpoint, {with_body: body, fixture: 'query_response'})
|
200
208
|
|
201
209
|
# retrieve calls describe to get the list of available fields.
|
202
|
-
subject.
|
210
|
+
expect(subject).to receive(:describe).with("Opportunity").and_return(fields)
|
203
211
|
|
204
212
|
@result = subject.find_where("Opportunity", {Id: ["006A000000LbkT5IAJ", "006A000000AbkTcIAQ"]})
|
205
213
|
end
|
206
214
|
|
207
215
|
it "should retrieve records from string condition" do
|
208
|
-
|
216
|
+
stub_api_request(endpoint, {with_body: body, fixture: 'query_response'})
|
209
217
|
# retrieve calls describe to get the list of available fields.
|
210
|
-
subject.
|
218
|
+
expect(subject).to receive(:describe).with("Opportunity").and_return(fields)
|
211
219
|
|
212
220
|
@result = subject.find_where("Opportunity", "Id = '006A000000LbkT5IAJ' AND Amount = 0.0")
|
213
221
|
end
|
214
222
|
|
215
223
|
it "should retrieve records from string condition and specify fields" do
|
216
|
-
|
217
|
-
subject.
|
224
|
+
stub_api_request(endpoint, {with_body: body, fixture: 'query_response'})
|
225
|
+
expect(subject).to_not receive(:describe)
|
218
226
|
|
219
227
|
@result = subject.find_where("Opportunity", "Id = '006A000000LbkT5IAJ' AND Amount = 0.0", ["Id", "Name", "Description", "StageName"])
|
220
228
|
end
|
@@ -224,29 +232,31 @@ describe Soapforce::Client do
|
|
224
232
|
describe "query methods" do
|
225
233
|
|
226
234
|
after(:each) do
|
227
|
-
@result.
|
228
|
-
@result.size.
|
229
|
-
@result.first.Name
|
230
|
-
@result.last.Name
|
235
|
+
expect(@result).to be_instance_of(Soapforce::QueryResult)
|
236
|
+
expect(@result.size).to eq 2
|
237
|
+
expect(@result.first.Name).to eq "Opportunity 1"
|
238
|
+
expect(@result.last.Name).to eq "Opportunity 2"
|
231
239
|
end
|
232
240
|
|
233
241
|
it "#query" do
|
234
|
-
|
235
|
-
|
242
|
+
soql = "SELECT Id, Name, StageName FROM Opportunity"
|
243
|
+
body = "<tns:query><tns:queryString>#{soql}</tns:queryString></tns:query>"
|
244
|
+
stub_api_request(endpoint, {with_body: body, fixture: 'query_response'})
|
236
245
|
|
237
|
-
@result = subject.query(
|
246
|
+
@result = subject.query(soql)
|
238
247
|
end
|
239
248
|
|
240
249
|
it "#query_all" do
|
241
|
-
|
242
|
-
|
250
|
+
soql = "SELECT Id, Name, StageName FROM Opportunity"
|
251
|
+
body = "<tns:queryAll><tns:queryString>#{soql}</tns:queryString></tns:queryAll>"
|
252
|
+
stub_api_request(endpoint, {with_body: body, fixture: 'query_all_response'})
|
243
253
|
|
244
|
-
@result = subject.query_all(
|
254
|
+
@result = subject.query_all(soql)
|
245
255
|
end
|
246
256
|
|
247
257
|
it "#query_more" do
|
248
258
|
body = "<tns:queryMore><tns:queryLocator>some_locator_string</tns:queryLocator></tns:queryMore>"
|
249
|
-
|
259
|
+
stub_api_request(endpoint, {with_body: body, fixture: 'query_more_response'})
|
250
260
|
|
251
261
|
@result = subject.query_more("some_locator_string")
|
252
262
|
end
|
@@ -258,9 +268,9 @@ describe Soapforce::Client do
|
|
258
268
|
it "should return search results" do
|
259
269
|
|
260
270
|
sosl = "FIND 'Name*' IN ALL FIELDS RETURNING Account (Id, Name), Contact, Opportunity, Lead"
|
261
|
-
|
262
|
-
body = "<tns:search><tns:searchString
|
263
|
-
|
271
|
+
# single quote encoding changed in ruby 2
|
272
|
+
body = "<tns:search><tns:searchString>FIND 'Name*' IN ALL FIELDS RETURNING Account (Id, Name), Contact, Opportunity, Lead</tns:searchString></tns:search>"
|
273
|
+
stub_api_request(endpoint, {with_body: body, fixture: 'search_response'})
|
264
274
|
|
265
275
|
subject.search(sosl)
|
266
276
|
end
|
@@ -275,33 +285,33 @@ describe Soapforce::Client do
|
|
275
285
|
|
276
286
|
it "should create new object" do
|
277
287
|
|
278
|
-
|
288
|
+
stub_api_request(endpoint, {with_body: @body, fixture: 'create_response'})
|
279
289
|
response = subject.create("Opportunity", @params)
|
280
290
|
|
281
|
-
response[:success].
|
282
|
-
response[:id].
|
291
|
+
expect(response[:success]).to eq true
|
292
|
+
expect(response[:id]).to eq "006A000000LbiizIAB"
|
283
293
|
end
|
284
294
|
|
285
295
|
it "should return false if object not created" do
|
286
|
-
|
296
|
+
stub_api_request(endpoint, {with_body: @body, fixture: 'create_response_failure'})
|
287
297
|
response = subject.create("Opportunity", @params)
|
288
|
-
response.
|
298
|
+
expect(response).to eq false
|
289
299
|
end
|
290
300
|
|
291
301
|
it "creates! new object" do
|
292
302
|
|
293
|
-
|
303
|
+
stub_api_request(endpoint, {with_body: @body, fixture: 'create_response'})
|
294
304
|
response = subject.create!("Opportunity", @params)
|
295
305
|
|
296
|
-
response[:success].
|
297
|
-
response[:id].
|
306
|
+
expect(response[:success]).to eq true
|
307
|
+
expect(response[:id]).to eq "006A000000LbiizIAB"
|
298
308
|
end
|
299
309
|
|
300
310
|
it "raises exception when create! fails" do
|
301
311
|
|
302
|
-
|
312
|
+
stub_api_request(endpoint, {with_body: @body, fixture: 'create_response_failure'})
|
303
313
|
expect {
|
304
|
-
|
314
|
+
subject.create!("Opportunity", @params)
|
305
315
|
}.to raise_error(Savon::Error)
|
306
316
|
|
307
317
|
end
|
@@ -314,33 +324,31 @@ describe Soapforce::Client do
|
|
314
324
|
end
|
315
325
|
|
316
326
|
it "updates existing object" do
|
317
|
-
|
327
|
+
stub_api_request(endpoint, {with_body: @body, fixture: 'update_response'})
|
318
328
|
response = subject.update("Opportunity", @params)
|
319
329
|
|
320
|
-
response[:success].
|
321
|
-
response[:id].
|
330
|
+
expect(response[:success]).to eq true
|
331
|
+
expect(response[:id]).to eq "006A000000LbiizIAB"
|
322
332
|
end
|
323
333
|
|
324
334
|
it "updates! existing object" do
|
325
|
-
|
335
|
+
stub_api_request(endpoint, {with_body: @body, fixture: 'update_response'})
|
326
336
|
response = subject.update!("Opportunity", @params)
|
327
337
|
|
328
|
-
response[:success].
|
329
|
-
response[:id].
|
338
|
+
expect(response[:success]).to eq true
|
339
|
+
expect(response[:id]).to eq "006A000000LbiizIAB"
|
330
340
|
end
|
331
341
|
|
332
342
|
it "returns false when update fails" do
|
333
|
-
|
334
|
-
stub = stub_api_request(endpoint, {with_body: @body, fixture: 'update_response_failure'})
|
343
|
+
stub_api_request(endpoint, {with_body: @body, fixture: 'update_response_failure'})
|
335
344
|
response = subject.update("Opportunity", @params)
|
336
|
-
response.
|
345
|
+
expect(response).to eq false
|
337
346
|
end
|
338
347
|
|
339
348
|
it "raises exception when update fails" do
|
340
|
-
|
341
|
-
stub = stub_api_request(endpoint, {with_body: @body, fixture: 'update_response_failure'})
|
349
|
+
stub_api_request(endpoint, {with_body: @body, fixture: 'update_response_failure'})
|
342
350
|
expect {
|
343
|
-
|
351
|
+
subject.update!("Opportunity", @params)
|
344
352
|
}.to raise_error(Savon::Error)
|
345
353
|
|
346
354
|
end
|
@@ -356,7 +364,7 @@ describe Soapforce::Client do
|
|
356
364
|
end
|
357
365
|
|
358
366
|
it "inserts new and updates existing objects" do
|
359
|
-
|
367
|
+
stub_api_request(endpoint, {with_body: @body, fixture: 'upsert_response'})
|
360
368
|
subject.upsert("Opportunity", "External_Id__c", @objects)
|
361
369
|
end
|
362
370
|
|
@@ -369,30 +377,31 @@ describe Soapforce::Client do
|
|
369
377
|
end
|
370
378
|
|
371
379
|
it "deletes existing object" do
|
372
|
-
|
380
|
+
stub_api_request(endpoint, {with_body: @body, fixture: 'delete_response'})
|
373
381
|
response = subject.delete(@id)
|
374
382
|
|
375
|
-
response[:success].
|
376
|
-
response[:id].
|
383
|
+
expect(response[:success]).to eq true
|
384
|
+
expect(response[:id]).to eq @id
|
377
385
|
end
|
378
386
|
|
379
387
|
it "returns false if delete fails" do
|
380
|
-
|
388
|
+
stub_api_request(endpoint, {with_body: @body, fixture: 'delete_response_failure'})
|
381
389
|
response = subject.delete(@id)
|
382
390
|
|
383
|
-
response.
|
391
|
+
expect(response).to eq false
|
384
392
|
end
|
385
393
|
|
386
394
|
it "deletes existing object with a bang" do
|
387
|
-
|
395
|
+
stub_api_request(endpoint, {with_body: @body, fixture: 'delete_response'})
|
388
396
|
response = subject.delete!(@id)
|
389
397
|
|
390
|
-
response
|
391
|
-
response[:
|
398
|
+
expect(response).to be_an_instance_of Soapforce::Result
|
399
|
+
expect(response[:success]).to eq true
|
400
|
+
expect(response[:id]).to eq @id
|
392
401
|
end
|
393
402
|
|
394
403
|
it "raises an exception if delete fails" do
|
395
|
-
|
404
|
+
stub_api_request(endpoint, {with_body: @body, fixture: 'delete_response_failure'})
|
396
405
|
expect {
|
397
406
|
subject.delete!(@id)
|
398
407
|
}.to raise_error(Savon::Error)
|
@@ -408,32 +417,34 @@ describe Soapforce::Client do
|
|
408
417
|
end
|
409
418
|
|
410
419
|
it "merges objects together" do
|
411
|
-
|
420
|
+
stub_api_request(endpoint, {with_body: @body, fixture: 'merge_response'})
|
412
421
|
response = subject.merge("Account", @object, @to_merge)
|
413
422
|
|
414
|
-
response
|
415
|
-
response[:
|
416
|
-
response[:
|
423
|
+
expect(response).to be_an_instance_of Soapforce::Result
|
424
|
+
expect(response[:success]).to eq true
|
425
|
+
expect(response[:id]).to eq @object[:id]
|
426
|
+
expect(response[:merged_record_ids]).to be_an(Array)
|
427
|
+
expect(response[:merged_record_ids].sort).to eq @to_merge
|
417
428
|
end
|
418
429
|
|
419
430
|
it "returns false if merge fails" do
|
420
|
-
|
431
|
+
stub_api_request(endpoint, {with_body: @body, fixture: 'merge_response_failure'})
|
421
432
|
response = subject.merge("Account", @object, @to_merge)
|
422
433
|
|
423
|
-
response.
|
434
|
+
expect(response).to eq false
|
424
435
|
end
|
425
436
|
|
426
437
|
it "merges objects with a bang" do
|
427
|
-
|
438
|
+
stub_api_request(endpoint, {with_body: @body, fixture: 'merge_response'})
|
428
439
|
response = subject.merge!("Account", @object, @to_merge)
|
429
440
|
|
430
|
-
response[:success].
|
431
|
-
response[:id].
|
432
|
-
response[:merged_record_ids].sort.
|
441
|
+
expect(response[:success]).to eq true
|
442
|
+
expect(response[:id]).to eq @object[:id]
|
443
|
+
expect(response[:merged_record_ids].sort).to eq @to_merge
|
433
444
|
end
|
434
445
|
|
435
446
|
it "raises an exception if merge fails" do
|
436
|
-
|
447
|
+
stub_api_request(endpoint, {with_body: @body, fixture: 'merge_response_failure'})
|
437
448
|
expect {
|
438
449
|
subject.merge!('Account', @object, @to_merge)
|
439
450
|
}.to raise_error(Savon::Error)
|
@@ -446,32 +457,42 @@ describe Soapforce::Client do
|
|
446
457
|
|
447
458
|
@body = '<tns:process><tns:actions xsi:type="tns:ProcessSubmitRequest"><tns:objectId>a00i0000007JBLJAA4</tns:objectId><tns:comments>Submitting for Approval</tns:comments></tns:actions></tns:process>'
|
448
459
|
|
449
|
-
|
460
|
+
stub_api_request(endpoint, {with_body: @body, fixture: 'process_submit_request_response'})
|
450
461
|
response = subject.process({objectId: "a00i0000007JBLJAA4", comments: "Submitting for Approval"})
|
451
462
|
|
452
|
-
response
|
453
|
-
response[:
|
463
|
+
expect(response).to be_an_instance_of(Soapforce::Result)
|
464
|
+
expect(response[:success]).to eq true
|
465
|
+
expect(response[:new_workitem_ids]).to eq "04ii000000098uLAAQ"
|
466
|
+
expect(response["newWorkitemIds"]).to eq "04ii000000098uLAAQ"
|
454
467
|
end
|
455
468
|
|
456
469
|
it "process submit request with approvers" do
|
457
470
|
|
458
471
|
@body = '<tns:process><tns:actions xsi:type="tns:ProcessSubmitRequest"><tns:objectId>a00i0000007JBLJAA4</tns:objectId><tns:comments>Submitting for Approval</tns:comments><tns:nextApproverIds>abcde12345</tns:nextApproverIds></tns:actions></tns:process>'
|
459
472
|
|
460
|
-
|
473
|
+
stub_api_request(endpoint, {with_body: @body, fixture: 'process_submit_request_response'})
|
461
474
|
response = subject.process({objectId: "a00i0000007JBLJAA4", comments: "Submitting for Approval", approverIds: "abcde12345"})
|
462
475
|
|
463
|
-
response[:success].
|
464
|
-
response[:new_workitem_ids].
|
476
|
+
expect(response[:success]).to eq true
|
477
|
+
expect(response[:new_workitem_ids]).to eq "04ii000000098uLAAQ"
|
465
478
|
end
|
466
479
|
|
467
480
|
it "process workitem request" do
|
468
481
|
@body = '<tns:process><tns:actions xsi:type="tns:ProcessWorkitemRequest"><tns:action>Removed</tns:action><tns:workitemId>a00i0000007JBLJAA4</tns:workitemId><tns:comments>Recalling Request</tns:comments></tns:actions></tns:process>'
|
469
482
|
|
470
|
-
|
483
|
+
stub_api_request(endpoint, {with_body: @body, fixture: 'process_workitem_request_response'})
|
471
484
|
response = subject.process({action: "Removed", workitemId: "a00i0000007JBLJAA4", comments: "Recalling Request"})
|
472
485
|
|
473
|
-
response[:success].
|
474
|
-
response[:instance_status].
|
486
|
+
expect(response[:success]).to eq true
|
487
|
+
expect(response[:instance_status]).to eq "Removed"
|
488
|
+
end
|
489
|
+
end
|
490
|
+
|
491
|
+
def fields_hash
|
492
|
+
if subject.tag_style == :raw
|
493
|
+
{"fields" => [{"name" => "Id"},{"name" => "Name"},{"name" => "Description"},{"name" => "StageName"}]}
|
494
|
+
else
|
495
|
+
{:fields => [{:name => "Id"},{:name => "Name"},{:name => "Description"},{:name => "StageName"}]}
|
475
496
|
end
|
476
497
|
end
|
477
498
|
|