aboutsummaryrefslogtreecommitdiffstats
path: root/spec/models/refinery/blog/category_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/refinery/blog/category_spec.rb')
-rw-r--r--spec/models/refinery/blog/category_spec.rb42
1 files changed, 42 insertions, 0 deletions
diff --git a/spec/models/refinery/blog/category_spec.rb b/spec/models/refinery/blog/category_spec.rb
new file mode 100644
index 0000000..9c4a7d3
--- /dev/null
+++ b/spec/models/refinery/blog/category_spec.rb
@@ -0,0 +1,42 @@
+require 'spec_helper'
+
+module Refinery
+ module Blog
+ describe Category do
+ let(:category) { FactoryGirl.create(:blog_category) }
+
+ describe "validations" do
+ it "requires title" do
+ FactoryGirl.build(:blog_category, :title => "").should_not be_valid
+ end
+
+ it "won't allow duplicate titles" do
+ FactoryGirl.build(:blog_category, :title => category.title).should_not be_valid
+ end
+ end
+
+ describe "blog posts association" do
+ it "has a posts attribute" do
+ category.should respond_to(:posts)
+ end
+
+ it "returns posts by published_at date in descending order" do
+ first_post = category.posts.create!({ :title => "Breaking News: Joe Sak is hot stuff you guys!!", :body => "True story.", :published_at => Time.now.yesterday })
+ latest_post = category.posts.create!({ :title => "parndt is p. okay", :body => "For a Kiwi.", :published_at => Time.now })
+
+ category.posts.first.should == latest_post
+ end
+
+ end
+
+ describe "#post_count" do
+ it "returns post count in category" do
+ 2.times do
+ category.posts << FactoryGirl.create(:blog_post)
+ end
+ category.post_count.should == 2
+ end
+ end
+ end
+ end
+end \ No newline at end of file