Fixed issue #1095 - Zendesk import: Error while importing ticket field with dash in name.

This commit is contained in:
Thorsten Eckel 2017-05-30 18:32:28 +02:00
parent 329ab853a2
commit 2bbb2c9519
3 changed files with 67 additions and 19 deletions

View file

@ -15,8 +15,7 @@ module Import
private private
def local_name(object_field) def local_name(object_field)
return @local_name if @local_name @local_name ||= remote_name(object_field).gsub(%r{[\s\/]}, '_').underscore.gsub(/_{2,}/, '_')
@local_name = remote_name(object_field).gsub(/\s/, '_').downcase
end end
def remote_name(object_field) def remote_name(object_field)
@ -28,7 +27,7 @@ module Import
end end
def backend_class(object_field) def backend_class(object_field)
"Import::Zendesk::ObjectAttribute::#{object_field.type .capitalize}".constantize "Import::Zendesk::ObjectAttribute::#{object_field.type.capitalize}".constantize
end end
def object_name def object_name

View file

@ -3,4 +3,32 @@ require 'lib/import/zendesk/object_field_examples'
RSpec.describe Import::Zendesk::TicketField do RSpec.describe Import::Zendesk::TicketField do
it_behaves_like 'Import::Zendesk::ObjectField' it_behaves_like 'Import::Zendesk::ObjectField'
it 'handles fields with dashes in title' do
zendesk_object = double(
id: 1337,
title: 'Priority - Simple',
key: 'priority_simple',
type: 'text',
removable: true,
active: true,
position: 1,
required_in_portal: true,
visible_in_portal: true,
required: true,
description: 'Example field',
)
expect(ObjectManager::Attribute).to receive(:migration_execute).and_return(true)
expect do
described_class.new(zendesk_object)
end.not_to raise_error
ObjectManager::Attribute.remove(
object: 'Ticket',
name: zendesk_object.key,
)
end
end end

View file

@ -136,7 +136,14 @@ class ZendeskImportTest < ActiveSupport::TestCase
checks.each { |check| checks.each { |check|
user = User.find(check[:id]) user = User.find(check[:id])
check[:data].each { |key, value| check[:data].each { |key, value|
assert_equal(value, user[key], "user.#{key} for user_id #{check[:id]}") user_value = user[key]
text = "user.#{key} for user_id #{check[:id]}"
if value.nil?
assert_nil(user_value, text)
else
assert_equal(value, user_value, text)
end
} }
assert_equal(check[:roles], user.roles.sort.to_a, "#{user.login} roles") assert_equal(check[:roles], user.roles.sort.to_a, "#{user.login} roles")
assert_equal(check[:groups], user.groups.sort.to_a, "#{user.login} groups") assert_equal(check[:groups], user.groups.sort.to_a, "#{user.login} groups")
@ -247,7 +254,14 @@ class ZendeskImportTest < ActiveSupport::TestCase
checks.each { |check| checks.each { |check|
organization = Organization.find(check[:id]) organization = Organization.find(check[:id])
check[:data].each { |key, value| check[:data].each { |key, value|
assert_equal(value, organization[key], "organization.#{key} for organization_id #{check[:id]}") organization_value = organization[key]
text = "organization.#{key} for organization_id #{check[:id]}"
if value.nil?
assert_nil(organization_value, text)
else
assert_equal(value, organization_value, text)
end
} }
} }
end end
@ -282,7 +296,7 @@ class ZendeskImportTest < ActiveSupport::TestCase
id: 2, id: 2,
data: { data: {
title: 'test', title: 'test',
#note: 'This is the first comment. Feel free to delete this sample ticket.', #note: 'This is the first comment. Feel free to delete this sample ticket.',
note: 'test email', note: 'test email',
create_article_type_id: 1, create_article_type_id: 1,
create_article_sender_id: 2, create_article_sender_id: 2,
@ -293,11 +307,11 @@ class ZendeskImportTest < ActiveSupport::TestCase
owner_id: 1, owner_id: 1,
customer_id: 6, customer_id: 6,
organization_id: 2, organization_id: 2,
test_checkbox: true, test_checkbox: true,
custom_integer: 999, custom_integer: 999,
custom_dropdown: 'key2', custom_drop_down: 'key2',
custom_decimal: '1.6', custom_decimal: '1.6',
not_existing: nil, not_existing: nil,
}, },
}, },
{ {
@ -315,12 +329,12 @@ If you\'re reading this message in your email, click the ticket number link that
priority_id: 1, priority_id: 1,
owner_id: 1, owner_id: 1,
customer_id: 7, customer_id: 7,
organization_id: nil, organization_id: nil,
test_checkbox: false, test_checkbox: false,
custom_integer: nil, custom_integer: nil,
custom_dropdown: '', custom_drop_down: '',
custom_decimal: nil, custom_decimal: nil,
not_existing: nil, not_existing: nil,
}, },
}, },
{ {
@ -376,7 +390,14 @@ If you\'re reading this message in your email, click the ticket number link that
checks.each { |check| checks.each { |check|
ticket = Ticket.find(check[:id]) ticket = Ticket.find(check[:id])
check[:data].each { |key, value| check[:data].each { |key, value|
assert_equal(value, ticket[key], "ticket.#{key} for ticket_id #{check[:id]}") ticket_value = ticket[key]
text = "ticket.#{key} for ticket_id #{check[:id]}"
if value.nil?
assert_nil(ticket_value, text)
else
assert_equal(value, ticket_value, text)
end
} }
} }
end end
@ -471,7 +492,7 @@ If you\'re reading this message in your email, click the ticket number link that
custom_date custom_date
custom_integer custom_integer
custom_regex custom_regex
custom_dropdown custom_drop_down
) )
assert_equal(copmare_fields, local_fields, 'ticket fields') assert_equal(copmare_fields, local_fields, 'ticket fields')