Skip to content

Commit

Permalink
fix HabitRPG#1954 . Start updating API tests, beginning with challeng…
Browse files Browse the repository at this point in the history
…es. Use

test to fix "challenge updates not updating users' tasks"
  • Loading branch information
lefnire committed Jan 3, 2014
1 parent ae080fd commit 2c1eb95
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 115 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"main": "./src/server.js",
"dependencies": {
"habitrpg-shared": "git://github.com/HabitRPG/habitrpg-shared#develop",
"derby-auth": "git://github.com/lefnire/derby-auth#master",
"connect-mongo": "*",
"passport-facebook": "~1.0.0",
"express": "*",
Expand All @@ -16,9 +15,7 @@
"coffee-script": "*",
"nconf": "*",
"icalendar": "git://github.com/lefnire/node-icalendar#master",
"superagent": "~0.12.4",
"resolve": "~0.2.3",
"expect.js": "~0.2.0",
"lodash": "~2.2.1",
"async": "~0.2.9",
"optimist": "~0.5.2",
Expand Down Expand Up @@ -80,6 +77,9 @@
"mocha": "~1.12.1",
"karma-mocha": "~0.1.0",
"csv": "~0.3.6",
"mongoskin": "~0.6.1"
"mongoskin": "~0.6.1",
"expect.js": "~0.2.0",
"superagent": "~0.15.7",
"superagent-defaults": "~0.1.5"
}
}
1 change: 1 addition & 0 deletions src/controllers/challenges.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ api.create = function(req, res){

waterfall = waterfall.concat([
function(cb) { // if we're dealing with prize above, arguemnts will be `group, numRows, cb` - else `cb`
req.body.leader = user._id;
var chal = new Challenge(req.body); // FIXME sanitize
chal.members.push(user._id);
chal.save(cb)
Expand Down
8 changes: 4 additions & 4 deletions src/models/challenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ function syncableAttrs(task) {
* Compare whether any changes have been made to tasks. If so, we'll want to sync those changes to subscribers
*/
function comparableData(obj) {
return (
_.chain(obj.habits.concat(obj.dailys).concat(obj.todos).concat(obj.rewards))
return JSON.stringify(
_(obj.habits.concat(obj.dailys).concat(obj.todos).concat(obj.rewards))
.sortBy('id') // we don't want to update if they're sort-order is different
.transform(function(result, task){
result.push(syncableAttrs(task));
}))
.toString(); // for comparing arrays easily
})
.value())
}

ChallengeSchema.methods.isOutdated = function(newData) {
Expand Down
Loading

0 comments on commit 2c1eb95

Please sign in to comment.