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.

Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +60 -0
  3. data/.rubocop_todo.yml +117 -0
  4. data/.travis.yml +3 -5
  5. data/CHANGELOG.md +6 -0
  6. data/README.md +2 -0
  7. data/Rakefile +1 -1
  8. data/lib/restforce/abstract_client.rb +1 -1
  9. data/lib/restforce/attachment.rb +1 -3
  10. data/lib/restforce/concerns/api.rb +22 -17
  11. data/lib/restforce/concerns/authentication.rb +4 -3
  12. data/lib/restforce/concerns/base.rb +42 -31
  13. data/lib/restforce/concerns/caching.rb +1 -3
  14. data/lib/restforce/concerns/canvas.rb +0 -2
  15. data/lib/restforce/concerns/connection.rb +18 -12
  16. data/lib/restforce/concerns/picklists.rb +10 -10
  17. data/lib/restforce/concerns/streaming.rb +9 -4
  18. data/lib/restforce/concerns/verbs.rb +0 -2
  19. data/lib/restforce/config.rb +19 -13
  20. data/lib/restforce/data/client.rb +8 -1
  21. data/lib/restforce/mash.rb +6 -10
  22. data/lib/restforce/middleware.rb +3 -1
  23. data/lib/restforce/middleware/authentication.rb +21 -7
  24. data/lib/restforce/middleware/authentication/password.rb +5 -9
  25. data/lib/restforce/middleware/authentication/token.rb +4 -8
  26. data/lib/restforce/middleware/authorization.rb +0 -3
  27. data/lib/restforce/middleware/caching.rb +4 -4
  28. data/lib/restforce/middleware/instance_url.rb +3 -5
  29. data/lib/restforce/middleware/logger.rb +7 -7
  30. data/lib/restforce/middleware/mashify.rb +2 -3
  31. data/lib/restforce/middleware/multipart.rb +15 -8
  32. data/lib/restforce/middleware/raise_error.rb +2 -1
  33. data/lib/restforce/patches/parts.rb +2 -3
  34. data/lib/restforce/signed_request.rb +2 -2
  35. data/lib/restforce/sobject.rb +1 -3
  36. data/lib/restforce/tooling/client.rb +1 -3
  37. data/lib/restforce/upload_io.rb +1 -3
  38. data/lib/restforce/version.rb +1 -1
  39. data/restforce.gemspec +7 -4
  40. data/spec/integration/abstract_client_spec.rb +123 -75
  41. data/spec/integration/data/client_spec.rb +24 -12
  42. data/spec/spec_helper.rb +2 -2
  43. data/spec/support/client_integration.rb +23 -17
  44. data/spec/support/concerns.rb +2 -2
  45. data/spec/support/event_machine.rb +3 -3
  46. data/spec/support/fixture_helpers.rb +16 -12
  47. data/spec/support/middleware.rb +16 -8
  48. data/spec/unit/abstract_client_spec.rb +1 -1
  49. data/spec/unit/attachment_spec.rb +2 -1
  50. data/spec/unit/collection_spec.rb +13 -4
  51. data/spec/unit/concerns/api_spec.rb +15 -13
  52. data/spec/unit/concerns/authentication_spec.rb +20 -17
  53. data/spec/unit/concerns/base_spec.rb +2 -2
  54. data/spec/unit/concerns/caching_spec.rb +2 -2
  55. data/spec/unit/concerns/canvas_spec.rb +3 -3
  56. data/spec/unit/concerns/connection_spec.rb +6 -7
  57. data/spec/unit/concerns/streaming_spec.rb +8 -8
  58. data/spec/unit/config_spec.rb +6 -6
  59. data/spec/unit/data/client_spec.rb +1 -1
  60. data/spec/unit/mash_spec.rb +1 -1
  61. data/spec/unit/middleware/authentication/password_spec.rb +14 -12
  62. data/spec/unit/middleware/authentication/token_spec.rb +12 -10
  63. data/spec/unit/middleware/authentication_spec.rb +15 -11
  64. data/spec/unit/middleware/authorization_spec.rb +1 -1
  65. data/spec/unit/middleware/gzip_spec.rb +1 -1
  66. data/spec/unit/middleware/instance_url_spec.rb +2 -2
  67. data/spec/unit/middleware/mashify_spec.rb +2 -2
  68. data/spec/unit/middleware/raise_error_spec.rb +23 -7
  69. data/spec/unit/sobject_spec.rb +16 -9
  70. data/spec/unit/tooling/client_spec.rb +1 -1
  71. 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 { lambda { client.authenticate! } }
5
+ subject(:authenticate!) { client.authenticate! }
6
6
 
7
7
  context 'when there is no authentication middleware' do
8
8
  before do
9
- client.stub :authentication_middleware => nil
9
+ client.stub authentication_middleware: nil
10
10
  end
11
11
 
12
- it { should raise_error Restforce::AuthenticationError, 'No authentication middleware present' }
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 :authentication_middleware => authentication_middleware
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(:authenticate! => 'foo'))
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 :username_password? => true
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 :username_password? => false
45
- client.stub :oauth_refresh? => true
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 :options => options
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
- { :username => 'foo',
63
- :password => 'bar',
64
- :client_id => 'client',
65
- :client_secret => 'secret' }
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 :options => options
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
- { :refresh_token => 'token',
87
- :client_id => 'client',
88
- :client_secret => 'secret' }
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 :options => { :instance_url => 'foo' }
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 :options => options
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 :options => options
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) { { :client_secret => 'secret' } }
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, :builder => builder
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) { {:adapter => Faraday.default_adapter} }
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(:options => options)
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!(:mashify => true)
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!(:mashify => false)
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 :options => {:adapter => :typhoeus}
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, :event_machine => true do
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 :faye => faye_double
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 :options => {
26
- :instance_url => '/url',
27
- :api_version => '30.0',
28
- :oauth_token => 'secret'
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 :authenticate! => OpenStruct.new({ :access_token => 'secret2' })
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).
@@ -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, :timeout,
57
- :oauth_token, :refresh_token, :instance_url, :api_version, :host, :authentication_retries,
58
- :proxy_uri, :authentication_callback, :mashify].each do |attr|
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 :log? => false
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 :log? => true
90
+ Restforce.stub log?: true
91
91
  Restforce.configuration.logger.should_receive(:debug).with('foobar')
92
92
  end
93
93
 
@@ -7,4 +7,4 @@ describe Restforce::Client do
7
7
  it { should < Restforce::Concerns::Picklists }
8
8
  it { should < Restforce::Concerns::Streaming }
9
9
  it { should < Restforce::Concerns::Canvas }
10
- end
10
+ end
@@ -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) { [{ :foo => 'hello' }, { :bar => 'world' }] }
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
- { :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' }
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(:body => "grant_type=password&client_id=client_id&client_secret=" \
16
- "client_secret&username=foo&password=barsecurity_token").
17
- to_return(:status => 200, :body => fixture(:auth_success_response))
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(:body => "grant_type=password&client_id=client_id&client_secret=" \
22
- "client_secret&username=foo&password=barsecurity_token").
23
- to_return(:status => 400, :body => fixture(:auth_error_response))
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
- { :host => 'login.salesforce.com',
6
- :refresh_token => 'refresh_token',
7
- :client_id => 'client_id',
8
- :client_secret => 'client_secret' }
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(:body => "grant_type=refresh_token&refresh_token=refresh_token&" \
14
- "client_id=client_id&client_secret=client_secret").
15
- to_return(:status => 200, :body => fixture(:auth_success_response))
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(:body => "grant_type=refresh_token&refresh_token=refresh_token&" \
20
- "client_id=client_id&client_secret=client_secret").
21
- to_return(:status => 400, :body => fixture(:refresh_error_response))
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
- { :host => 'login.salesforce.com',
6
- :proxy_uri => 'https://not-a-real-site.com',
7
- :authentication_retries => retries }
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 :body => 'foo', :request => { :proxy => nil }
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 :log? => false
52
+ Restforce.stub log?: false
53
53
  end
54
54
 
55
- its(:handlers) { should include FaradayMiddleware::ParseJson,
56
- Faraday::Adapter::NetHttp }
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 :log? => true
64
+ Restforce.stub log?: true
63
65
  end
64
66
 
65
- its(:handlers) { should include FaradayMiddleware::ParseJson,
66
- Restforce::Middleware::Logger, Faraday::Adapter::NetHttp }
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
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Restforce::Middleware::Authorization do
4
- let(:options) { { :oauth_token => 'token' } }
4
+ let(:options) { { oauth_token: 'token' } }
5
5
 
6
6
  describe '.call' do
7
7
  subject { lambda { middleware.call(env) } }
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Restforce::Middleware::Gzip do
4
- let(:options) { { :oauth_token => 'token' } }
4
+ let(:options) { { oauth_token: 'token' } }
5
5
 
6
6
  # Return a gzipped string.
7
7
  def gzip(str)