From 930a59ae67c3daab6ca3a6984a2c7cbe586972c9 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 6 Jun 2017 19:16:46 +0300 Subject: [PATCH] Change domain registrar_id and registrant_id to NOT NULL #480 --- app/models/domain.rb | 7 ++-- ...in_registrar_and_registrant_to_not_null.rb | 6 ++++ db/structure.sql | 6 ++-- spec/models/domain_spec.rb | 32 ++++++++++++------- 4 files changed, 34 insertions(+), 17 deletions(-) create mode 100644 db/migrate/20170606150352_change_domain_registrar_and_registrant_to_not_null.rb diff --git a/app/models/domain.rb b/app/models/domain.rb index 172ab2039..6d16d617f 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -19,8 +19,8 @@ class Domain < ActiveRecord::Base # TODO: whois requests ip whitelist for full info for own domains and partial info for other domains # TODO: most inputs should be trimmed before validatation, probably some global logic? - belongs_to :registrar - belongs_to :registrant + belongs_to :registrar, required: true + belongs_to :registrant, required: true # TODO: should we user validates_associated :registrant here? has_many :admin_domain_contacts @@ -104,8 +104,7 @@ class Domain < ActiveRecord::Base validates :name_dirty, domain_name: true, uniqueness: true validates :puny_label, length: { maximum: 63 } - validates :period, numericality: { only_integer: true } - validates :registrant, :registrar, presence: true + validates :period, presence: true, numericality: { only_integer: true } validate :validate_reservation def validate_reservation diff --git a/db/migrate/20170606150352_change_domain_registrar_and_registrant_to_not_null.rb b/db/migrate/20170606150352_change_domain_registrar_and_registrant_to_not_null.rb new file mode 100644 index 000000000..d2cdfa114 --- /dev/null +++ b/db/migrate/20170606150352_change_domain_registrar_and_registrant_to_not_null.rb @@ -0,0 +1,6 @@ +class ChangeDomainRegistrarAndRegistrantToNotNull < ActiveRecord::Migration + def change + change_column :domains, :registrar_id, :integer, null: false + change_column :domains, :registrant_id, :integer, null: false + end +end diff --git a/db/structure.sql b/db/structure.sql index 2e0ee39dd..a6c0bc1c4 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -1033,12 +1033,12 @@ ALTER SEQUENCE domain_transfers_id_seq OWNED BY domain_transfers.id; CREATE TABLE domains ( id integer NOT NULL, name character varying, - registrar_id integer, + registrar_id integer NOT NULL, registered_at timestamp without time zone, status character varying, valid_from timestamp without time zone, valid_to timestamp without time zone, - registrant_id integer, + registrant_id integer NOT NULL, auth_info character varying, created_at timestamp without time zone, updated_at timestamp without time zone, @@ -5154,3 +5154,5 @@ INSERT INTO schema_migrations (version) VALUES ('20170509215614'); INSERT INTO schema_migrations (version) VALUES ('20170606133501'); +INSERT INTO schema_migrations (version) VALUES ('20170606150352'); + diff --git a/spec/models/domain_spec.rb b/spec/models/domain_spec.rb index 10898793f..8d24a4312 100644 --- a/spec/models/domain_spec.rb +++ b/spec/models/domain_spec.rb @@ -33,16 +33,6 @@ RSpec.describe Domain do @domain = Domain.new end - it 'should not be valid' do - @domain.valid? - @domain.errors.full_messages.should match_array([ - "Admin domain contacts Admin contacts count must be between 1-10", - "Period Period is not a number", - "Registrant Registrant is missing", - "Registrar Registrar is missing" - ]) - end - it 'should not have any versions' do @domain.versions.should == [] end @@ -599,10 +589,30 @@ RSpec.describe Domain do end end -RSpec.describe Domain, db: false do +RSpec.describe Domain do it { is_expected.to alias_attribute(:on_hold_time, :outzone_at) } it { is_expected.to alias_attribute(:outzone_time, :outzone_at) } + describe 'registrar validation', db: false do + let(:domain) { described_class.new } + + it 'rejects absent' do + domain.registrar = nil + domain.validate + expect(domain.errors).to have_key(:registrar) + end + end + + describe 'registrant validation', db: false do + let(:domain) { described_class.new } + + it 'rejects absent' do + domain.registrant = nil + domain.validate + expect(domain.errors).to have_key(:registrant) + end + end + describe 'nameserver validation', db: true do let(:domain) { described_class.new }