add count of comments to posts partial

This commit is contained in:
Jared McCorkindale
2013-02-19 22:08:53 +11:00
committed by Miles Gould
parent 1bc963d169
commit cf678a45c4
2 changed files with 54 additions and 0 deletions

View File

@@ -21,3 +21,6 @@
:markdown
#{ strip_tags post.body }
.post-comments
= pluralize post.comments.count, "comment"

View File

@@ -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