Skip to content

Commit

Permalink
Handle 'category' property in context.contextActivities
Browse files Browse the repository at this point in the history
  • Loading branch information
brianjmiller committed Jan 24, 2014
1 parent 5641414 commit aaaeb72
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "tincanjs",
"description": "Tin Can API Library",
"version": "0.20.1",
"version": "0.21.1",
"private": false,
"main": "build/tincan-node.js",
"directories": {
Expand Down
22 changes: 20 additions & 2 deletions src/ContextActivities.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ TinCan client library
var ContextActivities = TinCan.ContextActivities = function (cfg) {
this.log("constructor");

/**
@property category
@type Array
*/
this.category = null;

/**
@property parent
@type Array
Expand Down Expand Up @@ -71,6 +77,7 @@ TinCan client library
var i,
j,
objProps = [
"category",
"parent",
"grouping",
"other"
Expand Down Expand Up @@ -100,11 +107,11 @@ TinCan client library

/**
@method add
@param String key Property to add value to one of "parent", "grouping", "other"
@param String key Property to add value to one of "category", "parent", "grouping", "other"
@return Number index where the value was added
*/
add: function (key, val) {
if (key !== "parent" && key !== "grouping" && key !== "other") {
if (key !== "category" && key !== "parent" && key !== "grouping" && key !== "other") {
return;
}

Expand Down Expand Up @@ -160,6 +167,17 @@ TinCan client library
}
}
}
if (this.category !== null && this.category.length > 0) {
if (version === "0.9" || version === "0.95") {
this.log("[WARNING] version does not support the 'category' property");
}
else {
result.category = [];
for (i = 0; i < this.category.length; i += 1) {
result.category.push(this.category[i].asVersion(version));
}
}
}

return result;
}
Expand Down
28 changes: 27 additions & 1 deletion test/js/unit/ContextActivities.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
function () {
var obj = new TinCan.ContextActivities (),
nullProps = [
"category",
"parent",
"grouping",
"other"
Expand Down Expand Up @@ -121,7 +122,7 @@
]
}
],
props = [ "parent", "other", "grouping" ],
props = [ "category", "parent", "other", "grouping" ],
i,
j,
instanceConfig,
Expand Down Expand Up @@ -163,6 +164,31 @@
latest: {}
}
},
{
name: "category 1",
instanceConfig: {
category: commonActivity
},
versions: {
latest: { category: [ commonRaw ] },
"0.95": {},
"0.9": {}
}
},
{
name: "category 2",
instanceConfig: {
category: [
commonActivity,
commonActivity2
]
},
versions: {
latest: { category: [ commonRaw, commonRaw2 ] },
"0.95": {},
"0.9": {}
}
},
{
name: "parent 1",
instanceConfig: {
Expand Down
2 changes: 1 addition & 1 deletion yuidoc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.20.1",
"version": "0.21.1",
"name": "TinCanJS",
"description": "Library for working with Tin Can API in JavaScript",
"url": "http://rusticisoftware.github.com/TinCanJS/",
Expand Down

0 comments on commit aaaeb72

Please sign in to comment.