restforce 2.1.1 → 2.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c933281225117c041f54a23bd3141f5c8d1f9e8d
4
- data.tar.gz: 153b2c10c1dca6035afb0675d5ebeab94ce27df9
3
+ metadata.gz: 307702db9af787319aab32acd6a4d2d6969be792
4
+ data.tar.gz: b62523a1931297c0598f7c52043b5e4dbf0afe0b
5
5
  SHA512:
6
- metadata.gz: fac6beab45f4f1819edbb8f58195c9a6b9e085cc5dfb9fce2903231fe6bed89a3da30e142053b86860e7636ec7d331424cd0f9c3e5b29b6692bc3a5e1fd1b145
7
- data.tar.gz: aa9bcae26b2041087aa53d81ee27b77d3b224f54f8e0732a54b8a0210680aaaf33f174aa35666599646e49cbf96d56d272b43c18b77eb9c2f8caa9b85f531089
6
+ metadata.gz: f8a11572c3132c5f223ddc6d3159908957c4a250b4fb7805a4156c7f258e5789b30a58c6ce93a07f23c86d8b1068741a041326c8d5c8dcaad7f7c7bee4c7ba35
7
+ data.tar.gz: 17d37b8a1b9546fd3b90e211c73baa7ae6bb3cd7c429a22dd8f062c3e90a59bbfe5fe20aa36e86ed70ba8d10895c0b01f952edb099ebe52da69d2de6fa11f53e
data/README.md CHANGED
@@ -483,6 +483,8 @@ created/updated.
483
483
 
484
484
  _See also: [Force.com Streaming API docs](http://www.salesforce.com/us/developer/docs/api_streaming/index.htm)_
485
485
 
486
+ *Note:* Restforce's streaming implementation is known to be compatible with version `0.8.9` of the faye gem.
487
+
486
488
  * * *
487
489
 
488
490
  ### Caching
@@ -601,4 +603,4 @@ Using the scripts in `./script` instead of `bundle exec rspec`, `bundle console`
601
603
  2. Create your feature branch (`git checkout -b my-new-feature`)
602
604
  3. Commit your changes (`git commit -am 'Added some feature'`)
603
605
  4. Push to the branch (`git push origin my-new-feature`)
604
- 5. Create new Pull Request
606
+ 5. Create new Pull Request
@@ -38,14 +38,14 @@ module Restforce
38
38
  builder.use Restforce::Middleware::Authorization, self, options
39
39
  # Ensures the instance url is set.
40
40
  builder.use Restforce::Middleware::InstanceURL, self, options
41
- # Parses returned JSON response into a hash.
42
- builder.response :json, content_type: /\bjson$/
43
41
  # Caches GET requests.
44
42
  builder.use Restforce::Middleware::Caching, cache, options if cache
45
43
  # Follows 30x redirects.
46
44
  builder.use FaradayMiddleware::FollowRedirects
47
45
  # Raises errors for 40x responses.
48
46
  builder.use Restforce::Middleware::RaiseError
47
+ # Parses returned JSON response into a hash.
48
+ builder.response :json, content_type: /\bjson$/
49
49
  # Log request/responses
50
50
  builder.use Restforce::Middleware::Logger,
51
51
  Restforce.configuration.logger,
@@ -18,7 +18,7 @@ module Restforce
18
18
  end
19
19
 
20
20
  def use_cache?
21
- !@options.key?(:use_cache) || @options[:use_cache]
21
+ @options.fetch(:use_cache, true)
22
22
  end
23
23
  end
24
24
  end
@@ -16,11 +16,18 @@ module Restforce
16
16
  end
17
17
 
18
18
  def message
19
- "#{body.first['errorCode']}: #{body.first['message']}"
19
+ "#{body['errorCode']}: #{body['message']}"
20
20
  end
21
21
 
22
22
  def body
23
- JSON.parse(@env[:body])
23
+ @body = (@env[:body].respond_to?(:first) ? @env[:body].first : @env[:body])
24
+
25
+ case @body
26
+ when Hash
27
+ @body
28
+ else
29
+ { 'errorCode' => '(error code missing)', 'message' => @body }
30
+ end
24
31
  end
25
32
 
26
33
  def response_values
@@ -1,3 +1,3 @@
1
1
  module Restforce
2
- VERSION = '2.1.1'
2
+ VERSION = '2.1.2'
3
3
  end
@@ -100,13 +100,22 @@ shared_examples_for Restforce::AbstractClient do
100
100
  status: 404,
101
101
  fixture: 'sobject/delete_error_response'
102
102
 
103
+ let(:error) do
104
+ JSON.parse(fixture('sobject/delete_error_response'))
105
+ end
106
+
103
107
  subject do
104
108
  lambda do
105
109
  client.update!('Account', Id: '001D000000INjVe', Name: 'Foobar')
106
110
  end
107
111
  end
108
112
 
109
- it { should raise_error Faraday::Error::ResourceNotFound }
113
+ it {
114
+ should raise_error(
115
+ Faraday::Error::ResourceNotFound,
116
+ "#{error.first['errorCode']}: #{error.first['message']}"
117
+ )
118
+ }
110
119
  end
111
120
  end
112
121
 
@@ -317,17 +326,20 @@ shared_examples_for Restforce::AbstractClient do
317
326
  end
318
327
 
319
328
  describe '.without_caching' do
320
- requests 'query\?q=SELECT%20some,%20fields%20FROM%20object',
321
- fixture: 'sobject/query_success_response'
329
+ let(:cache) { MockCache.new }
322
330
 
323
- before do
324
- cache.should_receive(:delete).and_call_original
325
- cache.should_receive(:fetch).and_call_original
331
+ it 'deletes the cached value before querying the API' do
332
+ stub = stub_api_request(
333
+ 'query\?q=SELECT%20some,%20fields%20FROM%20object',
334
+ fixture: 'sobject/query_success_response'
335
+ )
336
+ client.query('SELECT some, fields FROM object')
337
+
338
+ expect(cache).to receive(:delete).and_call_original.ordered
339
+ expect(cache).to receive(:read).and_call_original.ordered
340
+ client.without_caching { client.query('SELECT some, fields FROM object') }
341
+ expect(stub).to have_been_requested.twice
326
342
  end
327
-
328
- let(:cache) { MockCache.new }
329
- subject { client.without_caching { client.query('SELECT some, fields FROM object') } }
330
- it { should be_an Enumerable }
331
343
  end
332
344
 
333
345
  describe 'authentication retries' do
@@ -3,6 +3,14 @@ class MockCache
3
3
  @storage = {}
4
4
  end
5
5
 
6
+ def read(key)
7
+ @storage[key]
8
+ end
9
+
10
+ def write(key, value)
11
+ @storage[key] = value
12
+ end
13
+
6
14
  def fetch(key, &block)
7
15
  @storage[key] ||= block.call
8
16
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Restforce::Middleware::RaiseError do
4
- let(:body) { fixture('sobject/query_error_response') }
4
+ let(:body) { JSON.parse(fixture('sobject/query_error_response')) }
5
5
  let(:env) { { status: status, body: body } }
6
6
  let(:middleware) { described_class.new app }
7
7
 
@@ -37,12 +37,21 @@ describe Restforce::Middleware::RaiseError do
37
37
 
38
38
  context 'when the status code is 413' do
39
39
  let(:status) { 413 }
40
- let(:body) { '' } # Zero length response
41
40
 
42
41
  it "raises an error" do
43
42
  expect { on_complete }.to raise_error Faraday::Error::ClientError,
44
43
  'HTTP 413 - Request Entity Too Large'
45
44
  end
46
45
  end
46
+
47
+ context 'when status is 400+ and body is a string' do
48
+ let(:body) { 'An error occured' }
49
+ let(:status) { 404 }
50
+
51
+ it 'raises an error with a non-existing error code' do
52
+ expect { on_complete }.to raise_error Faraday::Error::ClientError,
53
+ "(error code missing): #{body}"
54
+ end
55
+ end
47
56
  end
48
57
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restforce
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric J. Holmes
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-08-20 00:00:00.000000000 Z
12
+ date: 2015-11-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday