From f8dde9b3cf58377fd803893f1ee69ce942ae6e8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=C4=A3is=20Ozols?= Date: Tue, 7 Dec 2010 16:21:20 +0200 Subject: Added some rspec tests for blog category model. --- spec/models/blog_categories_spec.rb | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'spec/models') diff --git a/spec/models/blog_categories_spec.rb b/spec/models/blog_categories_spec.rb index af10b3a..904e4c8 100644 --- a/spec/models/blog_categories_spec.rb +++ b/spec/models/blog_categories_spec.rb @@ -2,20 +2,32 @@ require 'spec_helper' Dir[File.expand_path('../../../features/support/factories/*.rb', __FILE__)].each{|factory| require factory} describe BlogCategory do - context "wiring up" do - + describe "validations" do before(:each) do - @category = Factory(:blog_category) + @attr = { :title => "RefineryCMS" } end - it "saves" do - @category.should_not be_nil + it "requires title" do + BlogCategory.new(@attr.merge(:title => "")).should_not be_valid end - it "has a blog post" do - BlogPost.last.categories.should include(@category) + 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 "have a posts attribute" do + BlogCategory.new.should respond_to(:posts) + 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 -- cgit v1.2.3