radiant-forum-extension 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. data/README.md +155 -0
  2. data/Rakefile +139 -0
  3. data/VERSION +1 -0
  4. data/app/controllers/admin/forums_controller.rb +11 -0
  5. data/app/controllers/forums_controller.rb +34 -0
  6. data/app/controllers/posts_controller.rb +238 -0
  7. data/app/controllers/topics_controller.rb +78 -0
  8. data/app/models/forum.rb +52 -0
  9. data/app/models/moderatorship.rb +5 -0
  10. data/app/models/post.rb +122 -0
  11. data/app/models/post_attachment.rb +73 -0
  12. data/app/models/topic.rb +162 -0
  13. data/app/views/admin/forums/_form.html.haml +25 -0
  14. data/app/views/admin/forums/edit.html.haml +5 -0
  15. data/app/views/admin/forums/index.html.haml +76 -0
  16. data/app/views/admin/forums/moderate.html.haml +2 -0
  17. data/app/views/admin/forums/new.html.haml +5 -0
  18. data/app/views/admin/forums/remove.html.haml +22 -0
  19. data/app/views/admin/pages/_edit_commentability.html.haml +9 -0
  20. data/app/views/admin/reader_settings/_forum.html.haml +4 -0
  21. data/app/views/admin/sites/_choose_forum_layout.html.haml +7 -0
  22. data/app/views/forums/_forum.html.haml +22 -0
  23. data/app/views/forums/index.html.haml +44 -0
  24. data/app/views/forums/show.html.haml +38 -0
  25. data/app/views/forums/show.rss.builder +13 -0
  26. data/app/views/layouts/feed.rss.builder +5 -0
  27. data/app/views/monitorships/create.rjs.erb +1 -0
  28. data/app/views/monitorships/destroy.rjs.erb +1 -0
  29. data/app/views/monitorships/index.html.erb +35 -0
  30. data/app/views/pages/_comment.html.haml +10 -0
  31. data/app/views/pages/_comments.html.haml +15 -0
  32. data/app/views/posts/_attachment.html.haml +2 -0
  33. data/app/views/posts/_form.html.haml +6 -0
  34. data/app/views/posts/_latest.html.haml +17 -0
  35. data/app/views/posts/_post.html.haml +67 -0
  36. data/app/views/posts/_post.rss.builder +13 -0
  37. data/app/views/posts/_reply.html.haml +36 -0
  38. data/app/views/posts/_search.html.haml +28 -0
  39. data/app/views/posts/_uploader.html.haml +16 -0
  40. data/app/views/posts/edit.html.haml +20 -0
  41. data/app/views/posts/index.html.haml +33 -0
  42. data/app/views/posts/index.rss.builder +14 -0
  43. data/app/views/posts/new.html.haml +14 -0
  44. data/app/views/posts/preview.html.haml +32 -0
  45. data/app/views/posts/search.html.haml +54 -0
  46. data/app/views/posts/search.rss.builder +14 -0
  47. data/app/views/posts/show.html.haml +10 -0
  48. data/app/views/reader_notifier/post.rhtml +14 -0
  49. data/app/views/readers/_extra_controls.html.haml +5 -0
  50. data/app/views/readers/show_with_posts.html.haml +47 -0
  51. data/app/views/topics/_form.html.haml +26 -0
  52. data/app/views/topics/_help.html.haml +8 -0
  53. data/app/views/topics/_locked.html.haml +2 -0
  54. data/app/views/topics/_topic.html.haml +35 -0
  55. data/app/views/topics/_topic.rss.builder +9 -0
  56. data/app/views/topics/comments.html.haml +5 -0
  57. data/app/views/topics/edit.html.haml +26 -0
  58. data/app/views/topics/index.html.haml +41 -0
  59. data/app/views/topics/index.rss.builder +14 -0
  60. data/app/views/topics/new.html.haml +40 -0
  61. data/app/views/topics/show.html.haml +45 -0
  62. data/app/views/topics/show.rss.builder +14 -0
  63. data/config/routes.rb +16 -0
  64. data/db/migrate/001_create_forum_tables.rb +64 -0
  65. data/db/migrate/002_pages_commentable.rb +16 -0
  66. data/db/migrate/003_extend_sites.rb +13 -0
  67. data/db/migrate/004_sample_layout.rb +41 -0
  68. data/db/migrate/005_post_attachments.rb +19 -0
  69. data/db/migrate/006_user_relations.rb +20 -0
  70. data/db/migrate/007_reader_ownership.rb +35 -0
  71. data/db/migrate/008_first_posts.rb +13 -0
  72. data/db/migrate/20090824111005_import_helpers.rb +15 -0
  73. data/forum_extension.rb +44 -0
  74. data/lib/forum_admin_ui.rb +37 -0
  75. data/lib/forum_helper.rb +109 -0
  76. data/lib/forum_page.rb +45 -0
  77. data/lib/forum_reader.rb +9 -0
  78. data/lib/forum_reader_notifier.rb +9 -0
  79. data/lib/forum_readers_controller.rb +15 -0
  80. data/lib/forum_red_cloth3.rb +10 -0
  81. data/lib/forum_red_cloth4.rb +21 -0
  82. data/lib/forum_site.rb +12 -0
  83. data/lib/forum_tags.rb +285 -0
  84. data/lib/tasks/radiant_forum_extension_tasks.rake +137 -0
  85. data/pkg/radiant-forum-extension-0.5.0.gem +0 -0
  86. data/public/images/admin/forum.png +0 -0
  87. data/public/images/admin/new-forum.png +0 -0
  88. data/public/images/admin/nominus.png +0 -0
  89. data/public/images/admin/noremove.png +0 -0
  90. data/public/images/emoticons/angry.gif +0 -0
  91. data/public/images/emoticons/bigsmile.gif +0 -0
  92. data/public/images/emoticons/confused.gif +0 -0
  93. data/public/images/emoticons/cool.gif +0 -0
  94. data/public/images/emoticons/cry.gif +0 -0
  95. data/public/images/emoticons/devil.gif +0 -0
  96. data/public/images/emoticons/neutral.gif +0 -0
  97. data/public/images/emoticons/sad.gif +0 -0
  98. data/public/images/emoticons/shamed.gif +0 -0
  99. data/public/images/emoticons/shocked.gif +0 -0
  100. data/public/images/emoticons/smile.gif +0 -0
  101. data/public/images/emoticons/surprised.gif +0 -0
  102. data/public/images/emoticons/tongue.gif +0 -0
  103. data/public/images/emoticons/wink.gif +0 -0
  104. data/public/images/forum/attachment.png +0 -0
  105. data/public/images/forum/attachment_link.png +0 -0
  106. data/public/images/forum/attachment_over.png +0 -0
  107. data/public/images/forum/chk_off.png +0 -0
  108. data/public/images/forum/chk_on.png +0 -0
  109. data/public/images/forum/feed_14.png +0 -0
  110. data/public/images/forum/feed_28.png +0 -0
  111. data/public/images/forum/post_14.png +0 -0
  112. data/public/images/forum/post_14_over.png +0 -0
  113. data/public/images/forum/rdo_off.png +0 -0
  114. data/public/images/forum/rdo_on.png +0 -0
  115. data/public/images/forum/wait_16_grey.gif +0 -0
  116. data/public/javascripts/platform/forum.js +175 -0
  117. data/public/javascripts/platform/remotecontent.js +89 -0
  118. data/public/stylesheets/admin/forum.css +87 -0
  119. data/public/stylesheets/platform/forum.css +70 -0
  120. data/radiant-forum-extension.gemspec +215 -0
  121. data/spec/controllers/admin/forums_controller_spec.rb +54 -0
  122. data/spec/controllers/forums_controller_spec.rb +42 -0
  123. data/spec/controllers/posts_controller_spec.rb +310 -0
  124. data/spec/controllers/topics_controller_spec.rb +133 -0
  125. data/spec/datasets/forum_layouts_dataset.rb +15 -0
  126. data/spec/datasets/forum_pages_dataset.rb +11 -0
  127. data/spec/datasets/forum_readers_dataset.rb +55 -0
  128. data/spec/datasets/forum_sites_dataset.rb +10 -0
  129. data/spec/datasets/forums_dataset.rb +28 -0
  130. data/spec/datasets/posts_dataset.rb +31 -0
  131. data/spec/datasets/topics_dataset.rb +37 -0
  132. data/spec/lib/forum_admin_ui_spec.rb +35 -0
  133. data/spec/lib/forum_page_spec.rb +63 -0
  134. data/spec/lib/forum_reader_notification_spec.rb +9 -0
  135. data/spec/lib/forum_reader_spec.rb +13 -0
  136. data/spec/lib/forum_site_spec.rb +39 -0
  137. data/spec/models/forum_spec.rb +48 -0
  138. data/spec/models/post_spec.rb +91 -0
  139. data/spec/models/topic_spec.rb +105 -0
  140. data/spec/spec.opts +6 -0
  141. data/spec/spec_helper.rb +44 -0
  142. data/vendor/plugins/acts_as_list/README +23 -0
  143. data/vendor/plugins/acts_as_list/init.rb +3 -0
  144. data/vendor/plugins/acts_as_list/lib/active_record/acts/list.rb +256 -0
  145. data/vendor/plugins/acts_as_list/test/list_test.rb +332 -0
  146. metadata +287 -0
@@ -0,0 +1,11 @@
1
+ class ForumPagesDataset < Dataset::Base
2
+ uses :home_page, :users
3
+
4
+ def load
5
+ create_page "Ordinary", :created_by => users(:admin)
6
+ create_page "Commentable", :commentable => true, :comments_closed => false, :created_by => users(:admin)
7
+ create_page "Uncommentable", :commentable => false, :comments_closed => false, :created_by => users(:admin)
8
+ create_page "Comments closed", :commentable => true, :comments_closed => true, :created_by => users(:admin)
9
+ end
10
+
11
+ end
@@ -0,0 +1,55 @@
1
+ require "authlogic/test_case"
2
+ class ForumReadersDataset < Dataset::Base
3
+ datasets = [:users]
4
+ datasets << :forum_sites if defined? Site
5
+ uses *datasets
6
+
7
+ def load
8
+ create_reader "Normal"
9
+ create_reader "Idle"
10
+ create_reader "Activated"
11
+ create_reader "User", :user_id => user_id(:existing)
12
+ create_reader "Admin", :user_id => user_id(:admin)
13
+ create_reader "Inactive", :activated_at => nil
14
+ end
15
+
16
+ helpers do
17
+ def create_reader(name, attributes={})
18
+ attributes = reader_attributes(attributes.update(:name => name))
19
+ reader = create_model Reader, name.symbolize, attributes
20
+ end
21
+
22
+ def reader_attributes(attributes={})
23
+ name = attributes[:name] || "John Doe"
24
+ symbol = name.symbolize
25
+ attributes = {
26
+ :name => name,
27
+ :email => "#{symbol}@spanner.org",
28
+ :password => "password",
29
+ :password_confirmation => "password",
30
+ :activated_at => Time.now.utc
31
+ }.merge(attributes)
32
+ attributes[:site_id] ||= site_id(:test) if Reader.reflect_on_association(:site)
33
+ attributes
34
+ end
35
+
36
+ def reader_params(attributes={})
37
+ password = attributes[:password] || "password"
38
+ reader_attributes(attributes).update(:password => password, :password_confirmation => password)
39
+ end
40
+
41
+ def login_as_reader(reader)
42
+ activate_authlogic
43
+ login_reader = reader.is_a?(Reader) ? reader : readers(reader)
44
+ ReaderSession.create(login_reader)
45
+ login_reader
46
+ end
47
+
48
+ def logout_reader
49
+ if session = ReaderSession.find
50
+ session.destroy
51
+ end
52
+ end
53
+ end
54
+
55
+ end
@@ -0,0 +1,10 @@
1
+ class ForumSitesDataset < Dataset::Base
2
+ uses :home_page
3
+
4
+ def load
5
+ create_record Site, :mysite, :name => 'My Site', :domain => 'mysite.domain.com', :base_domain => 'mysite.domain.com', :position => 1, :homepage_id => page_id(:home)
6
+ create_record Site, :yoursite, :name => 'Your Site', :domain => '^yoursite', :base_domain => 'yoursite.test.com', :position => 2
7
+ create_record Site, :test, :name => 'Test host', :domain => '^test\.', :base_domain => 'test.host', :position => 6
8
+ Page.current_site = sites(:test) if defined? Site
9
+ end
10
+ end
@@ -0,0 +1,28 @@
1
+ class ForumsDataset < Dataset::Base
2
+ uses :forum_sites if defined? Site
3
+
4
+ def load
5
+ create_forum "Public"
6
+ create_forum "Private"
7
+ create_forum "Misc"
8
+ create_forum "Comments", :for_comments => true
9
+ end
10
+
11
+ helpers do
12
+ def create_forum(name, attributes={})
13
+ create_model :forum, name.symbolize, attributes.update(:name => name)
14
+ end
15
+
16
+ def forum_attributes(attributes={})
17
+ name = attributes[:name] || "Forum"
18
+ symbol = name.symbolize
19
+ attributes = {
20
+ :name => name,
21
+ }.merge(attributes)
22
+ attributes[:site] = sites(:test) if defined? Site
23
+ attributes
24
+ end
25
+
26
+ end
27
+
28
+ end
@@ -0,0 +1,31 @@
1
+ class PostsDataset < Dataset::Base
2
+ uses :topics, :forum_readers
3
+
4
+ def load
5
+ Page.current_site = sites(:test) if defined? Site
6
+
7
+ create_post "First", :topic => topics(:older), :created_at => 2.days.ago, :body => 'first reply: to public topic'
8
+ create_post "Second", :topic => topics(:older), :created_at => 1.day.ago, :body => 'second reply: to public topic'
9
+ create_post "Third", :topic => topics(:private), :created_at => 4.hours.ago, :body => 'third reply: to private topic'
10
+ create_post "Comment", :topic => topics(:comments), :created_at => 1.day.ago, :body => 'first comment on page'
11
+ end
12
+
13
+ helpers do
14
+ def create_post(name, attributes={})
15
+ attributes = post_attributes(attributes.update(:name => name))
16
+ create_model :post, name.symbolize, attributes
17
+ end
18
+ end
19
+
20
+ def post_attributes(attributes={})
21
+ name = attributes[:name] || "A topic"
22
+ att = {
23
+ :name => name,
24
+ :reader => readers(:normal),
25
+ :created_at => Time.now
26
+ }.merge(attributes)
27
+ att[:site_id] ||= site_id(:test) if Reader.reflect_on_association(:site)
28
+ att
29
+ end
30
+
31
+ end
@@ -0,0 +1,37 @@
1
+ class TopicsDataset < Dataset::Base
2
+ uses :forum_readers, :forum_pages, :forums
3
+
4
+ def load
5
+ create_topic "older", :reader => readers(:normal), :forum => forums(:public), :body => 'this goes in the first post really', :created_at => 4.days.ago, :replied_at => 2.days.ago
6
+ create_topic "newer", :reader => readers(:normal), :forum => forums(:public), :body => 'this goes in the first post really', :created_at => 2.days.ago, :replied_at => 1.day.ago
7
+ create_topic "sticky", :reader => readers(:normal), :forum => forums(:private), :body => 'this goes in the first post really', :created_at => 2.days.ago, :replied_at => 3.days.ago, :sticky => true
8
+ create_topic "locked", :reader => readers(:normal), :forum => forums(:public), :body => 'this goes in the first post really', :locked => true, :replied_at => 1.year.ago
9
+ create_topic "private", :reader => readers(:normal), :forum => forums(:private), :body => 'this goes in the first post really', :created_at => 2.days.ago, :replied_at => 1.day.ago
10
+ create_topic "minimal", :reader => readers(:normal), :forum => forums(:misc), :body => 'this goes in the first post really'
11
+ create_topic "comments", :reader => readers(:normal), :forum => forums(:comments), :body => 'this goes in the first post really', :locked => false, :page => pages(:commentable)
12
+ end
13
+
14
+ helpers do
15
+ def create_topic(name, attributes={})
16
+ attributes = topic_attributes(attributes.update(:name => name))
17
+ create_model :topic, name.symbolize, attributes
18
+ end
19
+ end
20
+
21
+ def topic_attributes(attributes={})
22
+ name = attributes[:name] || "A topic"
23
+ att = {
24
+ :name => name,
25
+ :reader => readers(:normal),
26
+ :created_at => Time.now
27
+ }.merge(attributes)
28
+ attributes[:site_id] ||= site_id(:test) if Reader.reflect_on_association(:site)
29
+ att
30
+ end
31
+
32
+
33
+
34
+
35
+
36
+
37
+ end
@@ -0,0 +1,35 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ describe "AdminUI extensions for forum" do
4
+ before :each do
5
+ @admin = Radiant::AdminUI.new
6
+ @admin.forum = Radiant::AdminUI.load_default_forum_regions
7
+ end
8
+
9
+ it "should be included into Radiant::AdminUI" do
10
+ Radiant::AdminUI.included_modules.should include(ForumAdminUI)
11
+ end
12
+
13
+ it "should define a collection of Region Sets for forum" do
14
+ @admin.should respond_to('forum')
15
+ @admin.should respond_to('forums')
16
+ @admin.send('forum').should_not be_nil
17
+ @admin.send('forum').should be_kind_of(OpenStruct)
18
+ end
19
+
20
+ describe "should define default regions" do
21
+ %w{new edit remove index}.each do |action|
22
+
23
+ describe "for '#{action}'" do
24
+ before do
25
+ @forum = @admin.forum
26
+ @forum.send(action).should_not be_nil
27
+ end
28
+
29
+ it "as a RegionSet" do
30
+ @forum.send(action).should be_kind_of(Radiant::AdminUI::RegionSet)
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,63 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ describe 'Forum-extended page' do
4
+ dataset :posts
5
+ dataset :forum_pages
6
+
7
+ before do
8
+ login_as_reader(:normal)
9
+ 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
+
42
+ it "should normally be commentable" do
43
+ pages(:ordinary).locked?.should be_false
44
+ end
45
+
46
+ it "should be locked if marked not commentable" do
47
+ pages(:uncommentable).locked?.should be_true
48
+ end
49
+
50
+ it "should be locked if marked comments_closed" do
51
+ pages(:comments_closed).locked?.should be_true
52
+ end
53
+
54
+ it "should be locked if there is a commentable period and it has expired" do
55
+ Radiant::Config['forum.commentable_period'] = 28
56
+ page = pages(:commentable)
57
+ page.commentable_period.should == 28.days
58
+ page.locked?.should be_false
59
+ page.created_at = Time.now - 30.days
60
+ page.locked?.should be_true
61
+ end
62
+
63
+ end
@@ -0,0 +1,9 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ describe 'Forum-extended reader notification' do
4
+
5
+ it "should be able to send new message notifications" do
6
+
7
+ end
8
+
9
+ end
@@ -0,0 +1,13 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ describe 'Forum reader' do
4
+
5
+ it "should have a topics association" do
6
+ Reader.reflect_on_association(:topics).should_not be_nil
7
+ end
8
+
9
+ it "should have a posts association" do
10
+ Reader.reflect_on_association(:posts).should_not be_nil
11
+ end
12
+
13
+ end
@@ -0,0 +1,39 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ if defined? Site
4
+ Radiant::Config['reader.layout'] = 'This one'
5
+
6
+ describe 'Forum site' do
7
+ dataset :forum_layouts, :forum_sites
8
+
9
+ it "should have a forums association" do
10
+ Site.reflect_on_association(:forums).should_not be_nil
11
+ end
12
+
13
+ it "should have a topics association" do
14
+ Site.reflect_on_association(:topics).should_not be_nil
15
+ end
16
+
17
+ it "should have a posts association" do
18
+ Site.reflect_on_association(:posts).should_not be_nil
19
+ end
20
+
21
+ it "should have a forum_layout association" do
22
+ Site.reflect_on_association(:forum_layout).should_not be_nil
23
+ end
24
+
25
+ it "should return reader layout by default" do
26
+ site = sites(:test)
27
+ site.reader_layout = layouts(:reader)
28
+ site.layout_for(:forum).should == 'Reader'
29
+ end
30
+
31
+ it "should return forum layout name if specified" do
32
+ site = sites(:test)
33
+ site.reader_layout = layouts(:reader)
34
+ site.forum_layout = layouts(:forum)
35
+ site.layout_for(:forum).should == 'Forum'
36
+ end
37
+ end
38
+
39
+ end
@@ -0,0 +1,48 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Forum do
4
+ dataset :topics
5
+
6
+ before do
7
+ @site = Page.current_site = sites(:test) if defined? Site
8
+ @forum = forums(:public)
9
+ @reader = Reader.current = readers(:normal)
10
+ end
11
+
12
+ it "should require a name" do
13
+ @forum.name = nil
14
+ @forum.should_not be_valid
15
+ @forum.errors.on(:name).should_not be_empty
16
+ end
17
+
18
+ it "should list its topics in date order" do
19
+ @forum.topics.first.should == topics(:newer)
20
+ end
21
+
22
+ it "should list its topics with the sticky first" do
23
+ forums(:private).topics.first.should == topics(:sticky)
24
+ end
25
+
26
+ it "should report itself visible" do
27
+ forums(:public).visible_to?(@reader).should be_true
28
+ forums(:public).visible_to?(nil).should be_true
29
+ end
30
+
31
+ describe ".find_or_create_comments_forum" do
32
+
33
+ it "should return the existing comments forum when there is one" do
34
+ @forum = Forum.find_or_create_comments_forum
35
+ @forum.should == forums(:comments)
36
+ end
37
+
38
+ it "should create a comments forum if there is none" do
39
+ forums(:comments).delete
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)
45
+ end
46
+
47
+ end
48
+ end
@@ -0,0 +1,91 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Post do
4
+ dataset :posts
5
+ dataset :forum_readers
6
+
7
+ before do
8
+ @site = Page.current_site = sites(:test) if defined? Site
9
+ @reader = Reader.current = readers(:normal)
10
+ end
11
+
12
+ 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
+ it "should require body text" do
20
+ post = topics(:older).posts.build(:body => nil)
21
+ post.should_not be_valid
22
+ end
23
+
24
+ it "should get a reader automatically" do
25
+ post = topics(:older).posts.build(:body => 'authorless')
26
+ post.should be_valid
27
+ post.reader.should == @reader
28
+ end
29
+
30
+ it "should update topic reply data" do
31
+ post = topics(:older).posts.create!(:body => 'hullabaloo')
32
+ topic = Topic.find(topic_id(:older))
33
+ topic.last_post.should == post
34
+ topic.replied_by.should == @reader
35
+ topic.replied_at.should be_close(Time.now, 5.seconds)
36
+ end
37
+ end
38
+
39
+ describe "during the editable period" do
40
+ before do
41
+ Radiant::Config['forum.editable_period'] = 15
42
+ @post = topics(:older).posts.create!(:body => 'foo')
43
+ end
44
+
45
+ it "should be editable by its author" do
46
+ @post.editable_by?(@post.reader).should be_true
47
+ end
48
+
49
+ it "should not be editable by anyone else" do
50
+ @post.editable_by?(readers(:idle)).should be_false
51
+ end
52
+ end
53
+
54
+ describe "after the editable period" do
55
+ before do
56
+ Radiant::Config['forum.editable_period'] = 15
57
+ @post = topics(:older).posts.create!(:body => 'foo')
58
+ @post.created_at = Time.now - 16.minutes
59
+ end
60
+
61
+ it "should no longer be editable by its author" do
62
+ @post.editable_by?(@post.reader).should be_false
63
+ end
64
+ end
65
+
66
+ describe "on removal" do
67
+ it "should revert topic reply data" do
68
+ topicbefore = topics(:older)
69
+ last = topicbefore.last_post
70
+ post = topicbefore.posts.create!(:body => 'uh oh')
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
77
+ end
78
+ end
79
+
80
+ it "should report on which page of its topic it can be found" do
81
+ Radiant::Config['forum.posts_per_page'] = 25
82
+ firstpost = topics(:older).posts.create!(:body => 'foo')
83
+ 55.times do |i|
84
+ topics(:older).posts.create!(:body => 'rhubarb')
85
+ end
86
+ lastpost = topics(:older).posts.create!(:body => 'bar')
87
+ firstpost.topic_page.should == 1
88
+ lastpost.topic_page.should == 3
89
+ end
90
+
91
+ end