spec/models/forum_spec.rb in radiant-forum-extension-1.2.1 vs spec/models/forum_spec.rb in radiant-forum-extension-2.0.0
- old
+ new
@@ -1,9 +1,9 @@
require File.dirname(__FILE__) + '/../spec_helper'
describe Forum do
- dataset :topics
+ dataset :forums
before do
@site = Page.current_site = sites(:test) if defined? Site
@forum = forums(:public)
@reader = Reader.current = readers(:normal)
@@ -13,36 +13,47 @@
@forum.name = nil
@forum.should_not be_valid
@forum.errors.on(:name).should_not be_empty
end
- it "should list its topics in date order" do
- @forum.topics.first.should == topics(:newer)
+ describe "topics.bydate" do
+ it "should list its topics in descending date order" do
+ forums(:public).topics.bydate.first.should == topics(:newer)
+ forums(:private).topics.bydate.first.should == topics(:private)
+ end
end
- it "should list its topics with the sticky first" do
- forums(:private).topics.first.should == topics(:sticky)
+ describe "topics.stickyfirst" do
+ it "should list its topics with the sticky first" do
+ forums(:private).topics.stickyfirst.first.should == topics(:sticky)
+ end
end
- it "should report itself visible" do
- forums(:public).visible_to?(@reader).should be_true
- forums(:public).visible_to?(nil).should be_true
- end
+ describe "when the forum is public" do
+ before do
+ Radiant::Config['forum.public?'] = true
+ end
- describe ".find_or_create_comments_forum" do
+ it "should be visible to a reader" do
+ forums(:public).visible_to?(@reader).should be_true
+ end
- it "should return the existing comments forum when there is one" do
- @forum = Forum.find_or_create_comments_forum
- @forum.should == forums(:comments)
+ it "should be visible when there is no reader" do
+ forums(:public).visible_to?(nil).should be_true
end
+ end
- it "should create a comments forum if there is none" do
- forums(:comments).delete
- Forum.should_receive(:find_by_for_comments)
- @forum = Forum.find_or_create_comments_forum
- @forum.for_comments.should be_true
- @forum.name.should == 'Page Comments'
- @forum.created_at.should be_close(Time.now, 5.seconds)
+ describe "when the whole forum is private" do
+ before do
+ Radiant::Config['forum.public?'] = false
end
+
+ it "should be visible to a reader" do
+ forums(:public).visible_to?(@reader).should be_true
+ end
+ it "should not be visible when there is no reader" do
+ forums(:public).visible_to?(nil).should be_false
+ end
end
+
end