From d01944fe21bf440d869387087e62e6a1ff4566f7 Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Fri, 1 Aug 2014 17:52:35 +0300 Subject: [PATCH] Attach nameservers to domain --- app/helpers/epp/domains_helper.rb | 7 ++++++- app/models/domain.rb | 7 +++++++ db/migrate/20140801140249_rename_nameserver_name.rb | 5 +++++ db/schema.rb | 4 ++-- spec/epp/domain_spec.rb | 2 ++ 5 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20140801140249_rename_nameserver_name.rb diff --git a/app/helpers/epp/domains_helper.rb b/app/helpers/epp/domains_helper.rb index 706f9eb24..a2fc436e7 100644 --- a/app/helpers/epp/domains_helper.rb +++ b/app/helpers/epp/domains_helper.rb @@ -3,7 +3,7 @@ module Epp::DomainsHelper @domain = Domain.new(domain_create_params) Domain.transaction do - if @domain.save && @domain.attach_contacts(domain_contacts) + if @domain.save && @domain.attach_contacts(domain_contacts) && @domain.attach_nameservers(domain_nameservers) render '/epp/domains/create' else handle_errors @@ -50,6 +50,11 @@ module Epp::DomainsHelper res end + def domain_nameservers + ph = params_hash['epp']['command']['create']['create']['ns'] + ph[:hostObj] + end + def handle_errors super({ '2302' => [:epp_domain_taken, :epp_domain_reserved], diff --git a/app/models/domain.rb b/app/models/domain.rb index 40cde413b..bee844482 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -61,6 +61,13 @@ class Domain < ActiveRecord::Base ) end + def attach_nameservers(nameservers) + nameservers.each do |x| + self.nameservers << Nameserver.find_or_create_by(hostname: x) + end + save! + end + def validate_admin_contacts_count errors.add(:admin_contacts, :blank) if admin_contacts.empty? end diff --git a/db/migrate/20140801140249_rename_nameserver_name.rb b/db/migrate/20140801140249_rename_nameserver_name.rb new file mode 100644 index 000000000..bfb5e6cd0 --- /dev/null +++ b/db/migrate/20140801140249_rename_nameserver_name.rb @@ -0,0 +1,5 @@ +class RenameNameserverName < ActiveRecord::Migration + def change + rename_column :nameservers, :name, :hostname + end +end diff --git a/db/schema.rb b/db/schema.rb index b1093033e..e7b2b6dfd 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140731081816) do +ActiveRecord::Schema.define(version: 20140801140249) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -102,7 +102,7 @@ ActiveRecord::Schema.define(version: 20140731081816) do end create_table "nameservers", force: true do |t| - t.string "name" + t.string "hostname" t.string "ip" t.integer "ns_set_id" t.datetime "created_at" diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb index db8a73d39..874d1bd12 100644 --- a/spec/epp/domain_spec.rb +++ b/spec/epp/domain_spec.rb @@ -41,6 +41,8 @@ describe 'EPP Domain', epp: true do expect(Domain.first.registrar.name).to eq('Zone Media OÜ') expect(Domain.first.tech_contacts.count).to eq 2 expect(Domain.first.admin_contacts.count).to eq 1 + + expect(Domain.first.nameservers.count).to eq(2) end it 'does not create duplicate domain' do