Fixed issue #526 - Import throws error if run a second time.

This commit is contained in:
Thorsten Eckel 2016-12-12 11:46:48 +01:00
parent 51985bc67e
commit 0e7a84facf
3 changed files with 12 additions and 3 deletions

View file

@ -48,7 +48,7 @@ module Import
# only update roles if different (reduce sql statements) # only update roles if different (reduce sql statements)
if @local_customer.role_ids == customer[:role_ids] if @local_customer.role_ids == customer[:role_ids]
user.delete(:role_ids) customer.delete(:role_ids)
end end
log "update User.find_by(login: #{customer[:login]})" log "update User.find_by(login: #{customer[:login]})"

View file

@ -13,7 +13,10 @@ RSpec.describe Import::OTRS::CustomerUser do
def updates_with(zammad_structure) def updates_with(zammad_structure)
expect_organization_lookup expect_organization_lookup
expect(import_object).to receive(:find_by).and_return(existing_object) expect(import_object).to receive(:find_by).and_return(existing_object)
expect(existing_object).to receive(:role_ids).and_return([]).at_least(:once) # we delete the :role_ids from the zammad_structure to make sure that
# a) role_ids call returns the initial role_ids
# b) and update_attributes gets called without them
expect(existing_object).to receive(:role_ids).and_return(zammad_structure.delete(:role_ids)).at_least(:once)
expect(existing_object).to receive(:update_attributes).with(zammad_structure) expect(existing_object).to receive(:update_attributes).with(zammad_structure)
expect(import_object).not_to receive(:new) expect(import_object).not_to receive(:new)
start_import_test start_import_test

View file

@ -12,12 +12,18 @@ RSpec.describe Import::OTRS::User do
def updates_with(zammad_structure) def updates_with(zammad_structure)
expect(import_object).to receive(:find_by).and_return(existing_object) expect(import_object).to receive(:find_by).and_return(existing_object)
expect(existing_object).to receive(:role_ids).and_return([]) # we delete the :role_ids from the zammad_structure to make sure that
# a) role_ids call returns the initial role_ids
# b) and update_attributes gets called without them
expect(existing_object).to receive(:role_ids).and_return(zammad_structure.delete(:role_ids))
expect(existing_object).to receive(:update_attributes).with(zammad_structure) expect(existing_object).to receive(:update_attributes).with(zammad_structure)
expect(import_object).not_to receive(:new) expect(import_object).not_to receive(:new)
start_import_test start_import_test
end end
def role_delete_expecations(role_ids)
end
def load_user_json(file) def load_user_json(file)
json_fixture("import/otrs/user/#{file}") json_fixture("import/otrs/user/#{file}")
end end