Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,6 @@
# Version 5.2.1
* Reverted accidental change to object creation during sync.
* Added CI for the test suite.

# Version 5.3.0
* Changed salesforce_ar_sync to use bang (!) versions of Restforce CRUD methods to raise errors on Salesforce save failures instead of returning false.
9 changes: 4 additions & 5 deletions lib/salesforce_ar_sync/salesforce_sync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,20 +176,19 @@ def is_boolean?(attribute)

def salesforce_create_object(attributes)
attributes[self.class.salesforce_web_id_attribute_name.to_s] = id if self.class.salesforce_sync_web_id? && !new_record?
salesforce_id = SF_CLIENT.create(salesforce_object_name, format_attributes(attributes))
self.salesforce_id = salesforce_id
self.salesforce_id = SF_CLIENT.create!(salesforce_object_name, format_attributes(attributes))
@exists_in_salesforce = true
end

def salesforce_update_object(attributes)
attributes[self.class.salesforce_web_id_attribute_name.to_s] = id if self.class.salesforce_sync_web_id? && !new_record?

SF_CLIENT.update(salesforce_object_name, format_attributes(attributes).merge(Id: salesforce_id))
SF_CLIENT.update!(salesforce_object_name, format_attributes(attributes).merge(Id: salesforce_id))
end

def salesforce_delete_object
if ar_sync_outbound_delete?
SF_CLIENT.destroy(salesforce_object_name, salesforce_id)
SF_CLIENT.destroy!(salesforce_object_name, salesforce_id)
end
end

Expand Down Expand Up @@ -236,7 +235,7 @@ def salesforce_sync(*attrs)
def sync_web_id
return false if !self.class.salesforce_sync_web_id? || SalesforceArSync.config['SYNC_ENABLED'] == false

SF_CLIENT.update(salesforce_object_name, Id: salesforce_id, self.class.salesforce_web_id_attribute_name.to_s => get_activerecord_web_id) if salesforce_id
SF_CLIENT.update!(salesforce_object_name, Id: salesforce_id, self.class.salesforce_web_id_attribute_name.to_s => get_activerecord_web_id) if salesforce_id
end

def get_activerecord_web_id
Expand Down
2 changes: 1 addition & 1 deletion lib/salesforce_ar_sync/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module SalesforceArSync
VERSION = '5.2.1'
VERSION = '5.3.0'
end
10 changes: 5 additions & 5 deletions spec/salesforce_ar_sync/salesforce_ar_sync_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -521,14 +521,14 @@ class ProcessUpdateTest < ActiveRecord::Base
}
)

expect(SF_CLIENT).to receive(:update).with('Contact', expected_attributes)
expect(SF_CLIENT).to receive(:update!).with('Contact', expected_attributes)
contact.salesforce_update_object(contact.attributes)
end
end

context 'when the class should not sync web id' do
it 'calls SF_CLIENT.update with the correct parameters' do
expect(SF_CLIENT).to receive(:update).with('Contact', contact.attributes.merge(Id: contact.salesforce_id))
expect(SF_CLIENT).to receive(:update!).with('Contact', contact.attributes.merge(Id: contact.salesforce_id))
contact.salesforce_update_object(contact.attributes)
end
end
Expand All @@ -549,14 +549,14 @@ class ProcessUpdateTest < ActiveRecord::Base
SalesforceArSync.config['SYNC_ENABLED'] = true
stub_const('SF_CLIENT', restforce_client_stub)

allow(SF_CLIENT).to receive(:update)
allow(SF_CLIENT).to receive(:update!)
allow(contact).to receive(:salesforce_object_exists?).and_return(true)
end

context 'when supplied with which attributes to sync' do
it 'calls SF_CLIENT.update with the correct parameters' do
contact.salesforce_sync(:first_name, :email_address)
expect(SF_CLIENT).to have_received(:update).with(
expect(SF_CLIENT).to have_received(:update!).with(
'Contact',
Id: contact.salesforce_id,
Contact.salesforce_sync_attribute_mapping.invert[:first_name] => contact.first_name,
Expand All @@ -568,7 +568,7 @@ class ProcessUpdateTest < ActiveRecord::Base
context 'when supplied with invalid attributes to sync' do
it 'calls SF_CLIENT.update with the correct parameters' do
contact.salesforce_sync(:bad_attribute)
expect(SF_CLIENT).not_to have_received(:update)
expect(SF_CLIENT).not_to have_received(:update!)
end
end
end
Expand Down