Skip to content

Commit

Permalink
Merge pull request #3587 from consul/unregistered_poll_officers
Browse files Browse the repository at this point in the history
Show name and email for deleted poll officer's user account
  • Loading branch information
microweb10 committed Jun 5, 2019
2 parents a6f8969 + 1f76b25 commit 5e9cb24
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/models/poll/officer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ class Officer < ApplicationRecord

validates :user_id, presence: true, uniqueness: true

delegate :name, :email, to: :user
def name
user&.name || I18n.t("shared.author_info.author_deleted")
end

def email
user&.email || I18n.t("shared.author_info.email_deleted")
end

def voting_days_assigned_polls
officer_assignments.voting_days.includes(booth_assignment: :poll).
Expand Down
1 change: 1 addition & 0 deletions config/locales/en/general.yml
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,7 @@ en:
to: "To"
author_info:
author_deleted: User deleted
email_deleted: Email deleted
back: Go back
check: Select
check_all: All
Expand Down
1 change: 1 addition & 0 deletions config/locales/es/general.yml
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,7 @@ es:
to: "Hasta"
author_info:
author_deleted: Usuario eliminado
email_deleted: Email eliminado
back: Volver
check: Seleccionar
check_all: Todos
Expand Down
28 changes: 28 additions & 0 deletions spec/models/poll/officer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,34 @@

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)
Expand Down

0 comments on commit 5e9cb24

Please sign in to comment.