From e470cf7358349c2b1488a964842225d47b7e2fa2 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Wed, 27 Feb 2013 13:45:30 +0000 Subject: [PATCH] Send "N comments" links to the comments anchors. We have to call post.save in the posts/index specs, because post_path fails unless the post has been persisted (and hence had its slug generated). I think. That fixed the failing tests, anyway. --- app/views/posts/_single.html.haml | 3 ++- spec/views/posts/_single.html.haml_spec.rb | 10 +++------- spec/views/posts/index.html.haml_spec.rb | 2 ++ 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/app/views/posts/_single.html.haml b/app/views/posts/_single.html.haml index d08c586ef..abc2fcc5f 100644 --- a/app/views/posts/_single.html.haml +++ b/app/views/posts/_single.html.haml @@ -24,7 +24,8 @@ - unless defined?(hide_comments) .post-comments %ul.inline - %li.first= link_to pluralize(post.comments.count, "comment"), post + %li.first= link_to pluralize(post.comments.count, "comment"), + post_path(post, :anchor => 'comments') -if can? :create, Comment %li= link_to "Reply", new_comment_path(:post_id => post.id) %li= link_to "Permalink", post diff --git a/spec/views/posts/_single.html.haml_spec.rb b/spec/views/posts/_single.html.haml_spec.rb index 12e3dd58e..eebac11f4 100644 --- a/spec/views/posts/_single.html.haml_spec.rb +++ b/spec/views/posts/_single.html.haml_spec.rb @@ -62,7 +62,7 @@ describe "posts/_single" do end it "renders the number of comments" do - rendered.should contain "0 comments" + assert_select "a[href=#{post_path(@post)}\#comments]", "0 comments" end end @@ -73,11 +73,7 @@ describe "posts/_single" do end it "renders the number of comments" do - rendered.should contain "1 comment" - end - - it "contains a link to post" do - assert_select "a[href=#{post_path @post}]" + assert_select "a[href=#{post_path(@post)}\#comments]", "1 comment" end end @@ -89,7 +85,7 @@ describe "posts/_single" do end it "renders the number of comments" do - rendered.should contain "2 comments" + assert_select "a[href=#{post_path(@post)}\#comments]", "2 comments" end end diff --git a/spec/views/posts/index.html.haml_spec.rb b/spec/views/posts/index.html.haml_spec.rb index fd73a3a9f..684009801 100644 --- a/spec/views/posts/index.html.haml_spec.rb +++ b/spec/views/posts/index.html.haml_spec.rb @@ -6,6 +6,8 @@ describe "posts/index" do @author = FactoryGirl.create(:member) @post1 = FactoryGirl.build(:post, :author => @author) @post2 = FactoryGirl.build(:post, :author => @author) + @post1.save # needed to generate slugs and hence paths for posts + @post2.save assign(:posts, [@post1, @post2]) render end