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));
}
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));
}
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);
}
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;
}
Aggregations