From be057656e869d85e2a0da7f6e33b8e390cbcc11b Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Mon, 22 Jan 2018 13:03:34 +0200 Subject: [PATCH] Always require domain#transfer_code #660 --- app/models/domain.rb | 1 + ...180122105335_change_domains_transfer_code_to_not_null.rb | 5 +++++ db/structure.sql | 4 +++- test/models/domain_test.rb | 6 ++++++ 4 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20180122105335_change_domains_transfer_code_to_not_null.rb diff --git a/app/models/domain.rb b/app/models/domain.rb index 31ef08cca..3a120d214 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -104,6 +104,7 @@ class Domain < ActiveRecord::Base validates :name_dirty, domain_name: true, uniqueness: true validates :puny_label, length: { maximum: 63 } validates :period, presence: true, numericality: { only_integer: true } + validates :transfer_code, presence: true validate :validate_reservation def validate_reservation diff --git a/db/migrate/20180122105335_change_domains_transfer_code_to_not_null.rb b/db/migrate/20180122105335_change_domains_transfer_code_to_not_null.rb new file mode 100644 index 000000000..e4ee8fbc9 --- /dev/null +++ b/db/migrate/20180122105335_change_domains_transfer_code_to_not_null.rb @@ -0,0 +1,5 @@ +class ChangeDomainsTransferCodeToNotNull < ActiveRecord::Migration + def change + change_column_null :domains, :transfer_code, false + end +end diff --git a/db/structure.sql b/db/structure.sql index 3f3c2b7f2..8e7d649bf 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -998,7 +998,7 @@ CREATE TABLE domains ( valid_from timestamp without time zone, valid_to timestamp without time zone, registrant_id integer NOT NULL, - transfer_code character varying, + transfer_code character varying NOT NULL, created_at timestamp without time zone, updated_at timestamp without time zone, name_dirty character varying, @@ -5048,3 +5048,5 @@ INSERT INTO schema_migrations (version) VALUES ('20180120183441'); INSERT INTO schema_migrations (version) VALUES ('20180121165304'); +INSERT INTO schema_migrations (version) VALUES ('20180122105335'); + diff --git a/test/models/domain_test.rb b/test/models/domain_test.rb index c01980601..3d60ed515 100644 --- a/test/models/domain_test.rb +++ b/test/models/domain_test.rb @@ -9,6 +9,12 @@ class DomainTest < ActiveSupport::TestCase assert @domain.valid? end + def test_rejects_absent_transfer_code + @domain.transfer_code = nil + @domain.validate + assert @domain.invalid? + end + def test_generates_random_transfer_code_if_new domain = Domain.new another_domain = Domain.new