restforce 5.0.6 → 5.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +9 -9
- data/.rubocop.yml +2 -2
- data/CHANGELOG.md +22 -0
- data/Gemfile +10 -6
- data/README.md +53 -4
- data/lib/restforce/abstract_client.rb +1 -0
- data/lib/restforce/collection.rb +15 -1
- data/lib/restforce/concerns/api.rb +1 -1
- data/lib/restforce/concerns/composite_api.rb +104 -0
- data/lib/restforce/concerns/picklists.rb +1 -1
- data/lib/restforce/error_code.rb +24 -9
- data/lib/restforce/version.rb +1 -1
- data/lib/restforce.rb +2 -0
- data/restforce.gemspec +4 -13
- data/spec/integration/abstract_client_spec.rb +21 -24
- data/spec/integration/data/client_spec.rb +6 -2
- data/spec/spec_helper.rb +10 -0
- data/spec/support/client_integration.rb +7 -7
- data/spec/support/concerns.rb +1 -1
- data/spec/support/middleware.rb +1 -2
- data/spec/unit/collection_spec.rb +4 -4
- data/spec/unit/concerns/api_spec.rb +11 -11
- data/spec/unit/concerns/authentication_spec.rb +6 -6
- data/spec/unit/concerns/composite_api_spec.rb +143 -0
- data/spec/unit/concerns/streaming_spec.rb +4 -4
- data/spec/unit/config_spec.rb +1 -1
- data/spec/unit/middleware/authentication/jwt_bearer_spec.rb +4 -4
- data/spec/unit/middleware/authentication/password_spec.rb +2 -2
- data/spec/unit/middleware/authentication/token_spec.rb +2 -2
- data/spec/unit/middleware/gzip_spec.rb +2 -2
- data/spec/unit/middleware/raise_error_spec.rb +20 -10
- metadata +14 -94
@@ -98,17 +98,21 @@ shared_examples_for Restforce::Data::Client do
|
|
98
98
|
end
|
99
99
|
|
100
100
|
describe '.subscribe', event_machine: true do
|
101
|
+
let(:faye_double) { double('Faye') }
|
102
|
+
|
101
103
|
context 'when given a single pushtopic' do
|
102
104
|
it 'subscribes to the pushtopic' do
|
103
|
-
|
105
|
+
faye_double.should_receive(:subscribe).with(['/topic/PushTopic'])
|
106
|
+
client.stub faye: faye_double
|
104
107
|
client.subscribe('PushTopic')
|
105
108
|
end
|
106
109
|
end
|
107
110
|
|
108
111
|
context 'when given an array of pushtopics' do
|
109
112
|
it 'subscribes to each pushtopic' do
|
110
|
-
|
113
|
+
faye_double.should_receive(:subscribe).with(['/topic/PushTopic1',
|
111
114
|
'/topic/PushTopic2'])
|
115
|
+
client.stub faye: faye_double
|
112
116
|
client.subscribe(%w[PushTopic1 PushTopic2])
|
113
117
|
end
|
114
118
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -8,6 +8,8 @@ Bundler.require :default, :test
|
|
8
8
|
require 'faye' unless RUBY_PLATFORM == 'java'
|
9
9
|
|
10
10
|
require 'webmock/rspec'
|
11
|
+
require 'rspec/collection_matchers'
|
12
|
+
require 'rspec/its'
|
11
13
|
|
12
14
|
WebMock.disable_net_connect!
|
13
15
|
|
@@ -27,6 +29,14 @@ RSpec.configure do |config|
|
|
27
29
|
$stderr = original_stderr
|
28
30
|
$stdout = original_stdout
|
29
31
|
end
|
32
|
+
|
33
|
+
config.expect_with :rspec do |expectations|
|
34
|
+
expectations.syntax = %i[expect should]
|
35
|
+
end
|
36
|
+
|
37
|
+
config.mock_with :rspec do |mocks|
|
38
|
+
mocks.syntax = %i[expect should]
|
39
|
+
end
|
30
40
|
end
|
31
41
|
|
32
42
|
# Requires supporting ruby files with custom matchers and macros, etc,
|
@@ -5,7 +5,7 @@ module ClientIntegrationExampleGroup
|
|
5
5
|
base.class_eval do
|
6
6
|
let(:oauth_token) do
|
7
7
|
'00Dx0000000BV7z!AR8AQAxo9UfVkh8AlV0Gomt9Czx9LjHnSSpwBMmbRcgKFmxOtvxjTrKW19ye6P' \
|
8
|
-
|
8
|
+
'E3Ds1eQz3z8jr3W7_VbWmEu4Q8TVGSTHxs'
|
9
9
|
end
|
10
10
|
|
11
11
|
let(:refresh_token) { 'refresh' }
|
@@ -39,13 +39,13 @@ module ClientIntegrationExampleGroup
|
|
39
39
|
end
|
40
40
|
|
41
41
|
RSpec.configure do |config|
|
42
|
+
describes = lambda do |described|
|
43
|
+
described <= Restforce::AbstractClient
|
44
|
+
end
|
45
|
+
|
42
46
|
config.include self,
|
43
|
-
|
44
|
-
|
45
|
-
described <= Restforce::AbstractClient
|
46
|
-
end,
|
47
|
-
file_path: %r{spec/integration}
|
48
|
-
}
|
47
|
+
file_path: %r{spec/integration},
|
48
|
+
describes: describes
|
49
49
|
|
50
50
|
config.before mashify: false do
|
51
51
|
base_options.merge!(mashify: false)
|
data/spec/support/concerns.rb
CHANGED
data/spec/support/middleware.rb
CHANGED
@@ -13,7 +13,7 @@ describe Restforce::Collection do
|
|
13
13
|
|
14
14
|
it { should respond_to :each }
|
15
15
|
its(:size) { should eq 1 }
|
16
|
-
its(:has_next_page?) { should
|
16
|
+
its(:has_next_page?) { should be false }
|
17
17
|
it { should have_client client }
|
18
18
|
its(:page_size) { should eq 1 }
|
19
19
|
|
@@ -56,7 +56,7 @@ describe Restforce::Collection do
|
|
56
56
|
should(be_all { |page| expect(page).to be_a Restforce::Collection })
|
57
57
|
end
|
58
58
|
|
59
|
-
its(:has_next_page?) { should
|
59
|
+
its(:has_next_page?) { should be true }
|
60
60
|
it { should(be_all { |record| expect(record).to be_a Restforce::SObject }) }
|
61
61
|
its(:next_page) { should be_a Restforce::Collection }
|
62
62
|
end
|
@@ -71,13 +71,13 @@ describe Restforce::Collection do
|
|
71
71
|
context 'with size 1' do
|
72
72
|
let(:sobject_fixture) { 'sobject/query_success_response' }
|
73
73
|
|
74
|
-
it { should
|
74
|
+
it { should be false }
|
75
75
|
end
|
76
76
|
|
77
77
|
context 'with size 0' do
|
78
78
|
let(:sobject_fixture) { 'sobject/query_empty_response' }
|
79
79
|
|
80
|
-
it { should
|
80
|
+
it { should be true }
|
81
81
|
end
|
82
82
|
end
|
83
83
|
end
|
@@ -11,7 +11,7 @@ describe Restforce::Concerns::API do
|
|
11
11
|
it 'returns the user info from identity url' do
|
12
12
|
identity_url = double('identity_url')
|
13
13
|
response.body.stub(:identity).and_return(identity_url)
|
14
|
-
client.should_receive(:api_get).with.and_return(response)
|
14
|
+
client.should_receive(:api_get).with(no_args).and_return(response)
|
15
15
|
|
16
16
|
identity = double('identity')
|
17
17
|
identity.stub(:body).and_return(identity)
|
@@ -268,7 +268,7 @@ describe Restforce::Concerns::API do
|
|
268
268
|
|
269
269
|
it "delegates to :#{method}!" do
|
270
270
|
client.should_receive(:"#{method}!").
|
271
|
-
with(
|
271
|
+
with(no_args).
|
272
272
|
and_return(response)
|
273
273
|
expect(result).to eq response
|
274
274
|
end
|
@@ -276,7 +276,7 @@ describe Restforce::Concerns::API do
|
|
276
276
|
it 'rescues exceptions' do
|
277
277
|
[Faraday::ClientError].each do |exception_klass|
|
278
278
|
client.should_receive(:"#{method}!").
|
279
|
-
with(
|
279
|
+
with(no_args).
|
280
280
|
and_raise(exception_klass.new(nil))
|
281
281
|
expect(result).to eq false
|
282
282
|
end
|
@@ -314,7 +314,7 @@ describe Restforce::Concerns::API do
|
|
314
314
|
it 'sends an HTTP PATCH, and returns true' do
|
315
315
|
client.should_receive(:api_patch).
|
316
316
|
with('sobjects/Whizbang/1234', StageName: "Call Scheduled")
|
317
|
-
expect(result).to
|
317
|
+
expect(result).to be true
|
318
318
|
end
|
319
319
|
end
|
320
320
|
|
@@ -324,7 +324,7 @@ describe Restforce::Concerns::API do
|
|
324
324
|
it 'sends an HTTP PATCH, and encodes the ID' do
|
325
325
|
client.should_receive(:api_patch).
|
326
326
|
with('sobjects/Whizbang/1234%2F%3Fabc', StageName: "Call Scheduled")
|
327
|
-
expect(result).to
|
327
|
+
expect(result).to be true
|
328
328
|
end
|
329
329
|
end
|
330
330
|
|
@@ -348,7 +348,7 @@ describe Restforce::Concerns::API do
|
|
348
348
|
client.should_receive(:api_patch).
|
349
349
|
with('sobjects/Whizbang/External_ID__c/1234', {}).
|
350
350
|
and_return(response)
|
351
|
-
expect(result).to
|
351
|
+
expect(result).to be true
|
352
352
|
end
|
353
353
|
|
354
354
|
context 'and the response body is a string' do
|
@@ -357,7 +357,7 @@ describe Restforce::Concerns::API do
|
|
357
357
|
client.should_receive(:api_patch).
|
358
358
|
with('sobjects/Whizbang/External_ID__c/1234', {}).
|
359
359
|
and_return(response)
|
360
|
-
expect(result).to
|
360
|
+
expect(result).to be true
|
361
361
|
end
|
362
362
|
end
|
363
363
|
end
|
@@ -431,7 +431,7 @@ describe Restforce::Concerns::API do
|
|
431
431
|
client.should_receive(:api_patch).
|
432
432
|
with('sobjects/Whizbang/External_ID__c/%E3%81%82', {}).
|
433
433
|
and_return(response)
|
434
|
-
expect(result).to
|
434
|
+
expect(result).to be true
|
435
435
|
end
|
436
436
|
end
|
437
437
|
end
|
@@ -448,7 +448,7 @@ describe Restforce::Concerns::API do
|
|
448
448
|
client.should_receive(:api_patch).
|
449
449
|
with('sobjects/Whizbang/External_ID__c/1234', {}).
|
450
450
|
and_return(response)
|
451
|
-
expect(result).to
|
451
|
+
expect(result).to be true
|
452
452
|
end
|
453
453
|
end
|
454
454
|
end
|
@@ -462,7 +462,7 @@ describe Restforce::Concerns::API do
|
|
462
462
|
it 'sends and HTTP delete, and returns true' do
|
463
463
|
client.should_receive(:api_delete).
|
464
464
|
with('sobjects/Whizbang/1234')
|
465
|
-
expect(result).to
|
465
|
+
expect(result).to be true
|
466
466
|
end
|
467
467
|
|
468
468
|
context 'when the id field contains special characters' do
|
@@ -471,7 +471,7 @@ describe Restforce::Concerns::API do
|
|
471
471
|
it 'sends an HTTP delete, and encodes the ID' do
|
472
472
|
client.should_receive(:api_delete).
|
473
473
|
with('sobjects/Whizbang/1234%2F%3Fabc')
|
474
|
-
expect(result).to
|
474
|
+
expect(result).to be true
|
475
475
|
end
|
476
476
|
end
|
477
477
|
end
|
@@ -80,11 +80,11 @@ describe Restforce::Concerns::Authentication do
|
|
80
80
|
client_secret: 'secret' }
|
81
81
|
end
|
82
82
|
|
83
|
-
it { should
|
83
|
+
it { should be_truthy }
|
84
84
|
end
|
85
85
|
|
86
86
|
context 'when username and password options are not provided' do
|
87
|
-
it { should_not
|
87
|
+
it { should_not be_truthy }
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
@@ -103,11 +103,11 @@ describe Restforce::Concerns::Authentication do
|
|
103
103
|
client_secret: 'secret' }
|
104
104
|
end
|
105
105
|
|
106
|
-
it { should
|
106
|
+
it { should be_truthy }
|
107
107
|
end
|
108
108
|
|
109
109
|
context 'when oauth options are not provided' do
|
110
|
-
it { should_not
|
110
|
+
it { should_not be true }
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
@@ -128,11 +128,11 @@ describe Restforce::Concerns::Authentication do
|
|
128
128
|
client_id: 'client' }
|
129
129
|
end
|
130
130
|
|
131
|
-
it { should
|
131
|
+
it { should be_truthy }
|
132
132
|
end
|
133
133
|
|
134
134
|
context 'when jwt options are not provided' do
|
135
|
-
it { should_not
|
135
|
+
it { should_not be true }
|
136
136
|
end
|
137
137
|
end
|
138
138
|
end
|
@@ -0,0 +1,143 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Restforce::Concerns::CompositeAPI do
|
6
|
+
let(:endpoint) { 'composite' }
|
7
|
+
|
8
|
+
before do
|
9
|
+
client.should_receive(:options).and_return(api_version: 38.0)
|
10
|
+
end
|
11
|
+
|
12
|
+
shared_examples_for 'composite requests' do
|
13
|
+
it '#create' do
|
14
|
+
client.
|
15
|
+
should_receive(:api_post).
|
16
|
+
with(endpoint, { compositeRequest: [
|
17
|
+
{
|
18
|
+
method: 'POST',
|
19
|
+
url: '/services/data/v38.0/sobjects/Object',
|
20
|
+
body: { name: 'test' },
|
21
|
+
referenceId: 'create_ref'
|
22
|
+
}
|
23
|
+
], allOrNone: all_or_none, collateSubrequests: false }.to_json).
|
24
|
+
and_return(response)
|
25
|
+
|
26
|
+
client.send(method) do |subrequests|
|
27
|
+
subrequests.create('Object', 'create_ref', name: 'test')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
it '#update' do
|
32
|
+
client.
|
33
|
+
should_receive(:api_post).
|
34
|
+
with(endpoint, { compositeRequest: [
|
35
|
+
{
|
36
|
+
method: 'PATCH',
|
37
|
+
url: '/services/data/v38.0/sobjects/Object/123',
|
38
|
+
body: { name: 'test' },
|
39
|
+
referenceId: 'update_ref'
|
40
|
+
}
|
41
|
+
], allOrNone: all_or_none, collateSubrequests: false }.to_json).
|
42
|
+
and_return(response)
|
43
|
+
|
44
|
+
client.send(method) do |subrequests|
|
45
|
+
subrequests.update('Object', 'update_ref', id: '123', name: 'test')
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
it '#destroy' do
|
50
|
+
client.
|
51
|
+
should_receive(:api_post).
|
52
|
+
with(endpoint, { compositeRequest: [
|
53
|
+
{
|
54
|
+
method: 'DELETE',
|
55
|
+
url: '/services/data/v38.0/sobjects/Object/123',
|
56
|
+
referenceId: 'destroy_ref'
|
57
|
+
}
|
58
|
+
], allOrNone: all_or_none, collateSubrequests: false }.to_json).
|
59
|
+
and_return(response)
|
60
|
+
|
61
|
+
client.send(method) do |subrequests|
|
62
|
+
subrequests.destroy('Object', 'destroy_ref', '123')
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
it '#upsert' do
|
67
|
+
client.
|
68
|
+
should_receive(:api_post).
|
69
|
+
with(endpoint, { compositeRequest: [
|
70
|
+
{
|
71
|
+
method: 'PATCH',
|
72
|
+
url: '/services/data/v38.0/sobjects/Object/extIdField__c/456',
|
73
|
+
body: { name: 'test' },
|
74
|
+
referenceId: 'upsert_ref'
|
75
|
+
}
|
76
|
+
], allOrNone: all_or_none, collateSubrequests: false }.to_json).
|
77
|
+
and_return(response)
|
78
|
+
|
79
|
+
client.send(method) do |subrequests|
|
80
|
+
subrequests.upsert('Object', 'upsert_ref', 'extIdField__c',
|
81
|
+
extIdField__c: '456', name: 'test')
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'multiple subrequests' do
|
86
|
+
client.
|
87
|
+
should_receive(:api_post).
|
88
|
+
with(endpoint, { compositeRequest: [
|
89
|
+
{
|
90
|
+
method: 'POST',
|
91
|
+
url: '/services/data/v38.0/sobjects/Object',
|
92
|
+
body: { name: 'test' },
|
93
|
+
referenceId: 'create_ref'
|
94
|
+
},
|
95
|
+
{
|
96
|
+
method: 'PATCH',
|
97
|
+
url: '/services/data/v38.0/sobjects/Object/123',
|
98
|
+
body: { name: 'test' },
|
99
|
+
referenceId: 'update_ref'
|
100
|
+
},
|
101
|
+
{
|
102
|
+
method: 'DELETE',
|
103
|
+
url: '/services/data/v38.0/sobjects/Object/123',
|
104
|
+
referenceId: 'destroy_ref'
|
105
|
+
}
|
106
|
+
], allOrNone: all_or_none, collateSubrequests: false }.to_json).
|
107
|
+
and_return(response)
|
108
|
+
|
109
|
+
client.send(method) do |subrequests|
|
110
|
+
subrequests.create('Object', 'create_ref', name: 'test')
|
111
|
+
subrequests.update('Object', 'update_ref', id: '123', name: 'test')
|
112
|
+
subrequests.destroy('Object', 'destroy_ref', '123')
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'fails if more than 25 requests' do
|
117
|
+
expect do
|
118
|
+
client.send(method) do |subrequests|
|
119
|
+
26.times do |i|
|
120
|
+
subrequests.upsert('Object', "upsert_ref_#{i}", 'extIdField__c',
|
121
|
+
extIdField__c: '456', name: 'test')
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end.to raise_error(ArgumentError)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
describe '#composite' do
|
129
|
+
let(:method) { :composite }
|
130
|
+
let(:all_or_none) { false }
|
131
|
+
let(:response) { double('Faraday::Response', body: { 'CompositeResponse' => [] }) }
|
132
|
+
it_behaves_like 'composite requests'
|
133
|
+
end
|
134
|
+
|
135
|
+
describe '#composite!' do
|
136
|
+
let(:method) { :composite! }
|
137
|
+
let(:all_or_none) { true }
|
138
|
+
let(:response) do
|
139
|
+
double('Faraday::Response', body: { 'CompositeResponse' => [] })
|
140
|
+
end
|
141
|
+
it_behaves_like 'composite requests'
|
142
|
+
end
|
143
|
+
end
|
@@ -13,10 +13,10 @@ describe Restforce::Concerns::Streaming, event_machine: true do
|
|
13
13
|
it 'subscribes to the topics with faye' do
|
14
14
|
faye_double.
|
15
15
|
should_receive(:subscribe).
|
16
|
-
with(channels
|
16
|
+
with(channels)
|
17
17
|
client.stub faye: faye_double
|
18
18
|
|
19
|
-
client.subscription(channels
|
19
|
+
client.subscription(channels)
|
20
20
|
end
|
21
21
|
|
22
22
|
context "replay_handlers" do
|
@@ -87,7 +87,7 @@ describe Restforce::Concerns::Streaming, event_machine: true do
|
|
87
87
|
end
|
88
88
|
|
89
89
|
it 'connects to the streaming api' do
|
90
|
-
client.stub authenticate!:
|
90
|
+
client.stub authenticate!: double(access_token: 'secret2')
|
91
91
|
faye_double = double('Faye::Client')
|
92
92
|
Faye::Client.
|
93
93
|
should_receive(:new).
|
@@ -110,7 +110,7 @@ describe Restforce::Concerns::Streaming, event_machine: true do
|
|
110
110
|
end
|
111
111
|
end
|
112
112
|
|
113
|
-
describe
|
113
|
+
describe "ReplayExtension" do
|
114
114
|
let(:handlers) { {} }
|
115
115
|
let(:extension) { Restforce::Concerns::Streaming::ReplayExtension.new(handlers) }
|
116
116
|
|
data/spec/unit/config_spec.rb
CHANGED
@@ -17,14 +17,14 @@ describe Restforce::Middleware::Authentication::JWTBearer do
|
|
17
17
|
let(:success_request) do
|
18
18
|
stub_login_request(
|
19
19
|
body: "grant_type=grant_type—urn:ietf:params:oauth:grant-type:jwt-bearer&" \
|
20
|
-
|
20
|
+
"assertion=abc1234567890"
|
21
21
|
).to_return(status: 200, body: fixture(:auth_success_response))
|
22
22
|
end
|
23
23
|
|
24
24
|
let(:fail_request) do
|
25
25
|
stub_login_request(
|
26
26
|
body: "grant_type=grant_type—urn:ietf:params:oauth:grant-type:jwt-bearer&" \
|
27
|
-
|
27
|
+
"assertion=abc1234567890"
|
28
28
|
).to_return(status: 400, body: fixture(:refresh_error_response))
|
29
29
|
end
|
30
30
|
end
|
@@ -47,14 +47,14 @@ describe Restforce::Middleware::Authentication::JWTBearer do
|
|
47
47
|
let(:success_request) do
|
48
48
|
stub_login_request(
|
49
49
|
body: "grant_type=grant_type—urn:ietf:params:oauth:grant-type:jwt-bearer&" \
|
50
|
-
|
50
|
+
"assertion=abc1234567890"
|
51
51
|
).to_return(status: 200, body: fixture(:auth_success_response))
|
52
52
|
end
|
53
53
|
|
54
54
|
let(:fail_request) do
|
55
55
|
stub_login_request(
|
56
56
|
body: "grant_type=grant_type—urn:ietf:params:oauth:grant-type:jwt-bearer&" \
|
57
|
-
|
57
|
+
"assertion=abc1234567890"
|
58
58
|
).to_return(status: 400, body: fixture(:refresh_error_response))
|
59
59
|
end
|
60
60
|
end
|
@@ -17,14 +17,14 @@ describe Restforce::Middleware::Authentication::Password do
|
|
17
17
|
let(:success_request) do
|
18
18
|
stub_login_request(
|
19
19
|
body: "grant_type=password&client_id=client_id&client_secret=client_secret" \
|
20
|
-
|
20
|
+
"&username=foo&password=barsecurity_token"
|
21
21
|
).to_return(status: 200, body: fixture(:auth_success_response))
|
22
22
|
end
|
23
23
|
|
24
24
|
let(:fail_request) do
|
25
25
|
stub_login_request(
|
26
26
|
body: "grant_type=password&client_id=client_id&client_secret=client_secret" \
|
27
|
-
|
27
|
+
"&username=foo&password=barsecurity_token"
|
28
28
|
).to_return(status: 400, body: fixture(:auth_error_response))
|
29
29
|
end
|
30
30
|
end
|
@@ -15,14 +15,14 @@ describe Restforce::Middleware::Authentication::Token do
|
|
15
15
|
let(:success_request) do
|
16
16
|
stub_login_request(
|
17
17
|
body: "grant_type=refresh_token&refresh_token=refresh_token&" \
|
18
|
-
|
18
|
+
"client_id=client_id&client_secret=client_secret"
|
19
19
|
).to_return(status: 200, body: fixture(:auth_success_response))
|
20
20
|
end
|
21
21
|
|
22
22
|
let(:fail_request) do
|
23
23
|
stub_login_request(
|
24
24
|
body: "grant_type=refresh_token&refresh_token=refresh_token&" \
|
25
|
-
|
25
|
+
"client_id=client_id&client_secret=client_secret"
|
26
26
|
).to_return(status: 400, body: fixture(:refresh_error_response))
|
27
27
|
end
|
28
28
|
end
|
@@ -58,11 +58,11 @@ describe Restforce::Middleware::Gzip do
|
|
58
58
|
env[:response_headers]['Content-Encoding'] = 'gzip'
|
59
59
|
end
|
60
60
|
|
61
|
-
it { should
|
61
|
+
it { should be true }
|
62
62
|
end
|
63
63
|
|
64
64
|
context 'when not gzipped' do
|
65
|
-
it { should
|
65
|
+
it { should be false }
|
66
66
|
end
|
67
67
|
end
|
68
68
|
end
|
@@ -14,8 +14,10 @@ describe Restforce::Middleware::RaiseError do
|
|
14
14
|
let(:status) { 404 }
|
15
15
|
|
16
16
|
it 'raises Restforce::NotFoundError' do
|
17
|
-
expect { on_complete }.to raise_error
|
18
|
-
|
17
|
+
expect { on_complete }.to raise_error do |error|
|
18
|
+
expect(error).to be_a Restforce::NotFoundError
|
19
|
+
expect(error.message).to start_with("INVALID_FIELD: error_message")
|
20
|
+
end
|
19
21
|
end
|
20
22
|
|
21
23
|
it 'raises an error that inherits from Faraday::ResourceNotFound' do
|
@@ -40,8 +42,10 @@ describe Restforce::Middleware::RaiseError do
|
|
40
42
|
let(:status) { 400 }
|
41
43
|
|
42
44
|
it "raises an error derived from the response's errorCode" do
|
43
|
-
expect { on_complete }.to raise_error
|
44
|
-
|
45
|
+
expect { on_complete }.to raise_error do |error|
|
46
|
+
expect(error).to be_a Restforce::ErrorCode::InvalidField
|
47
|
+
expect(error.message).to start_with("INVALID_FIELD: error_message")
|
48
|
+
end
|
45
49
|
end
|
46
50
|
|
47
51
|
it 'raises an error that inherits from Faraday::ClientError' do
|
@@ -53,8 +57,10 @@ describe Restforce::Middleware::RaiseError do
|
|
53
57
|
let(:status) { 401 }
|
54
58
|
|
55
59
|
it 'raises Restforce::UnauthorizedError' do
|
56
|
-
expect { on_complete }.to raise_error
|
57
|
-
|
60
|
+
expect { on_complete }.to raise_error do |error|
|
61
|
+
expect(error).to be_a Restforce::UnauthorizedError
|
62
|
+
expect(error.message).to start_with("INVALID_FIELD: error_message")
|
63
|
+
end
|
58
64
|
end
|
59
65
|
end
|
60
66
|
|
@@ -76,13 +82,17 @@ describe Restforce::Middleware::RaiseError do
|
|
76
82
|
let(:status) { 400 }
|
77
83
|
|
78
84
|
it 'raises a generic Restforce::ResponseError' do
|
79
|
-
expect { on_complete }.to raise_error
|
80
|
-
|
85
|
+
expect { on_complete }.to raise_error do |error|
|
86
|
+
expect(error).to be_a Restforce::ResponseError
|
87
|
+
expect(error.message).to start_with("(error code missing): An error occured")
|
88
|
+
end
|
81
89
|
end
|
82
90
|
|
83
91
|
it 'raises an error that inherits from Faraday::ClientError' do
|
84
|
-
expect { on_complete }.to raise_error
|
85
|
-
|
92
|
+
expect { on_complete }.to raise_error do |error|
|
93
|
+
expect(error).to be_a Faraday::ClientError
|
94
|
+
expect(error.message).to start_with("(error code missing): An error occured")
|
95
|
+
end
|
86
96
|
end
|
87
97
|
end
|
88
98
|
|