restforce-db 2.1.1 → 2.1.2
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 636dfb874caef4ef28885bf712c9dbe400f27105
|
4
|
+
data.tar.gz: e409ddc6eff3798561bdfbbe83f6f3a5e7051c22
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96b1901e99f411e68b711c7dd651f138df24434a8db50fbd98e934fa24763e067ba53994428757a6093b4f6ed360984539717fc7cc3aa2721e827bbc6b84362c
|
7
|
+
data.tar.gz: 9812e06b5f5c3a465e2410b16ad5edfe2d695d54ad43068a0c75a575d39a0d645782e24669833f35c10f8cdbe661e70131a8d5527cb08f3f00e1720e4db19e28
|
@@ -26,11 +26,13 @@ module Restforce
|
|
26
26
|
#
|
27
27
|
# sobject_type - A String name of an SObject Type in Salesforce.
|
28
28
|
# attributes - A Hash with keys corresponding to Salesforce field names.
|
29
|
+
# write_type - A Symbol reflecting the type of write operation. Accepted
|
30
|
+
# values are :create and :update. Defaults to :update.
|
29
31
|
#
|
30
32
|
# Returns a Hash.
|
31
|
-
def process(sobject_type, attributes)
|
33
|
+
def process(sobject_type, attributes, write_type = :update)
|
32
34
|
attributes.each_with_object({}) do |(field, value), processed|
|
33
|
-
next unless writable?(sobject_type, field)
|
35
|
+
next unless writable?(sobject_type, field, write_type)
|
34
36
|
processed[field] = value
|
35
37
|
end
|
36
38
|
end
|
@@ -41,24 +43,33 @@ module Restforce
|
|
41
43
|
#
|
42
44
|
# sobject_type - A String name of an SObject Type in Salesforce.
|
43
45
|
# field - A String Salesforce field API name.
|
46
|
+
# write_type - A Symbol reflecting the type of write operation. Accepted
|
47
|
+
# values are :create and :update.
|
44
48
|
#
|
45
49
|
# Returns a Boolean.
|
46
|
-
def writable?(sobject_type, field)
|
47
|
-
|
50
|
+
def writable?(sobject_type, field, write_type)
|
51
|
+
permissions = field_permissions(sobject_type)[field]
|
52
|
+
return false unless permissions
|
53
|
+
|
54
|
+
permissions[write_type]
|
48
55
|
end
|
49
56
|
|
50
57
|
# Internal: Get a collection of all fields for the passed Salesforce
|
51
|
-
# SObject Type, with an indication of whether or not they are writable
|
58
|
+
# SObject Type, with an indication of whether or not they are writable for
|
59
|
+
# both create and update actions.
|
52
60
|
#
|
53
61
|
# sobject_type - A String name of an SObject Type in Salesforce.
|
54
62
|
#
|
55
63
|
# Returns a Hash.
|
56
|
-
def
|
64
|
+
def field_permissions(sobject_type)
|
57
65
|
self.class.field_cache[sobject_type] ||= begin
|
58
66
|
fields = Restforce::DB.client.describe(sobject_type).fields
|
59
67
|
|
60
|
-
fields.each_with_object({}) do |field,
|
61
|
-
|
68
|
+
fields.each_with_object({}) do |field, permissions|
|
69
|
+
permissions[field["name"]] = {
|
70
|
+
create: field["createable"],
|
71
|
+
update: field["updateable"],
|
72
|
+
}
|
62
73
|
end
|
63
74
|
end
|
64
75
|
end
|
@@ -17,7 +17,7 @@ module Restforce
|
|
17
17
|
# Returns a Restforce::DB::Instances::Salesforce instance.
|
18
18
|
# Raises on any error from Salesforce.
|
19
19
|
def create!(from_record)
|
20
|
-
from_attributes = FieldProcessor.new.process(@record_type, from_record.attributes)
|
20
|
+
from_attributes = FieldProcessor.new.process(@record_type, from_record.attributes, :create)
|
21
21
|
record_id = DB.client.create!(@record_type, from_attributes)
|
22
22
|
|
23
23
|
from_record.update!(@mapping.lookup_column => record_id).after_sync
|
data/lib/restforce/db/version.rb
CHANGED
@@ -9,8 +9,9 @@ describe Restforce::DB::FieldProcessor do
|
|
9
9
|
describe "#process" do
|
10
10
|
let(:attributes) do
|
11
11
|
{
|
12
|
-
"
|
13
|
-
"
|
12
|
+
"Creatable" => "This field is create-only!",
|
13
|
+
"Updateable" => "And... this field is update-only!",
|
14
|
+
"Both" => "But... this field allows both!",
|
14
15
|
}
|
15
16
|
end
|
16
17
|
let(:dummy_client) do
|
@@ -21,18 +22,29 @@ describe Restforce::DB::FieldProcessor do
|
|
21
22
|
@already_run = true
|
22
23
|
|
23
24
|
Struct.new(:fields).new([
|
24
|
-
{ "name" => "
|
25
|
-
{ "name" => "
|
25
|
+
{ "name" => "Creatable", "createable" => true, "updateable" => false },
|
26
|
+
{ "name" => "Updateable", "createable" => false, "updateable" => true },
|
27
|
+
{ "name" => "Both", "createable" => true, "updateable" => true },
|
26
28
|
])
|
27
29
|
end
|
28
30
|
|
29
31
|
end
|
30
32
|
end
|
31
33
|
|
32
|
-
it "removes the read-only fields from the passed attribute Hash" do
|
34
|
+
it "removes the read-only fields from the passed attribute Hash on :create" do
|
33
35
|
Restforce::DB.stub(:client, dummy_client) do
|
34
|
-
expect(processor.process("CustomObject__c", attributes)).to_equal(
|
35
|
-
"
|
36
|
+
expect(processor.process("CustomObject__c", attributes, :create)).to_equal(
|
37
|
+
"Creatable" => attributes["Creatable"],
|
38
|
+
"Both" => attributes["Both"],
|
39
|
+
)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
it "removes the read-only fields from the passed attribute Hash on :update" do
|
44
|
+
Restforce::DB.stub(:client, dummy_client) do
|
45
|
+
expect(processor.process("CustomObject__c", attributes, :update)).to_equal(
|
46
|
+
"Updateable" => attributes["Updateable"],
|
47
|
+
"Both" => attributes["Both"],
|
36
48
|
)
|
37
49
|
end
|
38
50
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restforce-db
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Horner
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|