bulkforce 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,128 @@
1
+ #encoding: utf-8
2
+ require "spec_helper"
3
+
4
+ describe Bulkforce do
5
+ subject { described_class }
6
+ let(:client) { subject.new(username: nil, password: nil, security_token: nil) }
7
+ let!(:connection_builder_class) { class_spy("Bulkforce::ConnectionBuilder", new: connection_builder).as_stubbed_const }
8
+ let(:connection_builder) { instance_spy("Bulkforce::ConnectionBuilder", build: empty_connection) }
9
+
10
+ let(:empty_connection) { instance_spy("Bulkforce::Connection") }
11
+
12
+ let(:empty_batch) do
13
+ Object.new
14
+ end
15
+
16
+ before(:each) do
17
+ allow_any_instance_of(Bulkforce::ConnectionBuilder).to receive(:build).and_return(empty_connection)
18
+ end
19
+
20
+ {
21
+ upsert: [nil,[{"no" => "value"}], "upsert_id"],
22
+ update: [nil,[{"no" => "value"}]],
23
+ insert: [nil,[{"no" => "value"}]],
24
+ delete: [nil,[{"no" => "value"}]],
25
+ }.each do |method_name, values|
26
+ describe "##{method_name}" do
27
+ it "delegates to #start_job" do
28
+ s = client
29
+ expect(s).to receive(:start_job)
30
+ .with(method_name.to_s, *values)
31
+ s.send(method_name, *values)
32
+ end
33
+
34
+ it "triggers correct workflow" do
35
+ s = client
36
+ expect(empty_connection).to receive(:create_job).ordered
37
+ expect(empty_connection).to receive(:add_batch).ordered
38
+ expect(empty_connection).to receive(:close_job).ordered
39
+ res = s.send(method_name, *values)
40
+ expect(res).to be_a(Bulkforce::Batch)
41
+ end
42
+ end
43
+ end
44
+
45
+ describe "#query" do
46
+ it "triggers correct workflow" do
47
+ expect(Bulkforce::Batch)
48
+ .to receive(:new)
49
+ .and_return(empty_batch)
50
+
51
+ s = client
52
+ sobject_input = "sobject_stub"
53
+ query_input = "query_stub"
54
+ expect(empty_connection).to receive(:create_job).ordered
55
+ expect(empty_connection).to receive(:add_query).ordered
56
+ expect(empty_connection).to receive(:close_job).ordered
57
+ expect(empty_batch).to receive(:final_status).ordered
58
+ s.query(sobject_input, query_input)
59
+ end
60
+ end
61
+
62
+ describe "#configure" do
63
+ let(:api_version) { "spec_33.0" }
64
+ let(:username) { "spec_user" }
65
+ let(:password) { "spec_password" }
66
+ let(:security_token) { "spec_security_token" }
67
+ let(:host) { "spec_host" }
68
+
69
+ it "yields a configuration object" do
70
+ expect { |b| subject.configure(&b) }.to yield_with_args(an_instance_of(Bulkforce::Configuration))
71
+ end
72
+
73
+ it "passes correct values to connection builder", :aggregate_failures do
74
+ subject.configure do |config|
75
+ config.api_version = api_version
76
+ config.username = username
77
+ config.password = password
78
+ config.security_token = security_token
79
+ config.host = host
80
+ end
81
+ subject.new
82
+ expect(connection_builder_class).to have_received(:new).with(
83
+ api_version: api_version,
84
+ username: username,
85
+ password: password,
86
+ security_token: security_token,
87
+ host: host,
88
+ )
89
+ end
90
+ end
91
+
92
+ context "file upload" do
93
+ describe "#insert" do
94
+ prefix = Dir.tmpdir
95
+ FileUtils.touch("#{prefix}/attachment.pdf")
96
+ attachment_data = {
97
+ "ParentId" => "00Kk0001908kqkDEAQ",
98
+ "Name" => "attachment.pdf",
99
+ "Body" => File.new("#{prefix}/attachment.pdf")
100
+ }
101
+
102
+ {
103
+ upsert: [nil,[attachment_data.dup], "upsert_id"],
104
+ update: [nil,[attachment_data.dup]],
105
+ insert: [nil,[attachment_data.dup]],
106
+ delete: [nil,[attachment_data.dup]],
107
+ }.each do |method_name, values|
108
+ describe "##{method_name}" do
109
+ it "delegates to #start_job" do
110
+ s = client
111
+ expect(s).to receive(:start_job)
112
+ .with(method_name.to_s, *values)
113
+ s.send(method_name, *values)
114
+ end
115
+
116
+ it "triggers correct workflow" do
117
+ s = client
118
+ expect(empty_connection).to receive(:create_job).ordered
119
+ expect(empty_connection).to receive(:add_file_upload_batch).ordered
120
+ expect(empty_connection).to receive(:close_job).ordered
121
+ res = s.send(method_name, *values)
122
+ expect(res).to be_a(Bulkforce::Batch)
123
+ end
124
+ end
125
+ end
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,34 @@
1
+ require "simplecov"
2
+ require "coveralls"
3
+
4
+ SimpleCov.formatter = Coveralls::SimpleCov::Formatter
5
+ SimpleCov.start do
6
+ add_filter "spec"
7
+ end
8
+
9
+ require "dotenv"
10
+ require "bulkforce"
11
+ require "webmock/rspec"
12
+
13
+ Dir["./spec/support/**/*.rb"].each { |f| require f }
14
+
15
+ RSpec.configure do |config|
16
+ config.mock_with :rspec
17
+ config.order = "random"
18
+ config.filter_run_excluding skip: true
19
+
20
+ config.include Integration::Operations, type: :integration
21
+
22
+ config.before(:each) do
23
+ ENV.delete_if {|k| k =~ /^SALESFORCE_/}
24
+ end
25
+
26
+ config.before(:example, type: :integration) do
27
+ Dotenv.load
28
+ WebMock.disable!
29
+ end
30
+ end
31
+
32
+ def client
33
+ Bulkforce.new
34
+ end
@@ -0,0 +1,64 @@
1
+ module Integration
2
+ module Operations
3
+ def insert_contacts
4
+ client.insert(
5
+ "Contact", [
6
+ {
7
+ "FirstName" => "Leif",
8
+ "LastName" => "Propertybase",
9
+ "LeadSource" => "integration_test",
10
+ "Email" => "#{SecureRandom.hex(5)}@pba.io",
11
+ },
12
+ {
13
+ "FirstName" => "Peter",
14
+ "LastName" => "Propertybase",
15
+ "LeadSource" => "integration_test",
16
+ "Email" => "#{SecureRandom.hex(5)}@pba.io",
17
+ },
18
+ ]).final_status.freeze
19
+ end
20
+
21
+ def upsert_contacts
22
+ client.upsert(
23
+ "Contact",
24
+ [
25
+ {
26
+ "FirstName" => "Leif",
27
+ external_id => "leif_pba",
28
+ "LastName" => "Propertybase",
29
+ "LeadSource" => "integration_test",
30
+ "Email" => "#{SecureRandom.hex(5)}@pba.io",
31
+ },
32
+ {
33
+ "FirstName" => "Peter",
34
+ external_id => "peter_pba",
35
+ "LastName" => "Propertybase",
36
+ "LeadSource" => "integration_test",
37
+ "Email" => "#{SecureRandom.hex(5)}@pba.io",
38
+ },
39
+ ],
40
+ external_id,
41
+ ).final_status.freeze
42
+ end
43
+
44
+ def update_contacts
45
+ insert_contacts
46
+ all_contacts = query_all_test_contacts.map{|entry| entry.merge("FirstName" => "Updated") }
47
+ client.update("Contact", all_contacts).final_status.freeze
48
+ end
49
+
50
+ def delete_contacts
51
+ insert_contacts
52
+ all_contacts = query_all_test_contacts
53
+ client.delete("Contact", all_contacts).final_status.freeze
54
+ end
55
+
56
+ def query_all_test_contacts
57
+ client.query("Contact", "select Id from Contact where LeadSource = 'integration_test'")[:results]
58
+ end
59
+
60
+ def external_id
61
+ "pba__SystemExternalId__c"
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,21 @@
1
+ shared_examples "configuration settings" do |name:, expected_default:, env_variable:|
2
+ it "has default for #{name} set to #{expected_default}" do
3
+ expect(subject.send(name.to_sym)).to eq(expected_default)
4
+ end
5
+
6
+ it "can set #{name} to custom value" do
7
+ subject.send("#{name}=".to_sym, "custom value")
8
+ expect(subject.send(name.to_sym)).to eq("custom value")
9
+ end
10
+
11
+ it "can overwrite the default value by ENV variable" do
12
+ ENV[env_variable] = "value by env"
13
+ expect(subject.send(name.to_sym)).to eq("value by env")
14
+ end
15
+
16
+ it "can overwrite env variable by custom value" do
17
+ ENV[env_variable] = "value by env"
18
+ subject.send("#{name}=".to_sym, "custom value overwrites env")
19
+ expect(subject.send(name.to_sym)).to eq("custom value overwrites env")
20
+ end
21
+ end
metadata ADDED
@@ -0,0 +1,199 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bulkforce
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jorge Valdivia
8
+ - Leif Gensert
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-07-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: json
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: nori
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "<"
47
+ - !ruby/object:Gem::Version
48
+ version: '2.7'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "<"
54
+ - !ruby/object:Gem::Version
55
+ version: '2.7'
56
+ - !ruby/object:Gem::Dependency
57
+ name: nokogiri
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "<"
61
+ - !ruby/object:Gem::Version
62
+ version: '1.7'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "<"
68
+ - !ruby/object:Gem::Version
69
+ version: '1.7'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rubyzip
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '1.0'
77
+ - - "<"
78
+ - !ruby/object:Gem::Version
79
+ version: '1.2'
80
+ type: :runtime
81
+ prerelease: false
82
+ version_requirements: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '1.0'
87
+ - - "<"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.2'
90
+ - !ruby/object:Gem::Dependency
91
+ name: rspec
92
+ requirement: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "<"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.4'
97
+ type: :development
98
+ prerelease: false
99
+ version_requirements: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "<"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.4'
104
+ - !ruby/object:Gem::Dependency
105
+ name: webmock
106
+ requirement: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "<"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.22'
111
+ type: :development
112
+ prerelease: false
113
+ version_requirements: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "<"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.22'
118
+ description: This gem provides a super simple interface for the Salesforce Bulk API.
119
+ It provides support for insert, update, upsert, delete, and query.
120
+ email:
121
+ - jorge@valdivia.me
122
+ - leif@propertybase.com
123
+ executables: []
124
+ extensions: []
125
+ extra_rdoc_files: []
126
+ files:
127
+ - ".gitignore"
128
+ - ".rspec"
129
+ - ".ruby-version"
130
+ - ".travis.yml"
131
+ - Gemfile
132
+ - Guardfile
133
+ - LICENSE
134
+ - README.md
135
+ - Rakefile
136
+ - bulkforce.gemspec
137
+ - lib/bulkforce.rb
138
+ - lib/bulkforce/batch.rb
139
+ - lib/bulkforce/configuration.rb
140
+ - lib/bulkforce/connection.rb
141
+ - lib/bulkforce/connection_builder.rb
142
+ - lib/bulkforce/helper.rb
143
+ - lib/bulkforce/http.rb
144
+ - lib/bulkforce/version.rb
145
+ - spec/integration/delete_spec.rb
146
+ - spec/integration/insert_spec.rb
147
+ - spec/integration/query_spec.rb
148
+ - spec/integration/update_spec.rb
149
+ - spec/integration/upsert_spec.rb
150
+ - spec/lib/bulkforce/batch_spec.rb
151
+ - spec/lib/bulkforce/configuration_spec.rb
152
+ - spec/lib/bulkforce/connection_builder_spec.rb
153
+ - spec/lib/bulkforce/connection_spec.rb
154
+ - spec/lib/bulkforce/helper_spec.rb
155
+ - spec/lib/bulkforce/http_spec.rb
156
+ - spec/lib/bulkforce_spec.rb
157
+ - spec/spec_helper.rb
158
+ - spec/support/integration_helpers.rb
159
+ - spec/support/shared_examples.rb
160
+ homepage: https://github.com/propertybase/bulkforce
161
+ licenses:
162
+ - MIT
163
+ metadata: {}
164
+ post_install_message:
165
+ rdoc_options: []
166
+ require_paths:
167
+ - lib
168
+ required_ruby_version: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ required_rubygems_version: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ requirements: []
179
+ rubyforge_project: bulkforce
180
+ rubygems_version: 2.4.5
181
+ signing_key:
182
+ specification_version: 4
183
+ summary: Ruby support for the Salesforce Bulk API
184
+ test_files:
185
+ - spec/integration/delete_spec.rb
186
+ - spec/integration/insert_spec.rb
187
+ - spec/integration/query_spec.rb
188
+ - spec/integration/update_spec.rb
189
+ - spec/integration/upsert_spec.rb
190
+ - spec/lib/bulkforce/batch_spec.rb
191
+ - spec/lib/bulkforce/configuration_spec.rb
192
+ - spec/lib/bulkforce/connection_builder_spec.rb
193
+ - spec/lib/bulkforce/connection_spec.rb
194
+ - spec/lib/bulkforce/helper_spec.rb
195
+ - spec/lib/bulkforce/http_spec.rb
196
+ - spec/lib/bulkforce_spec.rb
197
+ - spec/spec_helper.rb
198
+ - spec/support/integration_helpers.rb
199
+ - spec/support/shared_examples.rb