2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-11-23 18:45:53 +08:00
|
|
|
require "rails_helper"
|
|
|
|
|
2022-07-28 10:27:38 +08:00
|
|
|
RSpec.describe Admin::UsersController do
|
2018-11-23 18:45:53 +08:00
|
|
|
let(:admin) { Fabricate(:admin) }
|
|
|
|
|
|
|
|
before { sign_in(admin) }
|
|
|
|
|
2023-01-07 04:42:16 +08:00
|
|
|
describe "#destroy" do
|
2018-11-23 18:45:53 +08:00
|
|
|
let(:delete_me) { Fabricate(:user) }
|
|
|
|
|
2022-07-28 00:14:14 +08:00
|
|
|
context "when user has voted" do
|
2018-11-23 18:45:53 +08: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
|