Fixed issue #2039: Import fails for ObjectManager Attribute with non-ASCII name.

This commit is contained in:
Thorsten Eckel 2018-05-23 18:46:01 +02:00
parent 4b98c61698
commit c21be6e928
2 changed files with 28 additions and 5 deletions

View file

@ -12,6 +12,7 @@ class Sequencer
# model_nos
# model_name
# model_name
# model_name
without_double_underscores.gsub(/_id(s?)$/, '_no\1')
end
@ -20,6 +21,7 @@ class Sequencer
# model_ids
# model_name
# model_name
# model_name
without_spaces_and_slashes.gsub(/_{2,}/, '_')
end
@ -28,7 +30,17 @@ class Sequencer
# model_ids
# model___name
# model_name
unsanitized_name.gsub(%r{[\s\/]}, '_').underscore
# model_name
transliterated.gsub(%r{[\s\/]}, '_').underscore
end
def transliterated
# Model ID
# Model IDs
# Model / Name
# Model Name
# Model Name
::ActiveSupport::Inflector.transliterate(unsanitized_name, '_'.freeze)
end
def unsanitized_name
@ -36,6 +48,9 @@ class Sequencer
# Model IDs
# Model / Name
# Model Name
# rubocop:disable Style/AsciiComments
# Mödel Nâmé
# rubocop:enable Style/AsciiComments
raise 'Missing implementation for unsanitized_name method'
end
end

View file

@ -11,7 +11,7 @@ RSpec.describe Sequencer::Unit::Import::Common::ObjectAttribute::SanitizedName,
context 'sanitizes' do
it 'whitespaces' do
it 'replaces whitespaces' do
provided = process do |instance|
expect(instance).to receive(:unsanitized_name).and_return('model name')
end
@ -19,7 +19,7 @@ RSpec.describe Sequencer::Unit::Import::Common::ObjectAttribute::SanitizedName,
expect(provided[:sanitized_name]).to eq('model_name')
end
it 'dashes' do
it 'replaces dashes' do
provided = process do |instance|
expect(instance).to receive(:unsanitized_name).and_return('model-name')
end
@ -27,7 +27,7 @@ RSpec.describe Sequencer::Unit::Import::Common::ObjectAttribute::SanitizedName,
expect(provided[:sanitized_name]).to eq('model_name')
end
it 'ids suffix' do
it 'replaces ids suffix' do
provided = process do |instance|
expect(instance).to receive(:unsanitized_name).and_return('Model Ids')
end
@ -35,12 +35,20 @@ RSpec.describe Sequencer::Unit::Import::Common::ObjectAttribute::SanitizedName,
expect(provided[:sanitized_name]).to eq('model_nos')
end
it 'id suffix' do
it 'replaces id suffix' do
provided = process do |instance|
expect(instance).to receive(:unsanitized_name).and_return('Model Id')
end
expect(provided[:sanitized_name]).to eq('model_no')
end
it 'replaces non-ASCII characters' do
provided = process do |instance|
expect(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')
end
end
end