mirror of
https://github.com/internetee/registry.git
synced 2025-08-05 09:21:43 +02:00
Merge branch 'registry-475-refactor-zones' into registry-475
# Conflicts: # db/schema-read-only.rb # db/structure.sql
This commit is contained in:
commit
dbca4d010a
12 changed files with 165 additions and 24 deletions
|
@ -10,4 +10,93 @@ RSpec.describe DNS::Zone do
|
|||
expect(described_class.origins).to eq('origins')
|
||||
end
|
||||
end
|
||||
|
||||
describe 'validation' do
|
||||
let(:zone) { described_class.new }
|
||||
|
||||
required_attributes = %i[
|
||||
origin
|
||||
ttl
|
||||
refresh
|
||||
retry
|
||||
expire
|
||||
minimum_ttl
|
||||
email
|
||||
master_nameserver
|
||||
]
|
||||
|
||||
required_attributes.each do |attr_name|
|
||||
it "rejects absent #{attr_name}", db: false do
|
||||
zone.send("#{attr_name}=", nil)
|
||||
zone.validate
|
||||
expect(zone.errors).to have_key(attr_name)
|
||||
end
|
||||
end
|
||||
|
||||
integer_attributes = %i[
|
||||
ttl
|
||||
refresh
|
||||
retry
|
||||
expire
|
||||
minimum_ttl
|
||||
]
|
||||
|
||||
integer_attributes.each do |attr_name|
|
||||
it "rejects non-integer #{attr_name}", db: false do
|
||||
zone.send("#{attr_name}=", 'test')
|
||||
zone.validate
|
||||
expect(zone.errors).to have_key(attr_name)
|
||||
end
|
||||
|
||||
it "accepts integer #{attr_name}", db: false do
|
||||
zone.send("#{attr_name}=", '1')
|
||||
zone.validate
|
||||
expect(zone.errors).to_not have_key(attr_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#used?', db: false do
|
||||
let!(:zone) { described_class.new }
|
||||
|
||||
context 'when domain uses zone' do
|
||||
before :example do
|
||||
allow(Domain).to receive(:uses_zone?).and_return(true)
|
||||
end
|
||||
|
||||
specify { expect(zone).to be_used }
|
||||
end
|
||||
|
||||
context 'when domain does not use zone' do
|
||||
before :example do
|
||||
allow(Domain).to receive(:uses_zone?).and_return(false)
|
||||
end
|
||||
|
||||
specify { expect(zone).to_not be_used }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'deletion', settings: false do
|
||||
let!(:zone) { create(:zone) }
|
||||
|
||||
context 'when zone is unused' do
|
||||
before :example do
|
||||
allow(zone).to receive(:used?).and_return(false)
|
||||
end
|
||||
|
||||
it 'is allowed' do
|
||||
expect { zone.destroy }.to change { described_class.count }.from(1).to(0)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when zone is used' do
|
||||
before :example do
|
||||
allow(zone).to receive(:used?).and_return(true)
|
||||
end
|
||||
|
||||
it 'is disallowed' do
|
||||
expect { zone.destroy }.to_not change { described_class.count }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -837,6 +837,19 @@ RSpec.describe Domain, db: false do
|
|||
end
|
||||
end
|
||||
|
||||
describe '::uses_zone?', db: true do
|
||||
let!(:zone) { create(:zone, origin: 'domain.tld') }
|
||||
|
||||
context 'when zone is used' do
|
||||
let!(:domain) { create(:domain, name: 'test.domain.tld') }
|
||||
specify { expect(described_class.uses_zone?(zone)).to be true }
|
||||
end
|
||||
|
||||
context 'when zone is unused' do
|
||||
specify { expect(described_class.uses_zone?(zone)).to be false }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#new_registrant_email' do
|
||||
let(:domain) { described_class.new(pending_json: { new_registrant_email: 'test@test.com' }) }
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ RSpec.describe 'admin zone create', settings: false do
|
|||
.to change { DNS::Zone.count }.from(0).to(1)
|
||||
end
|
||||
|
||||
text_attributes = %i[origin email master_nameserver]
|
||||
text_attributes = %i[origin email master_nameserver ns_records a_records a4_records]
|
||||
integer_attributes = %i[ttl refresh retry expire minimum_ttl]
|
||||
|
||||
text_attributes.each do |attr_name|
|
||||
|
|
|
@ -5,7 +5,7 @@ RSpec.describe 'admin zone update', settings: false do
|
|||
sign_in_to_admin_area
|
||||
end
|
||||
|
||||
text_attributes = %i[origin email master_nameserver]
|
||||
text_attributes = %i[origin email master_nameserver ns_records a_records a4_records]
|
||||
integer_attributes = %i[ttl refresh retry expire minimum_ttl]
|
||||
|
||||
text_attributes.each do |attr_name|
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue