Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/restforce/bulk/builder/xml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ def initialize(operation)
self.operation = operation
end

def job(object_name, content_type)
def job(object_name, content_type, external_id_field=nil, concurrency_mode=nil)
build_xml(:jobInfo) do |xml|
xml.operation operation
xml.object object_name
xml.externalIdFieldName external_id_field if external_id_field
xml.concurrencyMode concurrency_mode if concurrency_mode
xml.contentType content_type
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/restforce/bulk/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ class Job
}

class << self
def create(operation, object_name, content_type=:xml)
def create(operation, object_name, content_type=:xml, external_id_field=nil, concurrency_mode=nil)
builder = Restforce::Bulk::Builder::Xml.new(operation)
data = builder.job(object_name, JOB_CONTENT_TYPE_MAPPING[content_type.to_sym])
data = builder.job(object_name, JOB_CONTENT_TYPE_MAPPING[content_type.to_sym], external_id_field, concurrency_mode)

response = Restforce::Bulk.client.perform_request(:post, 'job', data)

Expand Down
2 changes: 1 addition & 1 deletion lib/restforce/bulk/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Restforce
module Bulk
VERSION = "0.1.0"
VERSION = "0.1.1"
end
end
20 changes: 20 additions & 0 deletions spec/restforce/bulk/job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

describe Restforce::Bulk::Job, mock_restforce: true do
let(:object_name) { 'Account' }
let(:external_id_field) { 'Name' }

let(:raw_response_body) { '' }

Expand All @@ -23,6 +24,15 @@
end
end

let(:xml_upsert) do
build_bulk_xml(:jobInfo) do |xml|
xml.operation operation
xml.object object_name
xml.externalIdFieldName external_id_field
xml.contentType operation_content_type
end
end

let(:raw_response_body) do
build_bulk_xml(:jobInfo) do |xml|
xml.id SecureRandom.hex(18)
Expand Down Expand Up @@ -78,6 +88,16 @@
expect(job.content_type).to eq(:csv)
end
end

context "with external_id" do
let(:operation) { 'upsert' }

it "adds an external id to xml if there is an external_id" do
expect_restforce_request(:post, "job", xml_upsert).and_return(restforce_response)

job = Restforce::Bulk::Job.create(operation, object_name, :xml, 'Name')
end
end
end

describe ".find(id)" do
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

Bundler.require
require 'restforce/bulk'
require 'securerandom'

ROOT_PATH = File.expand_path('../..', __FILE__)

Expand Down