From 6437845d9b8ce3532c7c1338fcdf7e39bf206f85 Mon Sep 17 00:00:00 2001 From: Bill Thompson Date: Fri, 17 Feb 2017 13:56:30 -0600 Subject: [PATCH] Domain update_expired returns the domain's correct expiration date and status --- enom.gemspec | 2 +- lib/enom/domain.rb | 22 +++++++++++++++++++++- test/domain_test.rb | 9 +++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/enom.gemspec b/enom.gemspec index 835a93a..b5184af 100644 --- a/enom.gemspec +++ b/enom.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = "enom" - s.version = "1.1.8" + s.version = "1.1.9" s.authors = ["James Miller"] s.summary = %q{Ruby wrapper for the Enom API} s.description = %q{Enom is a Ruby wrapper and command line interface for portions of the Enom domain reseller API.} diff --git a/lib/enom/domain.rb b/lib/enom/domain.rb index add50b3..00bd9a0 100644 --- a/lib/enom/domain.rb +++ b/lib/enom/domain.rb @@ -1,5 +1,6 @@ require 'active_support' require 'active_support/core_ext/object/blank' +require 'active_support/core_ext/date/calculations' require "public_suffix" module Enom @@ -199,7 +200,22 @@ def self.update_expired!(name, years = 1) } response = Client.request(request_params) - response['interface_response']['ErrCount'] == "0" ? Domain.find(name) : false + if response['interface_response']['ErrCount'] != "0" + return false + end + + domain = Domain.find(name) + # Enom doesn't make the new registration date and status immediately available in the find request, so + # we patch that value into the object if necessary. + if (domain.expiration_date < Date.today) + domain.expiration_date = domain.expiration_date.advance(years: years) + end + + if (domain.registration_status == "Expired") + domain.registration_status = "Registered" + end + + domain end def self.valid_renewal_length?(years) @@ -342,6 +358,10 @@ def registration_status return @registration_status end + def registration_status=(status) + @registration_status = status + end + def active? registration_status == "Registered" end diff --git a/test/domain_test.rb b/test/domain_test.rb index c35318b..91ecac8 100644 --- a/test/domain_test.rb +++ b/test/domain_test.rb @@ -189,6 +189,15 @@ class DomainTest < Test::Unit::TestCase should "renew the domain and return a domain object" do assert_equal @domain.name, "test123456test123456.com" end + + should "return the domain reflecting the new expiration date" do + original_expiration_date = Enom::Domain.find('test123456test123456.com').expiration_date + assert_equal @domain.expiration_date, original_expiration_date.advance(years: 1) + end + + should "return the domain reflecting the new regisration status" do + assert_true @domain.registration_status == "Registered" + end end context "finding a domain in your account" do