diff --git a/lib/import/zendesk/object_field.rb b/lib/import/zendesk/object_field.rb index ac0024271..7457cf1c2 100644 --- a/lib/import/zendesk/object_field.rb +++ b/lib/import/zendesk/object_field.rb @@ -15,8 +15,7 @@ module Import private def local_name(object_field) - return @local_name if @local_name - @local_name = remote_name(object_field).gsub(/\s/, '_').downcase + @local_name ||= remote_name(object_field).gsub(%r{[\s\/]}, '_').underscore.gsub(/_{2,}/, '_') end def remote_name(object_field) @@ -28,7 +27,7 @@ module Import end def backend_class(object_field) - "Import::Zendesk::ObjectAttribute::#{object_field.type .capitalize}".constantize + "Import::Zendesk::ObjectAttribute::#{object_field.type.capitalize}".constantize end def object_name diff --git a/spec/lib/import/zendesk/ticket_field_spec.rb b/spec/lib/import/zendesk/ticket_field_spec.rb index 71c5975fa..327acc058 100644 --- a/spec/lib/import/zendesk/ticket_field_spec.rb +++ b/spec/lib/import/zendesk/ticket_field_spec.rb @@ -3,4 +3,32 @@ require 'lib/import/zendesk/object_field_examples' RSpec.describe Import::Zendesk::TicketField do 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 diff --git a/test/integration/zendesk_import_test.rb b/test/integration/zendesk_import_test.rb index 709ff1f2f..3e59fa1de 100644 --- a/test/integration/zendesk_import_test.rb +++ b/test/integration/zendesk_import_test.rb @@ -136,7 +136,14 @@ class ZendeskImportTest < ActiveSupport::TestCase checks.each { |check| user = User.find(check[:id]) 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[:groups], user.groups.sort.to_a, "#{user.login} groups") @@ -247,7 +254,14 @@ class ZendeskImportTest < ActiveSupport::TestCase checks.each { |check| organization = Organization.find(check[:id]) 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 @@ -282,7 +296,7 @@ class ZendeskImportTest < ActiveSupport::TestCase id: 2, data: { 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', create_article_type_id: 1, create_article_sender_id: 2, @@ -293,11 +307,11 @@ class ZendeskImportTest < ActiveSupport::TestCase owner_id: 1, customer_id: 6, organization_id: 2, - test_checkbox: true, - custom_integer: 999, - custom_dropdown: 'key2', - custom_decimal: '1.6', - not_existing: nil, + test_checkbox: true, + custom_integer: 999, + custom_drop_down: 'key2', + custom_decimal: '1.6', + 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, owner_id: 1, customer_id: 7, - organization_id: nil, - test_checkbox: false, - custom_integer: nil, - custom_dropdown: '', - custom_decimal: nil, - not_existing: nil, + organization_id: nil, + test_checkbox: false, + custom_integer: nil, + custom_drop_down: '', + custom_decimal: 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| ticket = Ticket.find(check[:id]) 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 @@ -471,7 +492,7 @@ If you\'re reading this message in your email, click the ticket number link that custom_date custom_integer custom_regex - custom_dropdown + custom_drop_down ) assert_equal(copmare_fields, local_fields, 'ticket fields')