aboutsummaryrefslogtreecommitdiffstats
path: root/spec/models/blog_posts_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/blog_posts_spec.rb')
-rw-r--r--spec/models/blog_posts_spec.rb68
1 files changed, 46 insertions, 22 deletions
diff --git a/spec/models/blog_posts_spec.rb b/spec/models/blog_posts_spec.rb
index ef9d700..1b96ece 100644
--- a/spec/models/blog_posts_spec.rb
+++ b/spec/models/blog_posts_spec.rb
@@ -17,7 +17,7 @@ describe BlogPost do
end
it "requires body" do
- BlogPost.new(@attr.merge(:body => "")).should_not be_valid
+ BlogPost.new(@attr.merge(:body => nil)).should_not be_valid
end
end
@@ -46,11 +46,24 @@ describe BlogPost do
@blog_post.should respond_to(:categories)
end
end
+
+ describe "tags" do
+ it "acts as taggable" do
+ (post = Factory(:post)).should respond_to(:tag_list)
+ post.tag_list.should include("chicago")
+ end
+ end
+
+ describe "authors" do
+ it "are authored" do
+ BlogPost.instance_methods.map(&:to_sym).should include(:author)
+ end
+ end
describe "by_archive scope" do
it "returns all posts from specified month" do
- blog_post1 = Factory(:post, :published_at => Time.now - 2.minutes)
- blog_post2 = Factory(:post, :published_at => Time.now - 1.minute)
+ blog_post1 = Factory(:post, :published_at => Time.now.advance(:minutes => -2))
+ blog_post2 = Factory(:post, :published_at => Time.now.advance(:minutes => -1))
Factory(:post, :published_at => Time.now - 2.months)
date = "#{Time.now.month}/#{Time.now.year}"
BlogPost.by_archive(Time.parse(date)).count.should == 2
@@ -60,8 +73,8 @@ describe BlogPost do
describe "all_previous scope" do
it "returns all posts from previous months" do
- blog_post1 = Factory(:post, :published_at => Time.now - 1.month)
- blog_post2 = Factory(:post, :published_at => Time.now - 1.month)
+ blog_post1 = Factory(:post, :published_at => Time.now.advance(:months => -2))
+ blog_post2 = Factory(:post, :published_at => Time.now.advance(:months => -1))
Factory(:post, :published_at => Time.now)
BlogPost.all_previous.count.should == 2
BlogPost.all_previous.should == [blog_post2, blog_post1]
@@ -70,8 +83,8 @@ describe BlogPost do
describe "live scope" do
it "returns all posts which aren't in draft and pub date isn't in future" do
- blog_post1 = Factory(:post, :published_at => Time.now - 2.minutes)
- blog_post2 = Factory(:post, :published_at => Time.now - 1.minute)
+ blog_post1 = Factory(:post, :published_at => Time.now.advance(:minutes => -2))
+ blog_post2 = Factory(:post, :published_at => Time.now.advance(:minutes => -1))
Factory(:post, :draft => true)
Factory(:post, :published_at => Time.now + 1.minute)
BlogPost.live.count.should == 2
@@ -81,17 +94,29 @@ describe BlogPost do
describe "next scope" do
it "returns next article based on given article" do
- blog_post1 = Factory(:post)
- blog_post2 = Factory(:post, :published_at => Time.now + 1.minute)
+ blog_post1 = Factory(:post, :published_at => Time.now.advance(:minutes => -1))
+ blog_post2 = Factory(:post)
BlogPost.next(blog_post1).should == [blog_post2]
end
end
describe "previous scope" do
it "returns previous article based on given article" do
- blog_post1 = Factory(:post)
- blog_post2 = Factory(:post, :published_at => Time.now + 1.minute)
- BlogPost.next(blog_post1).should == [blog_post2]
+ blog_post1 = Factory(:post, :published_at => Time.now.advance(:minutes => -1))
+ blog_post2 = Factory(:post)
+ BlogPost.previous(blog_post2).should == [blog_post1]
+ end
+ end
+
+ describe "uncategorized scope" do
+ it "returns uncategorized posts if they exist" do
+ uncategorized_blog_post = Factory(:post)
+ categorized_blog_post = Factory(:post)
+
+ categorized_blog_post.categories << Factory(:blog_category)
+
+ BlogPost.uncategorized.should include uncategorized_blog_post
+ BlogPost.uncategorized.should_not include categorized_blog_post
end
end
@@ -105,23 +130,23 @@ describe BlogPost do
end
it "returns false if post pub date is in future" do
- Factory(:post, :published_at => Time.now + 1.minute).live?.should be_false
+ Factory(:post, :published_at => Time.now.advance(:minutes => 1)).live?.should be_false
end
end
describe "#next" do
it "returns next article when called on current article" do
- Factory(:post)
- blog_post = Factory(:post, :published_at => Time.now + 1.minute)
+ Factory(:post, :published_at => Time.now.advance(:minutes => -1))
+ blog_post = Factory(:post)
blog_posts = BlogPost.all
- blog_posts.first.next.should == blog_post
+ blog_posts.last.next.should == blog_post
end
end
describe "#prev" do
it "returns previous article when called on current article" do
Factory(:post)
- blog_post = Factory(:post, :published_at => Time.now - 1.minute)
+ blog_post = Factory(:post, :published_at => Time.now.advance(:minutes => -1))
blog_posts = BlogPost.all
blog_posts.first.prev.should == blog_post
end
@@ -150,10 +175,9 @@ describe BlogPost do
BlogPost.comments_allowed?.should be_true
end
- # TODO: fix this test
- # it "returns false if comments_allowed setting is set to false" do
- # RefinerySetting.set(:comments_allowed, false)
- # BlogPost.comments_allowed?.should be_false
- # end
+ it "returns false if comments_allowed setting is set to false" do
+ RefinerySetting.set(:comments_allowed, {:scoping => 'blog', :value => false})
+ BlogPost.comments_allowed?.should be_false
+ end
end
end