aboutsummaryrefslogtreecommitdiffstats
path: root/spec/models/blog_categories_spec.rb
blob: 53bc345143bc1bf0c7e59be387955273cb52edae (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require 'spec_helper'
Dir[File.expand_path('../../../features/support/factories/*.rb', __FILE__)].each{|factory| require factory}

describe BlogCategory do
  before(:each) do
    @attr = { :title => "RefineryCMS" }
  end

  describe "validations" do
    it "requires title" do
      BlogCategory.new(@attr.merge(:title => "")).should_not be_valid
    end

    it "won't allow duplicate titles" do
      BlogCategory.create!(@attr)
      BlogCategory.new(@attr).should_not be_valid
    end
  end

  describe "blog posts association" do
    it "has a posts attribute" do
      BlogCategory.new.should respond_to(:posts)
    end
    
    it "returns posts by published_at date in descending order" do
      @category = BlogCategory.create!(@attr)
      @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
      Factory(:post, :categories => [Factory(:blog_category)])
      Factory(:post, :categories => [Factory(:blog_category)])
      BlogCategory.first.post_count.should == 2
    end
  end
end