Browse Source

host name uniq validation

pull/1/head
Nicolae Claudius 12 years ago
parent
commit
7bc68d69d2
  1. 6
      app/models/a.rb
  2. 6
      spec/models/record_spec.rb

6
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"

6
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

Loading…
Cancel
Save