From 0bf88abcf1dc80e75fb1ea2efb8318e94fa67baa Mon Sep 17 00:00:00 2001 From: taitus Date: Tue, 14 May 2019 11:34:06 +0200 Subject: [PATCH] Allow to SignatureSheet parse new fields - In the previous version, each signature was equivalent to a document and we separated them by commas. Now each signature may also need the fields birth date and postal code. So we separated each signature with a semicolon and separated each of its fields by commas. Example old version: "12345678X, 87654321Y" Example new version: "12345678X, 31/12/1980, 28001; 87654321Y, 31/12/1981, 28002" - Update translations: "Write the numbers separated by commas (,)" to "Write the numbers separated by semicolons (;)" --- app/models/signature_sheet.rb | 12 ++++++--- config/locales/ast/admin.yml | 2 +- config/locales/ca/admin.yml | 2 +- config/locales/en/admin.yml | 2 +- config/locales/es-PE/admin.yml | 2 +- config/locales/es/admin.yml | 2 +- config/locales/fr/admin.yml | 2 +- config/locales/gl/admin.yml | 2 +- config/locales/he/admin.yml | 2 +- config/locales/id-ID/admin.yml | 2 +- config/locales/it/admin.yml | 2 +- config/locales/nl/admin.yml | 2 +- config/locales/pl-PL/admin.yml | 2 +- config/locales/ru/admin.yml | 2 +- config/locales/sl-SI/admin.yml | 2 +- config/locales/so-SO/admin.yml | 2 +- config/locales/sq-AL/admin.yml | 2 +- config/locales/sv-SE/admin.yml | 2 +- config/locales/val/admin.yml | 2 +- spec/features/admin/signature_sheets_spec.rb | 8 +++--- spec/models/signature_sheet_spec.rb | 28 +++++++++++++++----- 21 files changed, 52 insertions(+), 32 deletions(-) diff --git a/app/models/signature_sheet.rb b/app/models/signature_sheet.rb index a3513ca57..672017989 100644 --- a/app/models/signature_sheet.rb +++ b/app/models/signature_sheet.rb @@ -21,15 +21,21 @@ class SignatureSheet < ApplicationRecord end def verify_signatures - parsed_required_fields_to_verify_groups.each do |document_number| - signature = signatures.where(document_number: document_number).first_or_create + parsed_required_fields_to_verify_groups.each do |required_fields_to_verify| + document_number = required_fields_to_verify[0] + date_of_birth = required_fields_to_verify[1] + postal_code = required_fields_to_verify[2] + + signature = signatures.where(document_number: document_number, + date_of_birth: date_of_birth, + postal_code: postal_code).first_or_create signature.verify end update(processed: true) end def parsed_required_fields_to_verify_groups - required_fields_to_verify.split(/\r\n|\n|[,]/).collect {|d| d.gsub(/\s+/, "") } + required_fields_to_verify.split(/[;]/).collect {|d| d.gsub(/\s+/, "") }.map { |group| group.split(/[,]/)} end def signable_found diff --git a/config/locales/ast/admin.yml b/config/locales/ast/admin.yml index 84afe128a..0a954256e 100644 --- a/config/locales/ast/admin.yml +++ b/config/locales/ast/admin.yml @@ -886,7 +886,7 @@ ast: new: Nueva hoja de firmas new: title: Nueva hoja de firmas - document_numbers_note: "Introduce los números separados por comas (,)" + document_numbers_note: "Introduce los números separados por punto y coma (;)" submit: Crear hoja de firmas show: created_at: Creado diff --git a/config/locales/ca/admin.yml b/config/locales/ca/admin.yml index e3e96d18c..5f435a19d 100644 --- a/config/locales/ca/admin.yml +++ b/config/locales/ca/admin.yml @@ -862,7 +862,7 @@ ca: new: Nou full de signatures new: title: Nou full de signatures - document_numbers_note: "Introdueix els números separats per comes (,)" + document_numbers_note: "Introdueix els números separats per punt i coma (;)" submit: Crear full de signatures show: created_at: Creat diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 9ea373c83..c87a77835 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -1400,7 +1400,7 @@ en: new: New signature sheets new: title: New signature sheets - document_numbers_note: "Write the numbers separated by commas (,)" + document_numbers_note: "Write the numbers separated by semicolons (;)" submit: Create signature sheet show: created_at: Created diff --git a/config/locales/es-PE/admin.yml b/config/locales/es-PE/admin.yml index f487090dd..ee007e1cc 100644 --- a/config/locales/es-PE/admin.yml +++ b/config/locales/es-PE/admin.yml @@ -992,7 +992,7 @@ es-PE: new: Nueva hoja de firmas new: title: Nueva hoja de firmas - document_numbers_note: "Introduce los números separados por comas (,)" + document_numbers_note: "Introduce los números separados por punto y coma (;)" submit: Crear hoja de firmas show: created_at: Creado diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index ad1629d9d..9fb494dfb 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -1398,7 +1398,7 @@ es: new: Nueva hoja de firmas new: title: Nueva hoja de firmas - document_numbers_note: "Introduce los números separados por comas (,)" + document_numbers_note: "Introduce los números separados por punto y coma (;)" submit: Crear hoja de firmas show: created_at: Creado diff --git a/config/locales/fr/admin.yml b/config/locales/fr/admin.yml index d80ba691b..f2e7f74c4 100644 --- a/config/locales/fr/admin.yml +++ b/config/locales/fr/admin.yml @@ -1337,7 +1337,7 @@ fr: new: Nouvelle feuilles de signature new: title: Nouvelle feuilles de signature - document_numbers_note: "Saisir les numéros séparés par des virgules (,)" + document_numbers_note: "Saisir les numéros séparés par des points-virgules (;)" submit: Créer la feuille de signature show: created_at: Créé le diff --git a/config/locales/gl/admin.yml b/config/locales/gl/admin.yml index 88a9fa2ad..c72d04345 100644 --- a/config/locales/gl/admin.yml +++ b/config/locales/gl/admin.yml @@ -1277,7 +1277,7 @@ gl: new: Nova folla de sinaturas new: title: Nova folla de sinaturas - document_numbers_note: "Escribe os números separados por comas (,)" + document_numbers_note: "Escribe os números separados por puntos y comas (;)" submit: Crear folla de sinaturas show: created_at: Creado diff --git a/config/locales/he/admin.yml b/config/locales/he/admin.yml index 959001529..496cc21cd 100644 --- a/config/locales/he/admin.yml +++ b/config/locales/he/admin.yml @@ -1427,7 +1427,7 @@ he: new: דף חדש לחתימות new: title: דף חדש לחתימות - document_numbers_note: "נא לכתוב את המספרים מופרדים באמצעות פסיקים (,)" + document_numbers_note: "רשום את המספרים המופרדים בנקודות פסיק (;)" submit: יצירת דף לחתימות show: created_at: נוצר ב diff --git a/config/locales/id-ID/admin.yml b/config/locales/id-ID/admin.yml index 251f0cda5..2aa2a28a0 100644 --- a/config/locales/id-ID/admin.yml +++ b/config/locales/id-ID/admin.yml @@ -1066,7 +1066,7 @@ id: new: Baru tanda tangan lembar new: title: Baru tanda tangan lembar - document_numbers_note: "Menulis angka-angka yang dipisahkan oleh tanda koma (,)" + document_numbers_note: "Menulis angka-angka yang dipisahkan oleh titik koma (;)" submit: Membuat tanda tangan lembar show: created_at: Dibuat diff --git a/config/locales/it/admin.yml b/config/locales/it/admin.yml index 4af8f927a..979155101 100644 --- a/config/locales/it/admin.yml +++ b/config/locales/it/admin.yml @@ -1179,7 +1179,7 @@ it: new: Nuovo foglio di firma new: title: Nuovi fogli firma - document_numbers_note: "Con i numeri separati da virgole (,)" + document_numbers_note: "Con i numeri separati da punto e virgola (;)" submit: Creare foglio di firma show: created_at: Creato diff --git a/config/locales/nl/admin.yml b/config/locales/nl/admin.yml index e428a5ecd..9711c8d3b 100644 --- a/config/locales/nl/admin.yml +++ b/config/locales/nl/admin.yml @@ -1320,7 +1320,7 @@ nl: new: New signature sheets new: title: Niewe handtekeninglijst - document_numbers_note: "Write the numbers separated by commas (,)" + document_numbers_note: "Write the numbers separated by semicolons (;)" submit: Create signature sheet show: created_at: Aangemaakt diff --git a/config/locales/pl-PL/admin.yml b/config/locales/pl-PL/admin.yml index dc821d888..e1779213e 100644 --- a/config/locales/pl-PL/admin.yml +++ b/config/locales/pl-PL/admin.yml @@ -1315,7 +1315,7 @@ pl: new: Nowe arkusze podpisów new: title: Nowe arkusze podpisów - document_numbers_note: "Napisz liczby oddzielone przecinkami (,)" + document_numbers_note: "Napisz liczby oddzielone średnikami (;)" submit: Utwórz arkusz podpisu show: created_at: Stworzony diff --git a/config/locales/ru/admin.yml b/config/locales/ru/admin.yml index c27f2e8fb..48fb4ffba 100644 --- a/config/locales/ru/admin.yml +++ b/config/locales/ru/admin.yml @@ -1315,7 +1315,7 @@ ru: new: Новые подписные листы new: title: Новые подписные листы - document_numbers_note: "Впишите номера, разделенные запятыми (,)" + document_numbers_note: "Впишите номера, разделенные точкой с запятой (;)" submit: Создать подписной лист show: created_at: Создано diff --git a/config/locales/sl-SI/admin.yml b/config/locales/sl-SI/admin.yml index ff443f148..1866aa80c 100644 --- a/config/locales/sl-SI/admin.yml +++ b/config/locales/sl-SI/admin.yml @@ -947,7 +947,7 @@ sl: new: Novi podpisni listi new: title: Novi podpisni listi - document_numbers_note: "Napiši številke in jih loči z vejico (,)" + document_numbers_note: "Napiši številke in jih loči s podpičjem (;)" submit: Ustvair podpisni list show: created_at: Ustvarjen diff --git a/config/locales/so-SO/admin.yml b/config/locales/so-SO/admin.yml index 36a3ad072..3f3ef34f1 100644 --- a/config/locales/so-SO/admin.yml +++ b/config/locales/so-SO/admin.yml @@ -1184,7 +1184,7 @@ so: new: Warqadaha Cusub ee Saxixyada new: title: Warqadaha Cusub ee Saxixyada - document_numbers_note: "Qoor Lamaradaa oo ay ka socanyihiin qooyska(,)" + document_numbers_note: "Qoor Lamaradaa oo ay ka socanyihiin qooyska(;)" submit: Saame Warqada saxiixa show: created_at: Abuuray diff --git a/config/locales/sq-AL/admin.yml b/config/locales/sq-AL/admin.yml index ee631f052..42bee56fc 100644 --- a/config/locales/sq-AL/admin.yml +++ b/config/locales/sq-AL/admin.yml @@ -1186,7 +1186,7 @@ sq: new: Fletë të reja nënshkrimi new: title: Fletë të reja nënshkrimi - document_numbers_note: "Shkruani numrat që dëshironi të ndahen me presje (,)" + document_numbers_note: "Shkruani numrat që dëshironi të ndahen me pikëpresje (;)" submit: Krijo Fletë nënshkrimi show: created_at: Krijuar diff --git a/config/locales/sv-SE/admin.yml b/config/locales/sv-SE/admin.yml index e1224207a..5de9282fe 100644 --- a/config/locales/sv-SE/admin.yml +++ b/config/locales/sv-SE/admin.yml @@ -1230,7 +1230,7 @@ sv: new: Ny namninsamling new: title: Ny namninsamling - document_numbers_note: "Fyll i siffrorna separerade med kommatecken (,)" + document_numbers_note: "Fyll i siffrorna separerade av semikolon (;)" submit: Skapa namninsamling show: created_at: Skapad diff --git a/config/locales/val/admin.yml b/config/locales/val/admin.yml index 52a14372a..6292a908a 100644 --- a/config/locales/val/admin.yml +++ b/config/locales/val/admin.yml @@ -1235,7 +1235,7 @@ val: new: Nou full de signatures new: title: Nou full de signatures - document_numbers_note: "Escriu els números separats per comes (,)" + document_numbers_note: "Escriu els números separats per punt i coma (;)" submit: Crear full de signatures show: created_at: Creat diff --git a/spec/features/admin/signature_sheets_spec.rb b/spec/features/admin/signature_sheets_spec.rb index fb2877abc..4935eca28 100644 --- a/spec/features/admin/signature_sheets_spec.rb +++ b/spec/features/admin/signature_sheets_spec.rb @@ -39,7 +39,7 @@ describe "Signature sheets" do select "Citizen proposal", from: "signature_sheet_signable_type" fill_in "signature_sheet_signable_id", with: proposal.id - fill_in "signature_sheet_required_fields_to_verify", with: "12345678Z, 1234567L, 99999999Z" + fill_in "signature_sheet_required_fields_to_verify", with: "12345678Z; 1234567L; 99999999Z" click_button "Create signature sheet" expect(page).to have_content "Signature sheet created successfully" @@ -61,7 +61,7 @@ describe "Signature sheets" do select "Investment", from: "signature_sheet_signable_type" fill_in "signature_sheet_signable_id", with: investment.id - fill_in "signature_sheet_required_fields_to_verify", with: "12345678Z, 1234567L, 99999999Z" + fill_in "signature_sheet_required_fields_to_verify", with: "12345678Z; 1234567L; 99999999Z" click_button "Create signature sheet" expect(page).to have_content "Signature sheet created successfully" @@ -89,14 +89,14 @@ describe "Signature sheets" do user = Administrator.first.user signature_sheet = create(:signature_sheet, signable: proposal, - required_fields_to_verify: "12345678Z, 123A, 123B", + required_fields_to_verify: "12345678Z; 123A; 123B", author: user) signature_sheet.verify_signatures visit admin_signature_sheet_path(signature_sheet) expect(page).to have_content "Citizen proposal #{proposal.id}" - expect(page).to have_content "12345678Z, 123A, 123B" + expect(page).to have_content "12345678Z; 123A; 123B" expect(page).to have_content signature_sheet.created_at.strftime("%B %d, %Y %H:%M") expect(page).to have_content user.name diff --git a/spec/models/signature_sheet_spec.rb b/spec/models/signature_sheet_spec.rb index 6859348b0..c44697bce 100644 --- a/spec/models/signature_sheet_spec.rb +++ b/spec/models/signature_sheet_spec.rb @@ -57,10 +57,16 @@ describe SignatureSheet do describe "#verify_signatures" do it "creates signatures for each document number" do - signature_sheet = create(:signature_sheet, required_fields_to_verify: "123A, 456B") + signature_sheet = create(:signature_sheet, required_fields_to_verify: "123A; 456B") signature_sheet.verify_signatures expect(Signature.count).to eq(2) + expect(Signature.first.document_number).to eq("123A") + expect(Signature.first.date_of_birth).to eq(nil) + expect(Signature.first.postal_code).to eq(nil) + expect(Signature.last.document_number).to eq("456B") + expect(Signature.last.date_of_birth).to eq(nil) + expect(Signature.last.postal_code).to eq(nil) end it "marks signature sheet as processed" do @@ -71,17 +77,25 @@ describe SignatureSheet do end end - describe "#parsed_document_numbers" do - it "returns an array after spliting document numbers by newlines or commas" do - signature_sheet.document_numbers = "123A\r\n456B\n789C,123B" + describe "#parsed_required_fields_to_verify" do + it "returns an array after spliting document numbers by semicolons" do + signature_sheet.required_fields_to_verify = "123A\r\n;456B;\n789C;123B" - expect(signature_sheet.parsed_document_numbers).to eq(["123A", "456B", "789C", "123B"]) + expect(signature_sheet.parsed_required_fields_to_verify_groups).to eq([["123A"], ["456B"], ["789C"], ["123B"]]) + end + + it "returns an array after spliting all required_fields_to_verify by semicolons" do + required_fields_to_verify = "123A\r\n, 01/01/1980\r\n, 28001\r\n; 456B\n, 01/02/1980\n, 28002\n; 789C, 01/03/1980" + # signature_sheet.required_fields_to_verify = "123A\r\n456B\n789C;123B" + signature_sheet.required_fields_to_verify = required_fields_to_verify + + expect(signature_sheet.parsed_required_fields_to_verify_groups).to eq([["123A", "01/01/1980", "28001"], ["456B", "01/02/1980", "28002"], ["789C", "01/03/1980"]]) end it "strips spaces between number and letter" do - signature_sheet.document_numbers = "123 A\n456 B \n 789C" + signature_sheet.required_fields_to_verify = "123 A, 01/01/1980, 28001;\n456 B , 01/02/1980, 28002;\n 789C ,01/03/1980, 28 003" - expect(signature_sheet.parsed_document_numbers).to eq(["123A", "456B", "789C"]) + expect(signature_sheet.parsed_required_fields_to_verify_groups).to eq([["123A", "01/01/1980", "28001"], ["456B", "01/02/1980", "28002"], ["789C", "01/03/1980", "28003"]]) end end