Add admin zone specs

#475
This commit is contained in:
Artur Beljajev 2017-04-21 14:59:54 +03:00
parent bff7437277
commit 1ed7c7c95b
3 changed files with 94 additions and 0 deletions

View file

@ -0,0 +1,36 @@
require 'rails_helper'
RSpec.describe 'admin zone create' do
subject(:zone) { DNS::Zone.first }
before :example do
sign_in_to_admin_area
end
it 'creates new zone' do
expect { post admin_zones_path, zone: attributes_for(:zone) }
.to change { DNS::Zone.count }.from(0).to(1)
end
text_attributes = %i[origin email master_nameserver]
integer_attributes = %i[ttl refresh retry expire minimum_ttl]
text_attributes.each do |attr_name|
it "saves #{attr_name}" do
post admin_zones_path, { zone: attributes_for(:zone, attr_name => 'test') }
expect(zone.send(attr_name)).to eq('test')
end
end
integer_attributes.each do |attr_name|
it "saves #{attr_name}" do
post admin_zones_path, { zone: attributes_for(:zone, attr_name => '1') }
expect(zone.send(attr_name)).to eq(1)
end
end
it 'redirects to :index' do
post admin_zones_path, { zone: attributes_for(:zone) }
expect(response).to redirect_to admin_zones_url
end
end

View file

@ -0,0 +1,18 @@
require 'rails_helper'
RSpec.describe 'admin zone destroy' do
let!(:zone) { create(:zone) }
before :example do
sign_in_to_admin_area
end
it 'deletes zone' do
expect { delete admin_zone_path(zone) }.to change { DNS::Zone.count }.from(1).to(0)
end
it 'redirects to :index' do
delete admin_zone_path(zone)
expect(response).to redirect_to admin_zones_url
end
end

View file

@ -0,0 +1,40 @@
require 'rails_helper'
RSpec.describe 'admin zone update' do
before :example do
sign_in_to_admin_area
end
text_attributes = %i[origin email master_nameserver]
integer_attributes = %i[ttl refresh retry expire minimum_ttl]
text_attributes.each do |attr_name|
it "updates #{attr_name}" do
zone = create(:zone, attr_name => 'test')
patch admin_zone_path(zone), zone: attributes_for(:zone, attr_name => 'new-test')
zone.reload
expect(zone.send(attr_name)).to eq('new-test')
end
end
integer_attributes.each do |attr_name|
it "updates #{attr_name}" do
zone = create(:zone, attr_name => '1')
patch admin_zone_path(zone), zone: attributes_for(:zone, attr_name => '2')
zone.reload
expect(zone.send(attr_name)).to eq(2)
end
end
it 'redirects to :index' do
zone = create(:zone)
patch admin_zone_path(zone), { zone: attributes_for(:zone) }
expect(response).to redirect_to admin_zones_url
end
end