From e6405c5fc8582d67e9f6efe24bf513ee90d6bbe8 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Fri, 22 Mar 2019 16:26:55 +0200 Subject: [PATCH] Skip auction for blocked and reserved domains Closes #1120 --- app/models/concerns/domain/releasable.rb | 2 +- app/models/dns/domain_name.rb | 8 ++++++++ test/models/dns/domain_name_test.rb | 18 ++++++++++++++++++ .../domain/releasable/auctionable_test.rb | 18 ++++++++++++++++++ 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/app/models/concerns/domain/releasable.rb b/app/models/concerns/domain/releasable.rb index 84696784e6..c25af44bed 100644 --- a/app/models/concerns/domain/releasable.rb +++ b/app/models/concerns/domain/releasable.rb @@ -36,7 +36,7 @@ def releasable_domains def release if release_to_auction transaction do - domain_name.sell_at_auction + domain_name.sell_at_auction if domain_name.auctionable? destroy! end else diff --git a/app/models/dns/domain_name.rb b/app/models/dns/domain_name.rb index 3a45ddc745..a5b56df1b4 100644 --- a/app/models/dns/domain_name.rb +++ b/app/models/dns/domain_name.rb @@ -69,6 +69,10 @@ def reserved? ReservedDomain.where(name: name).any? end + def auctionable? + !not_auctionable? + end + def to_s name end @@ -77,6 +81,10 @@ def to_s attr_reader :name + def not_auctionable? + blocked? || reserved? + end + def zone_with_same_origin? DNS::Zone.where(origin: name).any? end diff --git a/test/models/dns/domain_name_test.rb b/test/models/dns/domain_name_test.rb index 4d66227d59..5385c1c0b5 100644 --- a/test/models/dns/domain_name_test.rb +++ b/test/models/dns/domain_name_test.rb @@ -141,4 +141,22 @@ def test_not_registered_when_domain_does_not_exist assert domain_name.not_registered? assert_not domain_name.registered? end + + def test_auctionable_when_not_blocked_or_reserved + domain_name = DNS::DomainName.new('shop.test') + assert_not domain_name.blocked? + assert_not domain_name.reserved? + + assert domain_name.auctionable? + end + + def test_not_auctionable_when_blocked + assert_equal 'blocked.test', blocked_domains(:one).name + assert_not DNS::DomainName.new('blocked.test').auctionable? + end + + def test_not_auctionable_when_reserved + assert_equal 'reserved.test', reserved_domains(:one).name + assert_not DNS::DomainName.new('reserved.test').auctionable? + end end diff --git a/test/models/domain/releasable/auctionable_test.rb b/test/models/domain/releasable/auctionable_test.rb index 9ed0abc7fc..751e0be88a 100644 --- a/test/models/domain/releasable/auctionable_test.rb +++ b/test/models/domain/releasable/auctionable_test.rb @@ -22,6 +22,24 @@ def test_sells_domain_at_auction assert @domain.domain_name.at_auction? end + def test_skips_auction_when_domains_is_blocked + assert_equal 'shop.test', @domain.name + blocked_domains(:one).update!(name: 'shop.test') + + @domain.release + + assert_not @domain.domain_name.at_auction? + end + + def test_skips_auction_when_domains_is_reserved + assert_equal 'shop.test', @domain.name + reserved_domains(:one).update!(name: 'shop.test') + + @domain.release + + assert_not @domain.domain_name.at_auction? + end + def test_deletes_registered_domain @domain.update!(delete_at: Time.zone.parse('2010-07-05 07:59')) travel_to Time.zone.parse('2010-07-05 08:00')