From 4413a1bb271a9e2b4b75a1a11067dc95c59afb2b Mon Sep 17 00:00:00 2001 From: Maciej Szlosarczyk Date: Wed, 3 Apr 2019 15:14:10 +0300 Subject: [PATCH 1/4] Create whois records on releasing domain to auction --- app/controllers/api/v1/auctions_controller.rb | 2 +- app/models/dns/domain_name.rb | 5 ++++- test/models/dns/domain_name_test.rb | 16 +++++++++++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/v1/auctions_controller.rb b/app/controllers/api/v1/auctions_controller.rb index c27284b33..bf92be930 100644 --- a/app/controllers/api/v1/auctions_controller.rb +++ b/app/controllers/api/v1/auctions_controller.rb @@ -52,7 +52,7 @@ module Api end def update_whois_from_auction(auction) - whois_record = Whois::Record.find_or_create_by(name: auction.domain) do |record| + whois_record = Whois::Record.find_or_create_by!(name: auction.domain) do |record| record.json = {} end diff --git a/app/models/dns/domain_name.rb b/app/models/dns/domain_name.rb index 0381d6241..d2ca9fa50 100644 --- a/app/models/dns/domain_name.rb +++ b/app/models/dns/domain_name.rb @@ -92,7 +92,10 @@ module DNS end def update_whois_from_auction(auction) - whois_record = Whois::Record.find_by!(name: name) + whois_record = Whois::Record.find_or_create_by!(name: name) do |record| + record.json = {} + end + whois_record.update_from_auction(auction) end end diff --git a/test/models/dns/domain_name_test.rb b/test/models/dns/domain_name_test.rb index e8b33e316..5d0dd5386 100644 --- a/test/models/dns/domain_name_test.rb +++ b/test/models/dns/domain_name_test.rb @@ -92,6 +92,20 @@ class DNS::DomainNameTest < ActiveSupport::TestCase assert_equal Time.zone.parse('2010-07-05 10:00'), @whois_record.updated_at end + def test_selling_at_auction_creates_whois_record + travel_to Time.zone.parse('2010-07-05 10:00') + domain_name = DNS::DomainName.new('new-auction.test') + + domain_name.sell_at_auction + + whois_record = Whois::Record.find_by(name: 'new-auction.test') + assert whois_record + + assert_equal Time.zone.parse('2010-07-05 10:00'), whois_record.updated_at + assert_equal Time.zone.parse('2010-07-05 10:00'), whois_record.created_at + assert_equal ['AtAuction'], whois_record.json['status'] + end + def test_at_auction domain_name = DNS::DomainName.new('auction.test') auctions(:one).update!(domain: 'auction.test', status: Auction.statuses[:started]) @@ -162,4 +176,4 @@ class DNS::DomainNameTest < ActiveSupport::TestCase assert_equal 'reserved.test', reserved_domains(:one).name assert_not DNS::DomainName.new('reserved.test').auctionable? end -end \ No newline at end of file +end From 04af820b94c4d23cca8071cf1a4bd0265a4b4102 Mon Sep 17 00:00:00 2001 From: Maciej Szlosarczyk Date: Wed, 3 Apr 2019 15:14:50 +0300 Subject: [PATCH 2/4] Fix test title --- test/integration/epp/domain/create/auction_idn_test.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/integration/epp/domain/create/auction_idn_test.rb b/test/integration/epp/domain/create/auction_idn_test.rb index 5fa19fd60..52bc49a98 100644 --- a/test/integration/epp/domain/create/auction_idn_test.rb +++ b/test/integration/epp/domain/create/auction_idn_test.rb @@ -15,7 +15,7 @@ class EppDomainCreateAuctionIdnTest < ApplicationIntegrationTest Domain.release_to_auction = false end - def test_registers_domain_with_ascii_idn_cannot_be_registered_without_registration_code + def test_domain_with_ascii_idn_cannot_be_registered_without_registration_code @idn_auction.update!(status: Auction.statuses[:payment_received], registration_code: "auction001") @@ -53,7 +53,7 @@ class EppDomainCreateAuctionIdnTest < ApplicationIntegrationTest response_xml.at_css('result msg').text end - def test_registers_domain_with_unicode_idn_cannot_be_registered_without_registration_code + def test_domain_with_unicode_idn_cannot_be_registered_without_registration_code @idn_auction.update!(status: Auction.statuses[:payment_received], registration_code: "auction001") @@ -91,7 +91,7 @@ class EppDomainCreateAuctionIdnTest < ApplicationIntegrationTest response_xml.at_css('result msg').text end - def test_registers_domain_with_ascii_idn_cannot_be_registered_without_winning_the_auction + def test_domain_with_ascii_idn_cannot_be_registered_without_winning_the_auction @idn_auction.started! request_xml = <<-XML @@ -128,7 +128,7 @@ class EppDomainCreateAuctionIdnTest < ApplicationIntegrationTest response_xml.at_css('result msg').text end - def test_registers_domain_with_unicode_idn_cannot_be_registered_without_winning_the_auction + def test_domain_with_unicode_idn_cannot_be_registered_without_winning_the_auction @idn_auction.started! request_xml = <<-XML @@ -165,7 +165,7 @@ class EppDomainCreateAuctionIdnTest < ApplicationIntegrationTest response_xml.at_css('result msg').text end - def test_registers_domain_with_unicode_idn_cannot_be_registered_without_winning_the_auction + def test_domain_with_unicode_idn_cannot_be_registered_without_winning_the_auction @idn_auction.started! request_xml = <<-XML From d0f3ef0fa0504d54c7a7c6ff87edb430c7925b81 Mon Sep 17 00:00:00 2001 From: Maciej Szlosarczyk Date: Thu, 4 Apr 2019 16:31:11 +0300 Subject: [PATCH 3/4] Add explicit error at the end of update_from_auction method --- app/models/whois/record.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/models/whois/record.rb b/app/models/whois/record.rb index d94c723ad..11c191cbd 100644 --- a/app/models/whois/record.rb +++ b/app/models/whois/record.rb @@ -17,7 +17,9 @@ module Whois update!(json: { name: auction.domain, status: ['PendingRegistration'], disclaimer: self.class.disclaimer }) + else + raise "Unknown status: #{auction.status}" end end end -end \ No newline at end of file +end From 1147f7c5b7c7246feba9a9e7d61a449262dd9521 Mon Sep 17 00:00:00 2001 From: Maciej Szlosarczyk Date: Mon, 8 Apr 2019 08:59:42 +0300 Subject: [PATCH 4/4] Remove error raise put in previously for debugging --- app/models/whois/record.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/models/whois/record.rb b/app/models/whois/record.rb index 11c191cbd..ae7422403 100644 --- a/app/models/whois/record.rb +++ b/app/models/whois/record.rb @@ -17,8 +17,6 @@ module Whois update!(json: { name: auction.domain, status: ['PendingRegistration'], disclaimer: self.class.disclaimer }) - else - raise "Unknown status: #{auction.status}" end end end