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 and gbp committed Nov 6, 2023
1 parent 96f8372 commit 65d05f9
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

Check warning on line 455 in spec/controllers/admin_user_controller_spec.rb

View workflow job for this annotation

GitHub Actions / build

[rubocop] reported by reviewdog 🐶 Use 2 (not 3) spaces for indentation. (https://rubystyle.guide#spaces-indentation) Raw Output: spec/controllers/admin_user_controller_spec.rb:455:2: C: Layout/IndentationWidth: Use 2 (not 3) spaces for indentation. (https://rubystyle.guide#spaces-indentation)
@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)

Check warning on line 461 in spec/controllers/admin_user_controller_spec.rb

View workflow job for this annotation

GitHub Actions / build

[rubocop] reported by reviewdog 🐶 Use 2 (not 6) spaces for indentation. (https://rubystyle.guide#spaces-indentation) Raw Output: spec/controllers/admin_user_controller_spec.rb:461:5: C: Layout/IndentationWidth: Use 2 (not 6) spaces for indentation. (https://rubystyle.guide#spaces-indentation)
comment_ids = comments.map(&:id)

expect {
post :destroy_comment, params: {
id: @user.id,

Check warning on line 466 in spec/controllers/admin_user_controller_spec.rb

View workflow job for this annotation

GitHub Actions / build

[rubocop] reported by reviewdog 🐶 Use 2 spaces for indentation in a hash, relative to the start of the line where the left curly brace is. Raw Output: spec/controllers/admin_user_controller_spec.rb:466:28: C: Layout/FirstHashElementIndentation: Use 2 spaces for indentation in a hash, relative to the start of the line where the left curly brace is.
comment_ids: comment_ids
}

Check warning on line 468 in spec/controllers/admin_user_controller_spec.rb

View workflow job for this annotation

GitHub Actions / build

[rubocop] reported by reviewdog 🐶 Indent the right brace the same as the start of the line where the left brace is. Raw Output: spec/controllers/admin_user_controller_spec.rb:468:26: C: Layout/FirstHashElementIndentation: Indent the right brace the same as the start of the line where the left brace is.
}.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)

Check warning on line 473 in spec/controllers/admin_user_controller_spec.rb

View workflow job for this annotation

GitHub Actions / build

[rubocop] reported by reviewdog 🐶 Use 2 (not 4) spaces for indentation. (https://rubystyle.guide#spaces-indentation) Raw Output: spec/controllers/admin_user_controller_spec.rb:473:3: C: Layout/IndentationWidth: Use 2 (not 4) spaces for indentation. (https://rubystyle.guide#spaces-indentation)
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,

Check warning on line 481 in spec/controllers/admin_user_controller_spec.rb

View workflow job for this annotation

GitHub Actions / build

[rubocop] reported by reviewdog 🐶 Use 2 spaces for indentation in a hash, relative to the start of the line where the left curly brace is. Raw Output: spec/controllers/admin_user_controller_spec.rb:481:25: C: Layout/FirstHashElementIndentation: Use 2 spaces for indentation in a hash, relative to the start of the line where the left curly brace is.
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 65d05f9

Please sign in to comment.