(
deftest
n-plus-one-detection-test-works
(
testing
"it does actually detect N+1 queries"
(
is
(
thrown-with-msg?
clojure.lang.ExceptionInfo
#"N\+1 hydration detected"
(
t2/hydrate
[
{
}
{
}
{
}
]
::some-silly-key-that-should-never-actually-be-hydrated!!!
)
)
)
)
(
testing
"it detects N+1 queries even when there's just one item"
(
is
(
thrown-with-msg?
clojure.lang.ExceptionInfo
#"N\+1 hydration detected"
(
t2/hydrate
[
{
}
]
::some-silly-key-that-should-never-actually-be-hydrated!!!
)
)
)
)
(
binding
[
*cached?*
(
atom
false
)
]
(
testing
"Hydration doesn't throw"
(
is
(
=
[
{
::just-a-fake-cached-hydration-function!!!
:cached
}
]
(
t2/hydrate
[
{
}
]
::just-a-fake-cached-hydration-function!!!
)
)
)
)
(
testing
"The 'cache' was populated"
(
is
(
=
true
@
*cached?*
)
)
)
)
)