From 39fad4515c8f5d91392f4039381b38f0a13ab0a7 Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Tue, 3 Feb 2015 10:34:12 +0200 Subject: [PATCH] Added whois_body --- app/models/domain.rb | 49 ++++++++++++++++++- .../whois/{public_domain.rb => domain.rb} | 2 +- app/models/whois/private_domain.rb | 5 -- app/models/whois/private_server.rb | 6 --- app/models/whois/public_server.rb | 6 --- app/models/whois/server.rb | 6 +++ config/application.rb | 2 + db/migrate/20150203074508_add_whois_body.rb | 5 ++ db/schema.rb | 3 +- spec/models/domain_spec.rb | 9 ++++ 10 files changed, 73 insertions(+), 20 deletions(-) rename app/models/whois/{public_domain.rb => domain.rb} (60%) delete mode 100644 app/models/whois/private_domain.rb delete mode 100644 app/models/whois/private_server.rb delete mode 100644 app/models/whois/public_server.rb create mode 100644 app/models/whois/server.rb create mode 100644 db/migrate/20150203074508_add_whois_body.rb diff --git a/app/models/domain.rb b/app/models/domain.rb index c08d4ce27..1fc279a52 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -51,11 +51,17 @@ class Domain < ActiveRecord::Base before_create :generate_auth_info before_create :set_validity_dates before_create :attach_default_contacts - after_save :manage_automatic_statuses before_save :touch_always_version def touch_always_version self.updated_at = Time.now end + before_save :update_whois_body + after_save :manage_automatic_statuses + after_save :delay_whois_server_update + def delay_whois_server_update + return if whois_body.blank? + delay.whois_server_update(name, whois_body) + end validates :name_dirty, domain_name: true, uniqueness: true validates :period, numericality: { only_integer: true } @@ -295,6 +301,47 @@ class Domain < ActiveRecord::Base log end + def update_whois_body + self.whois_body = <<-EOS + This Whois Server contains information on + Estonian Top Level Domain ee TLD + + domain: #{name} + registrar: #{registrar} + status: + registered: + changed: #{updated_at.to_s(:db)} + expire: + outzone: + delete: + + contact + name: + e-mail: + registrar: + created: + + contact: + + nsset: + nserver: + + registrar: + org: + url: + phone: + address: + created: + changed: + EOS + end + + def whois_server_update(name = name, whois_body = 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' diff --git a/app/models/whois/public_domain.rb b/app/models/whois/domain.rb similarity index 60% rename from app/models/whois/public_domain.rb rename to app/models/whois/domain.rb index 3c019eb02..5aa890af1 100644 --- a/app/models/whois/public_domain.rb +++ b/app/models/whois/domain.rb @@ -1,5 +1,5 @@ module Whois - class PublicDomain < PublicServer + class Domain < Whois::Server self.table_name = 'domains' end end diff --git a/app/models/whois/private_domain.rb b/app/models/whois/private_domain.rb deleted file mode 100644 index 9f3a79178..000000000 --- a/app/models/whois/private_domain.rb +++ /dev/null @@ -1,5 +0,0 @@ -module Whois - class PrivateDomain < PrivateServer - self.table_name = 'domains' - end -end diff --git a/app/models/whois/private_server.rb b/app/models/whois/private_server.rb deleted file mode 100644 index 385444902..000000000 --- a/app/models/whois/private_server.rb +++ /dev/null @@ -1,6 +0,0 @@ -module Whois - class PrivateServer < ActiveRecord::Base - self.abstract_class = true - # establish_connection :"#{Rails.env}_private_whois" - end -end diff --git a/app/models/whois/public_server.rb b/app/models/whois/public_server.rb deleted file mode 100644 index 579d99afb..000000000 --- a/app/models/whois/public_server.rb +++ /dev/null @@ -1,6 +0,0 @@ -module Whois - class PublicServer < ActiveRecord::Base - self.abstract_class = true - # establish_connection :"#{Rails.env}_public_whois" - end -end diff --git a/app/models/whois/server.rb b/app/models/whois/server.rb new file mode 100644 index 000000000..2cec52e4e --- /dev/null +++ b/app/models/whois/server.rb @@ -0,0 +1,6 @@ +module Whois + class Server < ActiveRecord::Base + self.abstract_class = true + establish_connection :"whois_#{Rails.env}" + end +end diff --git a/config/application.rb b/config/application.rb index 22245023d..6a0ba117e 100644 --- a/config/application.rb +++ b/config/application.rb @@ -39,6 +39,8 @@ module Registry # Instead, the errors will propagate normally just like in other Active Record callbacks. config.active_record.raise_in_transactional_callbacks = true + config.active_job.queue_adapter = :delayed_job + config.generators do |g| g.stylesheets false g.javascripts false diff --git a/db/migrate/20150203074508_add_whois_body.rb b/db/migrate/20150203074508_add_whois_body.rb new file mode 100644 index 000000000..cf29fc87e --- /dev/null +++ b/db/migrate/20150203074508_add_whois_body.rb @@ -0,0 +1,5 @@ +class AddWhoisBody < ActiveRecord::Migration + def change + add_column :domains, :whois_body, :text + end +end diff --git a/db/schema.rb b/db/schema.rb index 3ee58993c..c7ff5d055 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: 20150202084444) do +ActiveRecord::Schema.define(version: 20150203074508) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -199,6 +199,7 @@ ActiveRecord::Schema.define(version: 20150202084444) do t.string "period_unit", limit: 1 t.string "creator_str" t.string "updator_str" + t.text "whois_body" end create_table "epp_sessions", force: :cascade do |t| diff --git a/spec/models/domain_spec.rb b/spec/models/domain_spec.rb index e3c91cb1e..22192a6f9 100644 --- a/spec/models/domain_spec.rb +++ b/spec/models/domain_spec.rb @@ -33,6 +33,11 @@ describe Domain do it 'should not have any versions' do @domain.versions.should == [] end + + it 'should not have whois_body' do + @domain.whois_body.should == nil + end + end context 'with valid attributes' do @@ -51,6 +56,10 @@ describe Domain do @domain.errors.full_messages.should match_array([]) end + it 'should have whois_body' do + @domain.whois_body.present?.should == true + end + context 'with versioning' do it 'should not have one version' do with_versioning do