force 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +96 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +107 -0
- data/Guardfile +8 -0
- data/LICENSE +22 -0
- data/README.md +421 -0
- data/Rakefile +10 -0
- data/coverage/assets/0.7.1/application.css +1110 -0
- data/coverage/assets/0.7.1/application.js +626 -0
- data/coverage/assets/0.7.1/fancybox/blank.gif +0 -0
- data/coverage/assets/0.7.1/fancybox/fancy_close.png +0 -0
- data/coverage/assets/0.7.1/fancybox/fancy_loading.png +0 -0
- data/coverage/assets/0.7.1/fancybox/fancy_nav_left.png +0 -0
- data/coverage/assets/0.7.1/fancybox/fancy_nav_right.png +0 -0
- data/coverage/assets/0.7.1/fancybox/fancy_shadow_e.png +0 -0
- data/coverage/assets/0.7.1/fancybox/fancy_shadow_n.png +0 -0
- data/coverage/assets/0.7.1/fancybox/fancy_shadow_ne.png +0 -0
- data/coverage/assets/0.7.1/fancybox/fancy_shadow_nw.png +0 -0
- data/coverage/assets/0.7.1/fancybox/fancy_shadow_s.png +0 -0
- data/coverage/assets/0.7.1/fancybox/fancy_shadow_se.png +0 -0
- data/coverage/assets/0.7.1/fancybox/fancy_shadow_sw.png +0 -0
- data/coverage/assets/0.7.1/fancybox/fancy_shadow_w.png +0 -0
- data/coverage/assets/0.7.1/fancybox/fancy_title_left.png +0 -0
- data/coverage/assets/0.7.1/fancybox/fancy_title_main.png +0 -0
- data/coverage/assets/0.7.1/fancybox/fancy_title_over.png +0 -0
- data/coverage/assets/0.7.1/fancybox/fancy_title_right.png +0 -0
- data/coverage/assets/0.7.1/fancybox/fancybox-x.png +0 -0
- data/coverage/assets/0.7.1/fancybox/fancybox-y.png +0 -0
- data/coverage/assets/0.7.1/fancybox/fancybox.png +0 -0
- data/coverage/assets/0.7.1/favicon_green.png +0 -0
- data/coverage/assets/0.7.1/favicon_red.png +0 -0
- data/coverage/assets/0.7.1/favicon_yellow.png +0 -0
- data/coverage/assets/0.7.1/loading.gif +0 -0
- data/coverage/assets/0.7.1/magnify.png +0 -0
- data/coverage/assets/0.7.1/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/coverage/assets/0.7.1/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/coverage/assets/0.7.1/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/coverage/assets/0.7.1/smoothness/images/ui-icons_222222_256x240.png +0 -0
- data/coverage/assets/0.7.1/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
- data/coverage/assets/0.7.1/smoothness/images/ui-icons_454545_256x240.png +0 -0
- data/coverage/assets/0.7.1/smoothness/images/ui-icons_888888_256x240.png +0 -0
- data/coverage/assets/0.7.1/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/coverage/index.html +19808 -0
- data/force.gemspec +27 -0
- data/lib/force.rb +74 -0
- data/lib/force/abstract_client.rb +9 -0
- data/lib/force/attachment.rb +21 -0
- data/lib/force/client.rb +3 -0
- data/lib/force/collection.rb +45 -0
- data/lib/force/concerns/api.rb +321 -0
- data/lib/force/concerns/authentication.rb +39 -0
- data/lib/force/concerns/base.rb +59 -0
- data/lib/force/concerns/caching.rb +24 -0
- data/lib/force/concerns/canvas.rb +10 -0
- data/lib/force/concerns/connection.rb +74 -0
- data/lib/force/concerns/picklists.rb +87 -0
- data/lib/force/concerns/streaming.rb +31 -0
- data/lib/force/concerns/verbs.rb +67 -0
- data/lib/force/config.rb +140 -0
- data/lib/force/data/client.rb +18 -0
- data/lib/force/mash.rb +66 -0
- data/lib/force/middleware.rb +27 -0
- data/lib/force/middleware/authentication.rb +73 -0
- data/lib/force/middleware/authentication/password.rb +17 -0
- data/lib/force/middleware/authentication/token.rb +15 -0
- data/lib/force/middleware/authorization.rb +15 -0
- data/lib/force/middleware/caching.rb +22 -0
- data/lib/force/middleware/gzip.rb +31 -0
- data/lib/force/middleware/instance_url.rb +14 -0
- data/lib/force/middleware/logger.rb +40 -0
- data/lib/force/middleware/mashify.rb +16 -0
- data/lib/force/middleware/multipart.rb +55 -0
- data/lib/force/middleware/raise_error.rb +25 -0
- data/lib/force/signed_request.rb +48 -0
- data/lib/force/sobject.rb +68 -0
- data/lib/force/tooling/client.rb +11 -0
- data/lib/force/upload_io.rb +20 -0
- data/lib/force/version.rb +3 -0
- data/spec/fixtures/auth_error_response.json +4 -0
- data/spec/fixtures/auth_success_response.json +7 -0
- data/spec/fixtures/blob.jpg +0 -0
- data/spec/fixtures/expired_session_response.json +6 -0
- data/spec/fixtures/reauth_success_response.json +7 -0
- data/spec/fixtures/refresh_error_response.json +4 -0
- data/spec/fixtures/refresh_success_response.json +7 -0
- data/spec/fixtures/services_data_success_response.json +12 -0
- data/spec/fixtures/sobject/create_success_response.json +5 -0
- data/spec/fixtures/sobject/delete_error_response.json +1 -0
- data/spec/fixtures/sobject/describe_sobjects_success_response.json +31 -0
- data/spec/fixtures/sobject/list_sobjects_success_response.json +31 -0
- data/spec/fixtures/sobject/org_query_response.json +11 -0
- data/spec/fixtures/sobject/query_aggregate_success_response.json +23 -0
- data/spec/fixtures/sobject/query_empty_response.json +5 -0
- data/spec/fixtures/sobject/query_error_response.json +6 -0
- data/spec/fixtures/sobject/query_paginated_first_page_response.json +14 -0
- data/spec/fixtures/sobject/query_paginated_last_page_response.json +13 -0
- data/spec/fixtures/sobject/query_success_response.json +38 -0
- data/spec/fixtures/sobject/recent_success_response.json +18 -0
- data/spec/fixtures/sobject/search_error_response.json +6 -0
- data/spec/fixtures/sobject/search_success_response.json +16 -0
- data/spec/fixtures/sobject/sobject_describe_error_response.json +6 -0
- data/spec/fixtures/sobject/sobject_describe_success_response.json +1429 -0
- data/spec/fixtures/sobject/sobject_find_error_response.json +6 -0
- data/spec/fixtures/sobject/sobject_find_success_response.json +29 -0
- data/spec/fixtures/sobject/upsert_created_success_response.json +5 -0
- data/spec/fixtures/sobject/upsert_error_response.json +6 -0
- data/spec/fixtures/sobject/upsert_multiple_error_response.json +4 -0
- data/spec/fixtures/sobject/upsert_updated_success_response.json +0 -0
- data/spec/fixtures/sobject/write_error_response.json +6 -0
- data/spec/integration/abstract_client_spec.rb +306 -0
- data/spec/integration/data/client_spec.rb +90 -0
- data/spec/spec_helper.rb +20 -0
- 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/fixture_helpers.rb +45 -0
- data/spec/support/matchers.rb +11 -0
- data/spec/support/middleware.rb +76 -0
- data/spec/support/mock_cache.rb +13 -0
- data/spec/unit/abstract_client_spec.rb +11 -0
- data/spec/unit/attachment_spec.rb +15 -0
- data/spec/unit/collection_spec.rb +52 -0
- data/spec/unit/concerns/api_spec.rb +244 -0
- data/spec/unit/concerns/authentication_spec.rb +98 -0
- data/spec/unit/concerns/base_spec.rb +42 -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 +22 -0
- data/spec/unit/config_spec.rb +99 -0
- data/spec/unit/data/client_spec.rb +10 -0
- data/spec/unit/mash_spec.rb +36 -0
- data/spec/unit/middleware/authentication/password_spec.rb +31 -0
- data/spec/unit/middleware/authentication/token_spec.rb +24 -0
- data/spec/unit/middleware/authentication_spec.rb +67 -0
- data/spec/unit/middleware/authorization_spec.rb +11 -0
- data/spec/unit/middleware/gzip_spec.rb +66 -0
- data/spec/unit/middleware/instance_url_spec.rb +24 -0
- data/spec/unit/middleware/logger_spec.rb +19 -0
- data/spec/unit/middleware/mashify_spec.rb +11 -0
- data/spec/unit/middleware/raise_error_spec.rb +32 -0
- data/spec/unit/signed_request_spec.rb +24 -0
- data/spec/unit/sobject_spec.rb +86 -0
- data/spec/unit/tooling/client_spec.rb +7 -0
- data/tmp/rspec_guard_result +1 -0
- metadata +383 -0
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Force::Concerns::Authentication do
|
4
|
+
describe '.authenticate!' do
|
5
|
+
subject { lambda { client.authenticate! } }
|
6
|
+
|
7
|
+
context 'when there is no authentication middleware' do
|
8
|
+
before do
|
9
|
+
client.stub :authentication_middleware => nil
|
10
|
+
end
|
11
|
+
|
12
|
+
it { should raise_error Force::AuthenticationError, 'No authentication middleware present' }
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'when there is authentication middleware' do
|
16
|
+
let(:authentication_middleware) { double('Authentication Middleware') }
|
17
|
+
subject(:result) { client.authenticate! }
|
18
|
+
|
19
|
+
it 'authenticates using the middleware' do
|
20
|
+
client.stub :authentication_middleware => authentication_middleware
|
21
|
+
client.stub :options
|
22
|
+
authentication_middleware.
|
23
|
+
should_receive(:new).
|
24
|
+
with(nil, client, client.options).
|
25
|
+
and_return(double(:authenticate! => 'foo'))
|
26
|
+
expect(result).to eq 'foo'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '.authentication_middleware' do
|
32
|
+
subject { client.authentication_middleware }
|
33
|
+
|
34
|
+
context 'when username and password options are provided' do
|
35
|
+
before do
|
36
|
+
client.stub :username_password? => true
|
37
|
+
end
|
38
|
+
|
39
|
+
it { should eq Force::Middleware::Authentication::Password }
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'when oauth options are provided' do
|
43
|
+
before do
|
44
|
+
client.stub :username_password? => false
|
45
|
+
client.stub :oauth_refresh? => true
|
46
|
+
end
|
47
|
+
|
48
|
+
it { should eq Force::Middleware::Authentication::Token }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '.username_password?' do
|
53
|
+
subject { client.username_password? }
|
54
|
+
let(:options) { Hash.new }
|
55
|
+
|
56
|
+
before do
|
57
|
+
client.stub :options => options
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'when username and password options are provided' do
|
61
|
+
let(:options) do
|
62
|
+
{ :username => 'foo',
|
63
|
+
:password => 'bar',
|
64
|
+
:client_id => 'client',
|
65
|
+
:client_secret => 'secret' }
|
66
|
+
end
|
67
|
+
|
68
|
+
it { should be_true }
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'when username and password options are not provided' do
|
72
|
+
it { should_not be_true }
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe '.oauth_refresh?' do
|
77
|
+
subject { client.oauth_refresh? }
|
78
|
+
let(:options) { Hash.new }
|
79
|
+
|
80
|
+
before do
|
81
|
+
client.stub :options => options
|
82
|
+
end
|
83
|
+
|
84
|
+
context 'when oauth options are provided' do
|
85
|
+
let(:options) do
|
86
|
+
{ :refresh_token => 'token',
|
87
|
+
:client_id => 'client',
|
88
|
+
:client_secret => 'secret' }
|
89
|
+
end
|
90
|
+
|
91
|
+
it { should be_true }
|
92
|
+
end
|
93
|
+
|
94
|
+
context 'when oauth options are not provided' do
|
95
|
+
it { should_not be_true }
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Force::Concerns::Base do
|
4
|
+
describe '#new' do
|
5
|
+
context 'without options passed in' do
|
6
|
+
it 'does not raise an exception' do
|
7
|
+
expect {
|
8
|
+
klass.new
|
9
|
+
}.to_not raise_error
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'yields the builder to the block' do
|
14
|
+
klass.any_instance.stub :builder
|
15
|
+
expect { |b| klass.new(&b) }.to yield_control
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '.options' do
|
20
|
+
subject { lambda { client.options } }
|
21
|
+
it { should_not raise_error }
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '.instance_url' do
|
25
|
+
subject { client.instance_url }
|
26
|
+
|
27
|
+
context 'when options[:instance_url] is unset' do
|
28
|
+
it 'triggers an authentication' do
|
29
|
+
client.should_receive :authenticate!
|
30
|
+
subject
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'when options[:instance_url] is set' do
|
35
|
+
before do
|
36
|
+
client.stub :options => { :instance_url => 'foo' }
|
37
|
+
end
|
38
|
+
|
39
|
+
it { should eq 'foo' }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Force::Concerns::Caching do
|
4
|
+
describe '.without_caching' do
|
5
|
+
let(:options) { double('Options') }
|
6
|
+
|
7
|
+
before do
|
8
|
+
client.stub :options => options
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'runs the block with caching disabled' do
|
12
|
+
options.should_receive(:[]=).with(:use_cache, false)
|
13
|
+
options.should_receive(:delete).with(:use_cache)
|
14
|
+
expect { |b| client.without_caching(&b) }.to yield_control
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'when an exception is raised' do
|
18
|
+
it 'ensures the :use_cache is deleted' do
|
19
|
+
options.should_receive(:[]=).with(:use_cache, false)
|
20
|
+
options.should_receive(:delete).with(:use_cache)
|
21
|
+
expect {
|
22
|
+
client.without_caching do
|
23
|
+
raise 'Foo'
|
24
|
+
end
|
25
|
+
}.to raise_error 'Foo'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Force::Concerns::Canvas do
|
4
|
+
let(:options) { Hash.new }
|
5
|
+
|
6
|
+
before do
|
7
|
+
client.stub :options => options
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '.decode_signed_request' do
|
11
|
+
subject { client.decode_signed_request(signed_request) }
|
12
|
+
let(:signed_request) { double('Signed Request') }
|
13
|
+
|
14
|
+
context 'when the client_secret is set' do
|
15
|
+
let(:options) { { :client_secret => 'secret' } }
|
16
|
+
|
17
|
+
it 'delegates to Force::SignedRequest' do
|
18
|
+
Force::SignedRequest.should_receive(:decode).
|
19
|
+
with(signed_request, options[:client_secret])
|
20
|
+
client.decode_signed_request(signed_request)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'when the client_secret is not set' do
|
25
|
+
it 'raises an exception' do
|
26
|
+
expect { subject }.to raise_error 'client_secret not set.'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Force::Concerns::Connection do
|
4
|
+
describe '.middleware' do
|
5
|
+
subject { client.middleware }
|
6
|
+
let(:builder) { double('Faraday::Builder') }
|
7
|
+
|
8
|
+
before do
|
9
|
+
client.stub_chain :connection, :builder => builder
|
10
|
+
end
|
11
|
+
|
12
|
+
it { should eq builder }
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#adapter' do
|
16
|
+
before do
|
17
|
+
client.stub :options => {:adapter => :typhoeus}
|
18
|
+
end
|
19
|
+
|
20
|
+
its(:adapter) { should eq(:typhoeus) }
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Force do
|
4
|
+
before do
|
5
|
+
ENV['SALESFORCE_USERNAME'] = nil
|
6
|
+
ENV['SALESFORCE_PASSWORD'] = nil
|
7
|
+
ENV['SALESFORCE_SECURITY_TOKEN'] = nil
|
8
|
+
ENV['SALESFORCE_CLIENT_ID'] = nil
|
9
|
+
ENV['SALESFORCE_CLIENT_SECRET'] = nil
|
10
|
+
end
|
11
|
+
|
12
|
+
after do
|
13
|
+
Force.instance_variable_set :@configuration, nil
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#configuration' do
|
17
|
+
subject { Force.configuration }
|
18
|
+
|
19
|
+
it { should be_a Force::Configuration }
|
20
|
+
|
21
|
+
context 'by default' do
|
22
|
+
its(:api_version) { should eq '26.0' }
|
23
|
+
its(:host) { should eq 'login.salesforce.com' }
|
24
|
+
its(:authentication_retries) { should eq 3 }
|
25
|
+
its(:adapter) { should eq Faraday.default_adapter }
|
26
|
+
[:username, :password, :security_token, :client_id, :client_secret,
|
27
|
+
:oauth_token, :refresh_token, :instance_url, :compress, :timeout,
|
28
|
+
:proxy_uri, :authentication_callback].each do |attr|
|
29
|
+
its(attr) { should be_nil }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'when environment variables are defined' do
|
34
|
+
before do
|
35
|
+
{ 'SALESFORCE_USERNAME' => 'foo',
|
36
|
+
'SALESFORCE_PASSWORD' => 'bar',
|
37
|
+
'SALESFORCE_SECURITY_TOKEN' => 'foobar',
|
38
|
+
'SALESFORCE_CLIENT_ID' => 'client id',
|
39
|
+
'SALESFORCE_CLIENT_SECRET' => 'client secret',
|
40
|
+
'PROXY_URI' => 'proxy',
|
41
|
+
'SALESFORCE_HOST' => 'test.host.com' }.
|
42
|
+
each { |var, value| ENV.stub(:[]).with(var).and_return(value) }
|
43
|
+
end
|
44
|
+
|
45
|
+
its(:username) { should eq 'foo' }
|
46
|
+
its(:password) { should eq 'bar'}
|
47
|
+
its(:security_token) { should eq 'foobar' }
|
48
|
+
its(:client_id) { should eq 'client id' }
|
49
|
+
its(:client_secret) { should eq 'client secret' }
|
50
|
+
its(:proxy_uri) { should eq 'proxy' }
|
51
|
+
its(:host) { should eq 'test.host.com' }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '#configure' do
|
56
|
+
[:username, :password, :security_token, :client_id, :client_secret, :compress, :timeout,
|
57
|
+
:oauth_token, :refresh_token, :instance_url, :api_version, :host, :authentication_retries,
|
58
|
+
:proxy_uri, :authentication_callback].each do |attr|
|
59
|
+
it "allows #{attr} to be set" do
|
60
|
+
Force.configure do |config|
|
61
|
+
config.send("#{attr}=", 'foobar')
|
62
|
+
end
|
63
|
+
expect(Force.configuration.send(attr)).to eq 'foobar'
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe '#log?' do
|
69
|
+
subject { Force.log? }
|
70
|
+
|
71
|
+
context 'by default' do
|
72
|
+
it { should be_false }
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe '#log' do
|
77
|
+
context 'with logging disabled' do
|
78
|
+
before do
|
79
|
+
Force.stub :log? => false
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'doesnt log anytning' do
|
83
|
+
Force.configuration.logger.should_not_receive(:debug)
|
84
|
+
Force.log 'foobar'
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'with logging enabled' do
|
89
|
+
before do
|
90
|
+
Force.stub :log? => true
|
91
|
+
Force.configuration.logger.should_receive(:debug).with('foobar')
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'logs something' do
|
95
|
+
Force.log 'foobar'
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Force::Client do
|
4
|
+
subject { described_class }
|
5
|
+
|
6
|
+
it { should < Force::AbstractClient }
|
7
|
+
it { should < Force::Concerns::Picklists }
|
8
|
+
it { should < Force::Concerns::Streaming }
|
9
|
+
it { should < Force::Concerns::Canvas }
|
10
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Force::Mash do
|
4
|
+
describe '#build' do
|
5
|
+
subject { described_class.build(input, nil) }
|
6
|
+
|
7
|
+
context 'when array' do
|
8
|
+
let(:input) { [{ :foo => 'hello' }, { :bar => 'world' }] }
|
9
|
+
it { should be_all { |obj| expect(obj).to be_a Force::Mash } }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#klass' do
|
14
|
+
subject { described_class.klass(input) }
|
15
|
+
|
16
|
+
context 'when the hash has a "records" key' do
|
17
|
+
let(:input) { { 'records' => nil } }
|
18
|
+
it { should eq Force::Collection }
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'when the hash has an "attributes" key' do
|
22
|
+
let(:input) { { 'attributes' => { 'type' => 'Account' } } }
|
23
|
+
it { should eq Force::SObject }
|
24
|
+
|
25
|
+
context 'when the sobject type is an Attachment' do
|
26
|
+
let(:input) { { 'attributes' => { 'type' => 'Attachment' } } }
|
27
|
+
it { should eq Force::Attachment }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'else' do
|
32
|
+
let(:input) { {} }
|
33
|
+
it { should eq Force::Mash }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Force::Middleware::Authentication::Password do
|
4
|
+
let(:options) do
|
5
|
+
{ :host => 'login.salesforce.com',
|
6
|
+
:username => 'foo',
|
7
|
+
:password => 'bar',
|
8
|
+
:security_token => 'security_token',
|
9
|
+
:client_id => 'client_id',
|
10
|
+
:client_secret => 'client_secret' }
|
11
|
+
end
|
12
|
+
|
13
|
+
it_behaves_like 'authentication middleware' do
|
14
|
+
let(:success_request) do
|
15
|
+
stub_login_request(:body => "grant_type=password&client_id=client_id&client_secret=" \
|
16
|
+
"client_secret&username=foo&password=barsecurity_token").
|
17
|
+
to_return(:status => 200, :body => fixture(:auth_success_response))
|
18
|
+
end
|
19
|
+
|
20
|
+
let(:fail_request) do
|
21
|
+
stub_login_request(:body => "grant_type=password&client_id=client_id&client_secret=" \
|
22
|
+
"client_secret&username=foo&password=barsecurity_token").
|
23
|
+
to_return(:status => 400, :body => fixture(:auth_error_response))
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '.password' do
|
28
|
+
subject { middleware.password }
|
29
|
+
it { should eq 'barsecurity_token' }
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Force::Middleware::Authentication::Token do
|
4
|
+
let(:options) do
|
5
|
+
{ :host => 'login.salesforce.com',
|
6
|
+
:refresh_token => 'refresh_token',
|
7
|
+
:client_id => 'client_id',
|
8
|
+
:client_secret => 'client_secret' }
|
9
|
+
end
|
10
|
+
|
11
|
+
it_behaves_like 'authentication middleware' do
|
12
|
+
let(:success_request) do
|
13
|
+
stub_login_request(:body => "grant_type=refresh_token&refresh_token=refresh_token&" \
|
14
|
+
"client_id=client_id&client_secret=client_secret").
|
15
|
+
to_return(:status => 200, :body => fixture(:auth_success_response))
|
16
|
+
end
|
17
|
+
|
18
|
+
let(:fail_request) do
|
19
|
+
stub_login_request(:body => "grant_type=refresh_token&refresh_token=refresh_token&" \
|
20
|
+
"client_id=client_id&client_secret=client_secret").
|
21
|
+
to_return(:status => 400, :body => fixture(:refresh_error_response))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Force::Middleware::Authentication do
|
4
|
+
let(:options) do
|
5
|
+
{ :host => 'login.salesforce.com',
|
6
|
+
:proxy_uri => 'https://not-a-real-site.com',
|
7
|
+
:authentication_retries => retries }
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '.authenticate!' do
|
11
|
+
subject { lambda { middleware.authenticate! }}
|
12
|
+
it { should raise_error NotImplementedError }
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '.call' do
|
16
|
+
subject { lambda { middleware.call(env) } }
|
17
|
+
|
18
|
+
context 'when successfull' do
|
19
|
+
before do
|
20
|
+
app.should_receive(:call).once
|
21
|
+
end
|
22
|
+
|
23
|
+
it { should_not raise_error }
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'when an exception is thrown' do
|
27
|
+
before do
|
28
|
+
env.stub :body => 'foo', :request => { :proxy => nil }
|
29
|
+
middleware.stub :authenticate!
|
30
|
+
app.should_receive(:call).once.
|
31
|
+
and_raise(Force::UnauthorizedError.new('something bad'))
|
32
|
+
end
|
33
|
+
|
34
|
+
it { should raise_error Force::UnauthorizedError }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '.connection' do
|
39
|
+
subject(:connection) { middleware.connection }
|
40
|
+
|
41
|
+
its(:url_prefix) { should eq(URI.parse('https://login.salesforce.com')) }
|
42
|
+
its(:proxy) { should eq({ :uri => URI.parse('https://not-a-real-site.com') }) }
|
43
|
+
|
44
|
+
describe '.builder' do
|
45
|
+
subject(:builder) { connection.builder }
|
46
|
+
|
47
|
+
context 'with logging disabled' do
|
48
|
+
before do
|
49
|
+
Force.stub :log? => false
|
50
|
+
end
|
51
|
+
|
52
|
+
its(:handlers) { should include FaradayMiddleware::ParseJson,
|
53
|
+
Faraday::Adapter::NetHttp }
|
54
|
+
its(:handlers) { should_not include Force::Middleware::Logger }
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'with logging enabled' do
|
58
|
+
before do
|
59
|
+
Force.stub :log? => true
|
60
|
+
end
|
61
|
+
|
62
|
+
its(:handlers) { should include FaradayMiddleware::ParseJson,
|
63
|
+
Force::Middleware::Logger, Faraday::Adapter::NetHttp }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|