From b86e2d1edb20d4d5305cd8c261cf5ac5cb714fda Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Mon, 2 Feb 2015 12:07:59 +0200 Subject: [PATCH] Refactor country --- app/models/user.rb | 4 ++-- app/views/epp/contacts/_postal_info.xml.builder | 2 +- db/seeds.rb | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 8c49a5acb..35fbc9b8c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -9,8 +9,8 @@ class User < ActiveRecord::Base validates :username, :password, presence: true validates :identity_code, uniqueness: true, allow_blank: true - validates :identity_code, presence: true, if: -> { country.iso == 'EE' } - validates :email, presence: true, if: -> { country.iso != 'EE' } + validates :identity_code, presence: true, if: -> { country.alpha2 == 'EE' } + validates :email, presence: true, if: -> { country.alpha2 != 'EE' } validate :validate_identity_code diff --git a/app/views/epp/contacts/_postal_info.xml.builder b/app/views/epp/contacts/_postal_info.xml.builder index bec291a93..f9c6c5ee9 100644 --- a/app/views/epp/contacts/_postal_info.xml.builder +++ b/app/views/epp/contacts/_postal_info.xml.builder @@ -5,7 +5,7 @@ xml.tag!('contact:postalInfo', type: 'int') do if @disclosure.try(:addr) || @owner xml.tag!('contact:addr') do xml.tag!('contact:street', address.street) if address - xml.tag!('contact:cc', address.try(:country).try(:iso)) unless address.try(:country).nil? + xml.tag!('contact:cc', address.country_code) unless address.country_code.nil? xml.tag!('contact:city', address.city) if address end end diff --git a/db/seeds.rb b/db/seeds.rb index 3cedc25c9..84571e412 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -8,7 +8,7 @@ registrar1 = Registrar.where( reg_no: '10300220', address: 'Pärnu mnt 2, Tallinna linn, Harju maakond, 11415', email: 'registrar1@example.com', - country: Country.first + country_code: 'EE' ).first_or_create! ApiUser.where( @@ -23,7 +23,7 @@ registrar2 = Registrar.where( reg_no: '10529229', address: 'Vabaduse pst 32, 11316 Tallinn', email: 'registrar2@example.com', - country: Country.first + country_code: 'EE' ).first_or_create! ApiUser.where( @@ -38,7 +38,7 @@ User.where( password: 'test1', email: 'user1@example.ee', identity_code: '37810013855', - country: Country.where(name: 'Estonia').first + country_code: 'EE' ).first_or_create! User.where( @@ -46,7 +46,7 @@ User.where( password: 'test2', email: 'user2@example.ee', identity_code: '37810010085', - country: Country.where(name: 'Estonia').first + country_code: 'EE' ).first_or_create! User.where( @@ -54,7 +54,7 @@ User.where( password: 'test3', email: 'user3@example.ee', identity_code: '37810010727', - country: Country.where(name: 'Estonia').first + country_code: 'EE' ).first_or_create! User.update_all(roles: ['admin'])