Zendesk import: Improved exception text for ObjectManager Attribute errors and removed dependency of init_callback implementation.

This commit is contained in:
Thorsten Eckel 2017-05-30 12:04:10 +02:00
parent 2bbb2c9519
commit d77e73bb12
2 changed files with 18 additions and 3 deletions

View file

@ -13,12 +13,14 @@ module Import
private
def init_callback(_attribute)
raise 'Missing init_callback method implementation for this object attribute'
end
def add(object, name, attribute)
ObjectManager::Attribute.add( attribute_config(object, name, attribute) )
ObjectManager::Attribute.migration_execute(false)
rescue => e
# rubocop:disable Style/SpecialGlobalVars
raise $!, "Problem with ObjectManager Attribute '#{name}': #{$!}", $!.backtrace
end
def attribute_config(object, name, attribute)

View file

@ -2,7 +2,7 @@ require 'rails_helper'
RSpec.describe Import::Zendesk::ObjectAttribute do
it 'throws an exception if no init_callback is implemented' do
it 'extends ObjectManager Attribute exception text' do
attribute = double(
title: 'Example attribute',
@ -16,6 +16,19 @@ RSpec.describe Import::Zendesk::ObjectAttribute do
type: 'input',
)
expect { described_class.new('Ticket', 'example_field', attribute) }.to raise_error(RuntimeError)
error_text = 'some error'
expect(ObjectManager::Attribute).to receive(:add).and_raise(RuntimeError, error_text)
exception = nil
begin
described_class.new('Ticket', 'example_field', attribute)
rescue => e
exception = e
end
expect(exception).not_to be nil
expect(exception).to be_a(RuntimeError)
expect(exception.message).to include(error_text)
expect(exception.message).not_to eq(error_text)
end
end