Merge branch 'master' of github.com:domify/registry

This commit is contained in:
Martin Lensment 2015-02-03 11:20:00 +02:00
commit 2fb319bd96
10 changed files with 73 additions and 20 deletions

View file

@ -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'

View file

@ -1,5 +1,5 @@
module Whois
class PublicDomain < PublicServer
class Domain < Whois::Server
self.table_name = 'domains'
end
end

View file

@ -1,5 +0,0 @@
module Whois
class PrivateDomain < PrivateServer
self.table_name = 'domains'
end
end

View file

@ -1,6 +0,0 @@
module Whois
class PrivateServer < ActiveRecord::Base
self.abstract_class = true
# establish_connection :"#{Rails.env}_private_whois"
end
end

View file

@ -1,6 +0,0 @@
module Whois
class PublicServer < ActiveRecord::Base
self.abstract_class = true
# establish_connection :"#{Rails.env}_public_whois"
end
end

View file

@ -0,0 +1,6 @@
module Whois
class Server < ActiveRecord::Base
self.abstract_class = true
establish_connection :"whois_#{Rails.env}"
end
end

View file

@ -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

View file

@ -0,0 +1,5 @@
class AddWhoisBody < ActiveRecord::Migration
def change
add_column :domains, :whois_body, :text
end
end

View file

@ -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|

View file

@ -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