mirror of
https://github.com/internetee/registry.git
synced 2025-06-07 21:25:39 +02:00
Make replace_nameservers return an array of domain names
This commit is contained in:
parent
fb16e209ae
commit
b5f07682f4
2 changed files with 29 additions and 0 deletions
|
@ -132,14 +132,20 @@ class Registrar < ActiveRecord::Base
|
|||
# Audit log is needed, therefore no raw SQL
|
||||
def replace_nameservers(hostname, new_attributes)
|
||||
transaction do
|
||||
domain_list = []
|
||||
|
||||
nameservers.where(hostname: hostname).find_each do |original_nameserver|
|
||||
new_nameserver = Nameserver.new
|
||||
new_nameserver.domain = original_nameserver.domain
|
||||
new_nameserver.attributes = new_attributes
|
||||
new_nameserver.save!
|
||||
|
||||
domain_list << original_nameserver.domain.name
|
||||
|
||||
original_nameserver.destroy!
|
||||
end
|
||||
|
||||
domain_list
|
||||
end
|
||||
end
|
||||
|
||||
|
|
23
test/models/registrar/replace_nameservers_test.rb
Normal file
23
test/models/registrar/replace_nameservers_test.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
require 'test_helper'
|
||||
|
||||
class ReplaceNameserversTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
@registrar = registrars(:bestnames)
|
||||
end
|
||||
|
||||
def test_replace_nameservers_in_bulk_returns_domain_names
|
||||
new_attributes = { hostname: 'ns-updated1.bestnames.test', ipv4: '192.0.3.1',
|
||||
ipv6: '2001:db8::2' }
|
||||
result = @registrar.replace_nameservers('ns1.bestnames.test', new_attributes)
|
||||
|
||||
assert_equal(["airport.test", "shop.test"], result)
|
||||
end
|
||||
|
||||
def test_replace_nameservers_in_bulk_returns_empty_array_for_non_existent_base_nameserver
|
||||
new_attributes = { hostname: 'ns-updated1.bestnames.test', ipv4: '192.0.3.1',
|
||||
ipv6: '2001:db8::2' }
|
||||
result = @registrar.replace_nameservers('ns3.bestnames.test', new_attributes)
|
||||
|
||||
assert_equal([], result)
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue