From f81daff3b22857bb10dc3345d8355bcdb4f307ad Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Thu, 21 Jul 2022 08:43:57 +0300 Subject: [PATCH 1/2] added exception for auctions with no-bids and registred-domains statuses --- app/controllers/admin/auctions_controller.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/controllers/admin/auctions_controller.rb b/app/controllers/admin/auctions_controller.rb index c1023b705..b987bc133 100644 --- a/app/controllers/admin/auctions_controller.rb +++ b/app/controllers/admin/auctions_controller.rb @@ -111,7 +111,18 @@ module Admin Domain.exists?(name: domain_name) || BlockedDomain.exists?(name: domain_name) || Dispute.exists?(domain_name: domain_name) || - Auction.exists?(domain: domain_name) + exception_for_registred_or_unbided_existed_auctions(domain_name) + end + + def exception_for_registred_or_unbided_existed_auctions(domain_name) + return false unless Auction.exists?(domain: domain_name) + + auctions = Auction.where(domain: domain_name).order(:created_at) + last_record = auctions.last + + return false if last_record.domain_registered? || last_record.no_bids? + + true end def validate_table(table) From 0c7915811f9855b995d9120e741e48bb2a805d6f Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Thu, 21 Jul 2022 16:19:07 +0300 Subject: [PATCH 2/2] move restriction check from controller to model, added tests --- app/controllers/admin/auctions_controller.rb | 22 +--------- app/models/auction.rb | 18 ++++++++ test/models/auction_test.rb | 45 ++++++++++++++++++++ 3 files changed, 65 insertions(+), 20 deletions(-) diff --git a/app/controllers/admin/auctions_controller.rb b/app/controllers/admin/auctions_controller.rb index b987bc133..80f0d1a0b 100644 --- a/app/controllers/admin/auctions_controller.rb +++ b/app/controllers/admin/auctions_controller.rb @@ -31,7 +31,7 @@ module Admin def create auction = Auction.new(domain: params[:domain], status: Auction.statuses[:started], platform: 'manual') - if domain_exists_in_blocked_disputed_and_registered?(params[:domain]) + if Auction.domain_exists_in_blocked_disputed_and_registered?(params[:domain]) flash[:alert] = "Adding #{params[:domain]} failed - domain registered or regsitration is blocked" redirect_to admin_auctions_path and return end @@ -69,7 +69,7 @@ module Admin table.each do |row| record = row.to_h - if domain_exists_in_blocked_disputed_and_registered?(record['name']) + if Auction.domain_exists_in_blocked_disputed_and_registered?(record['name']) failed_names << record['name'] next @@ -107,24 +107,6 @@ module Admin Epp::Domain.check_availability(domain_name) end - def domain_exists_in_blocked_disputed_and_registered?(domain_name) - Domain.exists?(name: domain_name) || - BlockedDomain.exists?(name: domain_name) || - Dispute.exists?(domain_name: domain_name) || - exception_for_registred_or_unbided_existed_auctions(domain_name) - end - - def exception_for_registred_or_unbided_existed_auctions(domain_name) - return false unless Auction.exists?(domain: domain_name) - - auctions = Auction.where(domain: domain_name).order(:created_at) - last_record = auctions.last - - return false if last_record.domain_registered? || last_record.no_bids? - - true - end - def validate_table(table) first_row = table.headers first_row.include? 'name' diff --git a/app/models/auction.rb b/app/models/auction.rb index 465a827ec..9a2680c43 100644 --- a/app/models/auction.rb +++ b/app/models/auction.rb @@ -37,6 +37,24 @@ class Auction < ApplicationRecord find_by(domain: domain_name.to_s, status: PENDING_STATUSES) end + def self.domain_exists_in_blocked_disputed_and_registered?(domain_name) + Domain.exists?(name: domain_name) || + BlockedDomain.exists?(name: domain_name) || + Dispute.exists?(domain_name: domain_name) || + exception_for_registred_or_unbided_existed_auctions(domain_name) + end + + def self.exception_for_registred_or_unbided_existed_auctions(domain_name) + return false unless Auction.exists?(domain: domain_name) + + auctions = Auction.where(domain: domain_name).order(:created_at) + last_record = auctions.last + + return false if last_record.domain_registered? || last_record.no_bids? + + true + end + def start self.status = self.class.statuses[:started] save! diff --git a/test/models/auction_test.rb b/test/models/auction_test.rb index bdac5c79d..45197f1a3 100644 --- a/test/models/auction_test.rb +++ b/test/models/auction_test.rb @@ -28,6 +28,51 @@ class AuctionTest < ActiveSupport::TestCase assert @auction.started? end + def test_auction_with_no_bids_dont_have_any_restriction + @auction.update(status: :no_bids) + @auction.reload + + res = Auction.domain_exists_in_blocked_disputed_and_registered?(@auction.domain) + refute res + end + + def test_auction_with_domain_registered_dont_have_any_restriction + @auction.update(status: :domain_registered) + @auction.reload + + res = Auction.domain_exists_in_blocked_disputed_and_registered?(@auction.domain) + refute res + end + + def test_auction_with_started_has_restriction + @auction.update(status: :started) + @auction.reload + + res = Auction.domain_exists_in_blocked_disputed_and_registered?(@auction.domain) + assert res + end + + def test_blocked_domain_has_restriction + blocked_domain = blocked_domains(:one) + + res = Auction.domain_exists_in_blocked_disputed_and_registered?(blocked_domain.name) + assert res + end + + def test_dispute_domain_has_restriction + dispute_domain = disputes(:active) + + res = Auction.domain_exists_in_blocked_disputed_and_registered?(dispute_domain.domain_name) + assert res + end + + def test_exist_domain_has_restriction + domain = domains(:shop) + + res = Auction.domain_exists_in_blocked_disputed_and_registered?(domain.name) + assert res + end + def test_pending domain_name = DNS::DomainName.new('auction.test') assert_equal 'auction.test', @auction.domain