A platform for community discussion. Free, open, simple.
FIX: Reset likeAction when updating a cached post from JSON data (#29971)
Sérgio Saquetimd3595b611889
diff --git a/app/assets/javascripts/discourse/app/models/post.js b/app/assets/javascripts/discourse/app/models/post.jsindex 00d16c92062..69cdd292f9b 100644--- a/app/assets/javascripts/discourse/app/models/post.js+++ b/app/assets/javascripts/discourse/app/models/post.js@@ -63,6 +63,7 @@ function trackedPostProperty(target, propertyKey, descriptor) {export default class Post extends RestModel {static munge(json) {+ json.likeAction = null;if (json.actions_summary) {const lookup = EmberObject.create();diff --git a/app/assets/javascripts/discourse/tests/unit/models/post-test.js b/app/assets/javascripts/discourse/tests/unit/models/post-test.jsindex e9dd417967d..dc30ffca4a8 100644--- a/app/assets/javascripts/discourse/tests/unit/models/post-test.js+++ b/app/assets/javascripts/discourse/tests/unit/models/post-test.js@@ -116,4 +116,21 @@ module("Unit | Model | post", function (hooks) {);assert.strictEqual(post.version, 2, "the version number increased");});++ test("likeAction", function (assert) {+ const post = this.store.createRecord("post", {+ id: 1173,+ });++ post.likeAction = { count: 1 };+ assert.deepEqual(post.likeAction, { count: 1 }, "likeAction set");++ // creating a new record with the same id should reset the likeAction in the original post because instance+ // is cached and the information required to properly generate the field is not available in the new JSON data+ this.store.createRecord("post", {+ id: 1173,+ });++ assert.ok(post.likeAction === null, "likeAction was reset to null");+ });});