From 42f8e3d703082ae62f9c142f4fa588863aa930e5 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 3 Jan 2019 15:06:45 +0200 Subject: [PATCH] Add auction statuses --- app/models/whois_record.rb | 14 ++++--- .../{discarded.erb => inactive.erb} | 0 test/models/at_auction_record_test.rb | 11 ++++++ test/models/whois_record_test.rb | 39 +++++++++++++++++++ 4 files changed, 58 insertions(+), 6 deletions(-) rename app/views/whois_record/{discarded.erb => inactive.erb} (100%) create mode 100644 test/models/at_auction_record_test.rb diff --git a/app/models/whois_record.rb b/app/models/whois_record.rb index d64df56..ab3251b 100644 --- a/app/models/whois_record.rb +++ b/app/models/whois_record.rb @@ -5,9 +5,11 @@ class WhoisRecord < ActiveRecord::Base BLOCKED = 'Blocked'.freeze RESERVED = 'Reserved'.freeze DISCARDED = 'deleteCandidate'.freeze + AT_AUCTION = 'AtAuction'.freeze + PENDING_REGISTRATION = 'PendingRegistration'.freeze TEMPLATE_DIR = File.join(File.dirname(__FILE__), '../views/whois_record/').freeze - DISCARDED_TEMPLATE = (TEMPLATE_DIR + "discarded.erb").freeze + TEMPLATE_INACTIVE = (TEMPLATE_DIR + "inactive.erb").freeze LEGAL_PERSON_TEMPLATE = (TEMPLATE_DIR + "legal_person.erb").freeze PRIVATE_PERSON_TEMPLATE = (TEMPLATE_DIR + "private_person.erb").freeze @@ -17,10 +19,10 @@ def unix_body end def template - if discarded_blocked_or_reserved? - DISCARDED_TEMPLATE - else + if active? private_or_legal_person_template + else + TEMPLATE_INACTIVE end end @@ -60,7 +62,7 @@ def private_or_legal_person_template end end - def discarded_blocked_or_reserved? - !(([BLOCKED, RESERVED, DISCARDED] & json['status']).empty?) + def active? + (([BLOCKED, RESERVED, DISCARDED, AT_AUCTION, PENDING_REGISTRATION] & json['status']).empty?) end end diff --git a/app/views/whois_record/discarded.erb b/app/views/whois_record/inactive.erb similarity index 100% rename from app/views/whois_record/discarded.erb rename to app/views/whois_record/inactive.erb diff --git a/test/models/at_auction_record_test.rb b/test/models/at_auction_record_test.rb new file mode 100644 index 0000000..9e6829f --- /dev/null +++ b/test/models/at_auction_record_test.rb @@ -0,0 +1,11 @@ +require_relative '../test_helper' +require_relative '../../app/models/whois_record' + +class WhoisRecordAtAuctionTest < Minitest::Test + def setup + super + + end + + +end diff --git a/test/models/whois_record_test.rb b/test/models/whois_record_test.rb index 7d0d26f..97a1320 100644 --- a/test/models/whois_record_test.rb +++ b/test/models/whois_record_test.rb @@ -26,4 +26,43 @@ def test_deserializes_tech_contacts assert_equal 'Jack', contact.name assert_equal %w[one], contact.disclosed_attributes end + + def test_returns_inactive_record_unix_body_when_domain_is_at_auction + @whois_record = WhoisRecord.new(name: 'shop.test', json: { name: 'shop.test', + status: [WhoisRecord::AT_AUCTION] }) + + expected_output = begin + "Estonia .ee Top Level Domain WHOIS server\n" \ + "\n" \ + "Domain:\n" \ + "name: shop.test\n" \ + "status: AtAuction\n" \ + "\n" \ + "Estonia .ee Top Level Domain WHOIS server\n" \ + "More information at http://internet.ee\n" \ + "" + end + + assert_equal expected_output, @whois_record.unix_body + end + + def test_returns_inactive_record_unix_body_when_domain_is_pending_registration + @whois_record = WhoisRecord.new(name: 'shop.test', + json: { name: 'shop.test', + status: [WhoisRecord::PENDING_REGISTRATION] }) + + expected_output = begin + "Estonia .ee Top Level Domain WHOIS server\n" \ + "\n" \ + "Domain:\n" \ + "name: shop.test\n" \ + "status: PendingRegistration\n" \ + "\n" \ + "Estonia .ee Top Level Domain WHOIS server\n" \ + "More information at http://internet.ee\n" \ + "" + end + + assert_equal expected_output, @whois_record.unix_body + end end