Change domain registrar_id and registrant_id to NOT NULL

#480
This commit is contained in:
Artur Beljajev 2017-06-06 19:16:46 +03:00
parent b20e31f3c8
commit 930a59ae67
4 changed files with 34 additions and 17 deletions

View file

@ -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

View file

@ -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

View file

@ -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');

View file

@ -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 }