Skip to content

Commit

Permalink
[test] Tests for cascading destruction
Browse files Browse the repository at this point in the history
  • Loading branch information
pksunkara committed Jul 8, 2012
1 parent 7d5a31c commit 3050990
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 17 deletions.
23 changes: 15 additions & 8 deletions test/fixtures/relationship.js
Expand Up @@ -56,6 +56,7 @@ fixtures.testData = [
_id: 'repository/user/christian/repository-1',
name: 'repository-1',
resource: 'Repository',
pull_request_ids: ['1'],
user_id: 'christian'
},
{
Expand Down Expand Up @@ -156,49 +157,49 @@ fixtures.testData = [
},
{
_id: 'follower/user/marak/pavan',
user: 'pavan',
name: 'pavan',
resource: 'Follower',
user_id: 'marak'
},
{
_id: 'follower/user/marak/christian',
user: 'christian',
name: 'christian',
resource: 'Follower',
user_id: 'marak'
},
{
_id: 'follower/user/pavan/marak',
user: 'marak',
name: 'marak',
resource: 'Follower',
user_id: 'pavan'
},
{
_id: 'follower/user/pavan/christian',
user: 'christian',
name: 'christian',
resource: 'Follower',
user_id: 'pavan'
},
{
_id: 'following/user/marak/pavan',
user: 'pavan',
name: 'pavan',
resource: 'Following',
user_id: 'marak'
},
{
_id: 'following/user/pavan/marak',
user: 'marak',
name: 'marak',
resource: 'Following',
user_id: 'pavan'
},
{
_id: 'following/user/christian/marak',
user: 'marak',
name: 'marak',
resource: 'Following',
user_id: 'christian'
},
{
_id: 'following/user/christian/pavan',
user: 'pavan',
name: 'pavan',
resource: 'Following',
user_id: 'christian'
},
Expand Down Expand Up @@ -243,5 +244,11 @@ fixtures.testData = [
resource: 'Forum',
forum_id: 'forum/develop/nodejitsu',
forum_ids: []
},
{
_id: 'pull_request/repository/user/christian/repository-1/1',
title: 'Resourceful rocks!',
resource: 'PullRequest',
repository_id: 'user/christian/repository-1'
}
];
22 changes: 17 additions & 5 deletions test/macros/relationship.js
Expand Up @@ -49,6 +49,18 @@ macros.defineResources = function (e, resources) {
assert.equal(resource.schema.name, 'Repository');
}
},
'"pull_request"': {
topic: function () {
return resources[e].PullRequest = resourceful.define('pull_request', function () {
this.use(e.name, e.options);
this.string('title', { minLength: 1 });
this.parent('Repository');
});
},
'will be successful': function (resource) {
assert.equal(resource.schema.name, 'PullRequest');
}
},
'"team"': {
topic: function () {
return resources[e].Team = resourceful.define('team', function() {
Expand Down Expand Up @@ -77,7 +89,7 @@ macros.defineResources = function (e, resources) {
return resources[e].Membership = resourceful.define('membership', function() {
this.use(e.name, e.options);
this.string('team');
// this.parent('User');
this.parent('User');
});
},
'will be successful': function (resource) {
Expand All @@ -88,8 +100,8 @@ macros.defineResources = function (e, resources) {
topic: function () {
return resources[e].Follower = resourceful.define('follower', function() {
this.use(e.name, e.options);
this.string('user');
// this.parent('User');
this.string('name');
this.parent('User');
});
},
'will be successful': function (resource) {
Expand All @@ -100,8 +112,8 @@ macros.defineResources = function (e, resources) {
topic: function () {
return resources[e].Following = resourceful.define('following', function() {
this.use(e.name, e.options);
this.string('user');
// this.parent('User');
this.string('name');
this.parent('User');
});
},
'will be successful': function (resource) {
Expand Down
39 changes: 35 additions & 4 deletions test/relationship-test.js
Expand Up @@ -178,6 +178,7 @@ engines.forEach(function (e) {
assert.equal(obj.name, 'marak');
assert.equal(obj.resource, 'User');
assert.lengthOf(obj.repository_ids, 2);
assert.lengthOf(obj.follower_ids, 2);
},
"and when 'Parent.createChild()' is used": {
"successfully": {
Expand Down Expand Up @@ -392,14 +393,44 @@ engines.forEach(function (e) {
assert.equal(err.status, '404');
assert.isUndefined(obj);
}
},
"should result in his followings": {
topic: function () {
resources[e].Following.get('user/christian/marak', this.callback);
},
"getting destroyed": function (err, obj) {
assert.equal(err.status, 404);
assert.isUndefined(obj);
}
},
"should result in his memberships": {
topic: function () {
resources[e].Membership.get('user/christian/nodejitsu', this.callback);
},
"getting destroyed": function (err, obj) {
assert.equal(err.status, 404);
assert.isUndefined(obj);
}
}
}
}
}
}).addBatch({
// TODO: Cascading destroy should result in
// * reducing marak's follower count
// * reducing nodejitsu's user count
// * deleting christian following documents
// Cascading destroy should result in destroying
// pull_request/repository/user/christian/repository-1/1
"In database 'test'": {
topic: function () {
return null;
},
"issues of repositories of 'christian'": {
topic: function () {
resources[e].PullRequest.get('repository/user/christian/repository-1/1', this.callback);
},
"should be destroyed": function (err, obj) {
assert.equal(err.status, 404);
assert.isUndefined(obj);
}
}
}
}).export(module);
});

0 comments on commit 3050990

Please sign in to comment.