Skip to content

Commit

Permalink
Update admin_user_controller_spec.rb
Browse files Browse the repository at this point in the history
Add tests for comment destruction
  • Loading branch information
HelenWDTK authored Apr 1, 2023
1 parent 05857b9 commit 64c10ef
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions spec/controllers/admin_user_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -449,4 +449,46 @@
}.to change(ActsAsXapian::ActsAsXapianJob, :count).by(1)
end
end

describe 'POST destroy_comment' do

before(:each) do
@user = FactoryBot.create(:user)
request.env["HTTP_REFERER"] = admin_user_path(@user)
end

it 'destroys the selected comments' do
comments = FactoryBot.create_list(:visible_comment, 3, user: @user)
comment_ids = comments.map(&:id)

expect {
post :destroy_comment, params: {
id: @user.id,
comment_ids: comment_ids
}
}.to change(Comment, :count).by(-3)
end

it 'logs destroy_comment events for the deleted comments' do
allow(controller).to receive(:admin_current_user).and_return(@admin_user)
comments = FactoryBot.create_list(:visible_comment, 3, user: @user)
comment_ids = comments.map(&:id)
current_admin = FactoryBot.create(:admin_user)
sign_in current_admin

expect {
post :destroy_comment, params: {
id: @user.id,
comment_ids: comment_ids
}
}.to change(InfoRequestEvent, :count).by(3)

deleted_comment_events = InfoRequestEvent.where(event_type: 'destroy_comment')
expect(deleted_comment_events.count).to eq(3)
deleted_comment_events.each do |event|
expect(event.params[:deleted_comment_id]).to be_in(comment_ids)
expect(event.params[:editor]).to eq(@admin_user)
end
end
end
end

0 comments on commit 64c10ef

Please sign in to comment.