Sha256: e26dad582080a2420d994d9976777e135f27ab351f6a502ba35f4dcb11305042

Contents?: true

Size: 1.27 KB

Versions: 6

Compression:

Stored size: 1.27 KB

Contents

require 'spec_helper'
Dir[File.expand_path('../../../features/support/factories/*.rb', __FILE__)].each{|factory| require factory}

describe BlogCategory do
  before(:each) do
    @blog_category = Factory(:blog_category)
  end

  describe "validations" do
    it "requires title" do
      Factory.build(:blog_category, :title => "").should_not be_valid
    end

    it "won't allow duplicate titles" do
      Factory.build(:blog_category, :title => @blog_category.title).should_not be_valid
    end
  end

  describe "blog posts association" do
    it "has a posts attribute" do
      @blog_category.should respond_to(:posts)
    end
    
    it "returns posts by published_at date in descending order" do
      first_post = @blog_category.posts.create!({ :title => "Breaking News: Joe Sak is hot stuff you guys!!", :body => "True story.", :published_at => Time.now.yesterday })
      latest_post = @blog_category.posts.create!({ :title => "parndt is p. okay", :body => "For a kiwi.", :published_at => Time.now })

      @blog_category.posts.first.should == latest_post
    end
      
  end

  describe "#post_count" do
    it "returns post count in category" do
      2.times do
        @blog_category.posts << Factory(:post)
      end
      @blog_category.post_count.should == 2
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
refinerycms-blog-1.6.1 spec/models/blog_category_spec.rb
refinerycms-blog-1.6.0 spec/models/blog_category_spec.rb
refinerycms-blog-1.5.2 spec/models/blog_category_spec.rb
refinerycms-blog-1.5.1 spec/models/blog_category_spec.rb
refinerycms-blog-1.5.0 spec/models/blog_category_spec.rb
refinerycms-blog-1.4.0 spec/models/blog_category_spec.rb