2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
2018-12-14 01:59:19 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.shared_examples Import::Zendesk::ObjectAttribute::Base do
|
|
|
|
let(:attribute) do
|
|
|
|
double(
|
|
|
|
title: 'Example attribute',
|
|
|
|
description: 'Example attribute description',
|
|
|
|
removable: false,
|
|
|
|
active: true,
|
|
|
|
position: 12,
|
|
|
|
visible_in_portal: true,
|
|
|
|
required_in_portal: true,
|
|
|
|
required: true,
|
|
|
|
type: 'input',
|
|
|
|
custom_field_options: [],
|
|
|
|
regexp_for_validation: '',
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'exception handling' do
|
|
|
|
let(:error_text) { Faker::Lorem.sentence }
|
2019-04-15 01:41:17 +00:00
|
|
|
|
2018-12-14 01:59:19 +00:00
|
|
|
it 'extends ObjectManager Attribute exception message' do
|
|
|
|
expect(ObjectManager::Attribute).to receive(:add).and_raise(RuntimeError, error_text)
|
|
|
|
|
|
|
|
expect do
|
|
|
|
described_class.new('Ticket', 'example_field', attribute)
|
2021-05-12 11:37:44 +00:00
|
|
|
end.to raise_error(RuntimeError, %r{'example_field': #{error_text}$})
|
2018-12-14 01:59:19 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'argument handling' do
|
|
|
|
it 'takes an ObjectLookup name as the first argument' do
|
|
|
|
expect(ObjectManager::Attribute)
|
|
|
|
.to receive(:add).with(hash_including(object: 'Ticket'))
|
|
|
|
|
|
|
|
described_class.new('Ticket', 'example_field', attribute)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'accepts a constant ObjectLookup name' do
|
|
|
|
expect(ObjectManager::Attribute)
|
|
|
|
.to receive(:add).with(hash_including(object: 'Ticket'))
|
|
|
|
|
|
|
|
described_class.new(Ticket, 'example_field', attribute)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|