diff --git a/app/models/a.rb b/app/models/a.rb index f81eac8..b5e678d 100644 --- a/app/models/a.rb +++ b/app/models/a.rb @@ -17,7 +17,11 @@ class A < Record attr_accessor :host_domain validates :host_domain, :inclusion => {:in => Settings.host_domains}, :allow_blank => true - validates :name, :length => {:minimum => 4}, :if => :host? + validates :name, + :length => {:minimum => 4}, + :uniqueness => {:scope => [:domain_id, :type]}, + :if => :host? + validate do if host? && Settings.protected_hostnames.any? {|hn| name =~ /^#{hn}/i} errors[:name] << "cannot be used, please try another" diff --git a/spec/models/record_spec.rb b/spec/models/record_spec.rb index 0f0ce60..2e7a8b1 100644 --- a/spec/models/record_spec.rb +++ b/spec/models/record_spec.rb @@ -48,4 +48,10 @@ describe Record do query.to_sql.should == expected.gsub("\n", '').gsub(/\s+/, ' ').strip end + it "validates host a records dubles" do + host_a_record + host_a_record2 = build(:a, name: host_a_record.name, content: '127.0.0.2', domain: host_domain, user: user2) + host_a_record2.should have(1).errors_on(:name) + end + end