Skip to content
Browse files

added test demonstrating nesting subfields

  • Loading branch information...
1 parent 5575584 commit a0d98bf5782ed4ca7c263f919a11d9792e6e08b6 @jliszka jliszka committed Feb 24, 2012
View
5 src/test/scala/com/foursquare/rogue/QueryTest.scala
@@ -119,6 +119,7 @@ class QueryTest extends SpecsMatchers {
// BsonRecordField subfield queries
Venue where (_.claims.subfield(_.status) eqs ClaimStatus.approved) toString() must_== """db.venues.find({ "claims.status" : "Approved"})"""
Venue where (_.lastClaim.subfield(_.userid) eqs 123) toString() must_== """db.venues.find({ "lastClaim.uid" : 123})"""
+ Venue where (_.claims.subfield(_.source.subfield(_.name)) eqs "twitter") toString() must_== """db.venues.find({ "claims.source.name" : "twitter"})"""
// Enumeration list
OAuthConsumer where (_.privileges contains ConsumerPrivilege.awardBadges) toString() must_== """db.oauthconsumers.find({ "privileges" : "Award badges"})"""
@@ -246,8 +247,8 @@ class QueryTest extends SpecsMatchers {
// BsonRecordField and BsonRecordListField with nested Enumeration
val claims = List(VenueClaimBson.createRecord.userid(1).status(ClaimStatus.approved))
- Venue where (_.legacyid eqs 1) modify (_.claims setTo claims) toString() must_== query + """{ "$set" : { "claims" : [ { "status" : "Approved" , "uid" : 1}]}}""" + suffix
- Venue where (_.legacyid eqs 1) modify (_.lastClaim setTo claims.head) toString() must_== query + """{ "$set" : { "lastClaim" : { "status" : "Approved" , "uid" : 1}}}""" + suffix
+ Venue where (_.legacyid eqs 1) modify (_.claims setTo claims) toString() must_== query + """{ "$set" : { "claims" : [ { "status" : "Approved" , "uid" : 1 , "source" : { "name" : "" , "url" : ""}}]}}""" + suffix
+ Venue where (_.legacyid eqs 1) modify (_.lastClaim setTo claims.head) toString() must_== query + """{ "$set" : { "lastClaim" : { "status" : "Approved" , "uid" : 1 , "source" : { "name" : "" , "url" : ""}}}}""" + suffix
// Map
val m = Map("foo" -> 1L)
View
11 src/test/scala/com/foursquare/rogue/TestModels.scala
@@ -96,11 +96,20 @@ class VenueClaimBson extends BsonRecord[VenueClaimBson] {
def meta = VenueClaimBson
object userid extends LongField(this) { override def name = "uid" }
object status extends EnumNameField(this, ClaimStatus)
+ object source extends BsonRecordField(this, SourceBson)
}
object VenueClaimBson extends VenueClaimBson with BsonMetaRecord[VenueClaimBson] {
- override def fieldOrder = List(status, userid)
+ override def fieldOrder = List(status, userid, source)
}
+class SourceBson extends BsonRecord[SourceBson] {
+ def meta = SourceBson
+ object name extends StringField(this, 100)
+ object url extends StringField(this, 200)
+}
+object SourceBson extends SourceBson with BsonMetaRecord[SourceBson] {
+ override def fieldOrder = List(name, url)
+}
case class OneComment(timestamp: String, userid: Long, comment: String)
class Comment extends MongoRecord[Comment] with MongoId[Comment] {

0 comments on commit a0d98bf

Please sign in to comment.
Something went wrong with that request. Please try again.