Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit c9ce51b4
authored
Apr 01, 2015
by
Ruben Bridgewater
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor all and or where tests to use promises
1 parent
e7856524
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
37 deletions
test/integration/model/and-or-where.test.js
test/integration/model/and-or-where.test.js
View file @
c9ce51b
...
@@ -12,7 +12,7 @@ chai.use(datetime);
...
@@ -12,7 +12,7 @@ chai.use(datetime);
chai
.
config
.
includeStack
=
true
;
chai
.
config
.
includeStack
=
true
;
describe
(
Support
.
getTestDialectTeaser
(
'Model'
),
function
()
{
describe
(
Support
.
getTestDialectTeaser
(
'Model'
),
function
()
{
beforeEach
(
function
(
done
)
{
beforeEach
(
function
()
{
this
.
User
=
this
.
sequelize
.
define
(
'User'
,
{
this
.
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
DataTypes
.
STRING
,
username
:
DataTypes
.
STRING
,
secretValue
:
DataTypes
.
STRING
,
secretValue
:
DataTypes
.
STRING
,
...
@@ -22,17 +22,15 @@ describe(Support.getTestDialectTeaser('Model'), function() {
...
@@ -22,17 +22,15 @@ describe(Support.getTestDialectTeaser('Model'), function() {
aBool
:
DataTypes
.
BOOLEAN
aBool
:
DataTypes
.
BOOLEAN
});
});
this
.
User
.
sync
({
force
:
true
}).
success
(
function
()
{
return
this
.
User
.
sync
({
force
:
true
});
done
();
});
});
});
([
'or'
,
'and'
]).
forEach
(
function
(
method
)
{
([
'or'
,
'and'
]).
forEach
(
function
(
method
)
{
var
word
=
method
.
toUpperCase
();
var
word
=
method
.
toUpperCase
();
describe
.
skip
(
'Sequelize.'
+
method
,
function
()
{
describe
.
skip
(
'Sequelize.'
+
method
,
function
()
{
it
(
'can handle plain strings'
,
function
(
done
)
{
it
(
'can handle plain strings'
,
function
()
{
this
.
User
.
find
({
return
this
.
User
.
find
({
where
:
Sequelize
[
method
](
'1=1'
,
'2=2'
)
where
:
Sequelize
[
method
](
'1=1'
,
'2=2'
)
}).
on
(
'sql'
,
function
(
sql
)
{
}).
on
(
'sql'
,
function
(
sql
)
{
if
(
dialect
===
'mssql'
)
{
if
(
dialect
===
'mssql'
)
{
...
@@ -40,12 +38,11 @@ describe(Support.getTestDialectTeaser('Model'), function() {
...
@@ -40,12 +38,11 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}
else
{
}
else
{
expect
(
sql
).
to
.
contain
(
'WHERE (1=1 '
+
word
+
' 2=2) LIMIT 1'
);
expect
(
sql
).
to
.
contain
(
'WHERE (1=1 '
+
word
+
' 2=2) LIMIT 1'
);
}
}
done
();
});
});
});
});
it
(
'can handle arrays'
,
function
(
done
)
{
it
(
'can handle arrays'
,
function
()
{
this
.
User
.
find
({
return
this
.
User
.
find
({
where
:
Sequelize
[
method
]([
'1=?'
,
1
],
[
'2=?'
,
2
])
where
:
Sequelize
[
method
]([
'1=?'
,
1
],
[
'2=?'
,
2
])
}).
on
(
'sql'
,
function
(
sql
)
{
}).
on
(
'sql'
,
function
(
sql
)
{
if
(
dialect
===
'mssql'
)
{
if
(
dialect
===
'mssql'
)
{
...
@@ -53,12 +50,11 @@ describe(Support.getTestDialectTeaser('Model'), function() {
...
@@ -53,12 +50,11 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}
else
{
}
else
{
expect
(
sql
).
to
.
contain
(
'WHERE (1=1 '
+
word
+
' 2=2) LIMIT 1'
);
expect
(
sql
).
to
.
contain
(
'WHERE (1=1 '
+
word
+
' 2=2) LIMIT 1'
);
}
}
done
();
});
});
});
});
it
(
'can handle objects'
,
function
(
done
)
{
it
(
'can handle objects'
,
function
()
{
this
.
User
.
find
({
return
this
.
User
.
find
({
where
:
Sequelize
[
method
]({
username
:
'foo'
,
intVal
:
2
},
{
secretValue
:
'bar'
})
where
:
Sequelize
[
method
]({
username
:
'foo'
,
intVal
:
2
},
{
secretValue
:
'bar'
})
}).
on
(
'sql'
,
function
(
sql
)
{
}).
on
(
'sql'
,
function
(
sql
)
{
var
expectation
=
({
var
expectation
=
({
...
@@ -75,13 +71,11 @@ describe(Support.getTestDialectTeaser('Model'), function() {
...
@@ -75,13 +71,11 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}
}
expect
(
sql
).
to
.
contain
(
expectation
);
expect
(
sql
).
to
.
contain
(
expectation
);
done
();
});
});
});
});
it
(
'can handle numbers'
,
function
(
done
)
{
it
(
'can handle numbers'
,
function
()
{
this
.
User
.
find
({
return
this
.
User
.
find
({
where
:
Sequelize
[
method
](
1
,
2
)
where
:
Sequelize
[
method
](
1
,
2
)
}).
on
(
'sql'
,
function
(
sql
)
{
}).
on
(
'sql'
,
function
(
sql
)
{
var
expectation
=
({
var
expectation
=
({
...
@@ -98,16 +92,14 @@ describe(Support.getTestDialectTeaser('Model'), function() {
...
@@ -98,16 +92,14 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}
}
expect
(
sql
).
to
.
contain
(
expectation
);
expect
(
sql
).
to
.
contain
(
expectation
);
done
();
});
});
});
});
});
});
});
});
describe
.
skip
(
'Combinations of Sequelize.and and Sequelize.or'
,
function
()
{
describe
.
skip
(
'Combinations of Sequelize.and and Sequelize.or'
,
function
()
{
it
(
'allows nesting of Sequelize.or'
,
function
(
done
)
{
it
(
'allows nesting of Sequelize.or'
,
function
()
{
this
.
User
.
find
({
return
this
.
User
.
find
({
where
:
Sequelize
.
and
(
Sequelize
.
or
(
'1=1'
,
'2=2'
),
Sequelize
.
or
(
'3=3'
,
'4=4'
))
where
:
Sequelize
.
and
(
Sequelize
.
or
(
'1=1'
,
'2=2'
),
Sequelize
.
or
(
'3=3'
,
'4=4'
))
}).
on
(
'sql'
,
function
(
sql
)
{
}).
on
(
'sql'
,
function
(
sql
)
{
if
(
dialect
===
'mssql'
)
{
if
(
dialect
===
'mssql'
)
{
...
@@ -115,12 +107,11 @@ describe(Support.getTestDialectTeaser('Model'), function() {
...
@@ -115,12 +107,11 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}
else
{
}
else
{
expect
(
sql
).
to
.
contain
(
'WHERE ((1=1 OR 2=2) AND (3=3 OR 4=4)) LIMIT 1'
);
expect
(
sql
).
to
.
contain
(
'WHERE ((1=1 OR 2=2) AND (3=3 OR 4=4)) LIMIT 1'
);
}
}
done
();
});
});
});
});
it
(
'allows nesting of Sequelize.or using object notation'
,
function
(
done
)
{
it
(
'allows nesting of Sequelize.or using object notation'
,
function
()
{
this
.
User
.
find
({
return
this
.
User
.
find
({
where
:
Sequelize
.
and
(
Sequelize
.
or
({
username
:
{
eq
:
'foo'
}},
{
username
:
{
eq
:
'bar'
}}),
where
:
Sequelize
.
and
(
Sequelize
.
or
({
username
:
{
eq
:
'foo'
}},
{
username
:
{
eq
:
'bar'
}}),
Sequelize
.
or
({
id
:
{
eq
:
1
}},
{
id
:
{
eq
:
4
}}))
Sequelize
.
or
({
id
:
{
eq
:
1
}},
{
id
:
{
eq
:
4
}}))
}).
on
(
'sql'
,
function
(
sql
)
{
}).
on
(
'sql'
,
function
(
sql
)
{
...
@@ -138,12 +129,11 @@ describe(Support.getTestDialectTeaser('Model'), function() {
...
@@ -138,12 +129,11 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}
}
expect
(
sql
).
to
.
contain
(
expectation
);
expect
(
sql
).
to
.
contain
(
expectation
);
done
();
});
});
});
});
it
(
'allows nesting of Sequelize.and'
,
function
(
done
)
{
it
(
'allows nesting of Sequelize.and'
,
function
()
{
this
.
User
.
find
({
return
this
.
User
.
find
({
where
:
Sequelize
.
or
(
Sequelize
.
and
(
'1=1'
,
'2=2'
),
Sequelize
.
and
(
'3=3'
,
'4=4'
))
where
:
Sequelize
.
or
(
Sequelize
.
and
(
'1=1'
,
'2=2'
),
Sequelize
.
and
(
'3=3'
,
'4=4'
))
}).
on
(
'sql'
,
function
(
sql
)
{
}).
on
(
'sql'
,
function
(
sql
)
{
if
(
dialect
===
'mssql'
)
{
if
(
dialect
===
'mssql'
)
{
...
@@ -151,12 +141,11 @@ describe(Support.getTestDialectTeaser('Model'), function() {
...
@@ -151,12 +141,11 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}
else
{
}
else
{
expect
(
sql
).
to
.
contain
(
'WHERE ((1=1 AND 2=2) OR (3=3 AND 4=4)) LIMIT 1'
);
expect
(
sql
).
to
.
contain
(
'WHERE ((1=1 AND 2=2) OR (3=3 AND 4=4)) LIMIT 1'
);
}
}
done
();
});
});
});
});
it
(
'allows nesting of Sequelize.and using object notation'
,
function
(
done
)
{
it
(
'allows nesting of Sequelize.and using object notation'
,
function
()
{
this
.
User
.
find
({
return
this
.
User
.
find
({
where
:
Sequelize
.
or
(
Sequelize
.
and
({
username
:
{
eq
:
'foo'
}},
{
username
:
{
eq
:
'bar'
}}),
where
:
Sequelize
.
or
(
Sequelize
.
and
({
username
:
{
eq
:
'foo'
}},
{
username
:
{
eq
:
'bar'
}}),
Sequelize
.
and
({
id
:
{
eq
:
1
}},
{
id
:
{
eq
:
4
}}))
Sequelize
.
and
({
id
:
{
eq
:
1
}},
{
id
:
{
eq
:
4
}}))
}).
on
(
'sql'
,
function
(
sql
)
{
}).
on
(
'sql'
,
function
(
sql
)
{
...
@@ -174,24 +163,22 @@ describe(Support.getTestDialectTeaser('Model'), function() {
...
@@ -174,24 +163,22 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}
}
expect
(
sql
).
to
.
contain
(
expectation
);
expect
(
sql
).
to
.
contain
(
expectation
);
done
();
});
});
});
});
if
(
dialect
!==
'postgres'
)
{
if
(
dialect
!==
'postgres'
)
{
it
(
'still allows simple arrays lookups'
,
function
(
done
)
{
it
(
'still allows simple arrays lookups'
,
function
()
{
this
.
User
.
find
({
return
this
.
User
.
find
({
where
:
[
'id IN (?) OR id IN (?)'
,
[
1
,
2
],
[
3
,
4
]]
where
:
[
'id IN (?) OR id IN (?)'
,
[
1
,
2
],
[
3
,
4
]]
}).
on
(
'sql'
,
function
(
sql
)
{
}).
on
(
'sql'
,
function
(
sql
)
{
expect
(
sql
).
to
.
contain
(
'id IN (1, 2) OR id IN (3, 4)'
);
expect
(
sql
).
to
.
contain
(
'id IN (1, 2) OR id IN (3, 4)'
);
done
();
});
});
});
});
}
}
([
'find'
,
'findAll'
]).
forEach
(
function
(
finderMethod
)
{
([
'find'
,
'findAll'
]).
forEach
(
function
(
finderMethod
)
{
it
(
'correctly handles complex combinations'
,
function
(
done
)
{
it
(
'correctly handles complex combinations'
,
function
()
{
this
.
User
[
finderMethod
]({
return
this
.
User
[
finderMethod
]({
where
:
[
where
:
[
42
,
'2=2'
,
[
'1=?'
,
1
],
{
username
:
'foo'
},
42
,
'2=2'
,
[
'1=?'
,
1
],
{
username
:
'foo'
},
Sequelize
.
or
(
Sequelize
.
or
(
...
@@ -258,8 +245,6 @@ describe(Support.getTestDialectTeaser('Model'), function() {
...
@@ -258,8 +245,6 @@ describe(Support.getTestDialectTeaser('Model'), function() {
')'
')'
);
);
}
}
done
();
});
});
});
});
});
});
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment