FIX: Ensure that user exists before migrating.

This commit is contained in:
Guo Xiang Tan 2017-10-10 15:12:10 +08:00
parent 6bbac0a1e9
commit 0e52edd1fd
2 changed files with 15 additions and 1 deletions

View File

@ -105,7 +105,8 @@ module Jobs
end
if !(slack_discourse_username = site_settings_value('slack_discourse_username')).nil?
SiteSetting.chat_integration_discourse_username = slack_discourse_username
username = User.find_by(username: slack_discourse_username.downcase)&.username
SiteSetting.chat_integration_discourse_username = (username || Discourse.system_user.username)
end
end

View File

@ -41,6 +41,19 @@ RSpec.describe Jobs::DiscourseChatMigrateFromSlackOfficial do
expect(SiteSetting.chat_integration_slack_enabled).to eq(true)
expect(SiteSetting.chat_integration_enabled).to eq(true)
end
describe 'when slack_discourse_username is not valid' do
before do
SiteSetting.find_by(name: 'slack_discourse_username').update!(value: 'someguy')
end
it 'should default to the system user' do
described_class.new.execute_onceoff({})
expect(SiteSetting.chat_integration_discourse_username)
.to eq(Discourse.system_user.username)
end
end
end
describe 'when a uncategorized filter is present' do