Show other comments on post when editing a comment.

This commit is contained in:
Miles Gould
2013-04-29 21:44:30 +01:00
parent 2b84fa8bad
commit c53dd6797f
4 changed files with 11 additions and 4 deletions

View File

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

View File

@@ -1,5 +1,5 @@
%a{:name => "comments"}
- if !@comments.empty?
- if @comments
%h2
=pluralize(@comments.length, "comment")
- @comments.each do |c|

View File

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

View File

@@ -107,7 +107,4 @@ describe "posts/show" do
end
end