Exemplo n.º 1
0
  @Test
  public void useTheCommentsRelation() {
    // Create a new user and save it
    User bob = new User("*****@*****.**", "secret", "Bob").save();

    // Create a new post
    Post bobPost = new Post(bob, "My first post", "Hello world").save();

    // Post a first comment
    bobPost.addComment("Jeff", "Nice post");
    bobPost.addComment("Tom", "I knew that !");

    // Count things
    assertEquals(1, User.count());
    assertEquals(1, Post.count());
    assertEquals(2, Comment.count());

    // Retrieve Bob's post
    bobPost = Post.find("byAuthor", bob).first();
    assertNotNull(bobPost);

    // Navigate to comments
    assertEquals(2, bobPost.comments.size());
    assertEquals("Jeff", bobPost.comments.get(0).author);

    // Delete the post
    bobPost.delete();

    // Check that all comments have been deleted
    assertEquals(1, User.count());
    assertEquals(0, Post.count());
    assertEquals(0, Post.count());
    assertEquals(0, Comment.count());
  }
Exemplo n.º 2
0
 @Test
 public void testCascadeDelete() {
   Forum help = Forum.find("byName", "Play help").first();
   assertEquals(4, Topic.count());
   assertEquals(7, Post.count());
   help.delete();
   assertEquals(1, Topic.count());
   assertEquals(1, Post.count());
   User guillaume = User.find("byName", "Guillaume").first();
   assertEquals(0L, (long) guillaume.getTopicsCount());
 }
Exemplo n.º 3
0
 public static void index() {
   if (activeUser.isAdmin()) {
     Map<String, Long> stats = new TreeMap<String, Long>();
     stats.put("Dates", DateDim.count());
     stats.put("Sections", Section.count());
     stats.put("Forums", Forum.count());
     stats.put("Entries", Entry.count());
     stats.put("Threads", Thread.count());
     stats.put("Posts", Post.count());
     stats.put("Users", User.count());
     stats.put("Tags", Tag.count());
     render(stats);
   } else {
     forbidden();
   }
 }
Exemplo n.º 4
0
  public void createPost() {
    // Create a new user and save it
    User bob = new User("*****@*****.**", "secret", "Bob").save();

    // Create a new post
    new Post(bob, "My first post", "Hello world").save();

    // Test that the post has been created
    assertEquals(1, Post.count());

    // Retrieve all posts created by Bob
    List<Post> bobPosts = Post.find("byAuthor", bob).fetch();

    // Tests
    assertEquals(1, bobPosts.size());
    Post firstPost = bobPosts.get(0);
    assertNotNull(firstPost);
    assertEquals(bob, firstPost.author);
    assertEquals("My first post", firstPost.title);
    assertEquals("Hello world", firstPost.content);
    assertNotNull(firstPost.postedAt);
  }
Exemplo n.º 5
0
 /**
  * Get the number of posts unread by this user in a given thread
  *
  * @param thread
  * @return
  */
 public long getUnreadPostCount(Thread thread) {
   return Post.count("thread = ? and not ? member of e.readers", thread, this);
 }