FIX: Reset likeAction when updating a cached post from JSON data (#29971)
This commit addresses an issue where the like button would not be updated properly when reloading a post that lost the only like it had received.
This commit is contained in:
parent
a710d3f377
commit
d3595b6118
|
@ -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();
|
||||
|
||||
|
|
|
@ -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");
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue