Fixed bug #1663 - Exchange integration tries to import user twice and fails.

This commit is contained in:
Thorsten Eckel 2017-11-21 18:46:26 +01:00
parent b9d728f890
commit 492ca261ce
3 changed files with 96 additions and 1 deletions

View file

@ -12,7 +12,7 @@ class Sequencer
def process def process
state.provide(:remote_id) do state.provide(:remote_id) do
resource.fetch(attribute) resource.fetch(attribute).dup.to_s.downcase
end end
rescue KeyError => e rescue KeyError => e
handle_failure(e) handle_failure(e)

View file

@ -0,0 +1,70 @@
require 'rails_helper'
RSpec.describe Sequencer::Unit::Import::Common::Model::Attributes::RemoteId, sequencer: :unit do
it 'takes remote_id from id' do
parameters = {
resource: {
id: '123abc',
}
}
provided = process(parameters)
expect(provided).to include(remote_id: '123abc')
end
it 'takes remote_id from attribute method result' do
parameters = {
resource: {
other_attribute: '123abc',
}
}
provided = process(parameters) do |instance|
expect(instance).to receive(:attribute).and_return(:other_attribute)
end
expect(provided).to include(remote_id: '123abc')
end
it 'converts value to a String' do
parameters = {
resource: {
id: 1337,
}
}
provided = process(parameters)
expect(provided).to include(remote_id: '1337')
end
it 'downcases the value to prevent case sensivity issues with the ORM' do
parameters = {
resource: {
id: 'AbCdEfG',
}
}
provided = process(parameters)
expect(provided[:remote_id]).to eq(parameters[:resource][:id].downcase)
end
it 'duplicates the value to prevent attribute changes' do
parameters = {
resource: {
id: 'this is',
}
}
provided = process(parameters)
expect(provided[:remote_id]).to eq(parameters[:resource][:id])
parameters[:resource][:id] += ' a test'
expect(provided[:remote_id]).not_to eq(parameters[:resource][:id])
end
end

View file

@ -0,0 +1,25 @@
require 'rails_helper'
RSpec.describe Sequencer::Unit::Import::Common::Model::ExternalSync::Lookup, sequencer: :unit do
it 'finds model_class instances by remote_id' do
user = create(:user)
external_sync_source = 'test'
remote_id = '1337'
ExternalSync.create(
source: external_sync_source,
source_id: remote_id,
o_id: user.id,
object: user.class,
)
provided = process(
remote_id: remote_id,
model_class: user.class,
external_sync_source: external_sync_source,
)
expect(provided[:instance]).to eq(user)
end
end