mirror of
https://github.com/internetee/registry.git
synced 2025-06-11 07:04:47 +02:00
parent
00041df311
commit
80327d3447
4 changed files with 17 additions and 2 deletions
|
@ -5,7 +5,7 @@ class Nameserver < ActiveRecord::Base
|
||||||
belongs_to :domain, required: true
|
belongs_to :domain, required: true
|
||||||
|
|
||||||
# rubocop: disable Metrics/LineLength
|
# 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/ }
|
validates :hostname, presence: true, 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/ }
|
||||||
validate :val_ipv4
|
validate :val_ipv4
|
||||||
validate :val_ipv6
|
validate :val_ipv6
|
||||||
# rubocop: enable Metrics/LineLength
|
# rubocop: enable Metrics/LineLength
|
||||||
|
@ -40,6 +40,8 @@ class Nameserver < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_label_length
|
def check_label_length
|
||||||
|
return unless hostname
|
||||||
|
|
||||||
hostname_puny.split('.').each do |label|
|
hostname_puny.split('.').each do |label|
|
||||||
errors.add(:hostname, :puny_to_long) if label.length > 63
|
errors.add(:hostname, :puny_to_long) if label.length > 63
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
class ChangeNameserversHostnameToNotNull < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
change_column_null :nameservers, :hostname, false
|
||||||
|
end
|
||||||
|
end
|
|
@ -2221,7 +2221,7 @@ ALTER SEQUENCE messages_id_seq OWNED BY messages.id;
|
||||||
|
|
||||||
CREATE TABLE nameservers (
|
CREATE TABLE nameservers (
|
||||||
id integer NOT NULL,
|
id integer NOT NULL,
|
||||||
hostname character varying,
|
hostname character varying NOT NULL,
|
||||||
ipv4 character varying[] DEFAULT '{}'::character varying[],
|
ipv4 character varying[] DEFAULT '{}'::character varying[],
|
||||||
created_at timestamp without time zone,
|
created_at timestamp without time zone,
|
||||||
updated_at timestamp without time zone,
|
updated_at timestamp without time zone,
|
||||||
|
@ -5082,3 +5082,5 @@ INSERT INTO schema_migrations (version) VALUES ('20180129143538');
|
||||||
|
|
||||||
INSERT INTO schema_migrations (version) VALUES ('20180129232054');
|
INSERT INTO schema_migrations (version) VALUES ('20180129232054');
|
||||||
|
|
||||||
|
INSERT INTO schema_migrations (version) VALUES ('20180129233223');
|
||||||
|
|
||||||
|
|
|
@ -14,4 +14,10 @@ class NameserverTest < ActiveSupport::TestCase
|
||||||
@nameserver.validate
|
@nameserver.validate
|
||||||
assert @nameserver.invalid?
|
assert @nameserver.invalid?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_invalid_without_hostname
|
||||||
|
@nameserver.hostname = nil
|
||||||
|
@nameserver.validate
|
||||||
|
assert @nameserver.invalid?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue