This commit is contained in:
Martin Lensment 2015-04-29 12:13:34 +03:00
parent 70aba7d5d1
commit 4c503b6c1a
4 changed files with 21 additions and 8 deletions

View file

@ -3,7 +3,7 @@ class Registrar::NameserversController < RegistrarController
def index
if can_replace_hostnames?
res = Nameserver.replace_hostname_ends(
prc = Nameserver.replace_hostname_ends(
current_user.registrar.domains.includes(
:registrant, :nameservers, :admin_domain_contacts, :tech_domain_contacts, :domain_statuses,
:versions, :admin_contacts, :tech_contacts, :whois_record, :dnskeys
@ -12,7 +12,9 @@ class Registrar::NameserversController < RegistrarController
params[:hostname_end_replacement]
)
if res
if prc == 'replaced_none'
flash.now[:alert] = t('no_hostnames_replaced')
elsif prc == 'replaced_all'
params[:q][:hostname_end] = params[:hostname_end_replacement]
params[:hostname_end_replacement] = nil
flash.now[:notice] = t('all_hostnames_replaced')

View file

@ -50,7 +50,7 @@ class Nameserver < ActiveRecord::Base
)', "%#{old_end}"
)
res = true
count, success_count = 0.0, 0.0
domains.each do |d|
ns_attrs = { nameservers_attributes: [] }
@ -64,9 +64,16 @@ class Nameserver < ActiveRecord::Base
}
end
res = false unless d.update(ns_attrs)
success_count += 1 if d.update(ns_attrs)
count += 1
end
res
return 'replaced_none' if count == 0.0
prc = success_count / count
return 'replaced_all' if prc == 1.0
'replaced_some'
end
end
end

View file

@ -755,3 +755,4 @@ en:
hostnames_partially_replaced: 'Hostnames partially replaced'
hostnames_will_be_replaced_only_if_domain_validates_with_the_new_nameserver: 'Hostnames will be replaced only if domain validates with the new nameserver'
back_to_domains: 'Back to domains'
no_hostnames_replaced: 'No hostnames replaced'

View file

@ -70,26 +70,29 @@ describe Nameserver do
it 'should replace hostname ends' do
res = Nameserver.replace_hostname_ends(@api_user.registrar.domains, 'ns.ee', 'test.ee')
res.should == false
res.should == 'replaced_some'
@api_user.registrar.nameservers.where("hostname LIKE '%test.ee'").count.should == 4
@domain_1.nameservers.pluck(:hostname).should include('ns1.ns.ee', 'ns2.ns.ee', 'ns2.test.ee')
@domain_2.nameservers.pluck(:hostname).should include('ns1.test.ee', 'ns2.test.ee', 'ns3.test.ee')
res = Nameserver.replace_hostname_ends(@api_user.registrar.domains, 'test.ee', 'testing.ee')
res.should == true
res.should == 'replaced_all'
@api_user.registrar.nameservers.where("hostname LIKE '%testing.ee'").count.should == 4
@domain_1.nameservers.pluck(:hostname).should include('ns1.ns.ee', 'ns2.ns.ee', 'ns2.testing.ee')
@domain_2.nameservers.pluck(:hostname).should include('ns1.testing.ee', 'ns2.testing.ee', 'ns3.testing.ee')
res = Nameserver.replace_hostname_ends(@api_user.registrar.domains, 'ns.ee', 'test.ee')
res.should == true
res.should == 'replaced_all'
@api_user.registrar.nameservers.where("hostname LIKE '%test.ee'").count.should == 2
@domain_1.nameservers.pluck(:hostname).should include('ns1.test.ee', 'ns2.test.ee', 'ns2.testing.ee')
@domain_2.nameservers.pluck(:hostname).should include('ns1.testing.ee', 'ns2.testing.ee', 'ns3.testing.ee')
@domain_3.nameservers.pluck(:hostname).should include('ns1.ns.ee', 'ns2.ns.ee', 'ns3.test.ee')
res = Nameserver.replace_hostname_ends(@api_user.registrar.domains, 'xcv.ee', 'test.ee')
res.should == 'replaced_none'
end
end
end