restforce 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of restforce might be problematic. Click here for more details.

Files changed (63) hide show
  1. data/.travis.yml +1 -0
  2. data/CHANGELOG.md +7 -1
  3. data/Gemfile +4 -0
  4. data/Guardfile +11 -0
  5. data/README.md +19 -8
  6. data/lib/restforce.rb +44 -14
  7. data/lib/restforce/abstract_client.rb +9 -0
  8. data/lib/restforce/client.rb +1 -95
  9. data/lib/restforce/{client → concerns}/api.rb +9 -9
  10. data/lib/restforce/{client → concerns}/authentication.rb +9 -9
  11. data/lib/restforce/concerns/base.rb +58 -0
  12. data/lib/restforce/{client → concerns}/caching.rb +4 -4
  13. data/lib/restforce/concerns/canvas.rb +12 -0
  14. data/lib/restforce/{client → concerns}/connection.rb +13 -12
  15. data/lib/restforce/{client → concerns}/picklists.rb +1 -1
  16. data/lib/restforce/{client → concerns}/streaming.rb +3 -3
  17. data/lib/restforce/{client → concerns}/verbs.rb +4 -4
  18. data/lib/restforce/config.rb +40 -10
  19. data/lib/restforce/data/client.rb +18 -0
  20. data/lib/restforce/middleware/authentication.rb +9 -2
  21. data/lib/restforce/sobject.rb +1 -1
  22. data/lib/restforce/tooling/client.rb +13 -0
  23. data/lib/restforce/version.rb +1 -1
  24. data/spec/{lib/client_spec.rb → integration/abstract_client_spec.rb} +21 -214
  25. data/spec/integration/data/client_spec.rb +90 -0
  26. data/spec/spec_helper.rb +0 -14
  27. data/spec/support/client_integration.rb +45 -0
  28. data/spec/support/concerns.rb +18 -0
  29. data/spec/support/event_machine.rb +14 -0
  30. data/spec/support/middleware.rb +18 -1
  31. data/spec/unit/abstract_client_spec.rb +11 -0
  32. data/spec/{lib → unit}/attachment_spec.rb +3 -6
  33. data/spec/unit/collection_spec.rb +50 -0
  34. data/spec/unit/concerns/api_spec.rb +222 -0
  35. data/spec/unit/concerns/authentication_spec.rb +98 -0
  36. data/spec/unit/concerns/base_spec.rb +50 -0
  37. data/spec/unit/concerns/caching_spec.rb +29 -0
  38. data/spec/unit/concerns/canvas_spec.rb +30 -0
  39. data/spec/unit/concerns/connection_spec.rb +14 -0
  40. data/spec/{lib → unit}/config_spec.rb +13 -23
  41. data/spec/unit/data/client_spec.rb +10 -0
  42. data/spec/{lib → unit}/mash_spec.rb +0 -0
  43. data/spec/{lib → unit}/middleware/authentication/password_spec.rb +0 -4
  44. data/spec/{lib → unit}/middleware/authentication/token_spec.rb +0 -4
  45. data/spec/unit/middleware/authentication_spec.rb +67 -0
  46. data/spec/unit/middleware/authorization_spec.rb +11 -0
  47. data/spec/{lib → unit}/middleware/gzip_spec.rb +15 -30
  48. data/spec/unit/middleware/instance_url_spec.rb +24 -0
  49. data/spec/{lib → unit}/middleware/logger_spec.rb +4 -7
  50. data/spec/unit/middleware/mashify_spec.rb +11 -0
  51. data/spec/{lib → unit}/middleware/raise_error_spec.rb +4 -5
  52. data/spec/{lib → unit}/signed_request_spec.rb +0 -0
  53. data/spec/unit/sobject_spec.rb +68 -0
  54. data/spec/unit/tooling/client_spec.rb +7 -0
  55. metadata +75 -46
  56. data/lib/restforce/client/canvas.rb +0 -12
  57. data/spec/lib/collection_spec.rb +0 -52
  58. data/spec/lib/middleware/authentication_spec.rb +0 -69
  59. data/spec/lib/middleware/authorization_spec.rb +0 -17
  60. data/spec/lib/middleware/instance_url_spec.rb +0 -31
  61. data/spec/lib/middleware/mashify_spec.rb +0 -28
  62. data/spec/lib/sobject_spec.rb +0 -122
  63. data/spec/support/basic_client.rb +0 -37
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe Restforce::Middleware::InstanceURL do
4
+ describe '.call' do
5
+ subject { lambda { middleware.call(nil) } }
6
+
7
+ context 'when the instance url is not set' do
8
+ before do
9
+ client.stub_chain :connection, :url_prefix => URI.parse('http:/')
10
+ end
11
+
12
+ it { should raise_error Restforce::UnauthorizedError }
13
+ end
14
+
15
+ context 'when the instance url is set' do
16
+ before do
17
+ client.stub_chain :connection, :url_prefix => URI.parse('http://foobar.com/')
18
+ app.should_receive(:call).once
19
+ end
20
+
21
+ it { should_not raise_error }
22
+ end
23
+ end
24
+ end
@@ -1,13 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Restforce::Middleware::Logger do
4
- let(:app) { double('app') }
5
- let(:env) { { } }
6
4
  let(:logger) { double('logger') }
7
- let(:options) { { :host => 'login.salesforce.com', :client_secret => 'foo', :password => 'bar' } }
8
5
  let(:middleware) { described_class.new app, logger, options }
9
6
 
10
- describe 'logging' do
7
+ describe '.call' do
8
+ subject { lambda { middleware.call(env) } }
9
+
11
10
  before do
12
11
  app.should_receive(:call).once.and_return(app)
13
12
  app.should_receive(:on_complete).once { middleware.on_complete(env) }
@@ -15,8 +14,6 @@ describe Restforce::Middleware::Logger do
15
14
  logger.should_receive(:debug).with('response')
16
15
  end
17
16
 
18
- it 'logs the request and response' do
19
- middleware.call(env)
20
- end
17
+ it { should_not raise_error }
21
18
  end
22
19
  end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Restforce::Middleware::Mashify do
4
+ let(:env) { { :body => JSON.parse(fixture('sobject/query_success_response')) } }
5
+
6
+ describe '.call' do
7
+ subject { lambda { middleware.call(env) } }
8
+
9
+ it { should change { env[:body] }.to(kind_of(Restforce::Collection)) }
10
+ end
11
+ end
@@ -1,27 +1,26 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Restforce::Middleware::RaiseError do
4
- let(:app) { double('app') }
5
4
  let(:body) { fixture('sobject/query_error_response') }
6
5
  let(:env) { { :status => status, :body => body } }
7
6
  let(:middleware) { described_class.new app }
8
7
 
9
8
  describe '.on_complete' do
10
- subject { middleware.on_complete(env) }
9
+ subject { lambda { middleware.on_complete(env) } }
11
10
 
12
11
  context 'when the status code is 404' do
13
12
  let(:status) { 404 }
14
- specify { expect { subject }.to raise_error Faraday::Error::ResourceNotFound, 'INVALID_FIELD: error_message' }
13
+ it { should raise_error Faraday::Error::ResourceNotFound, 'INVALID_FIELD: error_message' }
15
14
  end
16
15
 
17
16
  context 'when the status code is 400' do
18
17
  let(:status) { 400 }
19
- specify { expect { subject }.to raise_error Faraday::Error::ClientError, 'INVALID_FIELD: error_message' }
18
+ it { should raise_error Faraday::Error::ClientError, 'INVALID_FIELD: error_message' }
20
19
  end
21
20
 
22
21
  context 'when the status code is 401' do
23
22
  let(:status) { 401 }
24
- specify { expect { subject }.to raise_error Restforce::UnauthorizedError, 'INVALID_FIELD: error_message' }
23
+ it { should raise_error Restforce::UnauthorizedError, 'INVALID_FIELD: error_message' }
25
24
  end
26
25
  end
27
26
  end
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+
3
+ describe Restforce::SObject do
4
+ let(:client) { double('Client') }
5
+ let(:hash) { JSON.parse(fixture('sobject/query_success_response'))['records'].first }
6
+ subject(:sobject) { described_class.new(hash, client) }
7
+
8
+ describe '#new' do
9
+ context 'with valid options' do
10
+ it { should be_a Restforce::SObject }
11
+ it { should have_client client }
12
+ its(:sobject_type) { should eq 'Whizbang' }
13
+ its(:Text_Label) { should eq 'Hi there!' }
14
+
15
+ describe 'children' do
16
+ subject(:children) { sobject.Whizbangs__r }
17
+
18
+ it { should be_a Restforce::Collection }
19
+
20
+ describe 'each child' do
21
+ it { should be_all { |sobject| expect(sobject).to be_a Restforce::SObject } }
22
+ it { should be_all { |sobject| expect(sobject).to have_client client } }
23
+ end
24
+ end
25
+
26
+ describe 'parent' do
27
+ subject(:parent) { sobject.ParentWhizbang__r }
28
+
29
+ it { should be_a Restforce::SObject }
30
+ its(:sobject_type) { should eq 'Whizbang' }
31
+ its(:Name) { should eq 'Parent Whizbang' }
32
+ it { should have_client client }
33
+ end
34
+ end
35
+ end
36
+
37
+ { :save => :update,
38
+ :save! => :update!,
39
+ :destroy => :destroy,
40
+ :destroy! => :destroy! }.each do |method, receiver|
41
+ describe ".#{method}" do
42
+ subject { lambda { sobject.send(method) } }
43
+
44
+ context 'when an Id was not queried' do
45
+ it { should raise_error ArgumentError, 'You need to query the Id for the record first.' }
46
+ end
47
+
48
+ context 'when an Id is present' do
49
+ before do
50
+ hash.merge!(:Id => '001D000000INjVe')
51
+ client.should_receive(receiver)
52
+ end
53
+
54
+ it { should_not raise_error }
55
+ end
56
+ end
57
+ end
58
+
59
+ describe '.describe' do
60
+ subject { lambda { sobject.describe } }
61
+
62
+ before do
63
+ client.should_receive(:describe).with('Whizbang')
64
+ end
65
+
66
+ it { should_not raise_error }
67
+ end
68
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe Restforce::Tooling::Client do
4
+ subject { described_class }
5
+
6
+ it { should < Restforce::AbstractClient }
7
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restforce
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-06 00:00:00.000000000 Z
12
+ date: 2013-06-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -151,22 +151,26 @@ files:
151
151
  - .travis.yml
152
152
  - CHANGELOG.md
153
153
  - Gemfile
154
+ - Guardfile
154
155
  - LICENSE
155
156
  - README.md
156
157
  - Rakefile
157
158
  - lib/restforce.rb
159
+ - lib/restforce/abstract_client.rb
158
160
  - lib/restforce/attachment.rb
159
161
  - lib/restforce/client.rb
160
- - lib/restforce/client/api.rb
161
- - lib/restforce/client/authentication.rb
162
- - lib/restforce/client/caching.rb
163
- - lib/restforce/client/canvas.rb
164
- - lib/restforce/client/connection.rb
165
- - lib/restforce/client/picklists.rb
166
- - lib/restforce/client/streaming.rb
167
- - lib/restforce/client/verbs.rb
168
162
  - lib/restforce/collection.rb
163
+ - lib/restforce/concerns/api.rb
164
+ - lib/restforce/concerns/authentication.rb
165
+ - lib/restforce/concerns/base.rb
166
+ - lib/restforce/concerns/caching.rb
167
+ - lib/restforce/concerns/canvas.rb
168
+ - lib/restforce/concerns/connection.rb
169
+ - lib/restforce/concerns/picklists.rb
170
+ - lib/restforce/concerns/streaming.rb
171
+ - lib/restforce/concerns/verbs.rb
169
172
  - lib/restforce/config.rb
173
+ - lib/restforce/data/client.rb
170
174
  - lib/restforce/mash.rb
171
175
  - lib/restforce/middleware.rb
172
176
  - lib/restforce/middleware/authentication.rb
@@ -182,6 +186,7 @@ files:
182
186
  - lib/restforce/middleware/raise_error.rb
183
187
  - lib/restforce/signed_request.rb
184
188
  - lib/restforce/sobject.rb
189
+ - lib/restforce/tooling/client.rb
185
190
  - lib/restforce/upload_io.rb
186
191
  - lib/restforce/version.rb
187
192
  - restforce.gemspec
@@ -216,28 +221,40 @@ files:
216
221
  - spec/fixtures/sobject/upsert_multiple_error_response.json
217
222
  - spec/fixtures/sobject/upsert_updated_success_response.json
218
223
  - spec/fixtures/sobject/write_error_response.json
219
- - spec/lib/attachment_spec.rb
220
- - spec/lib/client_spec.rb
221
- - spec/lib/collection_spec.rb
222
- - spec/lib/config_spec.rb
223
- - spec/lib/mash_spec.rb
224
- - spec/lib/middleware/authentication/password_spec.rb
225
- - spec/lib/middleware/authentication/token_spec.rb
226
- - spec/lib/middleware/authentication_spec.rb
227
- - spec/lib/middleware/authorization_spec.rb
228
- - spec/lib/middleware/gzip_spec.rb
229
- - spec/lib/middleware/instance_url_spec.rb
230
- - spec/lib/middleware/logger_spec.rb
231
- - spec/lib/middleware/mashify_spec.rb
232
- - spec/lib/middleware/raise_error_spec.rb
233
- - spec/lib/signed_request_spec.rb
234
- - spec/lib/sobject_spec.rb
224
+ - spec/integration/abstract_client_spec.rb
225
+ - spec/integration/data/client_spec.rb
235
226
  - spec/spec_helper.rb
236
- - spec/support/basic_client.rb
227
+ - spec/support/client_integration.rb
228
+ - spec/support/concerns.rb
229
+ - spec/support/event_machine.rb
237
230
  - spec/support/fixture_helpers.rb
238
231
  - spec/support/matchers.rb
239
232
  - spec/support/middleware.rb
240
233
  - spec/support/mock_cache.rb
234
+ - spec/unit/abstract_client_spec.rb
235
+ - spec/unit/attachment_spec.rb
236
+ - spec/unit/collection_spec.rb
237
+ - spec/unit/concerns/api_spec.rb
238
+ - spec/unit/concerns/authentication_spec.rb
239
+ - spec/unit/concerns/base_spec.rb
240
+ - spec/unit/concerns/caching_spec.rb
241
+ - spec/unit/concerns/canvas_spec.rb
242
+ - spec/unit/concerns/connection_spec.rb
243
+ - spec/unit/config_spec.rb
244
+ - spec/unit/data/client_spec.rb
245
+ - spec/unit/mash_spec.rb
246
+ - spec/unit/middleware/authentication/password_spec.rb
247
+ - spec/unit/middleware/authentication/token_spec.rb
248
+ - spec/unit/middleware/authentication_spec.rb
249
+ - spec/unit/middleware/authorization_spec.rb
250
+ - spec/unit/middleware/gzip_spec.rb
251
+ - spec/unit/middleware/instance_url_spec.rb
252
+ - spec/unit/middleware/logger_spec.rb
253
+ - spec/unit/middleware/mashify_spec.rb
254
+ - spec/unit/middleware/raise_error_spec.rb
255
+ - spec/unit/signed_request_spec.rb
256
+ - spec/unit/sobject_spec.rb
257
+ - spec/unit/tooling/client_spec.rb
241
258
  homepage: https://github.com/ejholmes/restforce
242
259
  licenses: []
243
260
  post_install_message:
@@ -252,7 +269,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
252
269
  version: '0'
253
270
  segments:
254
271
  - 0
255
- hash: 2514062890750763667
272
+ hash: -563972279919245116
256
273
  required_rubygems_version: !ruby/object:Gem::Requirement
257
274
  none: false
258
275
  requirements:
@@ -261,7 +278,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
261
278
  version: '0'
262
279
  segments:
263
280
  - 0
264
- hash: 2514062890750763667
281
+ hash: -563972279919245116
265
282
  requirements: []
266
283
  rubyforge_project:
267
284
  rubygems_version: 1.8.23
@@ -300,25 +317,37 @@ test_files:
300
317
  - spec/fixtures/sobject/upsert_multiple_error_response.json
301
318
  - spec/fixtures/sobject/upsert_updated_success_response.json
302
319
  - spec/fixtures/sobject/write_error_response.json
303
- - spec/lib/attachment_spec.rb
304
- - spec/lib/client_spec.rb
305
- - spec/lib/collection_spec.rb
306
- - spec/lib/config_spec.rb
307
- - spec/lib/mash_spec.rb
308
- - spec/lib/middleware/authentication/password_spec.rb
309
- - spec/lib/middleware/authentication/token_spec.rb
310
- - spec/lib/middleware/authentication_spec.rb
311
- - spec/lib/middleware/authorization_spec.rb
312
- - spec/lib/middleware/gzip_spec.rb
313
- - spec/lib/middleware/instance_url_spec.rb
314
- - spec/lib/middleware/logger_spec.rb
315
- - spec/lib/middleware/mashify_spec.rb
316
- - spec/lib/middleware/raise_error_spec.rb
317
- - spec/lib/signed_request_spec.rb
318
- - spec/lib/sobject_spec.rb
320
+ - spec/integration/abstract_client_spec.rb
321
+ - spec/integration/data/client_spec.rb
319
322
  - spec/spec_helper.rb
320
- - spec/support/basic_client.rb
323
+ - spec/support/client_integration.rb
324
+ - spec/support/concerns.rb
325
+ - spec/support/event_machine.rb
321
326
  - spec/support/fixture_helpers.rb
322
327
  - spec/support/matchers.rb
323
328
  - spec/support/middleware.rb
324
329
  - spec/support/mock_cache.rb
330
+ - spec/unit/abstract_client_spec.rb
331
+ - spec/unit/attachment_spec.rb
332
+ - spec/unit/collection_spec.rb
333
+ - spec/unit/concerns/api_spec.rb
334
+ - spec/unit/concerns/authentication_spec.rb
335
+ - spec/unit/concerns/base_spec.rb
336
+ - spec/unit/concerns/caching_spec.rb
337
+ - spec/unit/concerns/canvas_spec.rb
338
+ - spec/unit/concerns/connection_spec.rb
339
+ - spec/unit/config_spec.rb
340
+ - spec/unit/data/client_spec.rb
341
+ - spec/unit/mash_spec.rb
342
+ - spec/unit/middleware/authentication/password_spec.rb
343
+ - spec/unit/middleware/authentication/token_spec.rb
344
+ - spec/unit/middleware/authentication_spec.rb
345
+ - spec/unit/middleware/authorization_spec.rb
346
+ - spec/unit/middleware/gzip_spec.rb
347
+ - spec/unit/middleware/instance_url_spec.rb
348
+ - spec/unit/middleware/logger_spec.rb
349
+ - spec/unit/middleware/mashify_spec.rb
350
+ - spec/unit/middleware/raise_error_spec.rb
351
+ - spec/unit/signed_request_spec.rb
352
+ - spec/unit/sobject_spec.rb
353
+ - spec/unit/tooling/client_spec.rb
@@ -1,12 +0,0 @@
1
- module Restforce
2
- class Client
3
- module Canvas
4
-
5
- def decode_signed_request(signed_request)
6
- raise 'client_secret not set' unless @options[:client_secret]
7
- SignedRequest.decode(signed_request, @options[:client_secret])
8
- end
9
-
10
- end
11
- end
12
- end
@@ -1,52 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Restforce::Collection do
4
- let(:client) { double('client') }
5
-
6
- describe '#new' do
7
- subject { records }
8
-
9
- context 'without pagination' do
10
- let(:records) do
11
- described_class.new(JSON.parse(fixture('sobject/query_success_response')), client)
12
- end
13
-
14
- it { should respond_to :each }
15
- its(:size) { should eq 1 }
16
- its(:has_next_page?) { should be_false }
17
- specify { expect(subject.instance_variable_get(:@client)).to eq client }
18
-
19
- describe 'each record' do
20
- subject { records }
21
- it { should be_all { |record| expect(record).to be_a Restforce::SObject } }
22
- end
23
- end
24
-
25
- context 'with pagination' do
26
- let(:first_page) { JSON.parse(fixture('sobject/query_paginated_first_page_response')) }
27
- let(:next_page) { JSON.parse(fixture('sobject/query_paginated_last_page_response')) }
28
- let(:records) { described_class.new(first_page, client) }
29
-
30
- it { should respond_to :each }
31
- specify { expect(subject.instance_variable_get(:@client)).to eq client }
32
-
33
- context 'when only values from the first page are being requested' do
34
- before { client.should_not_receive(:get) }
35
-
36
- its(:size) { should eq 2 }
37
- its(:first) { should be_an_instance_of Restforce::SObject }
38
- end
39
-
40
- context 'when all of the values are being requested' do
41
- before do
42
- client.stub(:get).and_return(Faraday::Response.new(:body => Restforce::Collection.new(next_page, client)))
43
- end
44
-
45
- its(:pages) { should be_all { |page| expect(page).to be_a Restforce::Collection } }
46
- its(:has_next_page?) { should be_true }
47
- it { should be_all { |record| expect(record).to be_a Restforce::SObject } }
48
- specify { subject.next_page.should be_a Restforce::Collection }
49
- end
50
- end
51
- end
52
- end
@@ -1,69 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Restforce::Middleware::Authentication do
4
- let(:app) { double('app') }
5
- let(:env) { { } }
6
- let(:retries) { 3 }
7
- let(:options) { { :host => 'login.salesforce.com', :authentication_retries => retries } }
8
- let(:middleware) { described_class.new app, nil, options }
9
-
10
- describe '.authenticate!' do
11
- it 'raises an error' do
12
- expect {
13
- middleware.authenticate!
14
- }.to raise_error RuntimeError, 'not implemented'
15
- end
16
- end
17
-
18
- describe '.call' do
19
- context 'when all is good' do
20
- before do
21
- app.should_receive(:call).once
22
- end
23
-
24
- it 'calls the next middlware' do
25
- middleware.call(env)
26
- end
27
- end
28
-
29
- context 'when an exception is thrown' do
30
- before do
31
- env[:body] = 'foo'
32
- env[:request] = {:proxy => nil}
33
- end
34
-
35
- it 'attempts to authenticate' do
36
- app.should_receive(:call).once.and_raise(Restforce::UnauthorizedError.new('something bad'))
37
- middleware.should_receive(:authenticate!)
38
- expect { middleware.call(env) }.to raise_error Restforce::UnauthorizedError
39
- end
40
- end
41
- end
42
-
43
- describe '.connection' do
44
- subject { middleware.connection }
45
-
46
- its(:url_prefix) { should eq URI.parse('https://login.salesforce.com') }
47
-
48
- describe '.builder' do
49
- subject { middleware.connection.builder }
50
-
51
- context 'with logging disabled' do
52
- before do
53
- Restforce.stub!(:log?).and_return(false)
54
- end
55
-
56
- its(:handlers) { should include FaradayMiddleware::ParseJson, Faraday::Adapter::NetHttp }
57
- its(:handlers) { should_not include Restforce::Middleware::Logger }
58
- end
59
-
60
- context 'with logging enabled' do
61
- before do
62
- Restforce.stub!(:log?).and_return(true)
63
- end
64
-
65
- its(:handlers) { should include FaradayMiddleware::ParseJson, Restforce::Middleware::Logger, Faraday::Adapter::NetHttp }
66
- end
67
- end
68
- end
69
- end