diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index ed90a6213..d6bc30bd1 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -43,6 +43,7 @@ class CommentsController < ApplicationController # GET /comments/1/edit def edit @comment = Comment.find(params[:id]) + @comments = @comment.post.comments end # POST /comments diff --git a/app/views/posts/_comments.html.haml b/app/views/posts/_comments.html.haml index f68ed96c0..c06124014 100644 --- a/app/views/posts/_comments.html.haml +++ b/app/views/posts/_comments.html.haml @@ -1,5 +1,5 @@ %a{:name => "comments"} -- if !@comments.empty? +- if @comments %h2 =pluralize(@comments.length, "comment") - @comments.each do |c| diff --git a/spec/controllers/comments_controller_spec.rb b/spec/controllers/comments_controller_spec.rb index 02cc2960e..587d24407 100644 --- a/spec/controllers/comments_controller_spec.rb +++ b/spec/controllers/comments_controller_spec.rb @@ -57,6 +57,15 @@ describe CommentsController do get :edit, {:id => comment.to_param} assigns(:comment).should eq(comment) end + + it "assigns previous comments as @comments" do + post = FactoryGirl.create(:post) + old_comment = FactoryGirl.create(:comment, :post => post) + comment = FactoryGirl.create(:comment, :post => post) + get :edit, {:id => comment.to_param} + assigns(:comments).should eq([old_comment, comment]) + end + end describe "POST create" do diff --git a/spec/views/posts/show.html.haml_spec.rb b/spec/views/posts/show.html.haml_spec.rb index 34c21f9e0..d9682b015 100644 --- a/spec/views/posts/show.html.haml_spec.rb +++ b/spec/views/posts/show.html.haml_spec.rb @@ -107,7 +107,4 @@ describe "posts/show" do end - - - end