Skip to content

Commit

Permalink
Merge pull request #63 from internetee/15-disputed-status
Browse files Browse the repository at this point in the history
Allow WhoisRecord with reserved status to be both active/inactive
  • Loading branch information
vohmar authored May 22, 2020
2 parents aacfaae + c0f2f90 commit 9a86a48
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
13 changes: 9 additions & 4 deletions app/models/whois_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ class WhoisRecord < ActiveRecord::Base
DISCARDED = 'deleteCandidate'.freeze
AT_AUCTION = 'AtAuction'.freeze
PENDING_REGISTRATION = 'PendingRegistration'.freeze
DISPUTED = 'Disputed'.freeze

TEMPLATE_DIR = File.join(File.dirname(__FILE__), '../views/whois_record/').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

INACTIVE_STATUSES = [BLOCKED, DISCARDED, AT_AUCTION, PENDING_REGISTRATION].freeze

def unix_body
file = File.new(template)
ERB.new(file.read, nil, "-").result(binding)
Expand All @@ -38,6 +41,12 @@ def tech_contacts
json['tech_contacts'].map { |serialized_contact| deserialize_contact(serialized_contact) }
end

def active?
return false if json['registered'].nil?

(json['status'] & INACTIVE_STATUSES).empty?
end

private

def deserialize_registrant
Expand All @@ -61,8 +70,4 @@ def private_or_legal_person_template
LEGAL_PERSON_TEMPLATE
end
end

def active?
(([BLOCKED, RESERVED, DISCARDED, AT_AUCTION, PENDING_REGISTRATION] & json['status']).empty?)
end
end
31 changes: 31 additions & 0 deletions test/models/whois_record_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,35 @@ def test_returns_inactive_record_unix_body_when_domain_is_pending_registration

assert_equal expected_output, @whois_record.unix_body
end

def test_reserved_record_is_active_if_registered
@whois_record = WhoisRecord.new(name: 'shop.test',
json: { name: 'shop.test',
registered: Time.now,
status: [WhoisRecord::RESERVED] })
assert @whois_record.active?
end

def test_reserved_record_is_inactive_if_unregistered
@whois_record = WhoisRecord.new(name: 'shop.test',
json: { name: 'shop.test',
status: [WhoisRecord::RESERVED] })
assert !@whois_record.active?
end

def test_disputed_record_is_active_if_registered
@whois_record = WhoisRecord.new(name: 'shop.test',
json: { name: 'shop.test',
registered: Time.now,
status: [WhoisRecord::DISPUTED] })
assert @whois_record.active?
end

def test_disputed_record_is_inactive_if_unregistered
@whois_record = WhoisRecord.new(name: 'shop.test',
json: { name: 'shop.test',
status: [WhoisRecord::DISPUTED] })
assert !@whois_record.active?
end

end

0 comments on commit 9a86a48

Please sign in to comment.