Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[test] Tests for cascading destruction

  • Loading branch information...
commit 3050990cfd0b44cfc237fff441b4f1b0c9a73adf 1 parent 7d5a31c
@pksunkara pksunkara authored
View
23 test/fixtures/relationship.js
@@ -56,6 +56,7 @@ fixtures.testData = [
_id: 'repository/user/christian/repository-1',
name: 'repository-1',
resource: 'Repository',
+ pull_request_ids: ['1'],
user_id: 'christian'
},
{
@@ -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'
},
@@ -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'
}
];
View
22 test/macros/relationship.js
@@ -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() {
@@ -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) {
@@ -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) {
@@ -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) {
View
39 test/relationship-test.js
@@ -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": {
@@ -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);
});
Please sign in to comment.
Something went wrong with that request. Please try again.