Fixes #3310 - Zendesk import fails if fields with unsupported chars in its name are present.

This commit is contained in:
Thorsten Eckel 2020-11-30 17:31:53 +01:00
parent eaa1f1f92b
commit 9c8cfd83dd
5 changed files with 48 additions and 7 deletions

View file

@ -13,6 +13,8 @@ class Sequencer
# model_name
# model_name
# model_name
# model_name_
# model_name
without_double_underscores.gsub(/_id(s?)$/, '_no\1')
end
@ -22,16 +24,31 @@ class Sequencer
# model_name
# model_name
# model_name
without_spaces_and_slashes.gsub(/_{2,}/, '_')
# model_name_
# model_name
only_supported_chars.gsub(/_{2,}/, '_')
end
def without_spaces_and_slashes
def only_supported_chars
# model_id
# model_ids
# model___name
# model_name
# model__name
# model_name_
# model_name
transliterated.gsub(%r{[\s/]}, '_').underscore
downcased.split('').map { |char| char.match?(/[a-z0-9_]/) ? char : '_' }.join
end
def downcased
# model id
# model ids
# model / name
# model name
# model::name
# model name?
# model name
transliterated.downcase
end
def transliterated
@ -39,6 +56,8 @@ class Sequencer
# Model IDs
# Model / Name
# Model Name
# Model::Name
# Model Name?
# Model Name
::ActiveSupport::Inflector.transliterate(unsanitized_name, '_'.freeze)
end
@ -48,6 +67,8 @@ class Sequencer
# Model IDs
# Model / Name
# Model Name
# Model::Name
# Model Name?
# rubocop:disable Style/AsciiComments
# Mödel Nâmé
# rubocop:enable Style/AsciiComments

View file

@ -14,6 +14,8 @@ class Sequencer
# Model IDs
# Model / Name
# Model Name
# Model Name?
# Model::Name
resource['key']
end
end

View file

@ -17,6 +17,8 @@ class Sequencer
# Model IDs
# Model / Name
# Model Name
# Model Name?
# Model::Name
resource.title
end
end

View file

@ -48,7 +48,23 @@ RSpec.describe Sequencer::Unit::Import::Common::ObjectAttribute::SanitizedName,
allow(instance).to receive(:unsanitized_name).and_return('Ærøskøbing Ät Mödél')
end
expect(provided[:sanitized_name]).to eq('a_eroskobing_at_model')
expect(provided[:sanitized_name]).to eq('aeroskobing_at_model')
end
it 'replaces questionmark characters' do
provided = process do |instance|
allow(instance).to receive(:unsanitized_name).and_return('model?')
end
expect(provided[:sanitized_name]).to eq('model_')
end
it 'replaces colon characters' do
provided = process do |instance|
allow(instance).to receive(:unsanitized_name).and_return('mo::del')
end
expect(provided[:sanitized_name]).to eq('mo_del')
end
end
end

View file

@ -340,7 +340,7 @@ class ZendeskImportTest < ActiveSupport::TestCase
organization_id: 2,
test_checkbox: true,
custom_integer: 999,
custom_drop_down: 'key2',
custom_dropdown: 'key2',
custom_decimal: '1.6',
not_existing: nil,
},
@ -361,7 +361,7 @@ class ZendeskImportTest < ActiveSupport::TestCase
organization_id: nil,
test_checkbox: false,
custom_integer: nil,
custom_drop_down: '',
custom_dropdown: '',
custom_decimal: nil,
not_existing: nil,
},
@ -538,7 +538,7 @@ class ZendeskImportTest < ActiveSupport::TestCase
custom_date
custom_integer
custom_regex
custom_drop_down
custom_dropdown
]
assert_equal(copmare_fields, local_fields, 'ticket fields')