diff --git a/public/javascripts/app/helpers/text_formatter.js b/public/javascripts/app/helpers/text_formatter.js index 9fe59937d..c8dc9fafb 100644 --- a/public/javascripts/app/helpers/text_formatter.js +++ b/public/javascripts/app/helpers/text_formatter.js @@ -25,11 +25,11 @@ textFormatter.mentionify = function mentionify(text, mentions) { var mentionRegex = /@\{([^;]+); ([^\}]+)\}/g return text.replace(mentionRegex, function(mentionText, fullName, diasporaId) { - var personId = _.find(mentions, function(person){ + var person = _.find(mentions, function(person){ return person.diaspora_id == diasporaId - }).id - - return "" + fullName + "" + }) + + return person ? "" + fullName + "" : fullName; }) } diff --git a/spec/javascripts/app/helpers/text_formatter_spec.js b/spec/javascripts/app/helpers/text_formatter_spec.js index 14323996a..75882880c 100644 --- a/spec/javascripts/app/helpers/text_formatter_spec.js +++ b/spec/javascripts/app/helpers/text_formatter_spec.js @@ -103,7 +103,13 @@ describe("app.helpers.textFormatter", function(){ _.each([this.alice, this.bob], function(person) { expect(wrapper.find("a[href='/people/" + person.id + "']").text()).toContain(person.name) }) - }) + }); + + it('returns the name of the mention if the mention does not exist in the array', function(){ + var text = "hey there @{Chris Smith; chris@example.com}" + var formattedText = this.formatter.mentionify(text, []) + expect(formattedText.match(/\