restforce-db 0.3.2 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c7271f667addef9ca339a2452d20d4c59889d216
4
- data.tar.gz: 809ed0792d08ee7504f78e9bf3cc59d9c3ffb2f5
3
+ metadata.gz: dd0758b4ebbb0d3260025eab127182c669bbee09
4
+ data.tar.gz: 3d2218660c4c8eb834c866389848274f74a26911
5
5
  SHA512:
6
- metadata.gz: f1932d26bd6c8cb70ab2db91927f244f9847fbe1a49bd58255616daf7ee822f1a4228b2a26d045aa81ecea8aae00af09fc6fb9653b728f164dfb509a7ef7ec19
7
- data.tar.gz: 1609aebd03dfb25bcad99683ab9e390e9decb1125b615ff0414325c4cafbc4addabe846ffb85f9ee74930663fa4f7db86f4684fafa761c9dd354daf371b3e845
6
+ metadata.gz: c9316983f8e18d5cacf1cdcdc2c86a3be04a641661b7e14a0d9d2ecc6ef3b7e3c6750a4f1dc5f2b0f8bd706f8fe27795f6a8515f21dd0bd7184b8214c4482cd3
7
+ data.tar.gz: 943d6204c2a38790e9ec00ed309203cb6338007eb79a525b4f6aadde0650c514669d2f707fb9338063c6425cd3601dd4d738a6505d5012e7d315f29d4cd3ffd6
@@ -20,12 +20,19 @@ module Restforce
20
20
  attributes = @mapping.convert(@record_type, from_record.attributes)
21
21
 
22
22
  record = @record_type.new(attributes.merge(salesforce_id: from_record.id))
23
- @mapping.associations.each do |association, lookup|
23
+ associations = @mapping.associations.map do |association, lookup|
24
24
  associated = record.association(association).build
25
25
  lookup_id = from_record.record.send(lookup)
26
26
  build_association associated, lookup_id
27
27
  end
28
- record.save!
28
+
29
+ record.transaction do
30
+ record.save!
31
+
32
+ # We touch the synchronization timestamps here to ensure that they
33
+ # exceed the last updated timestamp.
34
+ associations.each { |association| association.touch(:synchronized_at) }
35
+ end
29
36
 
30
37
  Instances::ActiveRecord.new(@record_type, record, @mapping).after_sync
31
38
  end
@@ -85,11 +92,11 @@ module Restforce
85
92
  # Mapping's database record type. Right now, nested associations are
86
93
  # ignored.
87
94
  #
88
- # associated - The associatd database record.
95
+ # associated - The associated database record.
89
96
  # lookup_id - A Salesforce ID corresponding to the record type in the
90
97
  # Mapping defined for the associated database model.
91
98
  #
92
- # Returns a Boolean.
99
+ # Returns the associated ActiveRecord instance.
93
100
  def build_association(associated, lookup_id)
94
101
  return if lookup_id.nil?
95
102
 
@@ -98,12 +105,8 @@ module Restforce
98
105
  salesforce_instance = mapping.salesforce_record_type.find(lookup_id)
99
106
  attributes = mapping.convert(associated.class, salesforce_instance.attributes)
100
107
 
101
- associated.assign_attributes(
102
- attributes.merge(
103
- salesforce_id: lookup_id,
104
- synchronized_at: Time.now,
105
- ),
106
- )
108
+ associated.assign_attributes(attributes.merge(salesforce_id: lookup_id))
109
+ associated
107
110
  end
108
111
 
109
112
  end
@@ -3,7 +3,7 @@ module Restforce
3
3
  # :nodoc:
4
4
  module DB
5
5
 
6
- VERSION = "0.3.2"
6
+ VERSION = "0.3.3"
7
7
 
8
8
  end
9
9
 
@@ -99,6 +99,7 @@ describe Restforce::DB::RecordTypes::ActiveRecord do
99
99
  expect(user.email).to_equal("somebody@example.com")
100
100
  expect(user.salesforce_id).to_equal(association_id)
101
101
  expect(user.synchronized_at).to_not_be_nil
102
+ expect(user.synchronized_at).to_be(:>=, user.updated_at)
102
103
  end
103
104
  end
104
105
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restforce-db
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Horner