Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jun 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -723,6 +723,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 @@ -723,6 +723,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