restforce-db 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd0758b4ebbb0d3260025eab127182c669bbee09
|
4
|
+
data.tar.gz: 3d2218660c4c8eb834c866389848274f74a26911
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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
|
-
|
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
|
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
|
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
|
-
|
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
|
data/lib/restforce/db/version.rb
CHANGED
@@ -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
|