restforce 1.5.3 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of restforce might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.rubocop.yml +60 -0
- data/.rubocop_todo.yml +117 -0
- data/.travis.yml +3 -5
- data/CHANGELOG.md +6 -0
- data/README.md +2 -0
- data/Rakefile +1 -1
- data/lib/restforce/abstract_client.rb +1 -1
- data/lib/restforce/attachment.rb +1 -3
- data/lib/restforce/concerns/api.rb +22 -17
- data/lib/restforce/concerns/authentication.rb +4 -3
- data/lib/restforce/concerns/base.rb +42 -31
- data/lib/restforce/concerns/caching.rb +1 -3
- data/lib/restforce/concerns/canvas.rb +0 -2
- data/lib/restforce/concerns/connection.rb +18 -12
- data/lib/restforce/concerns/picklists.rb +10 -10
- data/lib/restforce/concerns/streaming.rb +9 -4
- data/lib/restforce/concerns/verbs.rb +0 -2
- data/lib/restforce/config.rb +19 -13
- data/lib/restforce/data/client.rb +8 -1
- data/lib/restforce/mash.rb +6 -10
- data/lib/restforce/middleware.rb +3 -1
- data/lib/restforce/middleware/authentication.rb +21 -7
- data/lib/restforce/middleware/authentication/password.rb +5 -9
- data/lib/restforce/middleware/authentication/token.rb +4 -8
- data/lib/restforce/middleware/authorization.rb +0 -3
- data/lib/restforce/middleware/caching.rb +4 -4
- data/lib/restforce/middleware/instance_url.rb +3 -5
- data/lib/restforce/middleware/logger.rb +7 -7
- data/lib/restforce/middleware/mashify.rb +2 -3
- data/lib/restforce/middleware/multipart.rb +15 -8
- data/lib/restforce/middleware/raise_error.rb +2 -1
- data/lib/restforce/patches/parts.rb +2 -3
- data/lib/restforce/signed_request.rb +2 -2
- data/lib/restforce/sobject.rb +1 -3
- data/lib/restforce/tooling/client.rb +1 -3
- data/lib/restforce/upload_io.rb +1 -3
- data/lib/restforce/version.rb +1 -1
- data/restforce.gemspec +7 -4
- data/spec/integration/abstract_client_spec.rb +123 -75
- data/spec/integration/data/client_spec.rb +24 -12
- data/spec/spec_helper.rb +2 -2
- data/spec/support/client_integration.rb +23 -17
- data/spec/support/concerns.rb +2 -2
- data/spec/support/event_machine.rb +3 -3
- data/spec/support/fixture_helpers.rb +16 -12
- data/spec/support/middleware.rb +16 -8
- data/spec/unit/abstract_client_spec.rb +1 -1
- data/spec/unit/attachment_spec.rb +2 -1
- data/spec/unit/collection_spec.rb +13 -4
- data/spec/unit/concerns/api_spec.rb +15 -13
- data/spec/unit/concerns/authentication_spec.rb +20 -17
- data/spec/unit/concerns/base_spec.rb +2 -2
- data/spec/unit/concerns/caching_spec.rb +2 -2
- data/spec/unit/concerns/canvas_spec.rb +3 -3
- data/spec/unit/concerns/connection_spec.rb +6 -7
- data/spec/unit/concerns/streaming_spec.rb +8 -8
- data/spec/unit/config_spec.rb +6 -6
- data/spec/unit/data/client_spec.rb +1 -1
- data/spec/unit/mash_spec.rb +1 -1
- data/spec/unit/middleware/authentication/password_spec.rb +14 -12
- data/spec/unit/middleware/authentication/token_spec.rb +12 -10
- data/spec/unit/middleware/authentication_spec.rb +15 -11
- data/spec/unit/middleware/authorization_spec.rb +1 -1
- data/spec/unit/middleware/gzip_spec.rb +1 -1
- data/spec/unit/middleware/instance_url_spec.rb +2 -2
- data/spec/unit/middleware/mashify_spec.rb +2 -2
- data/spec/unit/middleware/raise_error_spec.rb +23 -7
- data/spec/unit/sobject_spec.rb +16 -9
- data/spec/unit/tooling/client_spec.rb +1 -1
- metadata +23 -5
@@ -2,14 +2,17 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Restforce::Concerns::Authentication do
|
4
4
|
describe '.authenticate!' do
|
5
|
-
subject {
|
5
|
+
subject(:authenticate!) { client.authenticate! }
|
6
6
|
|
7
7
|
context 'when there is no authentication middleware' do
|
8
8
|
before do
|
9
|
-
client.stub :
|
9
|
+
client.stub authentication_middleware: nil
|
10
10
|
end
|
11
11
|
|
12
|
-
it
|
12
|
+
it "raises an error" do
|
13
|
+
expect { authenticate! }.to raise_error Restforce::AuthenticationError,
|
14
|
+
'No authentication middleware present'
|
15
|
+
end
|
13
16
|
end
|
14
17
|
|
15
18
|
context 'when there is authentication middleware' do
|
@@ -17,12 +20,12 @@ describe Restforce::Concerns::Authentication do
|
|
17
20
|
subject(:result) { client.authenticate! }
|
18
21
|
|
19
22
|
it 'authenticates using the middleware' do
|
20
|
-
client.stub :
|
23
|
+
client.stub authentication_middleware: authentication_middleware
|
21
24
|
client.stub :options
|
22
25
|
authentication_middleware.
|
23
26
|
should_receive(:new).
|
24
27
|
with(nil, client, client.options).
|
25
|
-
and_return(double(
|
28
|
+
and_return(double(authenticate!: 'foo'))
|
26
29
|
expect(result).to eq 'foo'
|
27
30
|
end
|
28
31
|
end
|
@@ -33,7 +36,7 @@ describe Restforce::Concerns::Authentication do
|
|
33
36
|
|
34
37
|
context 'when username and password options are provided' do
|
35
38
|
before do
|
36
|
-
client.stub
|
39
|
+
client.stub username_password?: true
|
37
40
|
end
|
38
41
|
|
39
42
|
it { should eq Restforce::Middleware::Authentication::Password }
|
@@ -41,8 +44,8 @@ describe Restforce::Concerns::Authentication do
|
|
41
44
|
|
42
45
|
context 'when oauth options are provided' do
|
43
46
|
before do
|
44
|
-
client.stub
|
45
|
-
client.stub
|
47
|
+
client.stub username_password?: false
|
48
|
+
client.stub oauth_refresh?: true
|
46
49
|
end
|
47
50
|
|
48
51
|
it { should eq Restforce::Middleware::Authentication::Token }
|
@@ -54,15 +57,15 @@ describe Restforce::Concerns::Authentication do
|
|
54
57
|
let(:options) { Hash.new }
|
55
58
|
|
56
59
|
before do
|
57
|
-
client.stub :
|
60
|
+
client.stub options: options
|
58
61
|
end
|
59
62
|
|
60
63
|
context 'when username and password options are provided' do
|
61
64
|
let(:options) do
|
62
|
-
{ :
|
63
|
-
:
|
64
|
-
:
|
65
|
-
:
|
65
|
+
{ username: 'foo',
|
66
|
+
password: 'bar',
|
67
|
+
client_id: 'client',
|
68
|
+
client_secret: 'secret' }
|
66
69
|
end
|
67
70
|
|
68
71
|
it { should be_true }
|
@@ -78,14 +81,14 @@ describe Restforce::Concerns::Authentication do
|
|
78
81
|
let(:options) { Hash.new }
|
79
82
|
|
80
83
|
before do
|
81
|
-
client.stub :
|
84
|
+
client.stub options: options
|
82
85
|
end
|
83
86
|
|
84
87
|
context 'when oauth options are provided' do
|
85
88
|
let(:options) do
|
86
|
-
{ :
|
87
|
-
:
|
88
|
-
:
|
89
|
+
{ refresh_token: 'token',
|
90
|
+
client_id: 'client',
|
91
|
+
client_secret: 'secret' }
|
89
92
|
end
|
90
93
|
|
91
94
|
it { should be_true }
|
@@ -41,10 +41,10 @@ describe Restforce::Concerns::Base do
|
|
41
41
|
|
42
42
|
context 'when options[:instance_url] is set' do
|
43
43
|
before do
|
44
|
-
client.stub :
|
44
|
+
client.stub options: { instance_url: 'foo' }
|
45
45
|
end
|
46
46
|
|
47
47
|
it { should eq 'foo' }
|
48
48
|
end
|
49
49
|
end
|
50
|
-
end
|
50
|
+
end
|
@@ -5,7 +5,7 @@ describe Restforce::Concerns::Caching do
|
|
5
5
|
let(:options) { double('Options') }
|
6
6
|
|
7
7
|
before do
|
8
|
-
client.stub :
|
8
|
+
client.stub options: options
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'runs the block with caching disabled' do
|
@@ -26,4 +26,4 @@ describe Restforce::Concerns::Caching do
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
29
|
-
end
|
29
|
+
end
|
@@ -4,7 +4,7 @@ describe Restforce::Concerns::Canvas do
|
|
4
4
|
let(:options) { Hash.new }
|
5
5
|
|
6
6
|
before do
|
7
|
-
client.stub :
|
7
|
+
client.stub options: options
|
8
8
|
end
|
9
9
|
|
10
10
|
describe '.decode_signed_request' do
|
@@ -12,7 +12,7 @@ describe Restforce::Concerns::Canvas do
|
|
12
12
|
let(:signed_request) { double('Signed Request') }
|
13
13
|
|
14
14
|
context 'when the client_secret is set' do
|
15
|
-
let(:options) { { :
|
15
|
+
let(:options) { { client_secret: 'secret' } }
|
16
16
|
|
17
17
|
it 'delegates to Restforce::SignedRequest' do
|
18
18
|
Restforce::SignedRequest.should_receive(:decode).
|
@@ -27,4 +27,4 @@ describe Restforce::Concerns::Canvas do
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
30
|
-
end
|
30
|
+
end
|
@@ -6,21 +6,20 @@ describe Restforce::Concerns::Connection do
|
|
6
6
|
let(:builder) { double('Faraday::Builder') }
|
7
7
|
|
8
8
|
before do
|
9
|
-
client.stub_chain :connection, :
|
9
|
+
client.stub_chain :connection, builder: builder
|
10
10
|
end
|
11
11
|
|
12
12
|
it { should eq builder }
|
13
13
|
end
|
14
14
|
|
15
15
|
describe 'private #connection' do
|
16
|
-
|
17
16
|
describe ':mashify option' do
|
18
|
-
let(:options) { {:
|
17
|
+
let(:options) { { adapter: Faraday.default_adapter } }
|
19
18
|
|
20
19
|
before(:each) do
|
21
20
|
client.stub(:authentication_middleware)
|
22
21
|
client.stub(:cache)
|
23
|
-
client.stub(:
|
22
|
+
client.stub(options: options)
|
24
23
|
end
|
25
24
|
|
26
25
|
describe 'with mashify not specified' do
|
@@ -32,7 +31,7 @@ describe Restforce::Concerns::Connection do
|
|
32
31
|
|
33
32
|
describe 'with mashify=true' do
|
34
33
|
before(:each) do
|
35
|
-
options.merge!(:
|
34
|
+
options.merge!(mashify: true)
|
36
35
|
end
|
37
36
|
|
38
37
|
it 'includes the Mashify middleware' do
|
@@ -43,7 +42,7 @@ describe Restforce::Concerns::Connection do
|
|
43
42
|
|
44
43
|
describe 'without mashify' do
|
45
44
|
before(:each) do
|
46
|
-
options.merge!(:
|
45
|
+
options.merge!(mashify: false)
|
47
46
|
end
|
48
47
|
|
49
48
|
it 'does not include the Mashify middleware' do
|
@@ -56,7 +55,7 @@ describe Restforce::Concerns::Connection do
|
|
56
55
|
|
57
56
|
describe '#adapter' do
|
58
57
|
before do
|
59
|
-
client.stub :
|
58
|
+
client.stub options: { adapter: :typhoeus }
|
60
59
|
end
|
61
60
|
|
62
61
|
its(:adapter) { should eq(:typhoeus) }
|
@@ -1,17 +1,17 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Restforce::Concerns::Streaming, :
|
3
|
+
describe Restforce::Concerns::Streaming, event_machine: true do
|
4
4
|
describe '.subscribe' do
|
5
5
|
let(:channels) { %w( channel1 channel2 ) }
|
6
6
|
let(:topics) { channels.map { |c| "/topic/#{c}" } }
|
7
|
-
let(:subscribe_block) { lambda{ 'subscribe' } }
|
7
|
+
let(:subscribe_block) { lambda { 'subscribe' } }
|
8
8
|
let(:faye_double) { double('Faye') }
|
9
9
|
|
10
10
|
it 'subscribes to the topics with faye' do
|
11
11
|
faye_double.
|
12
12
|
should_receive(:subscribe).
|
13
13
|
with(topics, &subscribe_block)
|
14
|
-
client.stub :
|
14
|
+
client.stub faye: faye_double
|
15
15
|
|
16
16
|
client.subscribe(channels, &subscribe_block)
|
17
17
|
end
|
@@ -22,15 +22,15 @@ describe Restforce::Concerns::Streaming, :event_machine => true do
|
|
22
22
|
|
23
23
|
context 'when authenticate! has already been called' do
|
24
24
|
before do
|
25
|
-
client.stub :
|
26
|
-
:
|
27
|
-
:
|
28
|
-
:
|
25
|
+
client.stub options: {
|
26
|
+
instance_url: '/url',
|
27
|
+
api_version: '30.0',
|
28
|
+
oauth_token: 'secret'
|
29
29
|
}
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'connects to the streaming api' do
|
33
|
-
client.stub
|
33
|
+
client.stub authenticate!: OpenStruct.new(access_token: 'secret2')
|
34
34
|
faye_double = double('Faye::Client')
|
35
35
|
Faye::Client.
|
36
36
|
should_receive(:new).
|
data/spec/unit/config_spec.rb
CHANGED
@@ -43,7 +43,7 @@ describe Restforce do
|
|
43
43
|
end
|
44
44
|
|
45
45
|
its(:username) { should eq 'foo' }
|
46
|
-
its(:password) { should eq 'bar'}
|
46
|
+
its(:password) { should eq 'bar' }
|
47
47
|
its(:security_token) { should eq 'foobar' }
|
48
48
|
its(:client_id) { should eq 'client id' }
|
49
49
|
its(:client_secret) { should eq 'client secret' }
|
@@ -53,9 +53,9 @@ describe Restforce do
|
|
53
53
|
end
|
54
54
|
|
55
55
|
describe '#configure' do
|
56
|
-
[:username, :password, :security_token, :client_id, :client_secret, :compress,
|
57
|
-
:oauth_token, :refresh_token, :instance_url, :api_version, :host, :
|
58
|
-
:
|
56
|
+
[:username, :password, :security_token, :client_id, :client_secret, :compress,
|
57
|
+
:timeout, :oauth_token, :refresh_token, :instance_url, :api_version, :host, :mashify,
|
58
|
+
:authentication_retries, :proxy_uri, :authentication_callback].each do |attr|
|
59
59
|
it "allows #{attr} to be set" do
|
60
60
|
Restforce.configure do |config|
|
61
61
|
config.send("#{attr}=", 'foobar')
|
@@ -76,7 +76,7 @@ describe Restforce do
|
|
76
76
|
describe '#log' do
|
77
77
|
context 'with logging disabled' do
|
78
78
|
before do
|
79
|
-
Restforce.stub
|
79
|
+
Restforce.stub log?: false
|
80
80
|
end
|
81
81
|
|
82
82
|
it 'doesnt log anytning' do
|
@@ -87,7 +87,7 @@ describe Restforce do
|
|
87
87
|
|
88
88
|
context 'with logging enabled' do
|
89
89
|
before do
|
90
|
-
Restforce.stub
|
90
|
+
Restforce.stub log?: true
|
91
91
|
Restforce.configuration.logger.should_receive(:debug).with('foobar')
|
92
92
|
end
|
93
93
|
|
data/spec/unit/mash_spec.rb
CHANGED
@@ -5,7 +5,7 @@ describe Restforce::Mash do
|
|
5
5
|
subject { described_class.build(input, nil) }
|
6
6
|
|
7
7
|
context 'when array' do
|
8
|
-
let(:input) { [{ :
|
8
|
+
let(:input) { [{ foo: 'hello' }, { bar: 'world' }] }
|
9
9
|
it { should be_all { |obj| expect(obj).to be_a Restforce::Mash } }
|
10
10
|
end
|
11
11
|
end
|
@@ -2,25 +2,27 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Restforce::Middleware::Authentication::Password do
|
4
4
|
let(:options) do
|
5
|
-
{ :
|
6
|
-
:
|
7
|
-
:
|
8
|
-
:
|
9
|
-
:
|
10
|
-
:
|
5
|
+
{ host: 'login.salesforce.com',
|
6
|
+
username: 'foo',
|
7
|
+
password: 'bar',
|
8
|
+
security_token: 'security_token',
|
9
|
+
client_id: 'client_id',
|
10
|
+
client_secret: 'client_secret' }
|
11
11
|
end
|
12
12
|
|
13
13
|
it_behaves_like 'authentication middleware' do
|
14
14
|
let(:success_request) do
|
15
|
-
stub_login_request(
|
16
|
-
"
|
17
|
-
|
15
|
+
stub_login_request(
|
16
|
+
body: "grant_type=password&client_id=client_id&client_secret=client_secret" \
|
17
|
+
"&username=foo&password=barsecurity_token"
|
18
|
+
).to_return(status: 200, body: fixture(:auth_success_response))
|
18
19
|
end
|
19
20
|
|
20
21
|
let(:fail_request) do
|
21
|
-
stub_login_request(
|
22
|
-
"
|
23
|
-
|
22
|
+
stub_login_request(
|
23
|
+
body: "grant_type=password&client_id=client_id&client_secret=client_secret" \
|
24
|
+
"&username=foo&password=barsecurity_token"
|
25
|
+
).to_return(status: 400, body: fixture(:auth_error_response))
|
24
26
|
end
|
25
27
|
end
|
26
28
|
|
@@ -2,23 +2,25 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Restforce::Middleware::Authentication::Token do
|
4
4
|
let(:options) do
|
5
|
-
{ :
|
6
|
-
:
|
7
|
-
:
|
8
|
-
:
|
5
|
+
{ host: 'login.salesforce.com',
|
6
|
+
refresh_token: 'refresh_token',
|
7
|
+
client_id: 'client_id',
|
8
|
+
client_secret: 'client_secret' }
|
9
9
|
end
|
10
10
|
|
11
11
|
it_behaves_like 'authentication middleware' do
|
12
12
|
let(:success_request) do
|
13
|
-
stub_login_request(
|
14
|
-
"
|
15
|
-
|
13
|
+
stub_login_request(
|
14
|
+
body: "grant_type=refresh_token&refresh_token=refresh_token&" \
|
15
|
+
"client_id=client_id&client_secret=client_secret"
|
16
|
+
).to_return(status: 200, body: fixture(:auth_success_response))
|
16
17
|
end
|
17
18
|
|
18
19
|
let(:fail_request) do
|
19
|
-
stub_login_request(
|
20
|
-
"
|
21
|
-
|
20
|
+
stub_login_request(
|
21
|
+
body: "grant_type=refresh_token&refresh_token=refresh_token&" \
|
22
|
+
"client_id=client_id&client_secret=client_secret"
|
23
|
+
).to_return(status: 400, body: fixture(:refresh_error_response))
|
22
24
|
end
|
23
25
|
end
|
24
26
|
end
|
@@ -2,13 +2,13 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Restforce::Middleware::Authentication do
|
4
4
|
let(:options) do
|
5
|
-
{ :
|
6
|
-
:
|
7
|
-
:
|
5
|
+
{ host: 'login.salesforce.com',
|
6
|
+
proxy_uri: 'https://not-a-real-site.com',
|
7
|
+
authentication_retries: retries }
|
8
8
|
end
|
9
9
|
|
10
10
|
describe '.authenticate!' do
|
11
|
-
subject { lambda { middleware.authenticate! }}
|
11
|
+
subject { lambda { middleware.authenticate! } }
|
12
12
|
it { should raise_error NotImplementedError }
|
13
13
|
end
|
14
14
|
|
@@ -25,7 +25,7 @@ describe Restforce::Middleware::Authentication do
|
|
25
25
|
|
26
26
|
context 'when an exception is thrown' do
|
27
27
|
before do
|
28
|
-
env.stub :
|
28
|
+
env.stub body: 'foo', request: { proxy: nil }
|
29
29
|
middleware.stub :authenticate!
|
30
30
|
app.should_receive(:call).once.
|
31
31
|
and_raise(Restforce::UnauthorizedError.new('something bad'))
|
@@ -49,21 +49,25 @@ describe Restforce::Middleware::Authentication do
|
|
49
49
|
|
50
50
|
context 'with logging disabled' do
|
51
51
|
before do
|
52
|
-
Restforce.stub
|
52
|
+
Restforce.stub log?: false
|
53
53
|
end
|
54
54
|
|
55
|
-
its(:handlers) {
|
56
|
-
|
55
|
+
its(:handlers) {
|
56
|
+
should include FaradayMiddleware::ParseJson,
|
57
|
+
Faraday::Adapter::NetHttp
|
58
|
+
}
|
57
59
|
its(:handlers) { should_not include Restforce::Middleware::Logger }
|
58
60
|
end
|
59
61
|
|
60
62
|
context 'with logging enabled' do
|
61
63
|
before do
|
62
|
-
Restforce.stub
|
64
|
+
Restforce.stub log?: true
|
63
65
|
end
|
64
66
|
|
65
|
-
its(:handlers) {
|
66
|
-
|
67
|
+
its(:handlers) {
|
68
|
+
should include FaradayMiddleware::ParseJson,
|
69
|
+
Restforce::Middleware::Logger, Faraday::Adapter::NetHttp
|
70
|
+
}
|
67
71
|
end
|
68
72
|
end
|
69
73
|
end
|