diff --git a/app/models/poll/voter.rb b/app/models/poll/voter.rb index 353d593b3..936d8af3b 100644 --- a/app/models/poll/voter.rb +++ b/app/models/poll/voter.rb @@ -11,16 +11,20 @@ class Poll end def has_not_voted - errors.add(:document_number, :has_voted) if has_voted? + errors.add(:document_number, :has_voted, name: name) if has_voted? end def census_api_response - CensusApi.new.call(document_type, document_number) + @census ||= CensusApi.new.call(document_type, document_number) end def has_voted? poll.voters.where(document_number: document_number, document_type: document_type).present? end + def name + @census.name + end + end end \ No newline at end of file diff --git a/config/locales/activerecord.en.yml b/config/locales/activerecord.en.yml index b719885b5..f34757195 100644 --- a/config/locales/activerecord.en.yml +++ b/config/locales/activerecord.en.yml @@ -87,7 +87,7 @@ en: attributes: document_number: not_in_census: "Document not in census" - has_voted: "Has already voted" + has_voted: "%{name} has already voted" proposal: attributes: tag_list: diff --git a/config/locales/activerecord.es.yml b/config/locales/activerecord.es.yml index 9d51505fe..a439a6c5c 100644 --- a/config/locales/activerecord.es.yml +++ b/config/locales/activerecord.es.yml @@ -87,7 +87,7 @@ es: attributes: document_number: not_in_census: "Este documento no aparece en el censo" - has_voted: "Ya ha votado" + has_voted: "%{name} ya ha votado" proposal: attributes: tag_list: diff --git a/lib/census_api.rb b/lib/census_api.rb index d80f420e7..eadfc549e 100644 --- a/lib/census_api.rb +++ b/lib/census_api.rb @@ -61,6 +61,10 @@ class CensusApi end end + def name + "#{data[:datos_habitante][:item][:nombre]} #{data[:datos_habitante][:item][:apellido1]}" + end + private def data @@ -106,7 +110,7 @@ class CensusApi end def stubbed_valid_response - {get_habita_datos_response: {get_habita_datos_return: {datos_habitante: { item: {fecha_nacimiento_string: "31-12-1980", identificador_documento: "12345678Z", descripcion_sexo: "Varón" }}, datos_vivienda: {item: {codigo_postal: "28013", codigo_distrito: "01"}}}}} + {get_habita_datos_response: {get_habita_datos_return: {datos_habitante: { item: {fecha_nacimiento_string: "31-12-1980", identificador_documento: "12345678Z", descripcion_sexo: "Varón", nombre: "José", apellido1: "García" }}, datos_vivienda: {item: {codigo_postal: "28013", codigo_distrito: "01"}}}}} end def stubbed_invalid_response