Search in sources :

Example 11 with Comment

use of org.mamute.model.Comment in project mamute by caelum.

the class CommentTest method should_verify_that_user_flagged_a_comment.

@Test
public void should_verify_that_user_flagged_a_comment() {
    User author = user("name", "email@email", 1l);
    User other = user("other", "other@brutal.com", 2l);
    User commentAuthor = user("name", "email@email", 1l);
    Comment comment = comment(commentAuthor, "comment");
    Flag flag = new Flag(FlagType.RUDE, author);
    comment.add(flag);
    assertTrue(comment.alreadyFlaggedBy(author));
    assertFalse(comment.alreadyFlaggedBy(other));
}
Also used : Comment(org.mamute.model.Comment) User(org.mamute.model.User) Flag(org.mamute.model.Flag) Test(org.junit.Test)

Example 12 with Comment

use of org.mamute.model.Comment in project mamute by caelum.

the class VoteDAOTest method should_find_question_from_votable.

@Test
public void should_find_question_from_votable() throws Exception {
    Question question = question(currentUser, tags);
    Answer answer = answer("answer answer answer answer answer", question, currentUser);
    Comment comment = comment(currentUser, "blabla blabla blabla blabla blabla blabla");
    question.add(comment);
    session.save(question);
    session.save(answer);
    session.save(comment);
    assertEquals(question, votes.contextOf(question));
    assertEquals(question, votes.contextOf(answer));
    assertEquals(question, votes.contextOf(comment));
}
Also used : Answer(org.mamute.model.Answer) Comment(org.mamute.model.Comment) Question(org.mamute.model.Question) Test(org.junit.Test)

Example 13 with Comment

use of org.mamute.model.Comment in project mamute by caelum.

the class FlaggableDAOTest method should_get_count_of_comments_with_two_flags.

@Test
public void should_get_count_of_comments_with_two_flags() throws Exception {
    Comment comment = comment();
    addFlags(comment, 10, author);
    session.save(comment);
    int count = flaggables.flaggedButVisibleCount(Comment.class);
    assertEquals(2, count);
}
Also used : Comment(org.mamute.model.Comment) Test(org.junit.Test)

Example 14 with Comment

use of org.mamute.model.Comment in project mamute by caelum.

the class VoteDAO method contextOf.

// TODO: refactor?
public ReputationEventContext contextOf(Votable votable) {
    boolean isNews = News.class.isAssignableFrom(votable.getClass());
    if (isNews) {
        return (ReputationEventContext) votable;
    }
    boolean isQuestionOrAnswer = !Comment.class.isAssignableFrom(votable.getClass());
    if (isQuestionOrAnswer) {
        return votable.getQuestion();
    }
    Question question = (Question) session.createQuery("select q from Question q join q.comments.comments c where c=:comment").setParameter("comment", votable).uniqueResult();
    if (question != null) {
        return question;
    }
    question = (Question) session.createQuery("select a.question from Answer a join a.comments.comments c where c=:comment").setParameter("comment", votable).uniqueResult();
    if (question != null) {
        return question;
    }
    ReputationEventContext ctx = (ReputationEventContext) session.createQuery("select news from News news join news.comments.comments c where c=:comment").setParameter("comment", votable).uniqueResult();
    return ctx;
}
Also used : Comment(org.mamute.model.Comment) ReputationEventContext(org.mamute.model.ReputationEventContext) Question(org.mamute.model.Question)

Aggregations

Comment (org.mamute.model.Comment)14 Test (org.junit.Test)9 Question (org.mamute.model.Question)4 Answer (org.mamute.model.Answer)3 LoggedUser (org.mamute.model.LoggedUser)3 User (org.mamute.model.User)3 RemoveAnythingFlaggedByModerator (org.mamute.model.flag.RemoveAnythingFlaggedByModerator)3 Flag (org.mamute.model.Flag)2 CustomBrutauthRules (br.com.caelum.brutauth.auth.annotations.CustomBrutauthRules)1 Get (br.com.caelum.vraptor.Get)1 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 FlaggableAndFlagCount (org.mamute.dto.FlaggableAndFlagCount)1 SuspectMassiveVote (org.mamute.dto.SuspectMassiveVote)1 CommentsAndVotes (org.mamute.model.CommentsAndVotes)1 ReputationEventContext (org.mamute.model.ReputationEventContext)1 VisibleCommentList (org.mamute.model.VisibleCommentList)1 Vote (org.mamute.model.Vote)1 MassiveVote (org.mamute.model.vote.MassiveVote)1