Attach nameservers directly to domain

This commit is contained in:
Martin Lensment 2014-07-31 11:21:22 +03:00
parent 7a9988236e
commit 4396ec665c
6 changed files with 19 additions and 5 deletions

View file

@ -3,7 +3,6 @@ class Domain < ActiveRecord::Base
#TODO most inputs should be trimmed before validatation, probably some global logic?
belongs_to :registrar
belongs_to :ns_set
belongs_to :owner_contact, class_name: 'Contact'
has_many :domain_contacts
@ -16,6 +15,7 @@ class Domain < ActiveRecord::Base
where(domain_contacts: {contact_type: Contact::CONTACT_TYPE_ADMIN})
}, through: :domain_contacts, source: :contact
has_and_belongs_to_many :nameservers
validates_presence_of :name

View file

@ -1,3 +1,4 @@
class Nameserver < ActiveRecord::Base
has_and_belongs_to_many :ns_sets
belongs_to :registrar
has_and_belongs_to_many :domains
end

View file

@ -0,0 +1,8 @@
class AddNameserversToDomain < ActiveRecord::Migration
def change
create_table :domains_nameservers do |t|
t.integer :domain_id
t.integer :nameserver_id
end
end
end

View file

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20140730141443) do
ActiveRecord::Schema.define(version: 20140731081816) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -74,6 +74,11 @@ ActiveRecord::Schema.define(version: 20140730141443) do
t.integer "period"
end
create_table "domains_nameservers", force: true do |t|
t.integer "domain_id"
t.integer "nameserver_id"
end
create_table "epp_sessions", force: true do |t|
t.string "session_id"
t.text "data"

View file

@ -2,7 +2,7 @@ require "rails_helper"
describe Domain do
it { should belong_to(:registrar) }
it { should belong_to(:ns_set) }
it { should have_and_belong_to_many(:nameservers)}
it { should belong_to(:owner_contact) }
it { should have_many(:tech_contacts) }
it { should have_many(:admin_contacts) }

View file

@ -1,5 +1,5 @@
require "rails_helper"
describe Nameserver do
it { should have_and_belong_to_many(:ns_sets) }
it { should have_and_belong_to_many(:domains) }
end