Skip to content

Commit

Permalink
Test named association with same-model plain association
Browse files Browse the repository at this point in the history
  • Loading branch information
mde committed Nov 15, 2012
1 parent 550ee64 commit 690c578
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
48 changes: 48 additions & 0 deletions test/adapters/shared.js
Expand Up @@ -429,6 +429,54 @@ tests = {
});
}

, 'test named hasMany with hasOne of same model': function (next) {
var u = User.create({
login: 'zzzz'
, password: 'zerb'
, confirmPassword: 'zerb'
});
u.save(function (err, data) {
if (err) {
throw err;
}
currentId = u.id;
User.first(currentId, {}, function (err, data) {
var user = data
, account;
if (err) {
throw err;
}
user.setProfile(Profile.create({
nickname: 'frang'
}));
user.addAvatar(Profile.create({
nickname: 'fffuuu'
}));
user.addAvatar(Profile.create({
nickname: 'derrrr'
}));
user.save(function (err, data) {
if (err) {
throw err;
}
user.getAvatars(function (err, data) {
if (err) {
throw err;
}
assert.equal(2, data.length);
user.getProfile(function (err, data) {
if (err) {
throw err;
}
assert.equal('frang', data.nickname);
next();
});
});
});
});
});
}

, 'test Static methods on model': function (next) {
User.findByLogin('asdf', function (err, data) {
assert.equal(data.length, 4);
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/user.js
Expand Up @@ -15,6 +15,7 @@ var User = function () {
this.hasOne('Profile');
this.hasMany('Accounts');
this.hasMany('Friends', {model: 'Users'});
this.hasMany('Avatars', {model: 'Profiles'});
};

User.prototype.someMethod = function () {
Expand Down

0 comments on commit 690c578

Please sign in to comment.