restforce_mock 0.4.1 → 0.5.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: 434a3ac1af85c541bc73f82aad09634926cd7b3c
4
- data.tar.gz: 53633396acd1c9ec3b57e54f32c454d374ca1af3
3
+ metadata.gz: 75614ebb2f242748ce0a507b8a67eea2bb83d8ef
4
+ data.tar.gz: 1a6fdf4d651054b110df083774af41d32019d51f
5
5
  SHA512:
6
- metadata.gz: 56dae95b0b15823cbe4281c8d031f37b5cbc48ab0e2178a54c1b80ff0780429af6bafa868b2915e57b0937c7490851a0e3ed2c94bbf5d9d27254e2d7577c3acc
7
- data.tar.gz: b07fd3ac88bcc822b2ee8c348321f893c662d2278bde51f1d1fe6acd97e7ccc6365e906c723574cf1d5171c9684310c1f9fc1d5b83848afd1e6463fc52a25b43
6
+ metadata.gz: 2286120b33fdb1fa4b3cea120e62ae1314c60d76fff290f279090a57bd1a9affb9fcd2165185e57f9f0dee7292ae48e351f1d16484853fbb16c14b2a33e9c43b
7
+ data.tar.gz: a91b1c1347a64ebcb4d248c3bc0cbafeca4d59a22addfd220503eef8058f0071305f3e90d184bfbf0c85c1fd0983c92122554ee690494033c401595bc1d4a354
data/CHANGELOG.md CHANGED
@@ -1,6 +1,9 @@
1
- ## 0.4.1
1
+ ## 0.5.0
2
2
 
3
+ * Validate that schema file is preset
4
+ * Validate that objects are present in schema
3
5
  * Remove update validation, better update validation coming
6
+ * Rake task to load schema (experimental)
4
7
 
5
8
  ## 0.4.0
6
9
 
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # RestforceMock
2
2
 
3
- - [![Build](http://img.shields.io/travis-ci/ilyakatz/restforce_mock.svg?style=flat-square)](https://travis-ci.org/ilyakatz/restforce_mock)
3
+ - [![Build](http://img.shields.io/travis-ci/ilyakatz/restforce_mock.svg?style=flat-square)](https://travis-ci.org/execonline-inc/restforce_mock)
4
4
  - [![Version](http://img.shields.io/gem/v/restforce_mock.svg?style=flat-square)](https://rubygems.org/gems/restforce_mock)
5
5
  - [![License](http://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](http://opensource.org/licenses/MIT)
6
6
 
@@ -43,8 +43,16 @@ This will direct all calls to `Restforce` to `RestforceMock`. Test as usual.
43
43
  ```ruby
44
44
  RestforceMock.configure do |config|
45
45
  config.schema_file = "spec/fixtures/schema.yml"
46
- config.error_on_required = true # raise error if required field is not set
46
+
47
+ # raise error if required field is not set (default: true)
48
+ config.error_on_required = true
47
49
  config.required_exclusions = [:LastModifiedById ...] # fields that should not be considered required
50
+
51
+ # raise error if schema is not available (default: false)
52
+ config.raise_on_schema_missing = true
53
+
54
+ # objects in SF that should be loaded into the schema used for RestforceMock
55
+ config.objects_for_schema = ["Contact", "Opportunity" ...]
48
56
  end
49
57
  ```
50
58
 
@@ -3,6 +3,7 @@ require "restforce_mock/configuration"
3
3
  require "restforce_mock/client"
4
4
  require "restforce_mock/sandbox"
5
5
  require "restforce_mock/schema_manager"
6
+ require "restforce_mock/error"
6
7
 
7
8
  module RestforceMock
8
9
  class << self
@@ -11,6 +11,7 @@ module RestforceMock
11
11
  url=~/sobjects\/(.+)\/(.+)/
12
12
  object=$1
13
13
  id=$2
14
+ validate_schema!(object)
14
15
  validate_presence!(object, id)
15
16
  update_object(object, id, attrs)
16
17
  end
@@ -19,6 +20,7 @@ module RestforceMock
19
20
  url=~/sobjects\/(.+)/
20
21
  sobject = $1
21
22
  id = SecureRandom.urlsafe_base64(13) #duplicates possible
23
+ validate_schema!(sobject)
22
24
  validate_requires!(sobject, attrs)
23
25
  add_object(sobject, id, attrs)
24
26
  return Body.new(id)
@@ -48,10 +50,26 @@ module RestforceMock
48
50
  end
49
51
  end
50
52
 
53
+ def validate_schema!(object)
54
+ if RestforceMock.configuration.raise_on_schema_missing
55
+ unless schema[object]
56
+ raise RestforceMock::Error.new("No schema for Salesforce object #{object}")
57
+ end
58
+ end
59
+ end
60
+
51
61
  private
52
62
 
53
63
  def schema
54
- RestforceMock::SchemaManager.new.load_schema(RestforceMock.configuration.schema_file)
64
+ @schema ||=
65
+ begin
66
+ manager = RestforceMock::SchemaManager.new
67
+ begin
68
+ manager.load_schema(RestforceMock.configuration.schema_file)
69
+ rescue Errno::ENOENT
70
+ raise RestforceMock::Error.new("No schema for Salesforce object is available")
71
+ end
72
+ end
55
73
  end
56
74
 
57
75
  class Body
@@ -3,11 +3,19 @@ module RestforceMock
3
3
  attr_accessor :schema_file
4
4
  attr_writer :error_on_required
5
5
  attr_writer :required_exclusions
6
+ attr_writer :raise_on_schema_missing
7
+ attr_accessor :objects_for_schema
8
+
9
+ attr_writer :objects_for_schema
6
10
 
7
11
  def error_on_required
8
12
  @error_on_required.nil? ? true : @error_on_required
9
13
  end
10
14
 
15
+ def raise_on_schema_missing
16
+ @raise_on_schema_missing.nil? ? false : @raise_on_schema_missing
17
+ end
18
+
11
19
  def required_exclusions
12
20
  @required_exclusions || default_exclusions
13
21
  end
@@ -0,0 +1,4 @@
1
+ module RestforceMock
2
+ class Error < StandardError
3
+ end
4
+ end
@@ -0,0 +1,14 @@
1
+ require "rake"
2
+
3
+ namespace :restforce_mock do
4
+ namespace :schema do
5
+ desc "Dump schema from Salesforce into file"
6
+ task load: :environment do
7
+ m = RestforceMock::SchemaManager.new
8
+ m.dump_schema(
9
+ RestforceMock.configuration.objects_for_schema,
10
+ RestforceMock.configuration.schema_file
11
+ )
12
+ end
13
+ end
14
+ end
@@ -1,3 +1,3 @@
1
1
  module RestforceMock
2
- VERSION = "0.4.1"
2
+ VERSION = "0.5.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.4.1
4
+ version: 0.5.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-10-06 00:00:00.000000000 Z
11
+ date: 2015-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: restforce
@@ -117,8 +117,10 @@ files:
117
117
  - lib/restforce_mock.rb
118
118
  - lib/restforce_mock/client.rb
119
119
  - lib/restforce_mock/configuration.rb
120
+ - lib/restforce_mock/error.rb
120
121
  - lib/restforce_mock/sandbox.rb
121
122
  - lib/restforce_mock/schema_manager.rb
123
+ - lib/restforce_mock/tasks.rb
122
124
  - lib/restforce_mock/version.rb
123
125
  - restforce_mock.gemspec
124
126
  homepage: https://github.com/ilyakatz/restforce_mock