Package com.rapleaf.jack.test_project.database_1.models

Examples of com.rapleaf.jack.test_project.database_1.models.Post


  public Set<Post> findByUpdatedAt(final Long value) throws IOException {
    return find(new HashMap<Enum, Object>(){{put(Post._Fields.updated_at, value);}});
  }

  public PostQueryBuilder query() {
    return new PostQueryBuilder(this);
  }
View Full Code Here


  public Set<User> findBySomeBoolean(final Boolean value) throws IOException {
    return find(new HashMap<Enum, Object>(){{put(User._Fields.some_boolean, value);}});
  }

  public UserQueryBuilder query() {
    return new UserQueryBuilder(this);
  }
View Full Code Here

  }
 
 
    public static void index() {
     
       Post frontPost = Post.find("order by postedAt desc").first();
         List<Post> olderPosts = Post.find(
             "order by postedAt desc"
         ).from(1).fetch(10);
         render(frontPost, olderPosts);
     
View Full Code Here

     
    }
   
   
    public static void show(Long id) {
        Post post = Post.findById(id);
        String randomID = Codec.UUID();
        render(post, randomID);
    }
View Full Code Here

            @Required(message="Author is required") String author,
            @Required(message="A message is required") String content,
            @Required(message="Please type the code") String code,
            String randomID)
    {
        Post post = Post.findById(postId);
        validation.equals(
            code, Cache.get(randomID)
        ).message("Invalid code. Please type it again");
        if(validation.hasErrors()) {
            render("Application/show.html", post, randomID);
        }
        post.addComment(author, content);
        flash.success("Thanks for posting %s", author);
        Cache.delete(randomID);
        show(postId);
    }
View Full Code Here

    public void createPost() {
        // Create a new user and save it
        User bob = new User("bob@gmail.com", "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 post created by bob
        List<Post> bobPosts = Post.find("byAuthorEmail", bob.email).asList();

        // Tests
        assertEquals(1, bobPosts.size());
        Post firstPost = bobPosts.get(0);
        assertNotNull(firstPost);
        assertEquals(bob.email, firstPost.authorEmail);
        assertEquals("My first post", firstPost.title);
        assertEquals("Hello world", firstPost.content);
        assertNotNull(firstPost.postedAt);
View Full Code Here

    public void postComments() {
        // Create a new user and save it
        User bob = new User("bob@gmail.com", "secret", "Bob").save();

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

        // Post a first comment
        new Comment(bobPost, "Jeff", "Nice post").save();
        new Comment(bobPost, "Tom", "I knew that !").save();
View Full Code Here

    public void useTheCommentsRelation() {
        // Create a new user and save it
        User bob = new User("bob@gmail.com", "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 the bob post
        bobPost = Post.find("byAuthorEmail", bob.email).first();
        assertNotNull(bobPost);

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

        // Delete the post
        bobPost.delete();

        // Chech the all comments have been deleted
        assertEquals(1, User.count());
        assertEquals(0, Post.count());
        assertEquals(0, Comment.count());
View Full Code Here

        // Find all comments related to bob posts
        List<Comment> bobComments = Comment.q().filter("post in", Post.find("authorEmail", "bob@gmail.com").asKeyList()).asList();
        assertEquals(3, bobComments.size());

        // Find the most recent post
        Post frontPost = Post.q().order("-postedAt").first();
        assertNotNull(frontPost);
        assertEquals("About the model layer", frontPost.title);

        // Check that this post has two comments
        assertEquals(2, frontPost.comments.size());

        // Post a new comment
        frontPost.addComment("Jim", "Hello guys");
        assertEquals(3, frontPost.comments.size());
        assertEquals(4, Comment.count());
    }
View Full Code Here

    public void testTags() {
        // Create a new user and save it
        User bob = new User("bob@gmail.com", "secret", "Bob").save();

        // Create a new post
        Post bobPost = new Post(bob, "My first post", "Hello world").save();
        Post anotherBobPost = new Post(bob, "My second post post", "Hello world").save();
       
        // Well
        assertEquals(0, Post.findTaggedWith("Red").size());
       
        // Tag it now
        bobPost.tagItWith("Red").tagItWith("Blue").save();
        anotherBobPost.tagItWith("Red").tagItWith("Green").save();
       
        // Check
        assertEquals(2, Post.findTaggedWith("Red").size());       
        assertEquals(1, Post.findTaggedWith("Blue").size());
        assertEquals(1, Post.findTaggedWith("Green").size());
View Full Code Here

TOP

Related Classes of com.rapleaf.jack.test_project.database_1.models.Post

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.