From 908a033b73e0327dac9c00fc12f8cbf093e1599b Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Mon, 14 Dec 2015 13:46:14 +0200 Subject: [PATCH] Story#109590460 - set business id validation --- app/models/contact.rb | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/models/contact.rb b/app/models/contact.rb index fcebe8632..1b96b9876 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -212,12 +212,16 @@ class Contact < ActiveRecord::Base end def ident_valid_format? - case ident_type - when 'priv' - case ident_country_code - when 'EE' - code = Isikukood.new(ident) - errors.add(:ident, :invalid_EE_identity_format) unless code.valid? + case ident_country_code + when 'EE'.freeze + case ident_type + when 'priv'.freeze + errors.add(:ident, :invalid_EE_identity_format) unless Isikukood.new(ident).valid? + when 'org'.freeze + last_char = ident.last + if ident.size != 8 || !%(1 8 9).freeze.include?(last_char) || ident !=~/\A[12][0-9]{6}[189]\z/ + errors.add(:ident, :invalid_EE_identity_format) + end end end end