radiant-forum-extension 1.2.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +37 -56
- data/VERSION +1 -1
- data/app/controllers/forum_base_controller.rb +78 -0
- data/app/controllers/forums_controller.rb +5 -34
- data/app/controllers/posts_controller.rb +61 -153
- data/app/controllers/topics_controller.rb +6 -63
- data/app/helpers/forum_helper.rb +24 -48
- data/app/models/forum.rb +5 -18
- data/app/models/post.rb +53 -55
- data/app/models/post_attachment.rb +9 -6
- data/app/models/topic.rb +20 -113
- data/app/views/admin/reader_configuration/_edit_forum.html.haml +4 -2
- data/app/views/admin/reader_configuration/_forum.html.haml +6 -2
- data/app/views/forums/_forum.html.haml +14 -20
- data/app/views/forums/_latest.html.haml +12 -0
- data/app/views/forums/_standard_parts.html.haml +49 -0
- data/app/views/forums/index.html.haml +16 -24
- data/app/views/forums/show.html.haml +18 -28
- data/app/views/pages/_comment.html.haml +1 -1
- data/app/views/posts/_attachments.html.haml +13 -0
- data/app/views/posts/_confirm_delete.html.haml +10 -0
- data/app/views/posts/_context.html.haml +16 -0
- data/app/views/posts/_edit_links.html.haml +11 -0
- data/app/views/posts/_form.html.haml +40 -2
- data/app/views/posts/_latest.html.haml +10 -17
- data/app/views/posts/_new_attachment.html.haml +2 -0
- data/app/views/posts/_post.html.haml +25 -60
- data/app/views/posts/{_search.html.haml → _search_form.html.haml} +1 -1
- data/app/views/posts/_uploader.html.haml +2 -2
- data/app/views/posts/edit.html.haml +26 -13
- data/app/views/posts/index.html.haml +19 -27
- data/app/views/posts/new.html.haml +27 -7
- data/app/views/posts/remove.html.haml +27 -0
- data/app/views/posts/show.html.haml +20 -7
- data/app/views/readers/_forum_messages.html.haml +20 -0
- data/app/views/readers/_messages_summary.html.haml +3 -0
- data/app/views/topics/_context.html.haml +12 -0
- data/app/views/topics/_latest.html.haml +14 -16
- data/app/views/topics/_locked.html.haml +1 -1
- data/app/views/topics/_replies.html.haml +6 -0
- data/app/views/topics/_reply.html.haml +23 -0
- data/app/views/topics/_topic.html.haml +14 -43
- data/app/views/topics/_voices.html.haml +5 -0
- data/app/views/topics/index.html.haml +11 -24
- data/app/views/topics/show.html.haml +25 -38
- data/config/initializers/radiant_config.rb +5 -1
- data/config/locales/en.yml +73 -27
- data/config/routes.rb +3 -4
- data/db/migrate/20101222160900_page_posts.rb +21 -0
- data/db/migrate/20101222163605_no_comment_forum.rb +10 -0
- data/db/migrate/20110105103827_topic_merely_associative.rb +23 -0
- data/db/migrate/20110111080550_detach_observer.rb +11 -0
- data/db/migrate/20110127113852_import_attachments.rb +9 -0
- data/forum_extension.rb +12 -13
- data/lib/commentable_model.rb +98 -0
- data/lib/forum_page.rb +2 -22
- data/lib/forum_reader_sessions_controller.rb +14 -0
- data/lib/forum_readers_controller.rb +2 -9
- data/lib/forum_red_cloth3.rb +23 -4
- data/lib/forum_red_cloth4.rb +23 -4
- data/lib/forum_tags.rb +298 -194
- data/lib/sanitize/config/forum.rb +47 -0
- data/public/images/furniture/blank.png +0 -0
- data/public/images/furniture/emoticons.png +0 -0
- data/public/javascripts/forum.js +349 -93
- data/public/javascripts/jquery.tools.min.js +195 -0
- data/public/punymce/blank.htm +1 -0
- data/public/punymce/css/content.css +4 -0
- data/public/punymce/css/editor.css +58 -0
- data/public/punymce/i18n/sv.js +28 -0
- data/public/punymce/img/icons.gif +0 -0
- data/public/punymce/img/icons_uncompressed.png +0 -0
- data/public/punymce/plugins/bbcode.js +1 -0
- data/public/punymce/plugins/bbcode_src.js +50 -0
- data/public/punymce/plugins/editsource/css/editor.css +3 -0
- data/public/punymce/plugins/editsource/editsource.js +1 -0
- data/public/punymce/plugins/editsource/editsource_src.js +81 -0
- data/public/punymce/plugins/editsource/img/icons.gif +0 -0
- data/public/punymce/plugins/emoticons/css/content.css +13 -0
- data/public/punymce/plugins/emoticons/css/editor.css +17 -0
- data/public/punymce/plugins/emoticons/emoticons.js +1 -0
- data/public/punymce/plugins/emoticons/emoticons_src.js +303 -0
- data/public/punymce/plugins/emoticons/img/emoticons.gif +0 -0
- data/public/punymce/plugins/emoticons/img/emoticons.png +0 -0
- data/public/punymce/plugins/emoticons/img/trans.gif +0 -0
- data/public/punymce/plugins/entities.js +1 -0
- data/public/punymce/plugins/entities_src.js +37 -0
- data/public/punymce/plugins/forceblocks.js +1 -0
- data/public/punymce/plugins/forceblocks_src.js +465 -0
- data/public/punymce/plugins/forcenl.js +1 -0
- data/public/punymce/plugins/forcenl_src.js +26 -0
- data/public/punymce/plugins/image/css/editor.css +1 -0
- data/public/punymce/plugins/image/image.js +1 -0
- data/public/punymce/plugins/image/image_src.js +30 -0
- data/public/punymce/plugins/image/img/icons.gif +0 -0
- data/public/punymce/plugins/link/css/editor.css +2 -0
- data/public/punymce/plugins/link/img/icons.gif +0 -0
- data/public/punymce/plugins/link/link.js +1 -0
- data/public/punymce/plugins/link/link_src.js +36 -0
- data/public/punymce/plugins/paste.js +1 -0
- data/public/punymce/plugins/paste_src.js +169 -0
- data/public/punymce/plugins/protect.js +1 -0
- data/public/punymce/plugins/protect_src.js +30 -0
- data/public/punymce/plugins/safari2x.js +1 -0
- data/public/punymce/plugins/safari2x_src.js +284 -0
- data/public/punymce/plugins/tabfocus.js +1 -0
- data/public/punymce/plugins/tabfocus_src.js +45 -0
- data/public/punymce/plugins/textcolor/css/editor.css +7 -0
- data/public/punymce/plugins/textcolor/img/icons.gif +0 -0
- data/public/punymce/plugins/textcolor/textcolor.js +1 -0
- data/public/punymce/plugins/textcolor/textcolor_src.js +73 -0
- data/public/punymce/puny_mce.js +1 -0
- data/public/punymce/puny_mce_full.js +1 -0
- data/public/punymce/puny_mce_src.js +1460 -0
- data/public/stylesheets/sass/forum.sass +175 -169
- data/radiant-forum-extension.gemspec +81 -19
- data/spec/controllers/admin/forums_controller_spec.rb +2 -2
- data/spec/controllers/forums_controller_spec.rb +3 -6
- data/spec/controllers/posts_controller_spec.rb +76 -59
- data/spec/controllers/topics_controller_spec.rb +4 -95
- data/spec/datasets/forum_readers_dataset.rb +1 -0
- data/spec/datasets/forums_dataset.rb +91 -10
- data/spec/lib/commentable_model_spec.rb +88 -0
- data/spec/lib/forum_page_spec.rb +2 -34
- data/spec/lib/forum_site_spec.rb +2 -3
- data/spec/lib/forum_tags_spec.rb +35 -0
- data/spec/models/forum_spec.rb +31 -20
- data/spec/models/post_spec.rb +40 -39
- data/spec/models/topic_spec.rb +29 -71
- data/spec/spec_helper.rb +10 -1
- metadata +84 -22
- data/app/views/posts/_reply.html.haml +0 -35
- data/app/views/posts/_upload.html.haml +0 -2
- data/app/views/posts/preview.html.haml +0 -32
- data/app/views/posts/search.html.haml +0 -63
- data/app/views/posts/search.rss.builder +0 -14
- data/app/views/topics/_form.html.haml +0 -30
- data/app/views/topics/_help.html.haml +0 -8
- data/app/views/topics/comments.html.haml +0 -6
- data/app/views/topics/edit.html.haml +0 -26
- data/app/views/topics/new.html.haml +0 -56
- data/spec/datasets/forum_pages_dataset.rb +0 -11
- data/spec/datasets/posts_dataset.rb +0 -31
- data/spec/datasets/topics_dataset.rb +0 -37
@@ -0,0 +1,88 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../spec_helper"
|
2
|
+
|
3
|
+
describe 'Post-holder' do
|
4
|
+
dataset :forums
|
5
|
+
|
6
|
+
before do
|
7
|
+
Radiant::Config['forum.paginate_posts?'] = true
|
8
|
+
@topic = topics(:empty)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "without replies" do
|
12
|
+
it "should announce posts but not replies" do
|
13
|
+
@topic.posts.count.should == 1
|
14
|
+
@topic.has_posts?.should be_true
|
15
|
+
@topic.has_replies?.should be_false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "with replies" do
|
20
|
+
before do
|
21
|
+
60.times do |i|
|
22
|
+
@topic.posts.create!(:body => "test #{i}", :reader => readers(:normal), :created_at => (100-i).minutes.ago)
|
23
|
+
end
|
24
|
+
@topic.posts.create!(:body => "test by another", :reader => readers(:idle))
|
25
|
+
@topic.reload
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should have many posts" do
|
29
|
+
@topic.posts.count.should == 62
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should report the number of replies to the original post" do
|
33
|
+
@topic.reply_count.should == 61
|
34
|
+
@topic.replies.length.should == @topic.reply_count
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should report the number of readers taking part" do
|
38
|
+
calculated = @topic.posts.map(&:reader).uniq
|
39
|
+
Rails.logger.warn ">>"
|
40
|
+
@topic.voice_count.should == calculated.length
|
41
|
+
Rails.logger.warn "<<"
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should report the number of readers replying" do
|
45
|
+
calculated = @topic.posts.map(&:reader).uniq - [@topic.posts.first.reader]
|
46
|
+
@topic.other_voice_count.should == calculated.length
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should report the list of readers taking part" do
|
50
|
+
@topic.voices.length.should == 3
|
51
|
+
@topic.voices.include?(readers(:notable)).should be_true
|
52
|
+
@topic.voices.include?(readers(:normal)).should be_true
|
53
|
+
@topic.voices.include?(readers(:idle)).should be_true
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should report the list of readers replying" do
|
57
|
+
@topic.other_voices.length.should == 2
|
58
|
+
@topic.other_voices.include?(readers(:notable)).should be_false
|
59
|
+
@topic.other_voices.include?(readers(:normal)).should be_true
|
60
|
+
@topic.other_voices.include?(readers(:idle)).should be_true
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should paginate its posts" do
|
64
|
+
@topic.paged?.should be_true
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should know on which page to find a given post" do
|
68
|
+
@topic.page_for(Post.find_by_body("test 16")).should == 1
|
69
|
+
@topic.page_for(Post.find_by_body("test 36")).should == 2
|
70
|
+
@topic.page_for(Post.find_by_body("test 56")).should == 3
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should read config to find the number of posts per page" do
|
74
|
+
Radiant::Config['forum.posts_per_page'] = 15
|
75
|
+
@topic.page_for(Post.find_by_body("test 16")).should == 2
|
76
|
+
@topic.page_for(Post.find_by_body("test 36")).should == 3
|
77
|
+
@topic.page_for(Post.find_by_body("test 56")).should == 4
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should know when it was last replied to" do
|
81
|
+
@topic.replied_at.should == @topic.posts.last.created_at
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should know by whom it was last replied to" do
|
85
|
+
@topic.replied_by.should == readers(:idle)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
data/spec/lib/forum_page_spec.rb
CHANGED
@@ -1,46 +1,14 @@
|
|
1
1
|
require File.dirname(__FILE__) + "/../spec_helper"
|
2
2
|
|
3
3
|
describe 'Forum-extended page' do
|
4
|
-
dataset :
|
5
|
-
dataset :forum_pages
|
4
|
+
dataset :forums
|
6
5
|
|
7
6
|
before do
|
8
7
|
login_as_reader(:normal)
|
9
8
|
end
|
10
|
-
|
11
|
-
it "should have a topic association" do
|
12
|
-
Page.reflect_on_association(:topic).should_not be_nil
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should create a new topic if it doesn't already have one" do
|
16
|
-
topic = pages(:ordinary).find_or_build_topic
|
17
|
-
topic.new_record?.should be_true
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should not create a topic if it does already have one" do
|
21
|
-
topic = pages(:commentable).find_or_build_topic
|
22
|
-
topic.new_record?.should be_false
|
23
|
-
topic.should == topics(:comments)
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should not create a topic if it isn't commentable" do
|
27
|
-
topic = pages(:uncommentable).find_or_build_topic
|
28
|
-
topic.should be_nil
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should know whether it has posts or not" do
|
32
|
-
page = pages(:ordinary)
|
33
|
-
topic = page.find_or_build_topic
|
34
|
-
topic.name = "Foo"
|
35
|
-
topic.body = "Bar"
|
36
|
-
topic.save
|
37
|
-
page.has_posts?.should be_false
|
38
|
-
topic.posts.create(:body => 'foo')
|
39
|
-
pages(:ordinary).has_posts?.should be_true
|
40
|
-
end
|
41
9
|
|
42
10
|
it "should normally be commentable" do
|
43
|
-
pages(:
|
11
|
+
pages(:uncommented).locked?.should be_false
|
44
12
|
end
|
45
13
|
|
46
14
|
it "should be locked if marked not commentable" do
|
data/spec/lib/forum_site_spec.rb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
require File.dirname(__FILE__) + "/../spec_helper"
|
2
2
|
|
3
3
|
if defined? Site
|
4
|
-
Radiant::Config['reader.layout'] = 'This one'
|
5
|
-
|
6
4
|
describe 'Forum site' do
|
7
|
-
dataset :
|
5
|
+
dataset :forums, :forum_sites
|
6
|
+
# Radiant::Config['reader.layout'] = 'Reader'
|
8
7
|
|
9
8
|
it "should have a forums association" do
|
10
9
|
Site.reflect_on_association(:forums).should_not be_nil
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe "Forum Tags" do
|
4
|
+
dataset :forums
|
5
|
+
|
6
|
+
let(:page){ pages(:commentable) }
|
7
|
+
|
8
|
+
describe "r:forum:topic tags" do
|
9
|
+
let(:topic){ topics(:older) }
|
10
|
+
let(:sticky){ topics(:sticky) }
|
11
|
+
let(:on_date){ I18n.l(topic.created_at, :format => :standard) }
|
12
|
+
let(:sticky_date){ I18n.l(sticky.created_at, :format => :standard) }
|
13
|
+
|
14
|
+
subject { page }
|
15
|
+
it { should render(%{<r:forum:topic id="#{topic.id}"><r:forum:topic:name /></r:forum:topic>}).as(topic.name) }
|
16
|
+
it { should render(%{<r:forum:topic id="#{topic.id}"><r:forum:topic:body /></r:forum:topic>}).as(topic.posts.first.body_html) }
|
17
|
+
it { should render(%{<r:forum:topic id="#{topic.id}"><r:forum:topic:author /></r:forum:topic>}).as("Normal") }
|
18
|
+
it { should render(%{<r:forum:topic id="#{topic.id}"><r:forum:topic:date /></r:forum:topic>}).as(on_date) }
|
19
|
+
it { should render(%{<r:forum:topic id="#{topic.id}"><r:forum:topic:url /></r:forum:topic>}).as("/forum/forums/#{topic.forum.id}/topics/#{topic.id}") }
|
20
|
+
it { should render(%{<r:forum:topic id="#{topic.id}"><r:forum:topic:context /></r:forum:topic>}).as(%{Started by <a href="/readers/#{reader_id(:normal)}">Normal</a> #{on_date}}) }
|
21
|
+
it { should render(%{<r:forum:topic id="#{topic.id}"><r:forum:topic:body /></r:forum:topic>}).as("<p>original topic message</p>") }
|
22
|
+
it { should render(%{<r:forum:topic id="#{topic.id}"><r:forum:topic:link /></r:forum:topic>}).as(%{<a href="/forum/forums/#{topic.forum.id}/topics/#{topic.id}">#{topic.name}</a>}) }
|
23
|
+
it { should render(%{<r:forum:topic id="#{topic.id}"><r:forum:topic:summary /></r:forum:topic>}).as(%{<li><a href="/forum/forums/#{topic.forum.id}/topics/#{topic.id}">#{topic.name}</a><br />Started by <a href="/readers/#{reader_id(:normal)}">Normal</a> #{on_date}</li>}) }
|
24
|
+
it { should render(%{<r:forum:topic id="#{sticky.id}"><r:forum:topic:summary /></r:forum:topic>}).as(%{<li><a href="/forum/forums/#{sticky.forum.id}/topics/#{sticky.id}">#{sticky.name}</a><br />Started by <a href="/readers/#{reader_id(:normal)}">Normal</a> #{sticky_date}</li>}) }
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "r:forum:post tags" do
|
28
|
+
let(:post){ posts(:second) }
|
29
|
+
let(:comment){ posts(:comment) }
|
30
|
+
subject { page }
|
31
|
+
it { should render(%{<r:forum:post id="#{post.id}"><r:forum:post:name /></r:forum:post>}).as(post.topic.name) }
|
32
|
+
it { should render(%{<r:forum:post id="#{comment.id}"><r:forum:post:name /></r:forum:post>}).as(comment.page.title) }
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
data/spec/models/forum_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
2
|
|
3
3
|
describe Forum do
|
4
|
-
dataset :
|
4
|
+
dataset :forums
|
5
5
|
|
6
6
|
before do
|
7
7
|
@site = Page.current_site = sites(:test) if defined? Site
|
@@ -15,34 +15,45 @@ describe Forum do
|
|
15
15
|
@forum.errors.on(:name).should_not be_empty
|
16
16
|
end
|
17
17
|
|
18
|
-
|
19
|
-
|
18
|
+
describe "topics.bydate" do
|
19
|
+
it "should list its topics in descending date order" do
|
20
|
+
forums(:public).topics.bydate.first.should == topics(:newer)
|
21
|
+
forums(:private).topics.bydate.first.should == topics(:private)
|
22
|
+
end
|
20
23
|
end
|
21
24
|
|
22
|
-
|
23
|
-
|
25
|
+
describe "topics.stickyfirst" do
|
26
|
+
it "should list its topics with the sticky first" do
|
27
|
+
forums(:private).topics.stickyfirst.first.should == topics(:sticky)
|
28
|
+
end
|
24
29
|
end
|
25
30
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
31
|
+
describe "when the forum is public" do
|
32
|
+
before do
|
33
|
+
Radiant::Config['forum.public?'] = true
|
34
|
+
end
|
30
35
|
|
31
|
-
|
36
|
+
it "should be visible to a reader" do
|
37
|
+
forums(:public).visible_to?(@reader).should be_true
|
38
|
+
end
|
32
39
|
|
33
|
-
it "should
|
34
|
-
|
35
|
-
|
40
|
+
it "should be visible when there is no reader" do
|
41
|
+
forums(:public).visible_to?(nil).should be_true
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "when the whole forum is private" do
|
46
|
+
before do
|
47
|
+
Radiant::Config['forum.public?'] = false
|
36
48
|
end
|
37
49
|
|
38
|
-
it "should
|
39
|
-
forums(:
|
40
|
-
Forum.should_receive(:find_by_for_comments)
|
41
|
-
@forum = Forum.find_or_create_comments_forum
|
42
|
-
@forum.for_comments.should be_true
|
43
|
-
@forum.name.should == 'Page Comments'
|
44
|
-
@forum.created_at.should be_close(Time.now, 5.seconds)
|
50
|
+
it "should be visible to a reader" do
|
51
|
+
forums(:public).visible_to?(@reader).should be_true
|
45
52
|
end
|
46
53
|
|
54
|
+
it "should not be visible when there is no reader" do
|
55
|
+
forums(:public).visible_to?(nil).should be_false
|
56
|
+
end
|
47
57
|
end
|
58
|
+
|
48
59
|
end
|
data/spec/models/post_spec.rb
CHANGED
@@ -1,49 +1,47 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
2
|
|
3
3
|
describe Post do
|
4
|
-
dataset :
|
5
|
-
dataset :forum_readers
|
4
|
+
dataset :forums
|
6
5
|
|
7
6
|
before do
|
8
|
-
@site = Page.current_site = sites(:test) if
|
9
|
-
@reader = Reader.current = readers(:normal)
|
7
|
+
@site = Page.current_site = sites(:test) if Page.respond_to? :current_site
|
10
8
|
end
|
11
9
|
|
12
10
|
describe "on creation" do
|
13
|
-
|
14
|
-
it "should require a topic" do
|
15
|
-
post = Post.new(:body => 'hullabaloo')
|
16
|
-
post.should_not be_valid
|
17
|
-
end
|
18
|
-
|
19
11
|
it "should require body text" do
|
20
|
-
post = topics(:older).posts.build(:body => nil)
|
12
|
+
post = topics(:older).posts.build(:body => nil, :reader => readers(:normal))
|
21
13
|
post.should_not be_valid
|
14
|
+
post.errors.on(:body).should_not be_nil
|
22
15
|
end
|
23
16
|
|
24
|
-
it "should
|
17
|
+
it "should require a reader" do
|
25
18
|
post = topics(:older).posts.build(:body => 'authorless')
|
26
|
-
post.
|
27
|
-
post.reader.
|
19
|
+
post.should_not be_valid
|
20
|
+
post.errors.on(:reader).should_not be_nil
|
28
21
|
end
|
29
22
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
23
|
+
describe "when added to a topic" do
|
24
|
+
before do
|
25
|
+
Rails.logger.warn ">>"
|
26
|
+
post = topics(:older).posts.create!(:body => 'newly added', :reader => readers(:idle))
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should update topic reply data" do
|
30
|
+
topic = Topic.find(topic_id(:older))
|
31
|
+
topic.replied_by.should == readers(:idle)
|
32
|
+
topic.replied_at.should be_close(Time.now, 10.seconds)
|
33
|
+
end
|
36
34
|
end
|
37
35
|
end
|
38
36
|
|
39
37
|
describe "during the editable period" do
|
40
38
|
before do
|
41
39
|
Radiant::Config['forum.editable_period'] = 15
|
42
|
-
@post = topics(:older).posts.create!(:body => 'foo')
|
40
|
+
@post = topics(:older).posts.create!(:body => 'foo', :reader => readers(:normal))
|
43
41
|
end
|
44
42
|
|
45
43
|
it "should be editable by its author" do
|
46
|
-
@post.editable_by?(
|
44
|
+
@post.editable_by?(readers(:normal)).should be_true
|
47
45
|
end
|
48
46
|
|
49
47
|
it "should not be editable by anyone else" do
|
@@ -54,38 +52,41 @@ describe Post do
|
|
54
52
|
describe "after the editable period" do
|
55
53
|
before do
|
56
54
|
Radiant::Config['forum.editable_period'] = 15
|
57
|
-
@post = topics(:older).posts.create!(:body => 'foo')
|
58
|
-
@post.created_at = Time.now - 16.minutes
|
55
|
+
@post = topics(:older).posts.create!(:body => 'foo', :reader => readers(:normal), :created_at => Time.now - 16.minutes)
|
59
56
|
end
|
60
57
|
|
61
|
-
it "should
|
58
|
+
it "should not be editable by its author" do
|
62
59
|
@post.editable_by?(@post.reader).should be_false
|
63
60
|
end
|
61
|
+
|
62
|
+
it "should not be editable by anyone else" do
|
63
|
+
@post.editable_by?(readers(:idle)).should be_false
|
64
|
+
end
|
64
65
|
end
|
65
66
|
|
66
67
|
describe "on removal" do
|
68
|
+
before do
|
69
|
+
@last = topics(:older).posts.last
|
70
|
+
@post = topics(:older).posts.create!(:body => 'uh oh', :reader => readers(:idle))
|
71
|
+
end
|
67
72
|
it "should revert topic reply data" do
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
post.destroy
|
73
|
-
topicafter = Topic.find(topic_id(:older))
|
74
|
-
topicafter.last_post.should == last
|
75
|
-
topicafter.replied_by.should == last.reader
|
76
|
-
topicafter.replied_at.should == last.created_at
|
73
|
+
@post.destroy
|
74
|
+
topic = Topic.find(topic_id(:older))
|
75
|
+
topic.replied_by.should == @last.reader
|
76
|
+
topic.replied_at.should be_close(@last.created_at, 1.second)
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
80
|
it "should report on which page of its topic it can be found" do
|
81
|
+
Radiant::Config['forum.paginate_posts?'] = true
|
81
82
|
Radiant::Config['forum.posts_per_page'] = 25
|
82
|
-
firstpost = topics(:older).posts.create!(:body => 'foo')
|
83
|
+
firstpost = topics(:older).posts.create!(:body => 'foo', :reader => readers(:normal))
|
83
84
|
55.times do |i|
|
84
|
-
topics(:older).posts.create!(:body => 'rhubarb')
|
85
|
+
topics(:older).posts.create!(:body => 'rhubarb', :reader => readers(:normal))
|
85
86
|
end
|
86
|
-
lastpost = topics(:older).posts.create!(:body => 'bar')
|
87
|
-
firstpost.
|
88
|
-
lastpost.
|
87
|
+
lastpost = topics(:older).posts.create!(:body => 'bar', :reader => readers(:idle))
|
88
|
+
firstpost.page_when_paginated.should == 1
|
89
|
+
lastpost.page_when_paginated.should == 3
|
89
90
|
end
|
90
91
|
|
91
92
|
end
|
data/spec/models/topic_spec.rb
CHANGED
@@ -1,26 +1,29 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
2
|
|
3
3
|
describe Topic do
|
4
|
-
dataset :
|
4
|
+
dataset :forums
|
5
5
|
|
6
|
-
before do
|
7
|
-
@site = Page.current_site = sites(:test) if defined? Site
|
8
|
-
@reader = Reader.current = readers(:normal)
|
9
|
-
end
|
10
|
-
|
11
6
|
describe "on creation" do
|
12
7
|
before do
|
13
|
-
@
|
8
|
+
@post = Post.create!(
|
9
|
+
:body => "first post body",
|
10
|
+
:reader_id => reader_id(:normal),
|
11
|
+
:topic_attributes => {
|
12
|
+
:name => 'testing',
|
13
|
+
:forum_id => forum_id(:public)
|
14
|
+
}
|
15
|
+
)
|
16
|
+
@topic = @post.topic
|
14
17
|
end
|
15
18
|
|
16
19
|
it "should set default values" do
|
17
20
|
@topic.sticky?.should be_false
|
18
21
|
@topic.locked?.should be_false
|
19
|
-
@topic.replied_by.should
|
20
|
-
@topic.replied_at.should be_close(
|
22
|
+
@topic.replied_by.should == readers(:normal)
|
23
|
+
@topic.replied_at.should be_close(Time.now, 1.minute)
|
21
24
|
end
|
22
25
|
|
23
|
-
[:name
|
26
|
+
[:name].each do |field|
|
24
27
|
it "should require a #{field}" do
|
25
28
|
@topic.send("#{field}=".intern, nil)
|
26
29
|
@topic.should_not be_valid
|
@@ -28,78 +31,33 @@ describe Topic do
|
|
28
31
|
end
|
29
32
|
end
|
30
33
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
it "should get a first post automatically" do
|
36
|
-
@topic.first_post.should_not be_nil
|
37
|
-
@topic.first_post.body.should == 'this is the first post body but validation requires it'
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should report itself visible" do
|
41
|
-
@topic.visible_to?(@reader).should be_true
|
42
|
-
@topic.visible_to?(nil).should be_true
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
describe "with posts" do
|
48
|
-
dataset :posts
|
49
|
-
|
50
|
-
before do
|
51
|
-
@topic = topics(:older)
|
52
|
-
60.times do |i|
|
53
|
-
@topic.posts.create!(:body => "test #{i}", :created_at => (100-i).minutes.ago)
|
34
|
+
describe "when the whole forum is public" do
|
35
|
+
before do
|
36
|
+
Radiant::Config['forum.public?'] = true
|
54
37
|
end
|
55
|
-
@topic.posts.create!(:body => "test by another", :reader => readers(:idle))
|
56
|
-
@topic.reload
|
57
|
-
end
|
58
38
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
end
|
63
|
-
|
64
|
-
it "should know on which page to find a given post" do
|
65
|
-
@topic.page_for(Post.find_by_body("test 15")).should == 1
|
66
|
-
@topic.page_for(Post.find_by_body("test 35")).should == 2
|
67
|
-
@topic.page_for(Post.find_by_body("test 55")).should == 3
|
68
|
-
end
|
69
|
-
|
70
|
-
it "should read config to find the number of posts per page" do
|
71
|
-
Radiant::Config['forum.posts_per_page'] = 15
|
72
|
-
@topic.page_for(Post.find_by_body("test 15")).should == 2
|
73
|
-
@topic.page_for(Post.find_by_body("test 35")).should == 3
|
74
|
-
@topic.page_for(Post.find_by_body("test 55")).should == 4
|
75
|
-
end
|
39
|
+
it "should be visible to a reader" do
|
40
|
+
@topic.visible_to?(@reader).should be_true
|
41
|
+
end
|
76
42
|
|
77
|
-
|
78
|
-
|
43
|
+
it "should be visible when there is no reader" do
|
44
|
+
@topic.visible_to?(nil).should be_true
|
45
|
+
end
|
79
46
|
end
|
80
47
|
|
81
|
-
describe "when
|
48
|
+
describe "when the whole forum is private" do
|
82
49
|
before do
|
83
|
-
|
84
|
-
newforum = forums(:private)
|
85
|
-
@newcount = newforum.posts_count
|
86
|
-
@topic.forum = newforum
|
87
|
-
@topic.save!
|
50
|
+
Radiant::Config['forum.public?'] = false
|
88
51
|
end
|
89
52
|
|
90
|
-
it "should
|
91
|
-
|
92
|
-
t.posts.each do |p|
|
93
|
-
p.forum_id.should == forum_id(:private)
|
94
|
-
end
|
53
|
+
it "should be visible to a reader" do
|
54
|
+
@topic.visible_to?(readers(:idle)).should be_true
|
95
55
|
end
|
96
56
|
|
97
|
-
it "should
|
98
|
-
|
99
|
-
tf = Forum.find(forum_id(:private))
|
100
|
-
ff.posts_count.should < @oldcount
|
101
|
-
tf.posts_count.should > @newcount
|
57
|
+
it "should not be visible when there is no reader" do
|
58
|
+
@topic.visible_to?(nil).should be_false
|
102
59
|
end
|
103
60
|
end
|
104
61
|
end
|
62
|
+
|
105
63
|
end
|