From 0e7a84facf8b7f5d40d52a7d349203c6abeb1011 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Mon, 12 Dec 2016 11:46:48 +0100 Subject: [PATCH] Fixed issue #526 - Import throws error if run a second time. --- lib/import/otrs/customer_user.rb | 2 +- spec/import/otrs/customer_user_spec.rb | 5 ++++- spec/import/otrs/user_spec.rb | 8 +++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/import/otrs/customer_user.rb b/lib/import/otrs/customer_user.rb index 1d98ba88d..211b14c8e 100644 --- a/lib/import/otrs/customer_user.rb +++ b/lib/import/otrs/customer_user.rb @@ -48,7 +48,7 @@ module Import # only update roles if different (reduce sql statements) if @local_customer.role_ids == customer[:role_ids] - user.delete(:role_ids) + customer.delete(:role_ids) end log "update User.find_by(login: #{customer[:login]})" diff --git a/spec/import/otrs/customer_user_spec.rb b/spec/import/otrs/customer_user_spec.rb index c208a7935..0eb948845 100644 --- a/spec/import/otrs/customer_user_spec.rb +++ b/spec/import/otrs/customer_user_spec.rb @@ -13,7 +13,10 @@ RSpec.describe Import::OTRS::CustomerUser do def updates_with(zammad_structure) expect_organization_lookup 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(import_object).not_to receive(:new) start_import_test diff --git a/spec/import/otrs/user_spec.rb b/spec/import/otrs/user_spec.rb index 87fa7ee89..60b1d9d90 100644 --- a/spec/import/otrs/user_spec.rb +++ b/spec/import/otrs/user_spec.rb @@ -12,12 +12,18 @@ RSpec.describe Import::OTRS::User do def updates_with(zammad_structure) 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(import_object).not_to receive(:new) start_import_test end + def role_delete_expecations(role_ids) + end + def load_user_json(file) json_fixture("import/otrs/user/#{file}") end