Require attribute

#660
This commit is contained in:
Artur Beljajev 2018-01-30 01:31:48 +02:00
parent 56e3f236bc
commit 00041df311
5 changed files with 30 additions and 3 deletions

View file

@ -2,7 +2,7 @@ class Nameserver < ActiveRecord::Base
include Versions # version/nameserver_version.rb
include EppErrors
belongs_to :domain
belongs_to :domain, required: true
# rubocop: disable Metrics/LineLength
validates :hostname, format: { with: /\A(([a-zA-Z0-9]|[a-zA-ZäöüõšžÄÖÜÕŠŽ0-9][a-zA-ZäöüõšžÄÖÜÕŠŽ0-9\-]*[a-zA-ZäöüõšžÄÖÜÕŠŽ0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])\z/ }

View file

@ -0,0 +1,5 @@
class ChangeNameserversDomainIdToNotNull < ActiveRecord::Migration
def change
change_column_null :nameservers, :domain_id, false
end
end

View file

@ -2226,7 +2226,7 @@ CREATE TABLE nameservers (
created_at timestamp without time zone,
updated_at timestamp without time zone,
ipv6 character varying[] DEFAULT '{}'::character varying[],
domain_id integer,
domain_id integer NOT NULL,
creator_str character varying,
updator_str character varying,
legacy_domain_id integer,
@ -3628,7 +3628,7 @@ ALTER TABLE ONLY settings
--
-- Name: unique_contact_code; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
-- Name: unique_contact_code; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
ALTER TABLE ONLY contacts
@ -5080,3 +5080,5 @@ INSERT INTO schema_migrations (version) VALUES ('20180126104903');
INSERT INTO schema_migrations (version) VALUES ('20180129143538');
INSERT INTO schema_migrations (version) VALUES ('20180129232054');

3
test/fixtures/nameservers.yml vendored Normal file
View file

@ -0,0 +1,3 @@
ns1:
hostname: ns1.bestnames.test
domain: shop

View file

@ -0,0 +1,17 @@
require 'test_helper'
class NameserverTest < ActiveSupport::TestCase
def setup
@nameserver = nameservers(:ns1)
end
def test_valid
assert @nameserver.valid?
end
def test_invalid_without_domain
@nameserver.domain = nil
@nameserver.validate
assert @nameserver.invalid?
end
end