1 require File.dirname(__FILE__) + '/../test_helper'
7 class ForumTest < Test::Unit::TestCase
8 fixtures :forums, :topics, :categories, :settings, :users, :groups, :forum_perms
11 assert_equal forums(:f1).topics.length, 2
12 assert_equal forums(:f2).topics.length, 2
13 assert_equal forums(:f3).topics.length, 0
17 assert_equal forums(:f1).category.cat_name, 'category one'
18 assert_equal forums(:f2).category.cat_name, 'category two'
19 assert_equal forums(:f3).category.cat_name, 'category one'
22 def test_update_on_forum
23 f = Forum.find_by_id 1
25 assert_equal f.num_topics, 2
26 assert_equal f.num_posts, 5
27 assert_equal f.last_post, topics(:f12).last_post
28 assert_equal f.last_post_id, 12
29 assert_equal f.last_poster, 'f12'
31 f = Forum.find_by_id 2
33 assert_equal f.num_topics, 2
34 assert_equal f.num_posts, 9
35 assert_equal f.last_post, topics(:f22).last_post
36 assert_equal f.last_post_id, 22
37 assert_equal f.last_poster, 'f22'
39 f = Forum.find_by_id 3
41 assert_equal f.num_topics, 0
42 assert_equal f.num_posts, 0
43 assert_nil f.last_post
44 assert_nil f.last_post_id
45 assert_nil f.last_poster
50 f.category = categories(:cat1)
52 f.redirect_url = 'blah'
54 for u in [users(:guest), users(:mod), users(:admin)]
55 assert_equal false,f.can_post?(u)
57 uu.group = groups(:can_post_topics)
58 assert_equal false, f.can_post?(uu)
59 uu.group = groups(:cant_post_topics)
60 assert_equal false, f.can_post?(uu)
64 fp.group_id = users(:u100).group.id
65 users(:u100).group.g_post_topics = true
70 assert_equal true, f.can_post?(users(:admin))
71 assert_equal true, f.can_post?(users(:mod))
72 uu = users(:guest).clone
73 uu.group = groups(:can_post_topics)
74 assert_equal true, f.can_post?(uu)
75 uu.group = groups(:cant_post_topics)
76 assert_equal false, f.can_post?(uu)
80 assert_equal true, f.can_post?(users(:u100))
81 fp.post_topics = false
83 assert_equal false, f.can_post?(users(:u100))
89 assert_equal true, f.can_view?(users(:u100))
92 fp.group_id = users(:u100).group.id
95 assert_equal true, f.can_view?(users(:u100))
98 assert_equal false, f.can_view?(users(:u100))
103 assert_raise(ActiveRecord::RecordNotFound) {Topic.find_by_id(topics(:f11).id)}
104 assert_raise(ActiveRecord::RecordNotFound) { Topic.find_by_id(topics(:f12).id)}
105 assert_not_nil Topic.find_by_id(topics(:f21).id)
106 assert_not_nil Topic.find_by_id(topics(:f22).id)
111 a.category = categories(:cat1)
113 assert_equal true, a.save
114 a.forum_name = 'a'*80
115 assert_equal true, a.save
117 assert_equal false, a.save
118 a.forum_name = 'a'*81
119 assert_equal false, a.save
122 def test_redirect_url
124 a.category = categories(:cat1)
125 assert_equal true, a.save
127 assert_equal true, a.save
128 a.redirect_url = 'a'*100
129 assert_equal true, a.save
131 assert_equal true, a.save
132 a.redirect_url = 'a'*101
133 assert_equal false, a.save
138 a.category = categories(:cat1)
139 assert_equal true, a.save
141 assert_equal true, a.save
142 a.last_poster = 'a'*200
143 assert_equal true, a.save
145 assert_equal true, a.save
146 a.last_poster = 'a'*201
147 assert_equal false, a.save
150 def test_remove_moderator
152 f.moderators = {users(:u100).id => 'u100', users(:u101).id => 'u101'}
154 Forum.remove_moderator(users(:u100))
156 assert_not_nil f.moderators[users(:u101).id]
157 assert_nil f.moderators[users(:u100).id]