From fa84d48530b5cbfe9e8b10aa2183ec104659f5a9 Mon Sep 17 00:00:00 2001 From: Paul McKissock Date: Tue, 25 Jun 2024 16:38:37 -0400 Subject: [PATCH] [#9] Added create reply test case. --- spec/controllers/comments_controller_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/spec/controllers/comments_controller_spec.rb b/spec/controllers/comments_controller_spec.rb index ad23b60..e634f0e 100644 --- a/spec/controllers/comments_controller_spec.rb +++ b/spec/controllers/comments_controller_spec.rb @@ -3,7 +3,9 @@ RSpec.describe CommentsController, type: :controller do let(:user) { create(:user) } let(:article) { create(:article, user: user) } + let(:parent_comment) { create(:comment, article: article, user: user) } let(:comment_params) { {text: "This is a test comment"} } + let(:reply_params) { {text: "This is a test reply", parent_id: parent_comment.id} } it "should not create comment when not logged in" do expect { @@ -30,6 +32,14 @@ }.by(1) end + it "should create a reply to a comment" do + parent_comment + expect { + post :create, params: {article_id: article.id, comment: reply_params} + }.to change { Comment.count }.by(1) + expect(Comment.last.parent_id).to eq(parent_comment.id) + end + it "should redirect to article after comment creation" do expect(post(:create, params: {article_id: article.id, comment: comment_params})).to redirect_to article_path(article) end