Show name and email for deleted poll officer's user account

Avoid to raise an exception `Module::DelegationError' when trying to
show the name and/or email of a poll officer whose user account has
been deleted.
We'll show a message "User deleted" and "Email deleted" instead.
This commit is contained in:
Julian Herrero
2019-05-31 18:29:11 +02:00
parent 90c1d681d0
commit 1f76b25e2a
4 changed files with 37 additions and 1 deletions

View File

@@ -2,6 +2,34 @@ require "rails_helper"
describe Poll::Officer do
describe "#name" do
let(:officer) { create(:poll_officer) }
it "returns user name if user is not deleted" do
expect(officer.name).to eq officer.user.name
end
it "returns 'User deleted' if user is deleted" do
officer.user.destroy
expect(officer.reload.name).to eq "User deleted"
end
end
describe "#email" do
let(:officer) { create(:poll_officer) }
it "returns user email if user is not deleted" do
expect(officer.email).to eq officer.user.email
end
it "returns 'Email deleted' if user is deleted" do
officer.user.destroy
expect(officer.reload.email).to eq "Email deleted"
end
end
describe "#voting_days_assigned_polls" do
it "returns all polls with this officer assigned during voting days" do
officer = create(:poll_officer)