Search in sources :

Example 11 with Tag

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

the class QuestionTest method should_return_true_if_question_has_pending_edits.

@Test
public void should_return_true_if_question_has_pending_edits() throws Exception {
    Tag ruby = tag("ruby");
    Tag java = tag("java");
    Question q = question.withTag(ruby).build();
    assertFalse(q.hasPendingEdits());
    QuestionInformation approved = new QuestionInformationBuilder().withTag(java).build();
    q.enqueueChange(approved, PENDING);
    assertTrue(q.hasPendingEdits());
}
Also used : QuestionInformationBuilder(org.mamute.model.QuestionInformationBuilder) Question(org.mamute.model.Question) Tag(org.mamute.model.Tag) QuestionInformation(org.mamute.model.QuestionInformation) Test(org.junit.Test)

Example 12 with Tag

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

the class InformationDAOTest method setup.

@Before
public void setup() {
    author = user("namename", "email@gmail.com");
    currentAuthor = new LoggedUser(author, null);
    java = new Tag("java", "", null);
    session.save(author);
    session.save(java);
    informations = new InformationDAO(session);
    question = newQuestion(author);
}
Also used : LoggedUser(org.mamute.model.LoggedUser) Tag(org.mamute.model.Tag) Before(org.junit.Before)

Example 13 with Tag

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

the class TagsValidatorTest method setup.

@Before
public void setup() {
    environment = mock(Environment.class);
    when(environment.get("tags.sanitizer.regex")).thenReturn("[a-zA-Z0-9-]");
    messageFactory = new MessageFactory(bundle);
    validator = new MockValidator();
    tagsValidator = new TagsValidator(environment, validator, messageFactory);
    User user = user("any", "any@brutal.com");
    java = new Tag("java", "", user);
    ruby = new Tag("ruby", "", user);
    rails = new Tag("rails", "", user);
    nonalpha = new Tag("java,mysql", "", user);
}
Also used : User(org.mamute.model.User) MessageFactory(org.mamute.factory.MessageFactory) MockValidator(br.com.caelum.vraptor.util.test.MockValidator) Environment(br.com.caelum.vraptor.environment.Environment) Tag(org.mamute.model.Tag) Before(org.junit.Before)

Example 14 with Tag

use of org.mamute.model.Tag 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;
}
Also used : Answer(org.mamute.model.Answer) SolrInputDocument(org.apache.solr.common.SolrInputDocument) ArrayList(java.util.ArrayList) Tag(org.mamute.model.Tag) Nullable(javax.annotation.Nullable)

Example 15 with Tag

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

the class RssController method rssByTag.

@Get
public void rssByTag(String tagName) throws IOException {
    Tag tag = tags.findByName(tagName);
    if (tag == null) {
        result.notFound();
        return;
    }
    List<RssContent> orderedByDate = questions.orderedByCreationDate(MAX_RESULTS, tag);
    String title = bundle.getMessage("questions.rss.title", bundle.getMessage("site.name"));
    String description = bundle.getMessage("questions.rss.description", bundle.getMessage("site.name"));
    buildRss(orderedByDate, title, description);
}
Also used : Tag(org.mamute.model.Tag) RssContent(org.mamute.model.interfaces.RssContent) Get(br.com.caelum.vraptor.Get)

Aggregations

Tag (org.mamute.model.Tag)21 Question (org.mamute.model.Question)9 Test (org.junit.Test)8 User (org.mamute.model.User)7 Before (org.junit.Before)5 LoggedUser (org.mamute.model.LoggedUser)5 Get (br.com.caelum.vraptor.Get)3 ArrayList (java.util.ArrayList)3 Answer (org.mamute.model.Answer)3 CustomBrutauthRules (br.com.caelum.brutauth.auth.annotations.CustomBrutauthRules)2 Post (br.com.caelum.vraptor.Post)2 InvisibleForUsersRule (org.mamute.dao.InvisibleForUsersRule)2 UserSummaryForTag (org.mamute.dto.UserSummaryForTag)2 Attachment (org.mamute.model.Attachment)2 QuestionInformation (org.mamute.model.QuestionInformation)2 QuestionInformationBuilder (org.mamute.model.QuestionInformationBuilder)2 ReputationEvent (org.mamute.model.ReputationEvent)2 TagPage (org.mamute.model.TagPage)2 Environment (br.com.caelum.vraptor.environment.Environment)1 VRaptorTestResult (br.com.caelum.vraptor.test.VRaptorTestResult)1