2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-11-23 05:45:53 -05:00
|
|
|
require "rails_helper"
|
|
|
|
|
2022-07-27 22:27:38 -04:00
|
|
|
RSpec.describe Admin::UsersController do
|
2018-11-23 05:45:53 -05:00
|
|
|
let(:admin) { Fabricate(:admin) }
|
|
|
|
|
|
|
|
before { sign_in(admin) }
|
|
|
|
|
|
|
|
describe '#destroy' do
|
|
|
|
let(:delete_me) { Fabricate(:user) }
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
context "when user has voted" do
|
2018-11-23 05:45:53 -05:00
|
|
|
let!(:topic) { Fabricate(:topic, user: admin) }
|
|
|
|
let!(:post) { Fabricate(:post, topic: topic, user: admin, raw: "[poll]\n- a\n- b\n[/poll]") }
|
|
|
|
|
|
|
|
it "deletes the user" do
|
|
|
|
poll = Poll.last
|
|
|
|
PollVote.create!(user: delete_me, poll: poll, poll_option: poll.poll_options.first)
|
|
|
|
|
|
|
|
delete "/admin/users/#{delete_me.id}.json"
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(User.exists?(id: delete_me.id)).to eq(false)
|
|
|
|
expect(PollVote.exists?(user_id: delete_me.id)).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|