FIX: Assign default value for category.findByIds method

FIX: Assign default value for category.findByIds method

From 036790d13c728e9d30223f0079d539b4de203e7f Mon Sep 17 00:00:00 2001
From: Vinoth Kannan <vinothkannan@vinkas.com>
Date: Thu, 22 Nov 2018 12:51:04 +0530
Subject: [PATCH] FIX: Assign default value for category.findByIds method


diff --git a/app/assets/javascripts/discourse/models/category.js.es6 b/app/assets/javascripts/discourse/models/category.js.es6
index 5c349d8..d5cb75b 100644
--- a/app/assets/javascripts/discourse/models/category.js.es6
+++ b/app/assets/javascripts/discourse/models/category.js.es6
@@ -257,7 +257,7 @@ Category.reopenClass({
     return Category.idMap()[id];
   },
 
-  findByIds(ids) {
+  findByIds(ids = []) {
     const categories = [];
     ids.forEach(id => {
       const found = Category.findById(id);
diff --git a/test/javascripts/models/category-test.js.es6 b/test/javascripts/models/category-test.js.es6
index 9e2437c..aa06c12 100644
--- a/test/javascripts/models/category-test.js.es6
+++ b/test/javascripts/models/category-test.js.es6
@@ -196,6 +196,8 @@ QUnit.test("findByIds", assert => {
     Discourse.Category.findByIds([1, 2, 3]),
     _.values(categories)
   );
+
+  assert.deepEqual(Discourse.Category.findByIds(), []);
 });
 
 QUnit.test("search with category name", assert => {

GitHub

This commit has been mentioned on Discourse Meta. There might be relevant details there:

This commit has been mentioned on Discourse Meta. There might be relevant details there:

I think we don’t have to use deepEqual here.

1 Like

https://github.com/discourse/discourse/commit/5969a31d73e749b116da27944e5ead4e8f332b3f done :+1:

2 Likes

Use deepEqual (formerlay same) to compare arrays. The equal (formerly equals) assertion only compares references in this case.

deepEqual is correct here.

2 Likes