@Test public void newTopic() { Forum test = new Forum("Test", "Yop"); User guillaume = User.find("byName", "Guillaume").first(); test.newTopic(guillaume, "Hello", "Yop ..."); assertEquals(2L, (long) guillaume.getTopicsCount()); assertEquals(1, test.topics.size()); assertEquals(1, test.getTopicsCount()); assertEquals(5, Topic.count()); }
@Test public void testCascadeDelete() { Forum help = Forum.find("byName", "Play help").first(); assertEquals(4, Topic.count()); assertEquals(7, Post.count()); help.delete(); assertEquals(1, Topic.count()); assertEquals(1, Post.count()); User guillaume = User.find("byName", "Guillaume").first(); assertEquals(0L, (long) guillaume.getTopicsCount()); }
@SecureAdmin public static void create(Long forumId, @Required String subject, String content) { if (validation.hasErrors()) { validation.keep(); params.flash(); flash.error("Please correct these errors !"); post(forumId); } Forum forum = Forum.findById(forumId); notFoundIfNull(forum); Topic newTopic = forum.newTopic(connectedUser(), subject, content); show(forumId, newTopic.id, null); }
public static void index() { if (activeUser.isAdmin()) { Map<String, Long> stats = new TreeMap<String, Long>(); stats.put("Dates", DateDim.count()); stats.put("Sections", Section.count()); stats.put("Forums", Forum.count()); stats.put("Entries", Entry.count()); stats.put("Threads", Thread.count()); stats.put("Posts", Post.count()); stats.put("Users", User.count()); stats.put("Tags", Tag.count()); render(stats); } else { forbidden(); } }
@SecureAdmin public static void post(Long forumId) { Forum forum = Forum.findById(forumId); notFoundIfNull(forum); render(forum); }