Skip to content

Commit

Permalink
[#9] Added create reply test case.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmckissock committed Jun 27, 2024
1 parent f47c06b commit fa84d48
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions spec/controllers/comments_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down

0 comments on commit fa84d48

Please sign in to comment.