Skip to content

Commit

Permalink
fix for deleting flagged comments
Browse files Browse the repository at this point in the history
  • Loading branch information
pushcx committed Apr 17, 2024
1 parent c7ef797 commit ca09a51
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/controllers/comments_controller.rb
Expand Up @@ -394,7 +394,7 @@ def find_comment
if @user && comment
comment.current_vote = Vote.where(user_id: @user.id,
story_id: comment.story_id, comment_id: comment.id).first
comment.vote_summary = Vote.comment_vote_summaries([comment.id])
comment.vote_summary = Vote.comment_vote_summaries([comment.id])[comment.id]
end

comment
Expand Down
29 changes: 26 additions & 3 deletions spec/requests/comments_spec.rb
Expand Up @@ -3,12 +3,13 @@
require "rails_helper"

describe "comments", type: :request do
let(:author) { create(:user) }
let(:comment) { create(:comment, user: author) }
let(:user) { create(:user) }
let(:comment) { create(:comment) }

before { sign_in user }

describe "upvoting" do
before { sign_in user }

it "works" do
expect(comment.score).to eq(1)
expect(comment.reload.score).to eq(1)
Expand All @@ -29,4 +30,26 @@
expect(Vote.where(user: user).count).to eq(0)
end
end

describe "deleting" do
before { sign_in author }

it "works" do
expect(comment.is_deletable_by_user?(author)).to be true
post "/comments/#{comment.short_id}/delete"
comment.reload
expect(comment.is_deleted).to be true
end

it "works even if the comment is flagged" do
Vote.vote_thusly_on_story_or_comment_for_user_because(
-1, comment.story_id, comment.id, user.id, "T"
)
expect(comment.is_deletable_by_user?(author)).to be true
puts comment.vote_summary, comment.vote_summary.class
post "/comments/#{comment.short_id}/delete"
comment.reload
expect(comment.is_deleted).to be true
end
end
end

0 comments on commit ca09a51

Please sign in to comment.