Make app.helpers.truncate tolerant to null and undefined
This commit is contained in:
parent
50a3f03bfc
commit
9d5e1f604d
2 changed files with 13 additions and 0 deletions
|
|
@ -1,5 +1,9 @@
|
|||
(function() {
|
||||
app.helpers.truncate = function(passedString, length) {
|
||||
if (passedString == null || passedString == undefined) {
|
||||
return passedString;
|
||||
}
|
||||
|
||||
if (passedString.length > length) {
|
||||
var lastBlank = passedString.lastIndexOf(' ', length);
|
||||
var trimstring = passedString.substring(0, Math.min(length, lastBlank));
|
||||
|
|
|
|||
9
spec/javascripts/app/helpers/truncate_spec.js
Normal file
9
spec/javascripts/app/helpers/truncate_spec.js
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
describe("app.helpers.truncate", function() {
|
||||
it("handles null values", function() {
|
||||
expect(app.helpers.truncate(null, 123)).toEqual(null);
|
||||
});
|
||||
|
||||
it("handles undefined", function() {
|
||||
expect(app.helpers.truncate(undefined, 123)).toEqual(undefined);
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue