Add dependent destroy and related test for deleting a user
This commit is contained in:
parent
64e191f60e
commit
9a1db8419c
3 changed files with 7 additions and 1 deletions
|
|
@ -33,6 +33,7 @@ module Admin
|
|||
|
||||
def destroy
|
||||
@user = User.find(params[:id])
|
||||
@user.events.destroy_all
|
||||
@user.destroy
|
||||
redirect_to admin_users_path, notice: 'User got deleted'
|
||||
end
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ class User < ActiveRecord::Base
|
|||
:name, :email_public, :biography, :nickname, :affiliation
|
||||
|
||||
has_many :event_users, dependent: :destroy
|
||||
has_many :events, -> { uniq }, through: :event_users
|
||||
has_many :events, -> { uniq }, through: :event_users, dependent: :destroy
|
||||
has_many :registrations, dependent: :destroy
|
||||
has_many :votes, dependent: :destroy
|
||||
has_many :voted_events, through: :votes, source: :events
|
||||
|
|
|
|||
|
|
@ -26,6 +26,11 @@ describe User do
|
|||
expect(user_with_all_roles.roles[2]).to eq(admin_role)
|
||||
end
|
||||
|
||||
it { should have_many(:events).dependent(:destroy) }
|
||||
it { should have_many(:event_users).dependent(:destroy) }
|
||||
it { should have_many(:registrations).dependent(:destroy) }
|
||||
it { should have_many(:votes).dependent(:destroy) }
|
||||
|
||||
describe '#role?' do
|
||||
shared_examples '#role?' do |user, role, expected|
|
||||
it "returns #{expected} for #{role}" do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue