Remove unused whois_records.body DB column

Part of https://github.com/internetee/rest-whois/issues/131
This commit is contained in:
Artur Beljajev 2018-11-08 00:44:19 +02:00
parent dea84915b5
commit 1a1c3c7d85
8 changed files with 1 additions and 127 deletions

View file

@ -25,18 +25,11 @@ class BlockedDomain < ActiveRecord::Base
wr = Whois::Record.find_or_initialize_by(name: name) wr = Whois::Record.find_or_initialize_by(name: name)
wr.json = @json = generate_json # we need @json to bind to class wr.json = @json = generate_json # we need @json to bind to class
wr.body = generate_body
wr.save wr.save
end end
alias_method :update_whois_record, :generate_data alias_method :update_whois_record, :generate_data
def generate_body
template = Rails.root.join("app/views/for_models/whois_other.erb".freeze)
ERB.new(template.read, nil, "-").result(binding)
end
def generate_json def generate_json
h = HashWithIndifferentAccess.new h = HashWithIndifferentAccess.new
h[:name] = self.name h[:name] = self.name

View file

@ -51,17 +51,10 @@ class ReservedDomain < ActiveRecord::Base
wr = Whois::Record.find_or_initialize_by(name: name) wr = Whois::Record.find_or_initialize_by(name: name)
wr.json = @json = generate_json # we need @json to bind to class wr.json = @json = generate_json # we need @json to bind to class
wr.body = generate_body
wr.save wr.save
end end
alias_method :update_whois_record, :generate_data alias_method :update_whois_record, :generate_data
def generate_body
template = Rails.root.join("app/views/for_models/whois_other.erb".freeze)
ERB.new(template.read, nil, "-").result(binding)
end
def generate_json def generate_json
h = HashWithIndifferentAccess.new h = HashWithIndifferentAccess.new
h[:name] = self.name h[:name] = self.name

View file

@ -3,7 +3,7 @@ class WhoisRecord < ActiveRecord::Base
belongs_to :domain belongs_to :domain
belongs_to :registrar belongs_to :registrar
validates :domain, :name, :body, :json, presence: true validates :domain, :name, :json, presence: true
before_validation :populate before_validation :populate
after_save :update_whois_server after_save :update_whois_server
@ -87,23 +87,15 @@ class WhoisRecord < ActiveRecord::Base
h h
end end
def generated_body
template_name = domain.discarded? ? 'whois_discarded.erb' : 'whois.erb'
template = Rails.root.join("app/views/for_models/#{template_name}".freeze)
ERB.new(template.read, nil, "-").result(binding)
end
def populate def populate
return if domain_id.blank? return if domain_id.blank?
self.json = generated_json self.json = generated_json
self.body = generated_body
self.name = json['name'] self.name = json['name']
self.registrar_id = domain.registrar_id if domain # for faster registrar updates self.registrar_id = domain.registrar_id if domain # for faster registrar updates
end end
def update_whois_server def update_whois_server
wd = Whois::Record.find_or_initialize_by(name: name) wd = Whois::Record.find_or_initialize_by(name: name)
wd.body = body
wd.json = json wd.json = json
wd.save wd.save
end end

View file

@ -1,67 +0,0 @@
<%- if json['disclaimer'].present? -%>
<%= json['disclaimer'].scan(/\S.{0,72}\S(?=\s|$)|\S+/).join("\n") %>
<%- end -%>
Estonia .ee Top Level Domain WHOIS server
Domain:
name: <%= json['name'] %>
<%- for st in Array(json['status']) -%>
status: <%= st %>
<%- end -%>
registered: <%= json['registered'].to_s.tr('T',' ').sub('+', ' +') %>
changed: <%= json['changed'].to_s.tr('T',' ').sub('+', ' +') %>
expire: <%= json['expire'].to_s.tr('T',' ').sub('+', ' +') %>
outzone: <%= json['outzone'].to_s.tr('T',' ').sub('+', ' +') %>
delete: <%= json['delete'].to_s.tr('T',' ').sub('+', ' +') %>
Registrant:
name: <%= json['registrant'] %>
<% if json['registrant_kind'] != 'priv' -%>
org id: <%= json['registrant_reg_no'] %>
country: <%= json['registrant_ident_country_code'] %>
<% end -%>
email: Not Disclosed - Visit www.internet.ee for webbased WHOIS
changed: <%= json['registrant_changed'].to_s.tr('T',' ').sub('+', ' +') %>
<%- if json['admin_contacts'].present? -%>
Administrative contact:
<%- for contact in json['admin_contacts'] -%>
name: Not Disclosed
email: Not Disclosed - Visit www.internet.ee for webbased WHOIS
changed: Not Disclosed
<%- end -%>
<%- end -%>
<% if json['tech_contacts'].present? %>
Technical contact:
<%- for contact in json['tech_contacts'] -%>
name: Not Disclosed
email: Not Disclosed - Visit www.internet.ee for webbased WHOIS
changed: Not Disclosed
<%- end -%>
<%- end -%>
Registrar:
name: <%= json['registrar'] %>
url: <%= json['registrar_website'] %>
phone: <%= json['registrar_phone'] %>
changed: <%= json['registrar_changed'].to_s.tr('T',' ').sub('+', ' +') %>
<%- if json['nameservers'].present? -%>
Name servers:
<%- for server in json['nameservers'] -%>
nserver: <%= server %>
<%- end -%>
changed: <%= json['nameservers_changed'].to_s.tr('T',' ').sub('+', ' +') %>
<%- end -%>
<%- if json['dnssec_keys'].present? -%>
DNSSEC:
<%- for key in json['dnssec_keys'] -%>
dnskey: <%= key %>
<%- end -%>
changed: <%= json['dnssec_changed'].to_s.tr('T',' ').sub('+', ' +') %>
<%- end -%>
Estonia .ee Top Level Domain WHOIS server
More information at http://internet.ee

View file

@ -1,8 +0,0 @@
Estonia .ee Top Level Domain WHOIS server
Domain:
name: <%= json['name'] %>
status: <%= json['status'] %>
Estonia .ee Top Level Domain WHOIS server
More information at http://internet.ee

View file

@ -1,8 +0,0 @@
Estonia .ee Top Level Domain WHOIS server
Domain:
name: <%= @json['name'] %>
status: <%= @json['status'] %>
Estonia .ee Top Level Domain WHOIS server
More information at http://internet.ee

View file

@ -1,6 +1,5 @@
shop: shop:
name: shop.test name: shop.test
domain: shop domain: shop
body: WHOIS text
json: json:
name: shop.test name: shop.test

View file

@ -32,29 +32,9 @@ class WhoisRecordTest < ActiveSupport::TestCase
end end
end end
def test_generated_body_has_justified_disclaimer
expected_disclaimer = begin
'Search results may not be used for commercial, advertising, recompilation,\n' \
'repackaging, redistribution, reuse, obscuring or other similar activities.'
end
expected_technical_contact = begin
'Technical contact:\n' \
'name: Not Disclosed\n' \
'email: Not Disclosed - Visit www.internet.ee for webbased WHOIS\n' \
'changed: Not Disclosed'
end
regexp_contact = Regexp.new(expected_technical_contact, Regexp::MULTILINE)
regexp_disclaimer = Regexp.new(expected_disclaimer, Regexp::MULTILINE)
assert_match(regexp_disclaimer, @record.body)
assert_match(regexp_contact, @record.body)
end
def test_whois_record_has_no_disclaimer_if_Setting_is_blank def test_whois_record_has_no_disclaimer_if_Setting_is_blank
Setting.stubs(:registry_whois_disclaimer, '') do Setting.stubs(:registry_whois_disclaimer, '') do
refute(@record.json['disclaimer']) refute(@record.json['disclaimer'])
refute_match(/Search results may not be used for commercial/, @record.body)
end end
end end