From d590b5d9375eaba621a8bce933179ca3c55bde79 Mon Sep 17 00:00:00 2001 From: Maciej Szlosarczyk Date: Mon, 1 Apr 2019 10:24:54 +0300 Subject: [PATCH 1/3] On status update, create WHOIS records for domains in auction Should fix sporadic errors we are seeing with the integration --- app/controllers/api/v1/auctions_controller.rb | 5 ++++- test/integration/api/v1/auctions/update_test.rb | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/v1/auctions_controller.rb b/app/controllers/api/v1/auctions_controller.rb index 5d896e1af5..558b801364 100644 --- a/app/controllers/api/v1/auctions_controller.rb +++ b/app/controllers/api/v1/auctions_controller.rb @@ -52,7 +52,10 @@ def serializable_hash_for_update_action(auction) end def update_whois_from_auction(auction) - whois_record = Whois::Record.find_by!(name: auction.domain) + whois_record = Whois::Record.find_or_create_by(name: auction.domain) do |record| + record.body = {} + end + whois_record.update_from_auction(auction) end end diff --git a/test/integration/api/v1/auctions/update_test.rb b/test/integration/api/v1/auctions/update_test.rb index 262b11cdfc..64b3a92f56 100644 --- a/test/integration/api/v1/auctions/update_test.rb +++ b/test/integration/api/v1/auctions/update_test.rb @@ -98,6 +98,19 @@ def test_updates_whois assert_equal Time.zone.parse('2010-07-05 10:00'), @whois_record.updated_at end + def test_creates_whois_record_if_does_not_exist + travel_to Time.zone.parse('2010-07-05 10:00') + assert_equal 'auction.test', @auction.domain + @whois_record.delete + + patch api_v1_auction_path(@auction.uuid), { status: Auction.statuses[:payment_received] } + .to_json, 'Content-Type' => Mime::JSON.to_s + + new_whois_record = Whois::Record.find_by(name: @auction.domain) + assert_equal Time.zone.parse('2010-07-05 10:00'), new_whois_record.updated_at + assert_equal ['PendingRegistration'], new_whois_record.json['status'] + end + def test_inaccessible_when_ip_address_is_not_allowed ENV['auction_api_allowed_ips'] = '' @@ -113,4 +126,4 @@ def test_auction_not_found 'Content-Type' => Mime::JSON.to_s end end -end \ No newline at end of file +end From 63efb48a2a69d5d380ff884b6e29b381ec24593f Mon Sep 17 00:00:00 2001 From: Maciej Szlosarczyk Date: Mon, 1 Apr 2019 14:30:28 +0300 Subject: [PATCH 2/3] replace body with JSON --- app/controllers/api/v1/auctions_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/v1/auctions_controller.rb b/app/controllers/api/v1/auctions_controller.rb index 558b801364..c27284b33a 100644 --- a/app/controllers/api/v1/auctions_controller.rb +++ b/app/controllers/api/v1/auctions_controller.rb @@ -53,7 +53,7 @@ def serializable_hash_for_update_action(auction) def update_whois_from_auction(auction) whois_record = Whois::Record.find_or_create_by(name: auction.domain) do |record| - record.body = {} + record.json = {} end whois_record.update_from_auction(auction) From e9a39bdc3b6afd2046ea7784954d4ef88a3865ca Mon Sep 17 00:00:00 2001 From: Maciej Szlosarczyk Date: Mon, 1 Apr 2019 14:45:55 +0300 Subject: [PATCH 3/3] Keep whois schema up to date with actual whois schema --- db/whois_schema.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/db/whois_schema.rb b/db/whois_schema.rb index 2857c62a40..7d3756dc13 100644 --- a/db/whois_schema.rb +++ b/db/whois_schema.rb @@ -41,7 +41,6 @@ create_table "whois_records", force: :cascade do |t| t.string "name" - t.text "body" t.json "json" t.datetime "created_at", null: false t.datetime "updated_at", null: false