mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 10:20:58 -06:00
FIX: couldn't delete users who voted on a poll
This commit is contained in:
parent
606faa2ee5
commit
f402d0d74f
@ -359,6 +359,10 @@ after_initialize do
|
||||
end
|
||||
end
|
||||
|
||||
User.class_eval do
|
||||
has_many :poll_votes, dependent: :delete_all
|
||||
end
|
||||
|
||||
validate(:post, :validate_polls) do |force = nil|
|
||||
return unless self.raw_changed? || force
|
||||
|
||||
@ -427,10 +431,6 @@ after_initialize do
|
||||
PollVote.where(user_id: source_user.id).update_all(user_id: target_user.id)
|
||||
end
|
||||
|
||||
on(:user_destroyed) do |user|
|
||||
PollVote.where(user_id: user.id).delete_all
|
||||
end
|
||||
|
||||
register_post_custom_field_type(DiscoursePoll::HAS_POLLS, :boolean)
|
||||
|
||||
topic_view_post_custom_fields_whitelister { [DiscoursePoll::HAS_POLLS] }
|
||||
|
28
plugins/poll/spec/requests/users_controller_spec.rb
Normal file
28
plugins/poll/spec/requests/users_controller_spec.rb
Normal file
@ -0,0 +1,28 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe Admin::UsersController do
|
||||
|
||||
let(:admin) { Fabricate(:admin) }
|
||||
|
||||
before { sign_in(admin) }
|
||||
|
||||
describe '#destroy' do
|
||||
let(:delete_me) { Fabricate(:user) }
|
||||
|
||||
context "user has voted" do
|
||||
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
|
Loading…
Reference in New Issue
Block a user