Remove roles when block or delete users
After a user assigned as a budget admin deletes their account or gets blocked by a moderator, the application throws an exception while loading the admin investment index page. As an erased user is not really deleted and neither its associated roles, the application was failing when trying to sort and administration without a username. In this case, the application was throwing an `ArgumentError: comparison of NilClass with String failed` exception. As a blocked user is not deleted or its roles, the application failed when trying to access the user name through the delegation in the Administrator. In this case, the application was throwing a `NoMethodError: undefined method `name' for nil:NilClass` exception.
This commit is contained in:
@@ -538,6 +538,19 @@ describe User do
|
||||
|
||||
expect(Identity.exists?(identity.id)).not_to be
|
||||
end
|
||||
|
||||
it "removes all user roles" do
|
||||
user = create(:user)
|
||||
[:administrator, :moderator, :manager, :sdg_manager, :valuator].each do |role|
|
||||
create(role, user: user)
|
||||
end
|
||||
|
||||
expect { user.erase }.to change { Administrator.count }.by(-1)
|
||||
.and change { Moderator.count }.by(-1)
|
||||
.and change { Manager.count }.by(-1)
|
||||
.and change { SDG::Manager.count }.by(-1)
|
||||
.and change { Valuator.count }.by(-1)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#take_votes_from" do
|
||||
@@ -749,6 +762,19 @@ describe User do
|
||||
expect(Legislation::Proposal.all).to eq [other_proposal]
|
||||
expect(Legislation::Proposal.with_hidden).to match_array [proposal, other_proposal]
|
||||
end
|
||||
|
||||
it "removes all user roles" do
|
||||
user = create(:user)
|
||||
[:administrator, :moderator, :manager, :sdg_manager, :valuator].each do |role|
|
||||
create(role, user: user)
|
||||
end
|
||||
|
||||
expect { user.block }.to change { Administrator.count }.by(-1)
|
||||
.and change { Moderator.count }.by(-1)
|
||||
.and change { Manager.count }.by(-1)
|
||||
.and change { SDG::Manager.count }.by(-1)
|
||||
.and change { Valuator.count }.by(-1)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#full_restore" do
|
||||
|
||||
Reference in New Issue
Block a user