不要怂,就是干,撸起袖子干!

Commit d0f998a0 by José Moreira

This is paranoid's fault too

1 parent a96f6ee1
Showing with 33 additions and 23 deletions
...@@ -15,15 +15,15 @@ describe(Support.getTestDialectTeaser("Include"), function () { ...@@ -15,15 +15,15 @@ describe(Support.getTestDialectTeaser("Include"), function () {
it( 'Try to include a required model. Result rows should match count', function ( done ) { it( 'Try to include a required model. Result rows should match count', function ( done ) {
var DT = DataTypes, var DT = DataTypes,
S = this.sequelize, S = this.sequelize,
User = S.define('User', { name: DT.STRING(40) }), User = S.define('User', { name: DT.STRING(40) }, { paranoid: true }),
SomeConnection = S.define('SomeConnection', { SomeConnection = S.define('SomeConnection', {
m: DT.STRING(40), m: DT.STRING(40),
fk: DT.INTEGER.UNSIGNED, fk: DT.INTEGER.UNSIGNED,
u: DT.INTEGER.UNSIGNED, u: DT.INTEGER.UNSIGNED,
}), }, { paranoid: true }),
A = S.define('A', { name: DT.STRING(40) }), A = S.define('A', { name: DT.STRING(40) }, { paranoid: true }),
B = S.define('B', { name: DT.STRING(40) }), B = S.define('B', { name: DT.STRING(40) }, { paranoid: true }),
C = S.define('C', { name: DT.STRING(40) }) C = S.define('C', { name: DT.STRING(40) }, { paranoid: true })
// Associate them // Associate them
User.hasMany( SomeConnection ) User.hasMany( SomeConnection )
...@@ -34,9 +34,9 @@ describe(Support.getTestDialectTeaser("Include"), function () { ...@@ -34,9 +34,9 @@ describe(Support.getTestDialectTeaser("Include"), function () {
.belongsTo( B, { foreignKey: 'fk', }) .belongsTo( B, { foreignKey: 'fk', })
.belongsTo( C, { foreignKey: 'fk', }) .belongsTo( C, { foreignKey: 'fk', })
A.hasMany( SomeConnection ) A.hasMany( SomeConnection, { foreignKey: 'fk', })
B.hasMany( SomeConnection ) B.hasMany( SomeConnection, { foreignKey: 'fk', })
C.hasMany( SomeConnection ) C.hasMany( SomeConnection, { foreignKey: 'fk', })
// Sync them // Sync them
S.sync({ force: true }).done( function ( err ) { expect( err ).not.to.be.ok; S.sync({ force: true }).done( function ( err ) { expect( err ).not.to.be.ok;
...@@ -51,12 +51,22 @@ describe(Support.getTestDialectTeaser("Include"), function () { ...@@ -51,12 +51,22 @@ describe(Support.getTestDialectTeaser("Include"), function () {
]).done( function ( err, users ) { expect( err ).not.to.be.ok; expect( users ).to.be.length( 5 ) ]).done( function ( err, users ) { expect( err ).not.to.be.ok; expect( users ).to.be.length( 5 )
SomeConnection.bulkCreate([ // Lets count, m: A and u: 1 SomeConnection.bulkCreate([ // Lets count, m: A and u: 1
{ u: 1, m: 'A', fk: 1 }, // 1 { u: 1, m: 'A', fk: 1 }, // 1 // Will be deleted
{ u: 2, m: 'A', fk: 1 }, { u: 2, m: 'A', fk: 1 },
{ u: 3, m: 'A', fk: 1 }, { u: 3, m: 'A', fk: 1 },
{ u: 4, m: 'A', fk: 1 },
{ u: 5, m: 'A', fk: 1 },
{ u: 1, m: 'B', fk: 1 }, { u: 1, m: 'B', fk: 1 },
{ u: 2, m: 'B', fk: 1 },
{ u: 3, m: 'B', fk: 1 },
{ u: 4, m: 'B', fk: 1 },
{ u: 5, m: 'B', fk: 1 },
{ u: 1, m: 'C', fk: 1 }, { u: 1, m: 'C', fk: 1 },
{ u: 1, m: 'A', fk: 2 }, // 2 { u: 2, m: 'C', fk: 1 },
{ u: 3, m: 'C', fk: 1 },
{ u: 4, m: 'C', fk: 1 },
{ u: 5, m: 'C', fk: 1 },
{ u: 1, m: 'A', fk: 2 }, // 2 // Will be deleted
{ u: 4, m: 'A', fk: 2 }, { u: 4, m: 'A', fk: 2 },
{ u: 2, m: 'A', fk: 2 }, { u: 2, m: 'A', fk: 2 },
{ u: 1, m: 'A', fk: 3 }, // 3 { u: 1, m: 'A', fk: 3 }, // 3
...@@ -65,7 +75,7 @@ describe(Support.getTestDialectTeaser("Include"), function () { ...@@ -65,7 +75,7 @@ describe(Support.getTestDialectTeaser("Include"), function () {
{ u: 2, m: 'B', fk: 2 }, { u: 2, m: 'B', fk: 2 },
{ u: 1, m: 'A', fk: 4 }, // 4 { u: 1, m: 'A', fk: 4 }, // 4
{ u: 4, m: 'A', fk: 2 }, { u: 4, m: 'A', fk: 2 },
]).done( function ( err, conns ) { expect( err ).not.to.be.ok; expect( conns ).to.be.length( 14 ) ]).done( function ( err, conns ) { expect( err ).not.to.be.ok; expect( conns ).to.be.length( 24 )
A.bulkCreate([ A.bulkCreate([
{ name: 'Just' }, { name: 'Just' },
...@@ -84,15 +94,14 @@ describe(Support.getTestDialectTeaser("Include"), function () { ...@@ -84,15 +94,14 @@ describe(Support.getTestDialectTeaser("Include"), function () {
{ name: 'because we only want A' } { name: 'because we only want A' }
]).done( function ( err, cs ) { expect( err ).not.to.be.ok; expect( cs ).to.be.length( 1 ) ]).done( function ( err, cs ) { expect( err ).not.to.be.ok; expect( cs ).to.be.length( 1 )
// Now let's query an initial test // Delete some of conns to prove the concept
A.findAndCountAll().done( function ( err, result ) { SomeConnection.destroy({
m: 'A',
u: 1,
fk: [ 1, 2 ],
}).done( function ( err ) { expect( err ).not.to.be.ok
// Test variables // Last and most important queries ( we connected 4, but deleted 2, witch means we must get 2 only )
expect( err ).not.to.be.ok
expect( result.count ).to.be.equal( 5 )
expect( result.rows.length ).to.be.equal( 5 )
// Last and most important queries
A.findAndCountAll({ A.findAndCountAll({
include: [{ include: [{
...@@ -105,19 +114,20 @@ describe(Support.getTestDialectTeaser("Include"), function () { ...@@ -105,19 +114,20 @@ describe(Support.getTestDialectTeaser("Include"), function () {
limit: 5, limit: 5,
}).done( function ( err, result ) { })
.done( function ( err, result ) {
// Test variables // Test variables
expect( err ).not.to.be.ok expect( err ).not.to.be.ok
expect( result.count ).to.be.equal( 4 ) expect( result.count ).to.be.equal( 2 )
expect( result.rows.length ).to.be.equal( 4 ) expect( result.rows.length ).to.be.equal( 2 )
done() done()
// Last and most important queries - END // Last and most important queries - END
}) })
// Now let's query an initial test - END // Delete some of conns to prove the concept - END
}) })
// Create an enviroment - END // Create an enviroment - END
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!