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

Commit 4e462a75 by Sascha Depold

Test for find and findAll

1 parent 0cd08d93
Showing with 53 additions and 51 deletions
...@@ -119,59 +119,61 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () { ...@@ -119,59 +119,61 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
}) })
}) })
it('correctly handles complex combinations', function(done) { ;(['find', 'findAll']).forEach(function(finderMethod) {
this.User.find({ it('correctly handles complex combinations', function(done) {
where: [ this.User[finderMethod]({
42, "2=2", ["1=?", 1], { username: "foo" }, where: [
Sequelize.or(
42, "2=2", ["1=?", 1], { username: "foo" },
Sequelize.and( 42, "2=2", ["1=?", 1], { username: "foo" } ),
Sequelize.or( 42, "2=2", ["1=?", 1], { username: "foo" } )
),
Sequelize.and(
42, "2=2", ["1=?", 1], { username: "foo" }, 42, "2=2", ["1=?", 1], { username: "foo" },
Sequelize.or( 42, "2=2", ["1=?", 1], { username: "foo" } ), Sequelize.or(
Sequelize.and( 42, "2=2", ["1=?", 1], { username: "foo" } ) 42, "2=2", ["1=?", 1], { username: "foo" },
) Sequelize.and( 42, "2=2", ["1=?", 1], { username: "foo" } ),
] Sequelize.or( 42, "2=2", ["1=?", 1], { username: "foo" } )
}).on('sql', function(sql) { ),
if (Support.getTestDialect() === 'postgres') { Sequelize.and(
expect(sql).to.contain( 42, "2=2", ["1=?", 1], { username: "foo" },
'WHERE (' + [ Sequelize.or( 42, "2=2", ["1=?", 1], { username: "foo" } ),
'"Users"."id"=42 AND 2=2 AND 1=1 AND "Users"."username"=\'foo\' AND ', Sequelize.and( 42, "2=2", ["1=?", 1], { username: "foo" } )
'(', )
'"Users"."id"=42 OR 2=2 OR 1=1 OR "Users"."username"=\'foo\' OR ', ]
'("Users"."id"=42 AND 2=2 AND 1=1 AND "Users"."username"=\'foo\') OR ', }).on('sql', function(sql) {
'("Users"."id"=42 OR 2=2 OR 1=1 OR "Users"."username"=\'foo\')', if (Support.getTestDialect() === 'postgres') {
') AND ', expect(sql).to.contain(
'(', 'WHERE (' + [
'"Users"."id"=42 AND 2=2 AND 1=1 AND "Users"."username"=\'foo\' AND ', '"Users"."id"=42 AND 2=2 AND 1=1 AND "Users"."username"=\'foo\' AND ',
'("Users"."id"=42 OR 2=2 OR 1=1 OR "Users"."username"=\'foo\') AND ', '(',
'("Users"."id"=42 AND 2=2 AND 1=1 AND "Users"."username"=\'foo\')', '"Users"."id"=42 OR 2=2 OR 1=1 OR "Users"."username"=\'foo\' OR ',
')' '("Users"."id"=42 AND 2=2 AND 1=1 AND "Users"."username"=\'foo\') OR ',
].join("") + '("Users"."id"=42 OR 2=2 OR 1=1 OR "Users"."username"=\'foo\')',
')' ') AND ',
) '(',
} else { '"Users"."id"=42 AND 2=2 AND 1=1 AND "Users"."username"=\'foo\' AND ',
expect(sql).to.contain( '("Users"."id"=42 OR 2=2 OR 1=1 OR "Users"."username"=\'foo\') AND ',
"WHERE (" + [ '("Users"."id"=42 AND 2=2 AND 1=1 AND "Users"."username"=\'foo\')',
"`Users`.`id`=42 AND 2=2 AND 1=1 AND `Users`.`username`='foo' AND ", ')'
"(", ].join("") +
"`Users`.`id`=42 OR 2=2 OR 1=1 OR `Users`.`username`='foo' OR ", ')'
"(`Users`.`id`=42 AND 2=2 AND 1=1 AND `Users`.`username`='foo') OR ", )
"(`Users`.`id`=42 OR 2=2 OR 1=1 OR `Users`.`username`='foo')", } else {
") AND ", expect(sql).to.contain(
"(", "WHERE (" + [
"`Users`.`id`=42 AND 2=2 AND 1=1 AND `Users`.`username`='foo' AND ", "`Users`.`id`=42 AND 2=2 AND 1=1 AND `Users`.`username`='foo' AND ",
"(`Users`.`id`=42 OR 2=2 OR 1=1 OR `Users`.`username`='foo') AND ", "(",
"(`Users`.`id`=42 AND 2=2 AND 1=1 AND `Users`.`username`='foo')", "`Users`.`id`=42 OR 2=2 OR 1=1 OR `Users`.`username`='foo' OR ",
")" "(`Users`.`id`=42 AND 2=2 AND 1=1 AND `Users`.`username`='foo') OR ",
].join("") + "(`Users`.`id`=42 OR 2=2 OR 1=1 OR `Users`.`username`='foo')",
")" ") AND ",
) "(",
} "`Users`.`id`=42 AND 2=2 AND 1=1 AND `Users`.`username`='foo' AND ",
"(`Users`.`id`=42 OR 2=2 OR 1=1 OR `Users`.`username`='foo') AND ",
"(`Users`.`id`=42 AND 2=2 AND 1=1 AND `Users`.`username`='foo')",
")"
].join("") +
")"
)
}
done() done()
})
}) })
}) })
}) })
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!