From cf678a45c4b30ca67d5dcb88517557fa2d4fbd67 Mon Sep 17 00:00:00 2001 From: Jared McCorkindale Date: Tue, 19 Feb 2013 22:08:53 +1100 Subject: [PATCH] add count of comments to posts partial --- app/views/posts/_single.html.haml | 3 ++ spec/views/posts/_single.html.haml_spec.rb | 51 ++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 spec/views/posts/_single.html.haml_spec.rb diff --git a/app/views/posts/_single.html.haml b/app/views/posts/_single.html.haml index f07856c04..977352e98 100644 --- a/app/views/posts/_single.html.haml +++ b/app/views/posts/_single.html.haml @@ -21,3 +21,6 @@ :markdown #{ strip_tags post.body } + .post-comments + = pluralize post.comments.count, "comment" + diff --git a/spec/views/posts/_single.html.haml_spec.rb b/spec/views/posts/_single.html.haml_spec.rb new file mode 100644 index 000000000..830131c1d --- /dev/null +++ b/spec/views/posts/_single.html.haml_spec.rb @@ -0,0 +1,51 @@ +require 'spec_helper' + +describe "posts/_single" do + before(:each) do + @post = FactoryGirl.create(:post) + end + + context "0 comments" do + before(:each) do + render :partial => "single", :locals => { + :post => @post + } + end + + it "renders the number of comments" do + rendered.should contain "0 comments" + end + end + + context "1 comment" do + before(:each) do + @comment = FactoryGirl.create(:comment, :post => @post) + render :partial => "single", :locals => { + :post => @post + } + end + + it "renders the number of comments" do + rendered.should contain "1 comment" + end + end + + context "2 comments" do + before(:each) do + @comment = FactoryGirl.create(:comment, :post => @post) + @comment2 = FactoryGirl.create(:comment, :post => @post) + render :partial => "single", :locals => { + :post => @post + } + end + + it "renders the number of comments" do + rendered.should contain "2 comments" + end + end + +end + + + + \ No newline at end of file