From 44d5ccf4ff952ea17bdb072d67d0fe9714b44aba Mon Sep 17 00:00:00 2001 From: Yuri Kasperovich Date: Mon, 14 Jan 2019 14:19:48 +0300 Subject: [PATCH 1/5] Add sObject Collections create call --- lib/restforce/concerns/api.rb | 41 +++++++++++++++ ...posite_sobjects_create_error_response.json | 4 ++ ...site_sobjects_create_success_response.json | 7 +++ spec/integration/abstract_client_spec.rb | 50 +++++++++++++++++++ spec/unit/concerns/api_spec.rb | 22 ++++++++ 5 files changed, 124 insertions(+) create mode 100644 spec/fixtures/sobject/composite_sobjects_create_error_response.json create mode 100644 spec/fixtures/sobject/composite_sobjects_create_success_response.json diff --git a/lib/restforce/concerns/api.rb b/lib/restforce/concerns/api.rb index a14960a6..3a3bcc23 100644 --- a/lib/restforce/concerns/api.rb +++ b/lib/restforce/concerns/api.rb @@ -288,6 +288,47 @@ def create!(sobject, attrs) end alias insert! create! + # Public: Insert number of records. + # + # attrs_collection - Collection of attributes for new records. + # all_or_none - Fail all collection if one record creation fails. + # + # Examples + # + # # Add new accounts + # client.create_collection([{Name: 'Foo Inc.'}, {Name: 'Bar Corp.'}]) + # # => [{ 'id' => '0016000000MRatd', 'success' => true, 'errors' => [] }, + # # { 'id' => '0016000000MRert', 'success' => true, 'errors' => [] }] + # + # Returns array of result objects. + # Returns false if something bad happens. + def create_collection(*args) + create_collection!(*args) + rescue *exceptions + false + end + + # Public: Insert number of records. + # + # attrs_collection - Collection of attributes for new records. + # all_or_none - Fail all collection if one record creation fails. + # + # Examples + # + # # Add new accounts + # client.create_collection([{Name: 'Foo Inc.'}, {Name: 'Bar Corp.'}]) + # # => [{ 'id' => '0016000000MRatd', 'success' => true, 'errors' => [] }, + # # { 'id' => '0016000000MRert', 'success' => true, 'errors' => [] }] + # + # Returns array of result objects. + # Raises exceptions if an error is returned from Salesforce. + def create_collection!(attrs_collection, all_or_none = false) + raise ArgumentError, + 'Amount of records to create is limited to 200' if attrs_collection.size > 200 + + api_post('composite/sobjects', {records: attrs_collection, allOrNone: all_or_none}).body + end + # Public: Update a record. # # sobject - String name of the sobject. diff --git a/spec/fixtures/sobject/composite_sobjects_create_error_response.json b/spec/fixtures/sobject/composite_sobjects_create_error_response.json new file mode 100644 index 00000000..9b619018 --- /dev/null +++ b/spec/fixtures/sobject/composite_sobjects_create_error_response.json @@ -0,0 +1,4 @@ +{ + "message": "Json Deserialization failed on token 'null' and has left off in the middle of parsing a row. Will go to end of row to begin parsing the next row", + "errorCode": "INVALID_FIELD" +} diff --git a/spec/fixtures/sobject/composite_sobjects_create_success_response.json b/spec/fixtures/sobject/composite_sobjects_create_success_response.json new file mode 100644 index 00000000..532c1272 --- /dev/null +++ b/spec/fixtures/sobject/composite_sobjects_create_success_response.json @@ -0,0 +1,7 @@ +[ + { + "id": "some_id", + "errors": [ ], + "success": true + } +] diff --git a/spec/integration/abstract_client_spec.rb b/spec/integration/abstract_client_spec.rb index d8c30fe8..77dfbe5c 100644 --- a/spec/integration/abstract_client_spec.rb +++ b/spec/integration/abstract_client_spec.rb @@ -105,6 +105,56 @@ end end + describe '.create_collection!' do + requests 'composite/sobjects', + method: :post, + with_body: { + allOrNone: false, + records: [{Name: 'Foobar'}] + }, + fixture: 'sobject/composite_sobjects_create_success_response' + + subject { client.create_collection!([{Name: 'Foobar'}]) } + + it { should eq [{'id' => 'some_id', 'errors' => [], 'success' => true}] } + + context 'with invalid params' do + requests 'composite/sobjects', + method: :post, + status: 400, + with_body: { + allOrNone: false, + records: ['Foo'] + }, + fixture: 'sobject/composite_sobjects_create_error_response' + + subject { + lambda do + client.create_collection!(['Foo']) + end + } + + it { should raise_error(Faraday::ClientError) } + end + end + + describe '.create_collection' do + context 'with invalid params' do + requests 'composite/sobjects', + method: :post, + status: 400, + with_body: { + allOrNone: false, + records: ['Foo'] + }, + fixture: 'sobject/composite_sobjects_create_error_response' + + subject { client.create_collection(['Foo']) } + + it { should eq false } + end + end + describe '.update!' do context 'with invalid Id' do requests 'sobjects/Account/001D000000INjVe', diff --git a/spec/unit/concerns/api_spec.rb b/spec/unit/concerns/api_spec.rb index e109c8d4..af58c180 100644 --- a/spec/unit/concerns/api_spec.rb +++ b/spec/unit/concerns/api_spec.rb @@ -303,6 +303,28 @@ end end + describe '.create_collection!' do + let(:attrs) { [{'Name' => 'Foobar'}] } + subject(:result) { client.create_collection!(attrs) } + + it 'sends an HTTP POST, and returns list of result objects' do + response.stub(:body).and_return([{'id' => '1', 'success' => true, 'errors' => []}]) + client.should_receive(:api_post). + with('composite/sobjects', {records: attrs, allOrNone: false}). + and_return(response) + expect(result[0]).to eq({'id' => '1', 'success' => true, 'errors' => []}) + end + + context 'when number of records to create is more than 200' do + let(:attrs) { Array.new(201) } + + it "raises an error" do + expect { client.create_collection!(attrs) }.to raise_error( + ArgumentError, 'Amount of records to create is limited to 200') + end + end + end + describe '.update!' do let(:sobject) { 'Whizbang' } let(:attrs) { {} } From ea26ce2c36e0e356e954ff0928bc59cf80f01314 Mon Sep 17 00:00:00 2001 From: Yuri Kasperovich Date: Mon, 14 Jan 2019 15:40:54 +0300 Subject: [PATCH 2/5] Add sObject Collections update call --- lib/restforce/concerns/api.rb | 93 ++++++++--- ...=> composite_sobjects_error_response.json} | 0 ... composite_sobjects_success_response.json} | 0 spec/integration/abstract_client_spec.rb | 150 ++++++++++++------ spec/unit/concerns/api_spec.rb | 66 +++++--- 5 files changed, 211 insertions(+), 98 deletions(-) rename spec/fixtures/sobject/{composite_sobjects_create_error_response.json => composite_sobjects_error_response.json} (100%) rename spec/fixtures/sobject/{composite_sobjects_create_success_response.json => composite_sobjects_success_response.json} (100%) diff --git a/lib/restforce/concerns/api.rb b/lib/restforce/concerns/api.rb index 3a3bcc23..56dc5027 100644 --- a/lib/restforce/concerns/api.rb +++ b/lib/restforce/concerns/api.rb @@ -288,7 +288,46 @@ def create!(sobject, attrs) end alias insert! create! - # Public: Insert number of records. + # Public: Update a record. + # + # sobject - String name of the sobject. + # attrs - Hash of attributes to set on the record. + # + # Examples + # + # # Update the Account with Id '0016000000MRatd' + # client.update('Account', Id: '0016000000MRatd', Name: 'Whizbang Corp') + # + # Returns true if the sobject was successfully updated. + # Returns false if there was an error. + def update(*args) + update!(*args) + rescue *exceptions + false + end + + # Public: Update a record. + # + # sobject - String name of the sobject. + # attrs - Hash of attributes to set on the record. + # + # Examples + # + # # Update the Account with Id '0016000000MRatd' + # client.update!('Account', Id: '0016000000MRatd', Name: 'Whizbang Corp') + # + # Returns true if the sobject was successfully updated. + # Raises an exception if an error is returned from Salesforce. + def update!(sobject, attrs) + id = attrs.fetch(attrs.keys.find { |k, v| k.to_s.casecmp('id').zero? }, nil) + raise ArgumentError, 'ID field missing from provided attributes' unless id + + attrs_without_id = attrs.reject { |k, v| k.to_s.casecmp("id").zero? } + api_patch "sobjects/#{sobject}/#{CGI.escape(id)}", attrs_without_id + true + end + + # Public: Insert collection of records. # # attrs_collection - Collection of attributes for new records. # all_or_none - Fail all collection if one record creation fails. @@ -308,7 +347,7 @@ def create_collection(*args) false end - # Public: Insert number of records. + # Public: Insert collection of records. # # attrs_collection - Collection of attributes for new records. # all_or_none - Fail all collection if one record creation fails. @@ -317,8 +356,8 @@ def create_collection(*args) # # # Add new accounts # client.create_collection([{Name: 'Foo Inc.'}, {Name: 'Bar Corp.'}]) - # # => [{ 'id' => '0016000000MRatd', 'success' => true, 'errors' => [] }, - # # { 'id' => '0016000000MRert', 'success' => true, 'errors' => [] }] + # # => [{ 'id' => '1', 'success' => true, 'errors' => [] }, + # # { 'id' => '2', 'success' => true, 'errors' => [] }] # # Returns array of result objects. # Raises exceptions if an error is returned from Salesforce. @@ -329,43 +368,45 @@ def create_collection!(attrs_collection, all_or_none = false) api_post('composite/sobjects', {records: attrs_collection, allOrNone: all_or_none}).body end - # Public: Update a record. + # Public: Update collection of records. # - # sobject - String name of the sobject. - # attrs - Hash of attributes to set on the record. + # attrs_collection - Collection of attributes for existing records. + # all_or_none - Fail all collection if one record creation fails. # # Examples # - # # Update the Account with Id '0016000000MRatd' - # client.update('Account', Id: '0016000000MRatd', Name: 'Whizbang Corp') + # # Update accounts + # client.update_collection([{Id: '1', Name: 'Foo Inc.'}, {Id: '2', Name: 'Bar Corp.'}]) + # # => [{ 'id' => '1', 'success' => true, 'errors' => [] }, + # # { 'id' => '2', 'success' => true, 'errors' => [] }] # - # Returns true if the sobject was successfully updated. - # Returns false if there was an error. - def update(*args) - update!(*args) + # Returns array of result objects. + # Returns false if something bad happens. + def update_collection(*args) + update_collection!(*args) rescue *exceptions false end - # Public: Update a record. + # Public: Update collection of records. # - # sobject - String name of the sobject. - # attrs - Hash of attributes to set on the record. + # attrs_collection - Collection of attributes for existing records. + # all_or_none - Fail all collection if one record creation fails. # # Examples # - # # Update the Account with Id '0016000000MRatd' - # client.update!('Account', Id: '0016000000MRatd', Name: 'Whizbang Corp') + # # Update accounts + # client.update_collection([{Id: '1', Name: 'Foo Inc.'}, {Id: '2', Name: 'Bar Corp.'}]) + # # => [{ 'id' => '1', 'success' => true, 'errors' => [] }, + # # { 'id' => '2', 'success' => true, 'errors' => [] }] # - # Returns true if the sobject was successfully updated. - # Raises an exception if an error is returned from Salesforce. - def update!(sobject, attrs) - id = attrs.fetch(attrs.keys.find { |k, v| k.to_s.casecmp('id').zero? }, nil) - raise ArgumentError, 'ID field missing from provided attributes' unless id + # Returns array of result objects. + # Raises exceptions if an error is returned from Salesforce. + def update_collection!(attrs_collection, all_or_none = false) + raise ArgumentError, + 'Amount of records to update is limited to 200' if attrs_collection.size > 200 - attrs_without_id = attrs.reject { |k, v| k.to_s.casecmp("id").zero? } - api_patch "sobjects/#{sobject}/#{CGI.escape(id)}", attrs_without_id - true + api_patch('composite/sobjects', {records: attrs_collection, allOrNone: all_or_none}).body end # Public: Update or create a record based on an external ID diff --git a/spec/fixtures/sobject/composite_sobjects_create_error_response.json b/spec/fixtures/sobject/composite_sobjects_error_response.json similarity index 100% rename from spec/fixtures/sobject/composite_sobjects_create_error_response.json rename to spec/fixtures/sobject/composite_sobjects_error_response.json diff --git a/spec/fixtures/sobject/composite_sobjects_create_success_response.json b/spec/fixtures/sobject/composite_sobjects_success_response.json similarity index 100% rename from spec/fixtures/sobject/composite_sobjects_create_success_response.json rename to spec/fixtures/sobject/composite_sobjects_success_response.json diff --git a/spec/integration/abstract_client_spec.rb b/spec/integration/abstract_client_spec.rb index 77dfbe5c..3e154d18 100644 --- a/spec/integration/abstract_client_spec.rb +++ b/spec/integration/abstract_client_spec.rb @@ -105,56 +105,6 @@ end end - describe '.create_collection!' do - requests 'composite/sobjects', - method: :post, - with_body: { - allOrNone: false, - records: [{Name: 'Foobar'}] - }, - fixture: 'sobject/composite_sobjects_create_success_response' - - subject { client.create_collection!([{Name: 'Foobar'}]) } - - it { should eq [{'id' => 'some_id', 'errors' => [], 'success' => true}] } - - context 'with invalid params' do - requests 'composite/sobjects', - method: :post, - status: 400, - with_body: { - allOrNone: false, - records: ['Foo'] - }, - fixture: 'sobject/composite_sobjects_create_error_response' - - subject { - lambda do - client.create_collection!(['Foo']) - end - } - - it { should raise_error(Faraday::ClientError) } - end - end - - describe '.create_collection' do - context 'with invalid params' do - requests 'composite/sobjects', - method: :post, - status: 400, - with_body: { - allOrNone: false, - records: ['Foo'] - }, - fixture: 'sobject/composite_sobjects_create_error_response' - - subject { client.create_collection(['Foo']) } - - it { should eq false } - end - end - describe '.update!' do context 'with invalid Id' do requests 'sobjects/Account/001D000000INjVe', @@ -216,6 +166,106 @@ end end + describe '.create_collection!' do + requests 'composite/sobjects', + method: :post, + with_body: { + allOrNone: false, + records: [{Name: 'Foobar'}] + }, + fixture: 'sobject/composite_sobjects_success_response' + + subject { client.create_collection!([{Name: 'Foobar'}]) } + + it { should eq [{'id' => 'some_id', 'errors' => [], 'success' => true}] } + + context 'with invalid params' do + requests 'composite/sobjects', + method: :post, + status: 400, + with_body: { + allOrNone: false, + records: ['Foo'] + }, + fixture: 'sobject/composite_sobjects_error_response' + + subject { + lambda do + client.create_collection!(['Foo']) + end + } + + it { should raise_error(Faraday::ClientError) } + end + end + + describe '.create_collection' do + context 'with invalid params' do + requests 'composite/sobjects', + method: :post, + status: 400, + with_body: { + allOrNone: false, + records: ['Foo'] + }, + fixture: 'sobject/composite_sobjects_error_response' + + subject { client.create_collection(['Foo']) } + + it { should eq false } + end + end + + describe '.update_collection!' do + requests 'composite/sobjects', + method: :patch, + with_body: { + allOrNone: false, + records: [{Name: 'Foobar'}] + }, + fixture: 'sobject/composite_sobjects_success_response' + + subject { client.update_collection!([{Name: 'Foobar'}]) } + + it { should eq [{'id' => 'some_id', 'errors' => [], 'success' => true}] } + + context 'with invalid params' do + requests 'composite/sobjects', + method: :patch, + status: 400, + with_body: { + allOrNone: false, + records: ['Foo'] + }, + fixture: 'sobject/composite_sobjects_error_response' + + subject { + lambda do + client.update_collection!(['Foo']) + end + } + + it { should raise_error(Faraday::ClientError) } + end + end + + describe '.update_collection' do + context 'with invalid params' do + requests 'composite/sobjects', + method: :patch, + status: 400, + with_body: { + allOrNone: false, + records: ['Foo'] + }, + fixture: 'sobject/composite_sobjects_error_response' + + subject { client.update_collection(['Foo']) } + + it { should eq false } + end + end + describe '.upsert!' do context 'when updated' do requests 'sobjects/Account/External__c/foobar', diff --git a/spec/unit/concerns/api_spec.rb b/spec/unit/concerns/api_spec.rb index af58c180..b6aa697e 100644 --- a/spec/unit/concerns/api_spec.rb +++ b/spec/unit/concerns/api_spec.rb @@ -303,28 +303,6 @@ end end - describe '.create_collection!' do - let(:attrs) { [{'Name' => 'Foobar'}] } - subject(:result) { client.create_collection!(attrs) } - - it 'sends an HTTP POST, and returns list of result objects' do - response.stub(:body).and_return([{'id' => '1', 'success' => true, 'errors' => []}]) - client.should_receive(:api_post). - with('composite/sobjects', {records: attrs, allOrNone: false}). - and_return(response) - expect(result[0]).to eq({'id' => '1', 'success' => true, 'errors' => []}) - end - - context 'when number of records to create is more than 200' do - let(:attrs) { Array.new(201) } - - it "raises an error" do - expect { client.create_collection!(attrs) }.to raise_error( - ArgumentError, 'Amount of records to create is limited to 200') - end - end - end - describe '.update!' do let(:sobject) { 'Whizbang' } let(:attrs) { {} } @@ -358,6 +336,50 @@ end end + describe '.create_collection!' do + let(:attrs) { [{'Name' => 'Foobar'}] } + subject(:result) { client.create_collection!(attrs) } + + it 'sends an HTTP POST, and returns list of result objects' do + response.stub(:body).and_return([{'id' => '1', 'success' => true, 'errors' => []}]) + client.should_receive(:api_post). + with('composite/sobjects', {records: attrs, allOrNone: false}). + and_return(response) + expect(result[0]).to eq({'id' => '1', 'success' => true, 'errors' => []}) + end + + context 'when attributes collection size is more than 200' do + let(:attrs) { Array.new(201) } + + it "raises an error" do + expect { client.create_collection!(attrs) }.to raise_error( + ArgumentError, 'Amount of records to create is limited to 200') + end + end + end + + describe '.update_collection!' do + let(:attrs) { [{'id' => '1', 'Name' => 'Foobar'}] } + subject(:result) { client.update_collection!(attrs) } + + it 'sends an HTTP PATCH, and returns list of result objects' do + response.stub(:body).and_return([{'id' => '1', 'success' => true, 'errors' => []}]) + client.should_receive(:api_patch). + with('composite/sobjects', {records: attrs, allOrNone: false}). + and_return(response) + expect(result[0]).to eq({'id' => '1', 'success' => true, 'errors' => []}) + end + + context 'when attributes collection size is more than 200' do + let(:attrs) { Array.new(201) } + + it "raises an error" do + expect { client.update_collection!(attrs) }.to raise_error( + ArgumentError, 'Amount of records to update is limited to 200') + end + end + end + describe '.upsert!' do let(:sobject) { 'Whizbang' } let(:field) { :External_ID__c } From 8f65abe4c076f4a922abc3a69bd6036cb6e8866b Mon Sep 17 00:00:00 2001 From: Yuri Kasperovich Date: Thu, 24 Jan 2019 23:53:33 +0300 Subject: [PATCH 3/5] Add sObject Collections delete call --- lib/restforce/concerns/api.rb | 37 +++++++++++++++++ ...sobjects_destroy_bad_request_response.json | 6 +++ ...ite_sobjects_destroy_success_response.json | 7 ++++ spec/integration/abstract_client_spec.rb | 40 +++++++++++++++++++ spec/unit/concerns/api_spec.rb | 22 ++++++++++ 5 files changed, 112 insertions(+) create mode 100644 spec/fixtures/sobject/composite_sobjects_destroy_bad_request_response.json create mode 100644 spec/fixtures/sobject/composite_sobjects_destroy_success_response.json diff --git a/lib/restforce/concerns/api.rb b/lib/restforce/concerns/api.rb index 56dc5027..0ed6d0e7 100644 --- a/lib/restforce/concerns/api.rb +++ b/lib/restforce/concerns/api.rb @@ -409,6 +409,43 @@ def update_collection!(attrs_collection, all_or_none = false) api_patch('composite/sobjects', {records: attrs_collection, allOrNone: all_or_none}).body end + # Public: Delete collection of records. + # + # ids - List of IDs of objects to be deleted. + # all_or_none - Roll back the entire request when the deletion of any object fails. + # + # Examples + # + # # Delete collection of records + # client.destroy('0016000000MRatd', '0016000000ERats') + # + # Returns array of result objects. + # Returns false if an error is returned from Salesforce. + def destroy_collection(*args) + destroy_collection!(*args) + rescue *exceptions + false + end + + # Public: Delete collection of records. + # + # ids - List of IDs of objects to be deleted. + # all_or_none - Roll back the entire request when the deletion of any object fails. + # + # Examples + # + # # Delete collection of records + # client.destroy('0016000000MRatd', '0016000000ERats') + # + # Returns array of result objects. + # Raises exceptions if an error is returned from Salesforce. + def destroy_collection!(ids, all_or_none = false) + raise ArgumentError, + 'Amount of records to delete is limited to 200' if ids.size > 200 + + api_delete("composite/sobjects?ids=#{ids.join(',')}&allOrNone=#{all_or_none}").body + end + # Public: Update or create a record based on an external ID # # sobject - The name of the sobject to created. diff --git a/spec/fixtures/sobject/composite_sobjects_destroy_bad_request_response.json b/spec/fixtures/sobject/composite_sobjects_destroy_bad_request_response.json new file mode 100644 index 00000000..cebce329 --- /dev/null +++ b/spec/fixtures/sobject/composite_sobjects_destroy_bad_request_response.json @@ -0,0 +1,6 @@ +[ + { + "message" : "At least 1 Id is required.", + "errorCode" : "REQUIRED_FIELD_MISSING" + } +] diff --git a/spec/fixtures/sobject/composite_sobjects_destroy_success_response.json b/spec/fixtures/sobject/composite_sobjects_destroy_success_response.json new file mode 100644 index 00000000..d3cc4c08 --- /dev/null +++ b/spec/fixtures/sobject/composite_sobjects_destroy_success_response.json @@ -0,0 +1,7 @@ +[ + { + "id" : "Foo", + "success" : true, + "errors" : [ ] + } +] diff --git a/spec/integration/abstract_client_spec.rb b/spec/integration/abstract_client_spec.rb index 3e154d18..fd140db3 100644 --- a/spec/integration/abstract_client_spec.rb +++ b/spec/integration/abstract_client_spec.rb @@ -266,6 +266,46 @@ end end + describe '.destroy_collection!' do + context 'with valid params' do + requests 'composite/sobjects\?allOrNone=false&ids=Foo', + method: :delete, + fixture: 'sobject/composite_sobjects_destroy_success_response' + + subject { client.destroy_collection!(['Foo']) } + + it { should eq [{'id' => 'Foo', 'errors' => [], 'success' => true}] } + end + + context 'with invalid params' do + requests 'composite/sobjects\?allOrNone=false&ids=', + method: :delete, + status: 400, + fixture: 'sobject/composite_sobjects_destroy_bad_request_response' + + subject { + lambda do + client.destroy_collection!([]) + end + } + + it { should raise_error(Faraday::ClientError) } + end + end + + describe '.destroy_collection' do + context 'with invalid params' do + requests 'composite/sobjects\?allOrNone=false&ids=', + method: :delete, + status: 400, + fixture: 'sobject/composite_sobjects_destroy_bad_request_response' + + subject { client.destroy_collection([]) } + + it { should eq false } + end + end + describe '.upsert!' do context 'when updated' do requests 'sobjects/Account/External__c/foobar', diff --git a/spec/unit/concerns/api_spec.rb b/spec/unit/concerns/api_spec.rb index b6aa697e..8951a416 100644 --- a/spec/unit/concerns/api_spec.rb +++ b/spec/unit/concerns/api_spec.rb @@ -380,6 +380,28 @@ end end + describe '.destroy_collection!' do + let(:attrs) { ['1'] } + subject(:result) { client.destroy_collection!(attrs) } + + it 'sends an HTTP DELETE, and returns list of result objects' do + response.stub(:body).and_return([{'id' => '1', 'success' => true, 'errors' => []}]) + client.should_receive(:api_delete). + with('composite/sobjects?ids=1&allOrNone=false'). + and_return(response) + expect(result[0]).to eq({'id' => '1', 'success' => true, 'errors' => []}) + end + + context 'when ids collection size is more than 200' do + let(:attrs) { Array.new(201) } + + it "raises an error" do + expect { client.destroy_collection!(attrs) }.to raise_error( + ArgumentError, 'Amount of records to delete is limited to 200') + end + end + end + describe '.upsert!' do let(:sobject) { 'Whizbang' } let(:field) { :External_ID__c } From 6bd96ba953374fef35d7f778c0fd37d5e6135344 Mon Sep 17 00:00:00 2001 From: Yuri Kasperovich Date: Thu, 24 Jan 2019 23:54:12 +0300 Subject: [PATCH 4/5] Add additional contexts to collection call specs --- spec/integration/abstract_client_spec.rb | 28 ++++++++++++++---------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/spec/integration/abstract_client_spec.rb b/spec/integration/abstract_client_spec.rb index fd140db3..d059ffe4 100644 --- a/spec/integration/abstract_client_spec.rb +++ b/spec/integration/abstract_client_spec.rb @@ -167,17 +167,19 @@ end describe '.create_collection!' do - requests 'composite/sobjects', - method: :post, - with_body: { - allOrNone: false, - records: [{Name: 'Foobar'}] - }, - fixture: 'sobject/composite_sobjects_success_response' + context 'with valid params' do + requests 'composite/sobjects', + method: :post, + with_body: { + allOrNone: false, + records: [{Name: 'Foobar'}] + }, + fixture: 'sobject/composite_sobjects_success_response' - subject { client.create_collection!([{Name: 'Foobar'}]) } + subject { client.create_collection!([{Name: 'Foobar'}]) } - it { should eq [{'id' => 'some_id', 'errors' => [], 'success' => true}] } + it { should eq [{'id' => 'some_id', 'errors' => [], 'success' => true}] } + end context 'with invalid params' do requests 'composite/sobjects', @@ -217,7 +219,8 @@ end describe '.update_collection!' do - requests 'composite/sobjects', + context 'with valid params' do + requests 'composite/sobjects', method: :patch, with_body: { allOrNone: false, @@ -225,9 +228,10 @@ }, fixture: 'sobject/composite_sobjects_success_response' - subject { client.update_collection!([{Name: 'Foobar'}]) } + subject { client.update_collection!([{Name: 'Foobar'}]) } - it { should eq [{'id' => 'some_id', 'errors' => [], 'success' => true}] } + it { should eq [{'id' => 'some_id', 'errors' => [], 'success' => true}] } + end context 'with invalid params' do requests 'composite/sobjects', From 0211ed96050b9b9ae7e21d398e6bb593effce6e7 Mon Sep 17 00:00:00 2001 From: Yuri Kasperovich Date: Mon, 28 Jan 2019 20:04:32 +0300 Subject: [PATCH 5/5] Minor documentation fixes --- lib/restforce/concerns/api.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/restforce/concerns/api.rb b/lib/restforce/concerns/api.rb index 0ed6d0e7..9e3945f9 100644 --- a/lib/restforce/concerns/api.rb +++ b/lib/restforce/concerns/api.rb @@ -355,7 +355,7 @@ def create_collection(*args) # Examples # # # Add new accounts - # client.create_collection([{Name: 'Foo Inc.'}, {Name: 'Bar Corp.'}]) + # client.create_collection!([{Name: 'Foo Inc.'}, {Name: 'Bar Corp.'}]) # # => [{ 'id' => '1', 'success' => true, 'errors' => [] }, # # { 'id' => '2', 'success' => true, 'errors' => [] }] # @@ -396,7 +396,7 @@ def update_collection(*args) # Examples # # # Update accounts - # client.update_collection([{Id: '1', Name: 'Foo Inc.'}, {Id: '2', Name: 'Bar Corp.'}]) + # client.update_collection!([{Id: '1', Name: 'Foo Inc.'}, {Id: '2', Name: 'Bar Corp.'}]) # # => [{ 'id' => '1', 'success' => true, 'errors' => [] }, # # { 'id' => '2', 'success' => true, 'errors' => [] }] # @@ -417,7 +417,7 @@ def update_collection!(attrs_collection, all_or_none = false) # Examples # # # Delete collection of records - # client.destroy('0016000000MRatd', '0016000000ERats') + # client.destroy_collection('0016000000MRatd', '0016000000ERats') # # Returns array of result objects. # Returns false if an error is returned from Salesforce. @@ -435,7 +435,7 @@ def destroy_collection(*args) # Examples # # # Delete collection of records - # client.destroy('0016000000MRatd', '0016000000ERats') + # client.destroy_collection!('0016000000MRatd', '0016000000ERats') # # Returns array of result objects. # Raises exceptions if an error is returned from Salesforce.