restforce 2.5.2 → 2.5.3

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: 2fe36ce396f2e18efc3f6ca5baa391ba0d3e5ada
4
- data.tar.gz: e968e760eb726434e54576836985732221fd9457
3
+ metadata.gz: 37d2535283740f9a089e2a1fa91dd856b3047180
4
+ data.tar.gz: 68d9358e56b9c9150ac504549ad0baa031f1fa25
5
5
  SHA512:
6
- metadata.gz: 3a60bb6adcd71799a5bdbb4b19a41bfefa9aa554db975e3442ee3c90af2db4489a4f699029617dba0f50c5fe2fe2e0ed535160cfb617211cb0054f1cbc0ea165
7
- data.tar.gz: 9af84717f844c3497bcc357083e468fcb7fe4c50e070dac0465696bfbea001395335a01d18efdc02c29d1375ccd1af98638f6388ef6cca69d87a98bcca30e53e
6
+ metadata.gz: 6968dd3d8edd7559f36225b85325f9b2712836b30cde5e26393e676266013a7267f4e4b36e4273610cb33dda9dea95f8ebff862a021fd817e46528c29e34b04d
7
+ data.tar.gz: d7049225f2af6b649103a7b86b4d4487c0e4af5a4759db4345473d79562e74889384bee64a96c81980a8c9187ceaa6c78843d233413bf5ce291ea7bb714552d0
@@ -1,3 +1,10 @@
1
+ ## 2.5.3 (April 25, 2017)
2
+
3
+ * Raise an error where a custom external ID field name is supplied to `upsert` and `upsert!`, but it is missing from the provided attributes (@velveret)
4
+ * Use the Restforce client's configured SSL options for authentication requests (@jvdp)
5
+ * Fix bug where `upsert` and `upsert!` mutate the provided attributes, previously fixed in [v1.5.3](https://github.com/ejholmes/restforce/blob/master/CHANGELOG.md#153-jun-26-2015) (@velveret)
6
+
7
+
1
8
  ## 2.5.2 (Apr 3, 2017)
2
9
 
3
10
  * Ensure `Restforce::Middleware::Logger` is the last Faraday middleware to be called so everything is properly logged (including the effects of the `Gzip` and `CustomHeaders` middlewares which were previously running after it) (@jonnymacs)
data/Gemfile CHANGED
@@ -3,6 +3,7 @@ gemspec
3
3
 
4
4
  gem 'rake'
5
5
  gem 'jruby-openssl', :platforms => :jruby
6
+ gem 'faraday', '~> 0.11.0'
6
7
 
7
8
  group :development do
8
9
  gem 'guard-rspec'
@@ -3,5 +3,6 @@ gemspec
3
3
 
4
4
  gem 'rake'
5
5
  gem 'rack', '~> 1.6.4'
6
+ gem 'faraday', '~> 0.11.0'
6
7
  gem 'jruby-openssl', :platforms => :jruby
7
8
  gem 'public_suffix', '2.0.3'
data/README.md CHANGED
@@ -25,7 +25,7 @@ Features include:
25
25
 
26
26
  Add this line to your application's Gemfile:
27
27
 
28
- gem 'restforce', '~> 2.5.2'
28
+ gem 'restforce', '~> 2.5.3'
29
29
 
30
30
  And then execute:
31
31
 
@@ -317,7 +317,7 @@ module Restforce
317
317
  # Raises an exception if an error is returned from Salesforce.
318
318
  def update!(sobject, attrs)
319
319
  id = attrs.fetch(attrs.keys.find { |k, v| k.to_s.downcase == 'id' }, nil)
320
- raise ArgumentError, 'Id field missing from attrs.' unless id
320
+ raise ArgumentError, 'ID field missing from provided attributes' unless id
321
321
  attrs_without_id = attrs.reject { |k, v| k.to_s.downcase == "id" }
322
322
  api_patch "sobjects/#{sobject}/#{id}", attrs_without_id
323
323
  true
@@ -361,8 +361,13 @@ module Restforce
361
361
  # error returned if the external ID provided matches multiple records (in which
362
362
  # case the conflicting IDs can be found by looking at the response on the error)
363
363
  def upsert!(sobject, field, attrs)
364
+ attrs = attrs.dup
364
365
  external_id =
365
366
  extract_case_insensitive_string_or_symbol_key_from_hash!(attrs, field)
367
+ if field.to_s != "Id" && (external_id.nil? || external_id.strip.empty?)
368
+ raise ArgumentError, 'Specified external ID field missing from provided ' \
369
+ 'attributes'
370
+ end
366
371
 
367
372
  response =
368
373
  if field.to_s == "Id" && (external_id.nil? || external_id.strip.empty?)
@@ -81,7 +81,8 @@ module Restforce
81
81
 
82
82
  def faraday_options
83
83
  { url: "https://#{@options[:host]}",
84
- proxy: @options[:proxy_uri] }.reject { |k, v| v.nil? }
84
+ proxy: @options[:proxy_uri],
85
+ ssl: @options[:ssl] }
85
86
  end
86
87
  end
87
88
  end
@@ -1,3 +1,3 @@
1
1
  module Restforce
2
- VERSION = '2.5.2'.freeze
2
+ VERSION = '2.5.3'.freeze
3
3
  end
@@ -133,7 +133,7 @@ shared_examples_for Restforce::AbstractClient do
133
133
  describe '.update' do
134
134
  context 'with missing Id' do
135
135
  subject { lambda { client.update('Account', Name: 'Foobar') } }
136
- it { should raise_error ArgumentError, 'Id field missing from attrs.' }
136
+ it { should raise_error ArgumentError, 'ID field missing from provided attributes' }
137
137
  end
138
138
 
139
139
  context 'with invalid Id' do
@@ -282,116 +282,135 @@ describe Restforce::Concerns::API do
282
282
  end
283
283
  end
284
284
 
285
- describe '.create!' do
286
- let(:sobject) { 'Whizbang' }
287
- let(:attrs) { Hash.new }
288
- subject(:result) { client.create!(sobject, attrs) }
289
-
290
- it 'send an HTTP POST, and returns the id of the record' do
291
- response.body.stub(:[]).with('id').and_return('1234')
292
- client.should_receive(:api_post).
293
- with('sobjects/Whizbang', attrs).
294
- and_return(response)
295
- expect(result).to eq '1234'
285
+ context 'methods with attrs' do
286
+ before do
287
+ attrs.freeze
296
288
  end
297
- end
298
289
 
299
- describe '.update!' do
300
- let(:sobject) { 'Whizbang' }
301
- let(:attrs) { Hash.new }
302
- subject(:result) { client.update!(sobject, attrs) }
303
-
304
- context 'when the id field is present' do
305
- let(:attrs) { { id: '1234', StageName: "Call Scheduled" } }
290
+ describe '.create!' do
291
+ let(:sobject) { 'Whizbang' }
292
+ let(:attrs) { Hash.new }
293
+ subject(:result) { client.create!(sobject, attrs) }
306
294
 
307
- it 'sends an HTTP PATCH, and returns true' do
308
- client.should_receive(:api_patch).
309
- with('sobjects/Whizbang/1234', StageName: "Call Scheduled")
310
- expect(result).to be_true
295
+ it 'send an HTTP POST, and returns the id of the record' do
296
+ response.body.stub(:[]).with('id').and_return('1234')
297
+ client.should_receive(:api_post).
298
+ with('sobjects/Whizbang', attrs).
299
+ and_return(response)
300
+ expect(result).to eq '1234'
311
301
  end
312
302
  end
313
303
 
314
- context 'when the id field is missing from the attrs' do
315
- subject { lambda { result } }
316
- it { should raise_error ArgumentError, 'Id field missing from attrs.' }
317
- end
318
- end
304
+ describe '.update!' do
305
+ let(:sobject) { 'Whizbang' }
306
+ let(:attrs) { Hash.new }
307
+ subject(:result) { client.update!(sobject, attrs) }
319
308
 
320
- describe '.upsert!' do
321
- let(:sobject) { 'Whizbang' }
322
- let(:field) { :External_ID__c }
323
- let(:attrs) { { 'External_ID__c' => '1234' } }
324
- subject(:result) { client.upsert!(sobject, field, attrs) }
325
-
326
- context 'when the record is found and updated' do
327
- it 'returns true' do
328
- response.body.stub :[]
329
- client.should_receive(:api_patch).
330
- with('sobjects/Whizbang/External_ID__c/1234', {}).
331
- and_return(response)
332
- expect(result).to be_true
309
+ context 'when the id field is present' do
310
+ let(:attrs) { { id: '1234', StageName: "Call Scheduled" } }
311
+
312
+ it 'sends an HTTP PATCH, and returns true' do
313
+ client.should_receive(:api_patch).
314
+ with('sobjects/Whizbang/1234', StageName: "Call Scheduled")
315
+ expect(result).to be_true
316
+ end
333
317
  end
334
- end
335
318
 
336
- context 'when the record is found and created' do
337
- it 'returns the id of the record' do
338
- response.body.stub(:[]).with('id').and_return('4321')
339
- client.should_receive(:api_patch).
340
- with('sobjects/Whizbang/External_ID__c/1234', {}).
341
- and_return(response)
342
- expect(result).to eq '4321'
319
+ context 'when the id field is missing from the attrs' do
320
+ it "raises an error" do
321
+ expect { client.update!(sobject, attrs) }.
322
+ to raise_error(ArgumentError, 'ID field missing from provided attributes')
323
+ end
343
324
  end
344
325
  end
345
326
 
346
- context 'when using Id as the attribute' do
347
- let(:field) { :Id }
348
- let(:attrs) { { 'Id' => '4321' } }
327
+ describe '.upsert!' do
328
+ let(:sobject) { 'Whizbang' }
329
+ let(:field) { :External_ID__c }
330
+ let(:attrs) { { 'External_ID__c' => '1234' } }
331
+ subject(:result) { client.upsert!(sobject, field, attrs) }
349
332
 
350
- context 'and the value for Id is provided' do
333
+ context 'when the record is found and updated' do
334
+ it 'returns true' do
335
+ response.body.stub :[]
336
+ client.should_receive(:api_patch).
337
+ with('sobjects/Whizbang/External_ID__c/1234', {}).
338
+ and_return(response)
339
+ expect(result).to be_true
340
+ end
341
+ end
342
+
343
+ context 'when the record is found and created' do
351
344
  it 'returns the id of the record' do
352
345
  response.body.stub(:[]).with('id').and_return('4321')
353
346
  client.should_receive(:api_patch).
354
- with('sobjects/Whizbang/Id/4321', {}).
347
+ with('sobjects/Whizbang/External_ID__c/1234', {}).
355
348
  and_return(response)
356
349
  expect(result).to eq '4321'
357
350
  end
358
351
  end
359
352
 
360
- context 'and no value for Id is provided' do
361
- let(:attrs) { { 'External_ID__c' => '1234' } }
353
+ context 'when the external id field is missing from the attrs' do
354
+ let(:attrs) { Hash.new }
362
355
 
363
- it 'uses POST to create the record' do
364
- response.body.stub(:[]).with('id').and_return('4321')
365
- client.should_receive(:options).and_return(api_version: 38.0)
366
- client.should_receive(:api_post).
367
- with('sobjects/Whizbang/Id', attrs).
368
- and_return(response)
369
- expect(result).to eq '4321'
356
+ it 'raises an argument error' do
357
+ expect { client.upsert!(sobject, field, attrs) }.
358
+ to raise_error ArgumentError, 'Specified external ID field missing from ' \
359
+ 'provided attributes'
360
+ end
361
+ end
362
+
363
+ context 'when using Id as the attribute' do
364
+ let(:field) { :Id }
365
+ let(:attrs) { { 'Id' => '4321' } }
366
+
367
+ context 'and the value for Id is provided' do
368
+ it 'returns the id of the record, and original record still contains id' do
369
+ response.body.stub(:[]).with('id').and_return('4321')
370
+ client.should_receive(:api_patch).
371
+ with('sobjects/Whizbang/Id/4321', {}).
372
+ and_return(response)
373
+ expect(result).to eq '4321'
374
+ expect(attrs).to include('Id' => '4321')
375
+ end
370
376
  end
371
377
 
372
- it 'guards functionality for unsupported API versions' do
373
- client.should_receive(:options).and_return(api_version: 35.0)
374
- expect do
375
- client.upsert!(sobject, field, attrs)
376
- end.to raise_error Restforce::APIVersionError
378
+ context 'and no value for Id is provided' do
379
+ let(:attrs) { { 'External_ID__c' => '1234' } }
380
+
381
+ it 'uses POST to create the record' do
382
+ response.body.stub(:[]).with('id').and_return('4321')
383
+ client.should_receive(:options).and_return(api_version: 38.0)
384
+ client.should_receive(:api_post).
385
+ with('sobjects/Whizbang/Id', attrs).
386
+ and_return(response)
387
+ expect(result).to eq '4321'
388
+ end
389
+
390
+ it 'guards functionality for unsupported API versions' do
391
+ client.should_receive(:options).and_return(api_version: 35.0)
392
+ expect do
393
+ client.upsert!(sobject, field, attrs)
394
+ end.to raise_error Restforce::APIVersionError
395
+ end
377
396
  end
378
397
  end
379
398
  end
380
- end
381
399
 
382
- describe '.upsert! with multi bytes character' do
383
- let(:sobject) { 'Whizbang' }
384
- let(:field) { :External_ID__c }
385
- let(:attrs) { { 'External_ID__c' => "\u{3042}" } }
386
- subject(:result) { client.upsert!(sobject, field, attrs) }
387
-
388
- context 'when the record is found and updated' do
389
- it 'returns true' do
390
- response.body.stub :[]
391
- client.should_receive(:api_patch).
392
- with('sobjects/Whizbang/External_ID__c/%E3%81%82', {}).
393
- and_return(response)
394
- expect(result).to be_true
400
+ describe '.upsert! with multi bytes character' do
401
+ let(:sobject) { 'Whizbang' }
402
+ let(:field) { :External_ID__c }
403
+ let(:attrs) { { 'External_ID__c' => "\u{3042}" } }
404
+ subject(:result) { client.upsert!(sobject, field, attrs) }
405
+
406
+ context 'when the record is found and updated' do
407
+ it 'returns true' do
408
+ response.body.stub :[]
409
+ client.should_receive(:api_patch).
410
+ with('sobjects/Whizbang/External_ID__c/%E3%81%82', {}).
411
+ and_return(response)
412
+ expect(result).to be_true
413
+ end
395
414
  end
396
415
  end
397
416
  end
@@ -5,7 +5,8 @@ describe Restforce::Middleware::Authentication do
5
5
  { host: 'login.salesforce.com',
6
6
  proxy_uri: 'https://not-a-real-site.com',
7
7
  authentication_retries: retries,
8
- adapter: :net_http }
8
+ adapter: :net_http,
9
+ ssl: { version: :TLSv1_2 } }
9
10
  end
10
11
 
11
12
  describe '.authenticate!' do
@@ -81,5 +82,9 @@ describe Restforce::Middleware::Authentication do
81
82
  }
82
83
  end
83
84
  end
85
+
86
+ it "should have SSL config set" do
87
+ connection.ssl[:version].should eq(:TLSv1_2)
88
+ end
84
89
  end
85
90
  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.5.2
4
+ version: 2.5.3
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: 2017-04-03 00:00:00.000000000 Z
12
+ date: 2017-04-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday