restforce_mock 0.6.0 → 0.7.0

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: d3ff569736337f68e7b37276c0fe828582e536b3
4
- data.tar.gz: 0e764d7f47a41d1e85578250a156d1822763becd
3
+ metadata.gz: 503069008904b0403bf039de367bdb8249643b0d
4
+ data.tar.gz: 30fcfd99caf343ed29bc9708a33f42401b786113
5
5
  SHA512:
6
- metadata.gz: e2c82c655cd0e33dffbba1fbabcb4f64a2fb5bc71bc33480c2f66dbd8e0edec1e443165546adb63dabed895d514a1c0fd737cc7be9a7281c7717c7a09c32ea8d
7
- data.tar.gz: 498453766638324d6ba45dc83230508494a85e47d56c99f1a44da5e187bdd0ccc648c0f79ccec5a71f77fa36f42f5f45a63ff23960696fe591846e9493bba2f8
6
+ metadata.gz: 6e832bf92df18847f2219510b7be5ab06db7e3a5b81b819e584c0e305e6dac8cd3433d96094f38052621d055766fb0d52036288ca614e28b30b3b70221d2cc1d
7
+ data.tar.gz: 52dc0da9f71626370801ec424bb773df130b6c04aec4f93a6b3602eeaecd6c02a7da947624b43fd61d70e48c76fd532ca5b8185b01462eef9e2496f084cac6ba
data/README.md CHANGED
@@ -97,6 +97,24 @@ To access the object in the RestforceMock object
97
97
  RestforceMock::Sandbox.get_object("Contact", "HGUKK674J79HjsH")
98
98
  ```
99
99
 
100
+ To find an object with the salesforce find method
101
+
102
+ ```ruby
103
+ client = RestforceMock::Client.new
104
+ RestforceMock::Sandbox.add_object("Contact", '12345', {:Email=>"example@yahoo.com"})
105
+ client.find('Contact', '12345')
106
+ ```
107
+
108
+ To make a query with the salesforce query method
109
+
110
+ ```ruby
111
+ client = RestforceMock::Client.new
112
+ RestforceMock::Sandbox.add_object("Contact", '12345', {:Email=>"example@yahoo.com"})
113
+ client.query("Select Id FROM Contact WHERE Email = 'example@yahoo.com'")
114
+ ```
115
+
116
+ Note: when making a `find` or `query`, it should be in the format specified above.
117
+
100
118
  RestforceMock sandbox is **shared across all your tests** (same way as real Salesforce instace would be), hence,
101
119
  after completion of tests make sure to clean up if necessary
102
120
 
@@ -7,6 +7,25 @@ module RestforceMock
7
7
  include ::Restforce::Concerns::API
8
8
  include RestforceMock::Sandbox
9
9
 
10
+ def mashify?
11
+ true
12
+ end
13
+
14
+ def api_get(url, attrs = nil)
15
+ url=~/sobjects\/(.+)\/(.+)/
16
+ object=$1
17
+ id=$2
18
+
19
+ if !attrs.nil? && url == 'query'
20
+ query = attrs.values.first
21
+ response = get_object_from_query(query)
22
+ return Body.new(response, url)
23
+ else
24
+ response = get_object(object, id)
25
+ return Body.new(response)
26
+ end
27
+ end
28
+
10
29
  def api_patch(url, attrs)
11
30
  url=~/sobjects\/(.+)\/(.+)/
12
31
  object=$1
@@ -73,8 +92,17 @@ module RestforceMock
73
92
  end
74
93
 
75
94
  class Body
76
- def initialize(id)
77
- @body = {'id' => id}
95
+ def initialize(id, type= nil)
96
+ collection = {"totalSize"=>1, "done"=>true,
97
+ "records"=>[{"attributes"=>{"type"=>"Contact", "url"=>""}, "Id"=> id}]}
98
+
99
+ @body =
100
+
101
+ if type == 'query'
102
+ Restforce::Collection.new(collection, Restforce::Data::Client.new)
103
+ else
104
+ {'id' => id}
105
+ end
78
106
  end
79
107
 
80
108
  def body
@@ -12,10 +12,35 @@ module RestforceMock
12
12
  RestforceMock::Sandbox.add_object(name, id, values)
13
13
  end
14
14
 
15
+ def get_object(name, id)
16
+ RestforceMock::Sandbox.get_object(name, id)
17
+ end
18
+
15
19
  def self.get_object(name, id)
16
20
  storage[name][id]
17
21
  end
18
22
 
23
+ def get_object_from_query(query)
24
+ RestforceMock::Sandbox.find_object(query)
25
+ end
26
+
27
+ def self.find_object(query)
28
+ # This will only support making queries in this format:
29
+ # client.query("Select Id FROM Contact WHERE Email = 'debrah.obrian@yahoo.com'")
30
+
31
+ split_query = query.split
32
+
33
+ storage_name = split_query[3]
34
+ key = "#{split_query[5]}".to_sym
35
+ val = split_query.last
36
+ .gsub(/^'|'$/, '')
37
+ .gsub('\\', '')
38
+
39
+ if storage[storage_name].has_value?( key => val)
40
+ return storage[storage_name].keys.first
41
+ end
42
+ end
43
+
19
44
  def self.update_object(name, id, attrs)
20
45
  current = storage[name][id]
21
46
  storage[name][id] = current.merge(attrs)
@@ -1,3 +1,3 @@
1
1
  module RestforceMock
2
- VERSION = "0.6.0"
2
+ VERSION = "0.7.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restforce_mock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ilya Katz
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-12-28 00:00:00.000000000 Z
11
+ date: 2017-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: restforce
@@ -143,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
143
  version: '0'
144
144
  requirements: []
145
145
  rubyforge_project:
146
- rubygems_version: 2.4.8
146
+ rubygems_version: 2.6.10
147
147
  signing_key:
148
148
  specification_version: 4
149
149
  summary: Mock for Restforce gem