diff options
author | Uģis Ozols <ugis.ozolss@gmail.com> | 2010-12-07 16:21:20 +0200 |
---|---|---|
committer | Uģis Ozols <ugis.ozolss@gmail.com> | 2010-12-07 16:21:20 +0200 |
commit | f8dde9b3cf58377fd803893f1ee69ce942ae6e8f (patch) | |
tree | 10efcbb7170603fe9c3e16c49cbc7d59fe073b13 /spec | |
parent | 9ff63388f31b20f1ce76b9bc61147720b801dfae (diff) | |
download | refinerycms-blog-f8dde9b3cf58377fd803893f1ee69ce942ae6e8f.tar.gz refinerycms-blog-f8dde9b3cf58377fd803893f1ee69ce942ae6e8f.tar.bz2 refinerycms-blog-f8dde9b3cf58377fd803893f1ee69ce942ae6e8f.zip |
Added some rspec tests for blog category model.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/models/blog_categories_spec.rb | 26 |
1 files changed, 19 insertions, 7 deletions
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 |