Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 7
- Log:
Initial import of RForum 0.2 sources from a downloaded Tarball.
RForum is a Ruby On Rails based forum and mail gateway service.
- Author:
- adh
- Date:
- Sat Jul 22 18:43:13 +0100 2006
- Size:
- 3709 Bytes
- Properties:
- Property svn:executable is set
1 | #!/bin/env ruby |
2 | |
3 | require File.dirname(__FILE__) + '/../test_helper' |
4 | |
5 | class TopicTest < Test::Unit::TestCase |
6 | |
7 | def test_create |
8 | t = Topic.create(prototype_params(Topic)) |
9 | assert_equal 0, t.deleted |
10 | end |
11 | |
12 | def test_add_reply |
13 | create_fixtures 'forums', 'posts', 'topics' |
14 | topic = Topic.find(1) |
15 | reply = prototype(Post) |
16 | |
17 | topic.add_reply(reply) |
18 | |
19 | assert_equal topic.id, reply.topic_id |
20 | assert_equal topic.root_post.id, reply.parent_id |
21 | assert_nested_set_well_formed(topic.id) |
22 | end |
23 | |
24 | def test_posts_with_user_data |
25 | create_fixtures 'forums', 'posts', 'topics', 'users' |
26 | |
27 | posts = Topic.find(1).posts_with_user_data |
28 | |
29 | assert_equal (1..11).to_a, posts.collect{ |p| p.id }.sort |
30 | |
31 | post_for_unknown_user = posts.select { |p| p.id == 6 } |
32 | assert_equal 1, post_for_unknown_user.size |
33 | assert_nil post_for_unknown_user[0].user |
34 | |
35 | post_for_known_user = posts.select { |p| p.id == 2 } |
36 | assert_equal 1, post_for_known_user.size |
37 | user = post_for_known_user[0].user |
38 | ['name', 'firstname', 'lastname'].each { |attr| |
39 | assert_equal user[attr], post_for_known_user[0].user[attr] |
40 | } |
41 | end |
42 | |
43 | def test_posts_with_user_data_include_hidden |
44 | create_fixtures 'forums', 'posts', 'topics', 'users' |
45 | t = Topic.find(1) |
46 | |
47 | # before hiding the topic |
48 | posts = t.posts_with_user_data(include_hidden = true) |
49 | assert_equal (1..11).to_a, posts.collect{ |p| p.id }.sort |
50 | |
51 | t.hide |
52 | |
53 | # after hiding, with explicit include_hidden = false |
54 | posts = t.posts_with_user_data(include_hidden = false) |
55 | assert posts.empty? |
56 | |
57 | # after hiding, with implicit include_hidden = false |
58 | posts = t.posts_with_user_data |
59 | assert posts.empty? |
60 | |
61 | # after hiding, with explicit include_hidden = true |
62 | posts = t.posts_with_user_data(include_hidden = true) |
63 | assert_equal (1..11).to_a, posts.collect{ |p| p.id }.sort |
64 | end |
65 | |
66 | def test_root_post |
67 | create_fixtures 'posts', 'topics' |
68 | |
69 | p = Topic.find(2).root_post |
70 | |
71 | assert_equal Post.find(101), p |
72 | end |
73 | |
74 | def test_root_post_two_roots |
75 | create_fixtures 'posts', 'topics' |
76 | db.execute('UPDATE posts SET parent_id = NULL WHERE id = 2') |
77 | |
78 | assert_raises(RuntimeError) { p = Topic.find(1).root_post } |
79 | end |
80 | |
81 | def test_root_post_no_roots |
82 | create_fixtures 'posts', 'topics' |
83 | db.execute('UPDATE posts SET parent_id = 1 WHERE id = 1') |
84 | |
85 | assert_raises(RuntimeError) { p = Topic.find(1).root_post } |
86 | end |
87 | |
88 | def test_hidden_post_is_not_displayed |
89 | create_fixtures 'posts', 'topics' |
90 | hidden_post = Post.find(22) |
91 | assert hidden_post.hidden? |
92 | t = Topic.find(3) |
93 | |
94 | posts_excluding_hidden = t.posts_with_user_data.collect { |p| p.id } |
95 | all_posts = t.posts.collect { |p| p.id } |
96 | |
97 | assert_equal [22], all_posts - posts_excluding_hidden |
98 | end |
99 | |
100 | def test_hide |
101 | create_fixtures 'posts', 'topics' |
102 | |
103 | Topic.find(1).hide |
104 | |
105 | assert Topic.find(1).hidden? |
106 | assert_equal '0', db.select_one( |
107 | "SELECT COUNT(*) AS c FROM posts WHERE topic_id = 1 AND deleted = 0")['c'].to_s |
108 | end |
109 | |
110 | def test_unhide_recursive |
111 | create_fixtures 'posts', 'topics' |
112 | |
113 | Topic.find(1).hide |
114 | Topic.find(1).unhide(:recursive) |
115 | assert !Topic.find(1).hidden? |
116 | assert !Topic.find(1).root_post.hidden? |
117 | assert_equal '0', db.select_one( |
118 | "SELECT COUNT(*) AS c FROM posts WHERE topic_id = 1 AND deleted = 1")['c'].to_s |
119 | end |
120 | |
121 | def test_unhide_root |
122 | create_fixtures 'posts', 'topics' |
123 | |
124 | Topic.find(1).hide |
125 | Topic.find(1).unhide |
126 | assert !Topic.find(1).hidden? |
127 | assert !Topic.find(1).root_post.hidden? |
128 | assert db.select_one( |
129 | "SELECT COUNT(*) AS c FROM posts WHERE topic_id = 1 AND deleted = 1")['c'].to_i > 0 |
130 | end |
131 | |
132 | end |