salesforce_bulk_api 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 419b46235cab1eda869135553b8f186bceef0d48
4
- data.tar.gz: 52c4677c104986ae9c30fb5c342f4256f8613a1a
3
+ metadata.gz: 6ec5f79187db5cdcfcc991dbb8220e0bc0a23346
4
+ data.tar.gz: 0873d30f2a3faca6f54d3c2faf3da52c90a963bc
5
5
  SHA512:
6
- metadata.gz: 5ab2888d12f5493132ba2a6ea68eba8d771434072e041b138f2f08d68f379931668893c59a2300fe77172b5774db5cb8b039fb310dc79f906a65701be1d51427
7
- data.tar.gz: d1f428ebaea54fca2aec2019620690aab946b8ee5e8eb3a3bb333446bdf94f56f9bb2f2a5d436a038190328c4aab01d8b77e5185309aa2dde3211f7d11184c59
6
+ metadata.gz: 4a32896b615d513aa141dcc43f377e07971e1278eea1d89a6fd264184696b5384884d467d870adfa1f22f2bc935138bdaa2204d1724c7074d6a6f5fe116a38f0
7
+ data.tar.gz: fe6f1c0cb8f62f21265da9ff3bd5727a2e68dd28d022abd43c6d904b906f0cd2323399995acbe20f63ac9969e0a013f8b36ebb6c60ed37fa43e2bf5bb8d6e3ff
@@ -2,4 +2,5 @@ salesforce:
2
2
  client_id: client_id_here
3
3
  client_secret: client_secret_here
4
4
  user: sf_user@example.com
5
- passwordandtoken: passandtokenhere
5
+ passwordandtoken: passandtokenhere
6
+ test_account_id: 0013000000ymMBh
@@ -32,11 +32,8 @@ module SalesforceBulkApi
32
32
  response = @connection.post_xml(nil, path, xml, headers)
33
33
  response_parsed = XmlSimple.xml_in(response)
34
34
 
35
- begin
36
- @job_id = response_parsed['jobInfo']['id']
37
- rescue NoMethodError => e
38
- Rails.logger.error "SalesforceBulkApi: #{response_parsed['error']['exceptionCode']}: #{response_parsed['error']['exceptionMessage']}"
39
- end
35
+ @job_id = response_parsed['id'][0]
36
+
40
37
  end
41
38
 
42
39
  def close_job()
@@ -1,3 +1,3 @@
1
1
  module SalesforceBulkApi
2
- VERSION = '0.0.9'
2
+ VERSION = '0.0.10'
3
3
  end
@@ -9,55 +9,66 @@ describe SalesforceBulkApi do
9
9
  @sf_client = Databasedotcom::Client.new(:client_id => auth_hash['salesforce']['client_id'],
10
10
  :client_secret => auth_hash['salesforce']['client_secret'])
11
11
  @sf_client.authenticate(:username => auth_hash['salesforce']['user'], :password => auth_hash['salesforce']['passwordandtoken'])
12
+
13
+ @account_id = auth_hash['salesforce']['test_account_id']
14
+
12
15
  @api = SalesforceBulkApi::Api.new(@sf_client)
13
16
  end
14
17
 
18
+ after :each do
19
+
20
+ end
21
+
15
22
  describe 'upsert' do
16
23
 
17
24
  context 'when not passed get_result' do
18
- it "doesn't return the batches array" do
19
- res = @api.upsert('Account', [{:Id => '0013000000ymMBh', :Website => 'www.test.com'}], 'Id')
25
+ it "doesn't return the batches array" do
26
+ res = @api.upsert('Account', [{:Id => @account_id, :Website => 'www.test.com'}], 'Id')
20
27
  res['batches'].should be_nil
21
28
  end
22
29
  end
23
30
 
24
31
  context 'when passed get_result = true' do
25
32
  it 'returns the batches array' do
26
- res = @api.upsert('Account', [{:Id => '0013000000ymMBh', :Website => 'www.test.com'}], 'Id', true)
33
+ res = @api.upsert('Account', [{:Id => @account_id, :Website => 'www.test.com'}], 'Id', true)
27
34
  res['batches'][0]['response'].is_a? Array
28
- res['batches'][0]['response'][0].should eq({'id'=>['0013000000ymMBhAAM'], 'success'=>['true'], 'created'=>['false']})
35
+
36
+ res['batches'][0]['response'][0]['id'][0].should start_with(@account_id)
37
+ res['batches'][0]['response'][0]['success'].should eq ['true']
38
+ res['batches'][0]['response'][0]['created'].should eq ['false']
39
+
29
40
  end
30
41
  end
31
42
 
32
43
  context 'when passed send_nulls = true' do
33
44
  it 'sets the nil and empty attributes to NULL' do
34
- @api.update('Account', [{:Id => '0013000000ymMBh', :Website => 'abc123', :Other_Phone__c => '5678', :Gold_Star__c => true}], true)
35
- res = @api.query('Account', "SELECT Website, Other_Phone__c From Account WHERE Id = '0013000000ymMBh'")
45
+ @api.update('Account', [{:Id => @account_id, :Website => 'abc123', :Phone => '5678'}], true)
46
+ res = @api.query('Account', "SELECT Website, Phone From Account WHERE Id = '#{@account_id}'")
36
47
  res['batches'][0]['response'][0]['Website'][0].should eq 'abc123'
37
- res['batches'][0]['response'][0]['Other_Phone__c'][0].should eq '5678'
38
- res = @api.upsert('Account', [{:Id => '0013000000ymMBh', :Website => '', :Other_Phone__c => nil, :Gold_Star__c => false, :CRM_Last_Modified__c => nil}], 'Id', true, true)
39
- res['batches'][0]['response'][0].should eq({'id'=>['0013000000ymMBhAAM'], 'success'=>['true'], 'created'=>['false']})
40
- res = @api.query('Account', "SELECT Website, Other_Phone__c, Gold_Star__c, CRM_Last_Modified__c From Account WHERE Id = '0013000000ymMBh'")
48
+ res['batches'][0]['response'][0]['Phone'][0].should eq '5678'
49
+ res = @api.upsert('Account', [{:Id => @account_id, :Website => '', :Phone => nil}], 'Id', true, true)
50
+ res['batches'][0]['response'][0]['id'][0].should start_with(@account_id)
51
+ res['batches'][0]['response'][0]['success'].should eq ['true']
52
+ res['batches'][0]['response'][0]['created'].should eq ['false']
53
+ res = @api.query('Account', "SELECT Website, Phone From Account WHERE Id = '#{@account_id}'")
41
54
  res['batches'][0]['response'][0]['Website'][0].should eq({"xsi:nil" => "true"})
42
- res['batches'][0]['response'][0]['Other_Phone__c'][0].should eq({"xsi:nil" => "true"})
43
- res['batches'][0]['response'][0]['Gold_Star__c'][0].should eq('false')
44
- res['batches'][0]['response'][0]['CRM_Last_Modified__c'][0].should eq({"xsi:nil" => "true"})
55
+ res['batches'][0]['response'][0]['Phone'][0].should eq({"xsi:nil" => "true"})
45
56
  end
46
57
  end
47
58
 
48
59
  context 'when passed send_nulls = true and an array of fields not to null' do
49
60
  it 'sets the nil and empty attributes to NULL, except for those included in the list of fields to ignore' do
50
- @api.update('Account', [{:Id => '0013000000ymMBh', :Website => 'abc123', :Other_Phone__c => '5678', :Gold_Star__c => true}], true)
51
- res = @api.query('Account', "SELECT Website, Other_Phone__c From Account WHERE Id = '0013000000ymMBh'")
61
+ @api.update('Account', [{:Id => @account_id, :Website => 'abc123', :Phone => '5678'}], true)
62
+ res = @api.query('Account', "SELECT Website, Phone From Account WHERE Id = '#{@account_id}'")
52
63
  res['batches'][0]['response'][0]['Website'][0].should eq 'abc123'
53
- res['batches'][0]['response'][0]['Other_Phone__c'][0].should eq '5678'
54
- res = @api.upsert('Account', [{:Id => '0013000000ymMBh', :Website => '', :Other_Phone__c => nil, :Gold_Star__c => false, :CRM_Last_Modified__c => nil}], 'Id', true, true, [:Website, :Other_Phone__c])
55
- res['batches'][0]['response'][0].should eq({'id'=>['0013000000ymMBhAAM'], 'success'=>['true'], 'created'=>['false']})
56
- res = @api.query('Account', "SELECT Website, Other_Phone__c, Gold_Star__c, CRM_Last_Modified__c From Account WHERE Id = '0013000000ymMBh'")
64
+ res['batches'][0]['response'][0]['Phone'][0].should eq '5678'
65
+ res = @api.upsert('Account', [{:Id => @account_id, :Website => '', :Phone => nil}], 'Id', true, true, [:Website, :Phone])
66
+ res['batches'][0]['response'][0]['id'][0].should start_with(@account_id)
67
+ res['batches'][0]['response'][0]['success'].should eq ['true']
68
+ res['batches'][0]['response'][0]['created'].should eq ['false']
69
+ res = @api.query('Account', "SELECT Website, Phone From Account WHERE Id = '#{@account_id}'")
57
70
  res['batches'][0]['response'][0]['Website'][0].should eq('abc123')
58
- res['batches'][0]['response'][0]['Other_Phone__c'][0].should eq('5678')
59
- res['batches'][0]['response'][0]['Gold_Star__c'][0].should eq('false')
60
- res['batches'][0]['response'][0]['CRM_Last_Modified__c'][0].should eq({"xsi:nil" => "true"})
71
+ res['batches'][0]['response'][0]['Phone'][0].should eq('5678')
61
72
  end
62
73
  end
63
74
 
@@ -67,16 +78,18 @@ describe SalesforceBulkApi do
67
78
  context 'when there is not an error' do
68
79
  context 'when not passed get_result' do
69
80
  it "doesnt return the batches array" do
70
- res = @api.update('Account', [{:Id => '0013000000ymMBh', :Website => 'www.test.com'}])
81
+ res = @api.update('Account', [{:Id => @account_id, :Website => 'www.test.com'}])
71
82
  res['batches'].should be_nil
72
83
  end
73
84
  end
74
85
 
75
86
  context 'when passed get_result = true' do
76
87
  it 'returns the batches array' do
77
- res = @api.update('Account', [{:Id => '0013000000ymMBh', :Website => 'www.test.com'}], true)
88
+ res = @api.update('Account', [{:Id => @account_id, :Website => 'www.test.com'}], true)
78
89
  res['batches'][0]['response'].is_a? Array
79
- res['batches'][0]['response'][0].should eq({'id'=>['0013000000ymMBhAAM'], 'success'=>['true'], 'created'=>['false']})
90
+ res['batches'][0]['response'][0]['id'][0].should start_with(@account_id)
91
+ res['batches'][0]['response'][0]['success'].should eq ['true']
92
+ res['batches'][0]['response'][0]['created'].should eq ['false']
80
93
  end
81
94
  end
82
95
  end
@@ -84,16 +97,26 @@ describe SalesforceBulkApi do
84
97
  context 'when there is an error' do
85
98
  context 'when not passed get_result' do
86
99
  it "doesn't return the results array" do
87
- res = @api.update('Account', [{:Id => '0013000000ymMBh', :Website => 'www.test.com'},{:Id => 'abc123', :Website => 'www.test.com'}])
100
+ res = @api.update('Account', [{:Id => @account_id, :Website => 'www.test.com'},{:Id => 'abc123', :Website => 'www.test.com'}])
88
101
  res['batches'].should be_nil
89
102
  end
90
103
  end
91
104
 
92
105
  context 'when passed get_result = true with batches' do
93
106
  it 'returns the results array' do
94
- res = @api.update('Account', [{:Id => '0013000000ymMBh', :Website => 'www.test.com'}, {:Id => '0013000000ymMBh', :Website => 'www.test.com'}, {:Id => '0013000000ymMBh', :Website => 'www.test.com'}, {:Id => 'abc123', :Website => 'www.test.com'}], true, false, [], 2)
95
- res['batches'][0]['response'].should eq([{"id"=>["0013000000ymMBhAAM"], "success"=>["true"], "created"=>["false"]}, {"errors"=>[{"fields"=>["Id"], "message"=>["Account ID: id value of incorrect type: abc123"], "statusCode"=>["MALFORMED_ID"]}], "success"=>["false"], "created"=>["false"]}])
96
- res['batches'][1]['response'].should eq([{"id"=>["0013000000ymMBhAAM"], "success"=>["true"], "created"=>["false"]},{"id"=>["0013000000ymMBhAAM"], "success"=>["true"], "created"=>["false"]}])
107
+ res = @api.update('Account', [{:Id => @account_id, :Website => 'www.test.com'}, {:Id => @account_id, :Website => 'www.test.com'}, {:Id => @account_id, :Website => 'www.test.com'}, {:Id => 'abc123', :Website => 'www.test.com'}], true, false, [], 2)
108
+ res['batches'][0]['response'][0]['id'][0].should start_with(@account_id)
109
+ res['batches'][0]['response'][0]['success'].should eq ['true']
110
+ res['batches'][0]['response'][0]['created'].should eq ['false']
111
+
112
+ res['batches'][0]['response'][1].should eq({"errors"=>[{"fields"=>["Id"], "message"=>["Account ID: id value of incorrect type: abc123"], "statusCode"=>["MALFORMED_ID"]}], "success"=>["false"], "created"=>["false"]})
113
+
114
+ res['batches'][1]['response'][0]['id'][0].should start_with(@account_id)
115
+ res['batches'][1]['response'][0]['success'].should eq ['true']
116
+ res['batches'][1]['response'][0]['created'].should eq ['false']
117
+ res['batches'][1]['response'][1]['id'][0].should start_with(@account_id)
118
+ res['batches'][1]['response'][1]['success'].should eq ['true']
119
+ res['batches'][1]['response'][1]['created'].should eq ['false']
97
120
  end
98
121
  end
99
122
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: salesforce_bulk_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yatish Mehta
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-12 00:00:00.000000000 Z
11
+ date: 2014-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json