From 7ff09c75e37ab3f2e48d486796ccab38d9452b17 Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Tue, 31 Mar 2015 18:02:02 +0300 Subject: [PATCH] Whois body updated later with delayed job --- app/models/domain.rb | 43 +++++++++++++++++++------------------- spec/models/domain_spec.rb | 4 ++-- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/app/models/domain.rb b/app/models/domain.rb index f97769cae..33981f2a3 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -51,13 +51,8 @@ class Domain < ActiveRecord::Base def touch_always_version self.updated_at = Time.now end - before_save :update_whois_body - after_save :delay_whois_server_update - def delay_whois_server_update - return if whois_body.blank? - delay.whois_server_update(name, whois_body) - end after_save :manage_automatic_statuses + after_save :update_whois_body validates :name_dirty, domain_name: true, uniqueness: true validates :period, numericality: { only_integer: true } @@ -117,6 +112,14 @@ class Domain < ActiveRecord::Base nameservers.select { |x| !x.hostname.end_with?(name) } end + class << self + def convert_period_to_time(period, unit) + return period.to_i.days if unit == 'd' + return period.to_i.months if unit == 'm' + return period.to_i.years if unit == 'y' + end + end + def name=(value) value.strip! value.downcase! @@ -225,9 +228,15 @@ class Domain < ActiveRecord::Base log end + def update_whois_server + wd = Whois::Domain.find_or_initialize_by(name: name) + wd.whois_body = whois_body + wd.save + end + # rubocop:disable Metrics/MethodLength def update_whois_body - self.whois_body = <<-EOS + new_whois_body = <<-EOS This Whois Server contains information on Estonian Top Level Domain ee TLD @@ -251,7 +260,13 @@ class Domain < ActiveRecord::Base created: #{registrar.created_at.to_s(:db)} changed: #{registrar.updated_at.to_s(:db)} EOS + + if whois_body != new_whois_body + update_column(whois_body: new_whois_body) + update_whois_server + end end + handle_asynchronously :update_whois_body # rubocop:enable Metrics/MethodLength def contacts_body @@ -273,18 +288,4 @@ class Domain < ActiveRecord::Base end out end - - def whois_server_update(name, whois_body) - wd = Whois::Domain.find_or_initialize_by(name: name) - wd.whois_body = whois_body - wd.save - end - - class << self - def convert_period_to_time(period, unit) - return period.to_i.days if unit == 'd' - return period.to_i.months if unit == 'm' - return period.to_i.years if unit == 'y' - end - end end diff --git a/spec/models/domain_spec.rb b/spec/models/domain_spec.rb index 84cfa495f..11d33b964 100644 --- a/spec/models/domain_spec.rb +++ b/spec/models/domain_spec.rb @@ -74,8 +74,8 @@ describe Domain do domain.errors.full_messages.should match_array(["Admin domain contacts is invalid"]) end - it 'should have whois_body' do - @domain.whois_body.present?.should == true + it 'should not have whois_body present by default' do + @domain.whois_body.present?.should == false end context 'with versioning' do