metaforce 0.5.3 → 1.0.0a

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.
Files changed (72) hide show
  1. data/.gitignore +1 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +1 -11
  4. data/LICENSE +22 -0
  5. data/README.md +91 -96
  6. data/Rakefile +6 -14
  7. data/examples/example.rb +51 -0
  8. data/lib/metaforce/abstract_client.rb +76 -0
  9. data/lib/metaforce/client.rb +27 -0
  10. data/lib/metaforce/config.rb +41 -19
  11. data/lib/metaforce/job/crud.rb +13 -0
  12. data/lib/metaforce/job/deploy.rb +87 -0
  13. data/lib/metaforce/job/retrieve.rb +92 -0
  14. data/lib/metaforce/job.rb +183 -0
  15. data/lib/metaforce/login.rb +39 -0
  16. data/lib/metaforce/manifest.rb +18 -93
  17. data/lib/metaforce/metadata/client/crud.rb +86 -0
  18. data/lib/metaforce/metadata/client/file.rb +113 -0
  19. data/lib/metaforce/metadata/client.rb +7 -225
  20. data/lib/metaforce/services/client.rb +45 -86
  21. data/lib/metaforce/version.rb +1 -1
  22. data/lib/metaforce.rb +27 -7
  23. data/metaforce.gemspec +19 -16
  24. data/spec/fixtures/package.xml +1 -1
  25. data/spec/fixtures/payload.zip +0 -0
  26. data/spec/fixtures/requests/{describe_layout → foo}/invalid_session.xml +0 -0
  27. data/spec/fixtures/requests/send_email/success.xml +1 -0
  28. data/spec/lib/client_spec.rb +34 -0
  29. data/spec/lib/config_spec.rb +8 -50
  30. data/spec/lib/job/deploy_spec.rb +53 -0
  31. data/spec/lib/job/retrieve_spec.rb +28 -0
  32. data/spec/lib/job_spec.rb +95 -0
  33. data/spec/lib/login_spec.rb +18 -0
  34. data/spec/lib/manifest_spec.rb +22 -168
  35. data/spec/lib/metadata/client_spec.rb +84 -179
  36. data/spec/lib/metaforce_spec.rb +20 -0
  37. data/spec/lib/services/client_spec.rb +22 -35
  38. data/spec/spec_helper.rb +24 -3
  39. data/spec/support/client.rb +38 -0
  40. data/wsdl/26.0/metadata.xml +4750 -0
  41. data/wsdl/26.0/partner.xml +3340 -0
  42. metadata +114 -77
  43. data/Guardfile +0 -9
  44. data/bin/metaforce +0 -6
  45. data/lib/metaforce/core_extensions/string.rb +0 -31
  46. data/lib/metaforce/core_extensions.rb +0 -1
  47. data/lib/metaforce/custom_actions.rb +0 -29
  48. data/lib/metaforce/error.rb +0 -3
  49. data/lib/metaforce/login_details.rb +0 -28
  50. data/lib/metaforce/metadata/crud.rb +0 -103
  51. data/lib/metaforce/metadata/file.rb +0 -74
  52. data/lib/metaforce/metadata/transaction.rb +0 -100
  53. data/lib/metaforce/metadata.rb +0 -4
  54. data/lib/metaforce/rake/deploy.rb +0 -35
  55. data/lib/metaforce/rake/retrieve.rb +0 -39
  56. data/lib/metaforce/rake/tests.rb +0 -62
  57. data/lib/metaforce/rake.rb +0 -43
  58. data/lib/metaforce/services.rb +0 -1
  59. data/lib/metaforce/tasks/README.md +0 -62
  60. data/lib/metaforce/tasks/metaforce.rake +0 -5
  61. data/lib/metaforce/thor/metaforce.rb +0 -117
  62. data/lib/metaforce/types.rb +0 -249
  63. data/spec/.gitignore +0 -1
  64. data/spec/fixtures/sample/Rakefile +0 -2
  65. data/spec/fixtures/sample/metaforce.yml +0 -13
  66. data/spec/fixtures/sample/src/classes/TestClass.cls +0 -2
  67. data/spec/fixtures/sample/src/classes/TestClass.cls-meta.xml +0 -5
  68. data/spec/fixtures/sample/src/package.xml +0 -8
  69. data/spec/lib/core_extensions/string_spec.rb +0 -23
  70. data/spec/lib/metadata/crud_spec.rb +0 -66
  71. data/spec/lib/metadata/file_spec.rb +0 -17
  72. data/spec/lib/metadata/transaction_spec.rb +0 -68
@@ -1,50 +1,37 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe Metaforce::Services::Client do
4
- describe ".login" do
5
- context "when given invalid credentials" do
4
+ let(:client) { described_class.new(:session_id => 'foobar', :server_url => 'https://na12-api.salesforce.com/services/Soap/u/23.0/00DU0000000Ilbh') }
6
5
 
7
- it "raises an error" do
8
- savon.expects(:login).with(:username => 'invalid', :password => 'password').returns(:failure)
9
- expect { Metaforce::Services::Client.new(:username => 'invalid', :password => 'password') }.to raise_error
10
- end
6
+ it_behaves_like 'a client'
11
7
 
12
- end
13
- context "when given valid credentials" do
14
-
15
- it "returns a hash containing the session id and metadata server url" do
16
- savon.expects(:login).with(:username => 'valid', :password => 'password').returns(:success)
17
- session = Metaforce::Services::Client.new(:username => 'valid', :password => 'password').session
18
- session.should eq({ :session_id => "00DU0000000Ilbh!AQoAQHVcube9Z6CRlbR9Eg8ZxpJlrJ6X8QDbnokfyVZItFKzJsLHIRGiqhzJkYsNYRkd3UVA9.s82sbjEbZGUqP3mG6TP_P8",
19
- :metadata_server_url => "https://na12-api.salesforce.com/services/Soap/m/23.0/00DU0000000Albh",
20
- :services_url=>"https://na12-api.salesforce.com/services/Soap/u/23.0/00DU0000000Ilbh" })
8
+ describe '.describe_layout' do
9
+ context 'without a record type id' do
10
+ before do
11
+ savon.expects(:describe_layout).with('sObjectType' => 'Account').returns(:success)
21
12
  end
22
13
 
14
+ subject { client.describe_layout('Account') }
15
+ it { should be_a Hash }
23
16
  end
24
- context "when given a hash with strings" do
25
- it "works just like symbols" do
26
- savon.expects(:login).with(:username => 'valid', :password => 'password').returns(:success)
27
- session = Metaforce::Services::Client.new("username" => 'valid', "password" => 'password').session
28
- session.should eq({ :session_id => "00DU0000000Ilbh!AQoAQHVcube9Z6CRlbR9Eg8ZxpJlrJ6X8QDbnokfyVZItFKzJsLHIRGiqhzJkYsNYRkd3UVA9.s82sbjEbZGUqP3mG6TP_P8",
29
- :metadata_server_url => "https://na12-api.salesforce.com/services/Soap/m/23.0/00DU0000000Albh",
30
- :services_url=>"https://na12-api.salesforce.com/services/Soap/u/23.0/00DU0000000Ilbh" })
17
+
18
+ context 'with a record type id' do
19
+ before do
20
+ savon.expects(:describe_layout).with('sObjectType' => 'Account', 'recordTypeID' => '1234').returns(:success)
31
21
  end
22
+
23
+ subject { client.describe_layout('Account', '1234') }
24
+ it { should be_a Hash }
32
25
  end
33
26
  end
34
27
 
35
- describe "reauthentication" do
36
- let(:client) do
37
- savon.expects(:login).with(:username => 'valid', :password => 'password').returns(:success)
38
- client = Metaforce::Services::Client.new("username" => 'valid', "password" => 'password')
28
+ describe '.send_email' do
29
+ before do
30
+ savon.expects(:send_email).with(:messages => { :to_addresses => "foo@bar.com", :subject => "foo", :plain_text_body => "bar" },
31
+ :attributes! => { "ins0:messages" => { "xsi:type" => "ins0:SingleEmailMessage" } }).returns(:success)
39
32
  end
40
33
 
41
- context "when the session expires" do
42
- it "reauthenticates the user" do
43
- # savon.expects(:describe_layout).with('sObjectType' => 'Account').returns(:invalid_session)
44
- # savon.expects(:login).with(:username => 'valid', :password => 'password').returns(:success)
45
- # savon.expects(:describe_layout).with('sObjectType' => 'Account').returns(:success)
46
- # client.describe_layout('Account').should be_a(Hash)
47
- end
48
- end
34
+ subject { client.send_email(:to_addresses => 'foo@bar.com', subject: 'foo', plain_text_body: 'bar') }
35
+ it { should be_a Hash}
49
36
  end
50
37
  end
data/spec/spec_helper.rb CHANGED
@@ -1,13 +1,34 @@
1
- require "bundler"
1
+ require 'bundler'
2
2
  Bundler.require :default, :development
3
- require "pp"
3
+ require 'pp'
4
+
5
+ Dir['./spec/support/**/*.rb'].sort.each {|f| require f}
4
6
 
5
7
  RSpec.configure do |config|
6
- config.mock_with :mocha
7
8
  config.include Savon::Spec::Macros
9
+
10
+ config.before(:suite) do
11
+ Metaforce::Job.disable_threading!
12
+ end
13
+ end
14
+
15
+ RSpec::Matchers.define :set_default do |option|
16
+ chain :to do |value|
17
+ @value = value
18
+ end
19
+
20
+ match do |configuration|
21
+ @actual = configuration.send(option.to_sym)
22
+ @actual.should eq @value
23
+ end
24
+
25
+ failure_message_for_should do |configuration|
26
+ "Expected #{option} to be set to #{@value.inspect}, got #{@actual.inspect}"
27
+ end
8
28
  end
9
29
 
10
30
  Savon.configure do |config|
11
31
  config.log = false
12
32
  end
33
+
13
34
  Savon::Spec::Fixture.path = File.join(File.dirname(__FILE__), 'fixtures/requests')
@@ -0,0 +1,38 @@
1
+ shared_examples 'a client' do
2
+ describe 'when the session id expires' do
3
+ let(:exception) { Savon::SOAP::Fault.new(HTTPI::Response.new(403, {}, '')) }
4
+
5
+ before do
6
+ client.send(:client).should_receive(:request).once.and_raise(exception)
7
+ exception.stub(:message).and_return('INVALID_SESSION_ID')
8
+ end
9
+
10
+ context 'and no authentication handler is present' do
11
+ before do
12
+ client.stub(:authentication_handler).and_return(nil)
13
+ end
14
+
15
+ it 'raises the exception' do
16
+ expect { client.send(:request, :foo) }.to raise_error(exception)
17
+ end
18
+ end
19
+
20
+ context 'and an authentication handler is present' do
21
+ let(:handler) do
22
+ proc { |client, options| options = { session_id: 'foo' } }
23
+ end
24
+
25
+ before do
26
+ client.stub(:authentication_handler).and_return(handler)
27
+ end
28
+
29
+ it 'calls the authentication handler and resends the request' do
30
+ response = double('response')
31
+ response.stub(:body).and_return(Hashie::Mash.new(:foo_response => {:result => ''}))
32
+ client.send(:client).should_receive(:request).once.and_return(response)
33
+ handler.should_receive(:call).and_call_original
34
+ client.send(:request, :foo)
35
+ end
36
+ end
37
+ end
38
+ end