Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Test named association with same-model plain association

  • Loading branch information...
commit 690c578ce733d2a7efdc63abc434ee61bc84ba24 1 parent 550ee64
mde authored
Showing with 49 additions and 0 deletions.
  1. +48 −0 test/adapters/shared.js
  2. +1 −0  test/fixtures/user.js
View
48 test/adapters/shared.js
@@ -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);
View
1  test/fixtures/user.js
@@ -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 () {
Please sign in to comment.
Something went wrong with that request. Please try again.