-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the overloaded where method to Untyped.
See the updated guide/criteria.md for more details.
- Loading branch information
1 parent
874f18a
commit f1d475e
Showing
3 changed files
with
221 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
bson/src/test/scala/dsl/criteria/UntypedWhereSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
/* | ||
* Copyright 2013 Steve Vickers | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* Created on: Jun 15, 2014 | ||
*/ | ||
package reactivemongo.extensions.dsl.criteria | ||
|
||
import org.scalatest._ | ||
import org.scalatest.matchers._ | ||
|
||
import reactivemongo.bson._ | ||
|
||
/** | ||
* The '''UntypedWhereSpec''' type verifies the behaviour expected of the | ||
* `where` method in the [[reactivemongo.extensions.dsl.criteria.Untyped]] | ||
* `type`. | ||
* | ||
* @author svickers | ||
* | ||
*/ | ||
class UntypedWhereSpec | ||
extends FlatSpec | ||
with Matchers { | ||
/// Class Imports | ||
import Untyped._ | ||
|
||
"An Untyped where" should "support 1 placeholder" in | ||
{ | ||
val q = where { | ||
_.a === 1 | ||
} | ||
|
||
BSONDocument.pretty(q) shouldBe ( | ||
BSONDocument.pretty( | ||
BSONDocument( | ||
"a" -> BSONInteger(1) | ||
) | ||
) | ||
); | ||
} | ||
|
||
it should "support 2 placeholders" in | ||
{ | ||
val q = where { | ||
_.a === 1 && _.b === 2 | ||
} | ||
|
||
BSONDocument.pretty(q) shouldBe ( | ||
BSONDocument.pretty( | ||
BSONDocument( | ||
"$and" -> | ||
BSONArray( | ||
BSONDocument( | ||
"a" -> BSONInteger(1) | ||
), | ||
BSONDocument( | ||
"b" -> BSONInteger(2) | ||
) | ||
) | ||
) | ||
) | ||
); | ||
} | ||
|
||
it should "support 3 placeholders" in | ||
{ | ||
val q = where { | ||
_.a === 1 && _.b === 2 && _.c === 3 | ||
} | ||
|
||
BSONDocument.pretty(q) shouldBe ( | ||
BSONDocument.pretty( | ||
BSONDocument( | ||
"$and" -> | ||
BSONArray( | ||
BSONDocument( | ||
"a" -> BSONInteger(1) | ||
), | ||
BSONDocument( | ||
"b" -> BSONInteger(2) | ||
), | ||
BSONDocument( | ||
"c" -> BSONInteger(3) | ||
) | ||
) | ||
) | ||
) | ||
); | ||
} | ||
|
||
/// The library supports from 1 to 22 placeholders for the where method. | ||
it should "support 22 placeholders" in | ||
{ | ||
val q = where { | ||
_.p === 0 && | ||
_.p === 0 && | ||
_.p === 0 && | ||
_.p === 0 && | ||
_.p === 0 && | ||
_.p === 0 && | ||
_.p === 0 && | ||
_.p === 0 && | ||
_.p === 0 && | ||
_.p === 0 && | ||
_.p === 0 && | ||
_.p === 0 && | ||
_.p === 0 && | ||
_.p === 0 && | ||
_.p === 0 && | ||
_.p === 0 && | ||
_.p === 0 && | ||
_.p === 0 && | ||
_.p === 0 && | ||
_.p === 0 && | ||
_.p === 0 && | ||
_.p === 0 | ||
} | ||
|
||
BSONDocument.pretty(q) shouldBe ( | ||
BSONDocument.pretty( | ||
BSONDocument( | ||
"$and" -> | ||
BSONArray(List.fill(22)(BSONDocument("p" -> BSONInteger(0)))) | ||
) | ||
) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters