FIX: make sure every user instance has correct status tracking counter
This commit is contained in:
parent
fccbe5c604
commit
47917c0be4
|
@ -1178,6 +1178,32 @@ User.reopenClass(Singleton, {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
User.reopenClass({
|
||||||
|
create(args) {
|
||||||
|
args = args || {};
|
||||||
|
this.deleteStatusTrackingFields(args);
|
||||||
|
return this._super(args);
|
||||||
|
},
|
||||||
|
|
||||||
|
deleteStatusTrackingFields(args) {
|
||||||
|
// every user instance has to have it's own tracking fields
|
||||||
|
// when creating a new user model
|
||||||
|
// its _subscribersCount and _clearStatusTimerId fields
|
||||||
|
// should be equal to 0 and null
|
||||||
|
// here we makes sure that even if these fields
|
||||||
|
// will be passed in args they won't be set anyway
|
||||||
|
//
|
||||||
|
// this is something that could be implemented by making these fields private,
|
||||||
|
// but EmberObject doesn't support private fields
|
||||||
|
if (args.hasOwnProperty("_subscribersCount")) {
|
||||||
|
delete args._subscribersCount;
|
||||||
|
}
|
||||||
|
if (args.hasOwnProperty("_clearStatusTimerId")) {
|
||||||
|
delete args._clearStatusTimerId;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
// user status tracking
|
// user status tracking
|
||||||
User.reopen(Evented, {
|
User.reopen(Evented, {
|
||||||
_subscribersCount: 0,
|
_subscribersCount: 0,
|
||||||
|
|
|
@ -163,4 +163,20 @@ module("Unit | Model | user", function () {
|
||||||
user2.stopTrackingStatus();
|
user2.stopTrackingStatus();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("create() doesn't set internal status tracking fields", function (assert) {
|
||||||
|
const user = User.create({
|
||||||
|
_subscribersCount: 10,
|
||||||
|
_clearStatusTimerId: 100,
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.notOk(
|
||||||
|
user.hasOwnProperty("_subscribersCount"),
|
||||||
|
"_subscribersCount wasn't set"
|
||||||
|
);
|
||||||
|
assert.notOk(
|
||||||
|
user.hasOwnProperty("_clearStatusTimerId"),
|
||||||
|
"_clearStatusTimerId wasn't set"
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue