use of org.mamute.model.Answer in project mamute by caelum.
the class AnswerTest method return_true_if_answer_has_pending_edits.
@Test
public void return_true_if_answer_has_pending_edits() throws Exception {
Question myQuestion = question.withTitle("question title").withDescription("description").withAuthor(author).build();
Answer answer = answer("blablablab", myQuestion, author);
assertFalse(answer.hasPendingEdits());
AnswerInformation approved = new AnswerInformation(notMarked("blablabalblab"), new LoggedUser(editUser, null), answer, "");
answer.enqueueChange(approved, PENDING);
assertTrue(answer.hasPendingEdits());
}
use of org.mamute.model.Answer in project mamute by caelum.
the class SolrQuestionIndex method toDoc.
private SolrInputDocument toDoc(Question q) {
List<String> tagNames = Lists.transform(q.getTags(), new Function<Tag, String>() {
@Nullable
@Override
public String apply(@Nullable Tag tag) {
return tag.getName();
}
});
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", q.getId());
doc.addField("title", q.getTitle());
doc.addField("description", q.getMarkedDescription());
doc.addField("tags", join(tagNames));
String solution = null;
List<String> answers = new ArrayList<>();
for (Answer a : q.getAnswers()) {
if (a.isSolution()) {
solution = a.getDescription();
} else {
answers.add(a.getDescription());
}
}
if (solution != null) {
doc.addField("solution", solution);
}
if (answers.size() > 0) {
doc.addField("answers", join(answers));
}
return doc;
}
use of org.mamute.model.Answer in project mamute by caelum.
the class AnswerQuestionTest method should_answer_when_logged_in.
@Test
public void should_answer_when_logged_in() {
Question question = createQuestionWithDao(moderator(), "Titulo da questao hahaha", "Descricao da questao longa demais", tag("java"));
String description = "Resposta da questao do teste de edicao";
UserFlow navigation = login(navigate(), karmaNigga().getEmail());
navigation = answerQuestionWithFlow(navigation, question, description, false);
VRaptorTestResult questionAnswered = navigation.followRedirect().execute();
questionAnswered.wasStatus(200).isValid();
AnswerAndVotes answerAndVotes = questionAnswered.getObject("answers");
List<Answer> answers = new ArrayList<Answer>(answerAndVotes.getVotes().keySet());
Assert.assertEquals(description, answers.get(0).getDescription());
}
use of org.mamute.model.Answer in project mamute by caelum.
the class EditAnswerTest method should_edit_answer_of_other_author.
@Test
public void should_edit_answer_of_other_author() throws Exception {
User moderator = moderator();
Question question = createQuestionWithDao(moderator, "Titulo da questao hahaha", "Descricao da questao longa demais", tag("java"));
Answer answer = answerQuestionWithDao(moderator, question, "Resposta da questao do teste de edicao", false);
String newDescription = "my new description of the first answer";
UserFlow navigation = login(navigate(), karmaNigga().getEmail());
navigation = editAnswerWithFlow(navigation, answer, newDescription, "comment");
VRaptorTestResult answerEdited = navigation.followRedirect().execute();
answerEdited.wasStatus(200).isValid();
List<String> messagesList = messagesList(answerEdited);
assertTrue(messagesList.contains(message("status.pending")));
}
use of org.mamute.model.Answer in project mamute by caelum.
the class EditAnswerTest method should_edit_and_automatically_approve_moderator.
@Test
public void should_edit_and_automatically_approve_moderator() throws Exception {
User moderator = moderator();
Question question = createQuestionWithDao(moderator, "Titulo da questao hahaha", "Descricao da questao longa demais", tag("java"));
Answer answer = answerQuestionWithDao(karmaNigga(), question, "Resposta da questao do teste de edicao", false);
String newDescription = "my new description of the first answer";
UserFlow navigation = login(navigate(), moderator.getEmail());
navigation = editAnswerWithFlow(navigation, answer, newDescription, "comment");
VRaptorTestResult answerEdited = navigation.followRedirect().execute();
answerEdited.wasStatus(200).isValid();
List<String> messagesList = messagesList(answerEdited);
assertTrue(messagesList.contains(message("status.no_need_to_approve")));
AnswerAndVotes answerAndVotes = answerEdited.getObject("answers");
List<Answer> answers = new ArrayList<Answer>(answerAndVotes.getVotes().keySet());
assertEquals(newDescription, answers.get(0).getDescription());
}
Aggregations