Skip to content
Browse files

save

  • Loading branch information...
1 parent d12da46 commit 548cd7e7d98e12480a308be02aa24af035f8168c @leodagdag committed Mar 27, 2012
Showing with 10 additions and 6 deletions.
  1. +1 −1 app/models/Media.scala
  2. +7 −3 app/models/Post.scala
  3. +2 −2 test/models/PostSpec.scala
View
2 app/models/Media.scala
@@ -5,7 +5,7 @@ import com.mongodb.casbah.commons.Imports._
case class Media(_id: ObjectId = new ObjectId,
title: String,
- content: String = null)
+ content: Option(String) = None)
object Media extends SalatDAO[Media, ObjectId](collection = DB.connection("Media")) with Model[Media] {
View
10 app/models/Post.scala
@@ -7,8 +7,8 @@ import javax.persistence.EntityNotFoundException
case class Post(_id: ObjectId = new ObjectId,
title: String,
- content: String = null,
- var comments: List[Comment] = List.empty)
+ content: Option[String] = None,
+ var comments: List[Comment] = null)
object Post extends SalatDAO[Post, ObjectId](collection = DB.connection("Post")) with Model[Post] {
@@ -18,7 +18,11 @@ object Post extends SalatDAO[Post, ObjectId](collection = DB.connection("Post"))
val post = this.findOneByID(id)
post match {
case Some(post) =>
- post.comments = post.comments :+ comment
+ if(post.comments == null) {
+ post.comments = List(comment)
+ } else {
+ post.comments = post.comments :+ comment
+ }
this.save(post)
case _ => throw new EntityNotFoundException("Problem retrieving a post with id[%s]".format(id))
}
View
4 test/models/PostSpec.scala
@@ -27,7 +27,7 @@ class PostSpec extends Specification {
"create 1" in {
running(FakeApplication()) {
- val post = new Post(title = "titre", content = "content")
+ val post = new Post(title = "titre", content = Some("content"))
Post.save(post)
savedId = post._id
savedId mustNotEqual null
@@ -51,7 +51,7 @@ class PostSpec extends Specification {
"create 12 Posts" in {
running(FakeApplication()) {
for (i <- 1 to 12) {
- var post = new Post(title = "titre" + i, content = "content")
+ var post = new Post(title = "titre" + i)
Post.save(post)
if (i == 12) { deleteId = post._id }
}

0 comments on commit 548cd7e

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