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:
Senén Rodero Rodríguez
2022-05-04 12:53:30 +02:00
parent d797ec3ca0
commit c6190d0199
4 changed files with 80 additions and 0 deletions

View File

@@ -173,6 +173,28 @@ describe "Account" do
expect(page).to have_content "Invalid Email or username or password"
end
scenario "Erasing an account removes all related roles" do
user.update!(username: "Admin")
administrators = [create(:administrator, user: user),
create(:administrator, user: create(:user, username: "Other admin"))]
budget = create(:budget, administrators: administrators)
visit admin_budget_budget_investments_path(budget)
expect(page).to have_select options: ["All administrators", "Admin", "Other admin"]
visit account_path
click_link "Erase my account"
fill_in "user_erase_reason", with: "I don't want my roles anymore!"
click_button "Erase my account"
expect(page).to have_content "Goodbye! Your account has been cancelled. We hope to see you again soon."
login_as(administrators.last.user)
visit admin_budget_budget_investments_path(budget)
expect(page).to have_select options: ["All administrators", "Other admin"]
end
context "Recommendations" do
scenario "are enabled by default" do
visit account_path