From 19319d9d83b7107b21c9e0df5f025fb60b6ad50b Mon Sep 17 00:00:00 2001 From: Ryan Lue Date: Mon, 3 Sep 2018 09:36:24 +0800 Subject: [PATCH] Fix nil handling regression from #2152 fix --- lib/import/exchange/folder.rb | 2 +- spec/lib/import/exchange/folder_spec.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/import/exchange/folder.rb b/lib/import/exchange/folder.rb index c442179dd..50a9d481d 100644 --- a/lib/import/exchange/folder.rb +++ b/lib/import/exchange/folder.rb @@ -43,7 +43,7 @@ module Import end def display_path(folder) - display_name = folder.display_name.utf8_encode(fallback: :read_as_sanitized_binary) + display_name = folder.display_name&.utf8_encode(fallback: :read_as_sanitized_binary) parent_folder = find(folder.parent_folder_id) return display_name if parent_folder.blank? diff --git a/spec/lib/import/exchange/folder_spec.rb b/spec/lib/import/exchange/folder_spec.rb index 3ac924fdc..97b830980 100644 --- a/spec/lib/import/exchange/folder_spec.rb +++ b/spec/lib/import/exchange/folder_spec.rb @@ -10,6 +10,20 @@ RSpec.describe Import::Exchange::Folder do let(:child_folder) { double('EWS Folder') } let(:exception_case) { double('EWS Folder') } + context 'when folder.display_name returns nil' do + before do + allow(root_folder).to receive(:display_name).and_return(nil) + allow(root_folder).to receive(:parent_folder_id).and_return(nil) + + allow(subject).to receive(:find).with(any_args).and_return(root_folder) + allow(subject).to receive(:find).with(nil).and_return(nil) + end + + it 'returns nil' do + expect(subject.display_path(root_folder)).to be(nil) + end + end + context 'when server returns valid UTF-8' do before do allow(root_folder).to receive(:display_name).and_return('Root')