From 8f23ef510d7c8e1237fb1e1dba8d1bf8846c6e31 Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Mon, 4 May 2015 14:07:06 +0300 Subject: [PATCH] Added registrar legacy migration and don't allow blank nor colon in code --- app/models/registrar.rb | 2 +- ...0150504104922_add_legacy_registrar_code.rb | 63 +++++++++++++++++++ db/schema.rb | 2 +- spec/models/registrar_spec.rb | 24 +++++++ 4 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20150504104922_add_legacy_registrar_code.rb diff --git a/app/models/registrar.rb b/app/models/registrar.rb index 8436f7873..d297545a3 100644 --- a/app/models/registrar.rb +++ b/app/models/registrar.rb @@ -138,6 +138,6 @@ class Registrar < ActiveRecord::Base end def code=(code) - self[:code] = code.upcase if new_record? && code.present? + self[:code] = code.gsub(/[ :]/, '').upcase if new_record? && code.present? end end diff --git a/db/migrate/20150504104922_add_legacy_registrar_code.rb b/db/migrate/20150504104922_add_legacy_registrar_code.rb new file mode 100644 index 000000000..43659a4f2 --- /dev/null +++ b/db/migrate/20150504104922_add_legacy_registrar_code.rb @@ -0,0 +1,63 @@ +class AddLegacyRegistrarCode < ActiveRecord::Migration + def change + legacy_codes = [ + [1, "EEDIRECT"], + [2, "ALMIC"], + [3, "ELION"], + [4, "SPINTEK"], + [5, "LINXTELECOM"], + [6, "ZONE"], + [7, "WEBNEST"], + [8, "NETPOINT"], + [9, "EESTIDOMEENID"], + [10, "CEMTY"], + [11, "NORTHSIDE"], + [12, "EENET"], + [13, "ELKDATA"], + [14, "ELISA"], + [15, "OKIA"], + [16, "NAMEISP"], + [17, "ASCIO"], + [18, "TPT"], + [22, "TPT2"], + [23, "INFONET"], + [24, "INTERFRAME"], + [25, "DOMAININFO"], + [26, "DELETEDDOMAINS"], + [27, "WAVECOM"], + [28, "CACTUSHOSTING"], + [29, "IPMIRROR"], + [30, "ALFANET"], + [31, "RIKS"], + [32, "AKS"], + [33, "VIRTUAAL"], + [34, "MIKARE_BALTIC"], + [35, "COMPIC"], + [36, "NETIM"], + [37, "TRENET"], + [38, "INSTRA"], + [39, "123DOMAIN.EU"], + [40, "EDICY"], + [41, "MAJANDUSTARKVARA"], + [44, "SAFENAMES"], + [45, "INFOWEB"], + [46, "EURODNS"], + [47, "INNTER.NET"], + [48, "RADICENTER"], + [49, "DBWEB"], + [50, "NAMESHIELD"], + [51, "CEMTY_OU"], + [52, "INFOBIT"] + ] + + legacy_codes.each do |lc| + legacy_id = lc.first + legacy_code = lc.second + registrar = Registrar.find_by(legacy_id: legacy_id) + next if registrar.blank? + old_code = registrar.code + registrar.update_column(:code, legacy_code) + puts "Registrar code updated: #{registrar.id}; #{registrar.name}; old: #{old_code}; new: #{registrar.reload.code}" + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 86e8b4017..e2afbfa2d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150430121807) do +ActiveRecord::Schema.define(version: 20150504104922) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" diff --git a/spec/models/registrar_spec.rb b/spec/models/registrar_spec.rb index 63ec34bfc..208ae9906 100644 --- a/spec/models/registrar_spec.rb +++ b/spec/models/registrar_spec.rb @@ -65,6 +65,30 @@ describe Registrar do ]) end + it 'should remove blank from code' do + registrar = Fabricate.build(:registrar, code: 'with blank') + registrar.valid? + registrar.errors.full_messages.should match_array([ + ]) + registrar.code.should == 'WITHBLANK' + end + + it 'should remove colon from code' do + registrar = Fabricate.build(:registrar, code: 'with colon:and:blank') + registrar.valid? + registrar.errors.full_messages.should match_array([ + ]) + registrar.code.should == 'WITHCOLONANDBLANK' + end + + it 'should allow dot in code' do + registrar = Fabricate.build(:registrar, code: 'with.dot') + registrar.valid? + registrar.errors.full_messages.should match_array([ + ]) + registrar.code.should == 'WITH.DOT' + end + it 'should have one version' do with_versioning do @registrar.versions.should == []