From a0029d0a8058d1802074c31cba5fbe1cb86fc1e7 Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Thu, 27 Aug 2020 13:04:43 +0500 Subject: [PATCH] Fix error if domain name was nil. Used for some old history entries Closes #1663 --- app/models/domain.rb | 4 ++-- test/models/domain_test.rb | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/models/domain.rb b/app/models/domain.rb index a97a2bc8a..c60d11f3f 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -260,8 +260,8 @@ class Domain < ApplicationRecord end def name=(value) - value.strip! - value.downcase! + value&.strip! + value&.downcase! self[:name] = SimpleIDN.to_unicode(value) self[:name_puny] = SimpleIDN.to_ascii(value) self[:name_dirty] = value diff --git a/test/models/domain_test.rb b/test/models/domain_test.rb index 28083f9cc..ec6f60c52 100644 --- a/test/models/domain_test.rb +++ b/test/models/domain_test.rb @@ -270,6 +270,13 @@ class DomainTest < ActiveSupport::TestCase assert_equal 'shop.test', domain.domain_name.to_s end + def test_nil_name_doesnt_throw_error + domain = Domain.new(name: 'shop.test') + assert_nothing_raised do + domain.name = nil + end + end + def test_returns_registrant_user_domains_by_registrant registrant = contacts(:john).becomes(Registrant) assert_equal registrant, @domain.registrant