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: ae05f313a4856497d5e37bc09a9e24fcb628a35f
4
- data.tar.gz: d9b5c04629362aee84622de46ff4bd1d334a8e28
3
+ metadata.gz: 636dfb874caef4ef28885bf712c9dbe400f27105
4
+ data.tar.gz: e409ddc6eff3798561bdfbbe83f6f3a5e7051c22
5
5
  SHA512:
6
- metadata.gz: a117d3a1fa714b878db117a6ee967c1561512be5b249f0dc20db568f7a059c5fdf6918b5301ceb418866bb29fef1a413bc71cb93bbbff4d0e8bb94090f311b91
7
- data.tar.gz: 7af12f0f2da893178979807739b7fbeb7fb98ac939ab4971a14e1ed6c0e3966adcd6160f6fd0adacde258c166a907dcf5351fbed5dd2b473af700a64c4cf7996
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
- field_statuses(sobject_type)[field]
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 field_statuses(sobject_type)
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, output|
61
- output[field["name"]] = field["updateable"]
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
@@ -3,7 +3,7 @@ module Restforce
3
3
  # :nodoc:
4
4
  module DB
5
5
 
6
- VERSION = "2.1.1"
6
+ VERSION = "2.1.2"
7
7
 
8
8
  end
9
9
 
@@ -9,8 +9,9 @@ describe Restforce::DB::FieldProcessor do
9
9
  describe "#process" do
10
10
  let(:attributes) do
11
11
  {
12
- "Name" => "This field can be updated.",
13
- "Id" => "But... but... this field is read-only!",
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" => "Name", "updateable" => true },
25
- { "name" => "Id", "updateable" => false },
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
- "Name" => attributes["Name"],
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.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-20 00:00:00.000000000 Z
11
+ date: 2015-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord