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.
- data/.travis.yml +1 -0
- data/CHANGELOG.md +7 -1
- data/Gemfile +4 -0
- data/Guardfile +11 -0
- data/README.md +19 -8
- data/lib/restforce.rb +44 -14
- data/lib/restforce/abstract_client.rb +9 -0
- data/lib/restforce/client.rb +1 -95
- data/lib/restforce/{client → concerns}/api.rb +9 -9
- data/lib/restforce/{client → concerns}/authentication.rb +9 -9
- data/lib/restforce/concerns/base.rb +58 -0
- data/lib/restforce/{client → concerns}/caching.rb +4 -4
- data/lib/restforce/concerns/canvas.rb +12 -0
- data/lib/restforce/{client → concerns}/connection.rb +13 -12
- data/lib/restforce/{client → concerns}/picklists.rb +1 -1
- data/lib/restforce/{client → concerns}/streaming.rb +3 -3
- data/lib/restforce/{client → concerns}/verbs.rb +4 -4
- data/lib/restforce/config.rb +40 -10
- data/lib/restforce/data/client.rb +18 -0
- data/lib/restforce/middleware/authentication.rb +9 -2
- data/lib/restforce/sobject.rb +1 -1
- data/lib/restforce/tooling/client.rb +13 -0
- data/lib/restforce/version.rb +1 -1
- data/spec/{lib/client_spec.rb → integration/abstract_client_spec.rb} +21 -214
- data/spec/integration/data/client_spec.rb +90 -0
- data/spec/spec_helper.rb +0 -14
- data/spec/support/client_integration.rb +45 -0
- data/spec/support/concerns.rb +18 -0
- data/spec/support/event_machine.rb +14 -0
- data/spec/support/middleware.rb +18 -1
- data/spec/unit/abstract_client_spec.rb +11 -0
- data/spec/{lib → unit}/attachment_spec.rb +3 -6
- data/spec/unit/collection_spec.rb +50 -0
- data/spec/unit/concerns/api_spec.rb +222 -0
- data/spec/unit/concerns/authentication_spec.rb +98 -0
- data/spec/unit/concerns/base_spec.rb +50 -0
- data/spec/unit/concerns/caching_spec.rb +29 -0
- data/spec/unit/concerns/canvas_spec.rb +30 -0
- data/spec/unit/concerns/connection_spec.rb +14 -0
- data/spec/{lib → unit}/config_spec.rb +13 -23
- data/spec/unit/data/client_spec.rb +10 -0
- data/spec/{lib → unit}/mash_spec.rb +0 -0
- data/spec/{lib → unit}/middleware/authentication/password_spec.rb +0 -4
- data/spec/{lib → unit}/middleware/authentication/token_spec.rb +0 -4
- data/spec/unit/middleware/authentication_spec.rb +67 -0
- data/spec/unit/middleware/authorization_spec.rb +11 -0
- data/spec/{lib → unit}/middleware/gzip_spec.rb +15 -30
- data/spec/unit/middleware/instance_url_spec.rb +24 -0
- data/spec/{lib → unit}/middleware/logger_spec.rb +4 -7
- data/spec/unit/middleware/mashify_spec.rb +11 -0
- data/spec/{lib → unit}/middleware/raise_error_spec.rb +4 -5
- data/spec/{lib → unit}/signed_request_spec.rb +0 -0
- data/spec/unit/sobject_spec.rb +68 -0
- data/spec/unit/tooling/client_spec.rb +7 -0
- metadata +75 -46
- data/lib/restforce/client/canvas.rb +0 -12
- data/spec/lib/collection_spec.rb +0 -52
- data/spec/lib/middleware/authentication_spec.rb +0 -69
- data/spec/lib/middleware/authorization_spec.rb +0 -17
- data/spec/lib/middleware/instance_url_spec.rb +0 -31
- data/spec/lib/middleware/mashify_spec.rb +0 -28
- data/spec/lib/sobject_spec.rb +0 -122
- data/spec/support/basic_client.rb +0 -37
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Restforce::Middleware::Authorization do
|
4
|
-
let(:app) { double('app') }
|
5
|
-
let(:env) { { :request_headers => {} } }
|
6
|
-
let(:options) { { :oauth_token => 'token' } }
|
7
|
-
let(:middleware) { described_class.new app, nil, options }
|
8
|
-
|
9
|
-
before do
|
10
|
-
app.should_receive(:call)
|
11
|
-
middleware.call(env)
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'adds the oauth token to the headers' do
|
15
|
-
expect(env[:request_headers]['Authorization']).to eq 'OAuth token'
|
16
|
-
end
|
17
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Restforce::Middleware::InstanceURL do
|
4
|
-
let(:app) { double('app') }
|
5
|
-
let(:client) { double('client') }
|
6
|
-
let(:options) { { } }
|
7
|
-
let(:middleware) { described_class.new app, client, options }
|
8
|
-
|
9
|
-
context 'when the instance url is not set' do
|
10
|
-
before do
|
11
|
-
client.stub_chain(:connection, :url_prefix).and_return(URI.parse('http:/'))
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'raises an exception' do
|
15
|
-
expect {
|
16
|
-
middleware.call(nil)
|
17
|
-
}.to raise_error Restforce::UnauthorizedError
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
context 'when the instance url is set' do
|
22
|
-
before do
|
23
|
-
client.stub_chain(:connection, :url_prefix).and_return(URI.parse('http://foobar.com/'))
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'does not raise an exception' do
|
27
|
-
app.should_receive(:call).once
|
28
|
-
middleware.call(nil)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Restforce::Middleware::Mashify do
|
4
|
-
let(:app) { double('app') }
|
5
|
-
let(:options) { { } }
|
6
|
-
let(:middleware) { described_class.new app, nil, options }
|
7
|
-
|
8
|
-
before do
|
9
|
-
app.should_receive(:call)
|
10
|
-
middleware.call(env)
|
11
|
-
end
|
12
|
-
|
13
|
-
context 'when the body contains a records key' do
|
14
|
-
let(:env) { { :body => JSON.parse(fixture('sobject/query_success_response')) } }
|
15
|
-
|
16
|
-
it 'converts the response body into a restforce collection' do
|
17
|
-
expect(env[:body]).to be_a Restforce::Collection
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
context 'when the body does not contain records' do
|
22
|
-
let(:env) { { :body => { 'foo' => 'bar' } } }
|
23
|
-
|
24
|
-
it 'does not touch the body' do
|
25
|
-
expect(env[:body].foo).to eq 'bar'
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
data/spec/lib/sobject_spec.rb
DELETED
@@ -1,122 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Restforce::SObject do
|
4
|
-
include_context 'basic client'
|
5
|
-
|
6
|
-
let(:hash) { JSON.parse(fixture('sobject/query_success_response'))['records'].first }
|
7
|
-
let(:sobject) do
|
8
|
-
described_class.new(hash, client)
|
9
|
-
end
|
10
|
-
|
11
|
-
describe '#new' do
|
12
|
-
context 'with valid options' do
|
13
|
-
subject { sobject }
|
14
|
-
it { should be_a Restforce::SObject }
|
15
|
-
its(:sobject_type) { should eq 'Whizbang' }
|
16
|
-
its(:Text_Label) { should eq 'Hi there!' }
|
17
|
-
it { should have_client client }
|
18
|
-
|
19
|
-
describe 'children' do
|
20
|
-
subject { sobject.Whizbangs__r }
|
21
|
-
|
22
|
-
it { should be_a Restforce::Collection }
|
23
|
-
|
24
|
-
describe 'each child' do
|
25
|
-
subject { sobject.Whizbangs__r }
|
26
|
-
it { should be_all { |sobject| expect(sobject).to be_a Restforce::SObject } }
|
27
|
-
it { should be_all { |sobject| expect(sobject).to have_client client } }
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe 'parent' do
|
32
|
-
subject { sobject.ParentWhizbang__r }
|
33
|
-
|
34
|
-
it { should be_a Restforce::SObject }
|
35
|
-
its(:sobject_type) { should eq 'Whizbang' }
|
36
|
-
its(:Name) { should eq 'Parent Whizbang' }
|
37
|
-
it { should have_client client }
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe '.save' do
|
43
|
-
subject { sobject.save }
|
44
|
-
|
45
|
-
context 'when an Id was not queried' do
|
46
|
-
specify { expect { subject }.to raise_error RuntimeError, 'You need to query the Id for the record first.' }
|
47
|
-
end
|
48
|
-
|
49
|
-
context 'when an Id is present' do
|
50
|
-
requests 'sobjects/Whizbang/001D000000INjVe',
|
51
|
-
:method => :patch,
|
52
|
-
:with_body => "{\"Checkbox_Label\":false,\"Text_Label\":\"Hi there!\",\"Date_Label\":\"2010-01-01\"," +
|
53
|
-
"\"DateTime_Label\":\"2011-07-07T00:37:00.000+0000\",\"Picklist_Multiselect_Label\":\"four;six\"}"
|
54
|
-
|
55
|
-
before do
|
56
|
-
hash.merge!(:Id => '001D000000INjVe')
|
57
|
-
end
|
58
|
-
|
59
|
-
specify { expect { subject }.to_not raise_error }
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
describe '.save!' do
|
64
|
-
subject { sobject.save! }
|
65
|
-
|
66
|
-
context 'when an exception is raised' do
|
67
|
-
requests 'sobjects/Whizbang/001D000000INjVe',
|
68
|
-
:fixture => 'sobject/delete_error_response',
|
69
|
-
:method => :patch,
|
70
|
-
:status => 404
|
71
|
-
|
72
|
-
before do
|
73
|
-
hash.merge!(:Id => '001D000000INjVe')
|
74
|
-
end
|
75
|
-
|
76
|
-
specify { expect { subject }.to raise_error Faraday::Error::ResourceNotFound }
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
describe '.destroy' do
|
81
|
-
subject { sobject.destroy }
|
82
|
-
|
83
|
-
context 'when an Id was not queried' do
|
84
|
-
specify { expect { subject }.to raise_error RuntimeError, 'You need to query the Id for the record first.' }
|
85
|
-
end
|
86
|
-
|
87
|
-
context 'when an Id is present' do
|
88
|
-
requests 'sobjects/Whizbang/001D000000INjVe', :method => :delete
|
89
|
-
|
90
|
-
before do
|
91
|
-
hash.merge!(:Id => '001D000000INjVe')
|
92
|
-
end
|
93
|
-
|
94
|
-
specify { expect { subject }.to_not raise_error }
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
describe '.destroy!' do
|
99
|
-
subject { sobject.destroy! }
|
100
|
-
|
101
|
-
context 'when an exception is raised' do
|
102
|
-
requests 'sobjects/Whizbang/001D000000INjVe',
|
103
|
-
:fixture => 'sobject/delete_error_response',
|
104
|
-
:method => :delete,
|
105
|
-
:status => 404
|
106
|
-
|
107
|
-
before do
|
108
|
-
hash.merge!(:Id => '001D000000INjVe')
|
109
|
-
end
|
110
|
-
|
111
|
-
specify { expect { subject }.to raise_error Faraday::Error::ResourceNotFound }
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
describe '.describe' do
|
116
|
-
requests 'sobjects/Whizbang/describe',
|
117
|
-
:fixture => 'sobject/sobject_describe_success_response'
|
118
|
-
|
119
|
-
subject { sobject.describe }
|
120
|
-
it { should be_a Hash }
|
121
|
-
end
|
122
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
shared_context 'basic client' do
|
2
|
-
let(:oauth_token) { '00Dx0000000BV7z!AR8AQAxo9UfVkh8AlV0Gomt9Czx9LjHnSSpwBMmbRcgKFmxOtvxjTrKW19ye6PE3Ds1eQz3z8jr3W7_VbWmEu4Q8TVGSTHxs' }
|
3
|
-
let(:refresh_token) { 'refresh' }
|
4
|
-
let(:instance_url) { 'https://na1.salesforce.com' }
|
5
|
-
let(:username) { 'foo' }
|
6
|
-
let(:password) { 'bar' }
|
7
|
-
let(:security_token) { 'security_token' }
|
8
|
-
let(:client_id) { 'client_id' }
|
9
|
-
let(:client_secret) { 'client_secret' }
|
10
|
-
let(:cache) { nil }
|
11
|
-
|
12
|
-
let(:base_options) do
|
13
|
-
{
|
14
|
-
:oauth_token => oauth_token,
|
15
|
-
:refresh_token => refresh_token,
|
16
|
-
:instance_url => instance_url,
|
17
|
-
:username => username,
|
18
|
-
:password => password,
|
19
|
-
:security_token => security_token,
|
20
|
-
:client_id => client_id,
|
21
|
-
:client_secret => client_secret,
|
22
|
-
:cache => cache
|
23
|
-
}
|
24
|
-
end
|
25
|
-
|
26
|
-
let(:oauth_options) do
|
27
|
-
base_options.merge(:username => nil, :password => nil, :security_token => nil, :oauth_token => nil)
|
28
|
-
end
|
29
|
-
|
30
|
-
let(:password_options) do
|
31
|
-
base_options.merge(:oauth_token => nil, :refresh_token => nil, :instance_url => nil, :security_token => nil)
|
32
|
-
end
|
33
|
-
|
34
|
-
let(:client_options) { base_options }
|
35
|
-
|
36
|
-
let(:client) { Restforce::Client.new(client_options) }
|
37
|
-
end
|