salesforce_bulk_query 0.1.5 → 0.1.6

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: 7fa88413bbd297c98d25b68f77a9ca2988daf3eb
4
- data.tar.gz: dbcfba2b8107df4ab4deb4adfd28d6db5c4ac132
3
+ metadata.gz: 93410e3eaddd8559f8127d9cad6ed1223093da53
4
+ data.tar.gz: f24d761b7d5e39c67efc54eb99c9e9006a7b3330
5
5
  SHA512:
6
- metadata.gz: f5ae74d36d69674eb23a3ab57f6183d917556bda60192aa6ada277f12aced668c5038b39166be59a73b5b8016ed7bba1ffee4de538568edd1b08c31ee6abc4a2
7
- data.tar.gz: 873f7b3e6d52a74df309403fb0386264e55952b03aab625c9d44da340d088ceef8f006adfa1897f647ff16a37a6f5059c09bc7b07755266324b390e539acedf5
6
+ metadata.gz: d849ee9f3525ecd0a92c57d4c997c7158d7b830892b0aaa221b9b38d7e55d0042d08dd19a020f1729d7deea37df9790d1e81bf4dab6bf15042cf2197d5501033
7
+ data.tar.gz: 11c53de51a4c6cbe7541e63cf2f236900b559d12b464e287c79c7b800db1d13ff1ff6ae097a21030c59cb6cb95d24c2512844c459728b73a51aed6b8aba380dd
@@ -114,9 +114,10 @@ module SalesforceBulkQuery
114
114
 
115
115
  def query_count(sobject, from, to)
116
116
  # do it with retries, if it doesn't succeed, return nil, don't fail.
117
+ soql = "SELECT COUNT() FROM #{sobject} WHERE CreatedDate >= #{from} AND CreatedDate < #{to}"
117
118
  begin
118
119
  with_retries do
119
- q = @client.query("SELECT COUNT() FROM #{sobject} WHERE CreatedDate >= #{from} AND CreatedDate < #{to}")
120
+ q = @client.query(soql)
120
121
  return q.size
121
122
  end
122
123
  rescue Faraday::Error::TimeoutError => e
@@ -134,4 +135,4 @@ module SalesforceBulkQuery
134
135
  }
135
136
  end
136
137
  end
137
- end
138
+ end
@@ -1,3 +1,3 @@
1
1
  module SalesforceBulkQuery
2
- VERSION = '0.1.5'
2
+ VERSION = '0.1.6'
3
3
  end
@@ -8,6 +8,8 @@ require 'set'
8
8
  # test co nejak nafakuje tu situaci v twc
9
9
  describe SalesforceBulkQuery do
10
10
  before :all do
11
+ WebMock.allow_net_connect!
12
+
11
13
  @client = SpecHelper.create_default_restforce
12
14
  @api = SpecHelper.create_default_api(@client)
13
15
  @entity = ENV['ENTITY'] || 'Opportunity'
@@ -53,19 +55,46 @@ describe SalesforceBulkQuery do
53
55
  end
54
56
  end
55
57
  end
58
+ end
59
+ context "when we want to mock things" do
60
+ before(:each) do
61
+ WebMock.allow_net_connect!
62
+ end
63
+ after(:each) do
64
+ WebMock.allow_net_connect!
65
+ end
56
66
  it "catches the timeout error for query" do
57
67
  # stub the timeout on query
58
- query_url = "na12.salesforce.com/services/data/v#{@api_version}/query"
59
- # "https://na12.salesforce.com/services/data/v#{@api_version}/query?q=.*"
68
+ host = URI.parse(@api.instance_url).host
69
+ query_url = "#{host}/services/data/v#{@api_version}/query"
60
70
  query_regexp = Regexp.new(query_url)
71
+ # 4 timeouts (first get the oldest record), then fake a
72
+ # 0 count query response
73
+ stub_request(:get, query_regexp).to_timeout.times(4).then.to_return(
74
+ :body => "{\"totalSize\":0,\"done\":true,\"records\":[]}",
75
+ :headers => {
76
+ "date"=>"Wed, 04 Feb 2015 01:18:45 GMT",
77
+ "set-cookie"=>"BrowserId=hahaha;Path=/;Domain=.salesforce.com;Expires=never",
78
+ "expires"=>"Thu, 01 Jan 1970 00:00:00 GMT",
79
+ "sforce-limit-info"=>"api-usage=6666/15000",
80
+ "content-type"=>"application/json;charset=UTF-8",
81
+ "transfer-encoding"=>"chunked"}
82
+ )
61
83
 
62
- stub_request(:get, query_regexp).to_timeout.times(4).then.to_return(:body => "{\"totalSize\":0,\"done\":true,\"records\":[]}", :headers => {"User-Agent"=>"Faraday v0.8.9", "Authorization"=>"OAuth abcd"})
63
-
84
+ # do the actual request
64
85
  WebMock.allow_net_connect!
86
+ result = @api.query(
87
+ @entity,
88
+ "SELECT #{@field_list.join(', ')} FROM #{@entity}",
89
+ :count_lines => true,
90
+ :single_batch => true
91
+ )
65
92
 
66
- result = @api.query(@entity, "SELECT #{@field_list.join(', ')} FROM #{@entity}", :count_lines => true, :single_batch => true)
67
- require 'pry'; binding.pry
68
-
93
+ # check it
94
+ expect(result[:succeeded]).to be_true
95
+ expect(result[:unfinished_subqueries]).to be_empty
96
+ expect(result[:filenames]).not_to be_empty
97
+ expect(result[:jobs_done]).not_to be_empty
69
98
  end
70
99
  end
71
100
  context "when you give it all the options" do
data/spec/spec_helper.rb CHANGED
@@ -7,11 +7,6 @@ RSpec.configure do |c|
7
7
  c.run_all_when_everything_filtered = true
8
8
  c.filter_run_excluding :skip => true
9
9
  c.formatter = :documentation
10
-
11
- # whitelist codeclimate.com so test coverage can be reported
12
- c.after(:suite) do
13
- WebMock.disable_net_connect!(:allow => 'codeclimate.com')
14
- end
15
10
  end
16
11
 
17
12
  class SpecHelper
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: salesforce_bulk_query
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Petr Cvengros
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-03 00:00:00.000000000 Z
11
+ date: 2015-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json