FIX: do not crash when user.name is nil (#15)

FIX: do not crash when user.name is nil (#15)

The job should not explode when user.name is nil

diff --git a/app/jobs/bcc_post.rb b/app/jobs/bcc_post.rb
index 2ff5d74..6a57eaa 100644
--- a/app/jobs/bcc_post.rb
+++ b/app/jobs/bcc_post.rb
@@ -25,7 +25,8 @@ class ::Jobs::BccPost < ::Jobs::Base
       raw.gsub!(/%{@username}/i, "@" + target)
 
       user = User.find_by_username_or_email(target)
-      if !user.nil? then
+
+      if user&.name
         raw.gsub!(/%{name}/i, user.name)
       end
 
diff --git a/spec/jobs/bcc_post_spec.rb b/spec/jobs/bcc_post_spec.rb
index b5ea971..f905aad 100644
--- a/spec/jobs/bcc_post_spec.rb
+++ b/spec/jobs/bcc_post_spec.rb
@@ -33,6 +33,11 @@ describe ::Jobs::BccPost do
       expect(Topic.count).to eq(topic_count + 2)
     end
 
+    it "does not crash when user's name is empty" do
+      user0.update!(name: nil)
+      expect { ::Jobs::BccPost.new.execute(user_id: sender.id, create_params: create_params) }.not_to raise_error
+    end
+
     it 'works when mixing emails and usernames' do
       SiteSetting.enable_staged_users = true
       topic_count = Topic.count

GitHub sha: 6f2b91ff9181f6c31cb2c687bd1c1be44f96585a

This commit appears in #15 which was approved by tgxworld. It was merged by lis2.