Zendesk import: Improved exception text for ObjectManager Attribute errors and removed dependency of init_callback implementation.
This commit is contained in:
parent
2bbb2c9519
commit
d77e73bb12
2 changed files with 18 additions and 3 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue