mirror of
https://github.com/internetee/registry.git
synced 2025-07-23 19:20:37 +02:00
Merge branch 'story/114871365-address-cc-upcase' into staging
This commit is contained in:
commit
6576f19206
2 changed files with 27 additions and 7 deletions
|
@ -43,8 +43,8 @@ class Contact < ActiveRecord::Base
|
|||
self.ident_updated_at = Time.zone.now if new_record? && ident_updated_at.blank?
|
||||
end
|
||||
|
||||
before_validation :set_ident_country_code
|
||||
before_validation :prefix_code
|
||||
before_validation :val_upcase_country_code
|
||||
before_validation :val_prefix_code
|
||||
before_create :generate_auth_info
|
||||
|
||||
before_update :manage_emails
|
||||
|
@ -306,7 +306,7 @@ class Contact < ActiveRecord::Base
|
|||
end
|
||||
|
||||
# rubocop:disable Metrics/CyclomaticComplexity
|
||||
def prefix_code
|
||||
def val_prefix_code
|
||||
return nil unless new_record?
|
||||
return nil if registrar.blank?
|
||||
code = self[:code]
|
||||
|
@ -346,13 +346,17 @@ class Contact < ActiveRecord::Base
|
|||
destroy
|
||||
end
|
||||
|
||||
def set_ident_country_code
|
||||
return true unless ident_country_code_changed? && ident_country_code.present?
|
||||
code = Country.new(ident_country_code)
|
||||
if code
|
||||
def val_upcase_country_code
|
||||
if code = Country.new(ident_country_code)
|
||||
self.ident_country_code = code.alpha2
|
||||
else
|
||||
errors.add(:ident, :invalid_country_code)
|
||||
end if ident_country_code_changed? && ident_country_code.present?
|
||||
|
||||
if code = Country.new(country_code)
|
||||
self.country_code = code.alpha2
|
||||
else
|
||||
errors.add(:country_code, :invalid_country_code)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -32,5 +32,21 @@ namespace :convert do
|
|||
d.save!
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
desc 'Contact Address Country Code Upcase'
|
||||
task country_code_ucase: :environment do
|
||||
count = 0
|
||||
Contact.find_each do |c|
|
||||
if c.country_code.present? && c.country_code != c.country_code.upcase
|
||||
c.country_code = c.country_code.upcase
|
||||
c.update_columns(country_code: c.country_code.upcase)
|
||||
# c.send(:record_update)
|
||||
|
||||
count +=1
|
||||
puts "#{count} contacts has been changed" if count % 1000 == 0
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue