From 2a4c46e870ef31586d543cff349cb4d56f535ab7 Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Mon, 15 Sep 2014 11:19:52 +0300 Subject: [PATCH] Test on domain adding --- app/models/domain.rb | 6 ++++ app/views/admin/domains/new.haml | 4 +-- spec/features/domain_management_spec.rb | 40 +++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/app/models/domain.rb b/app/models/domain.rb index 32f5f2bde..488cd9f57 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -27,6 +27,7 @@ class Domain < ActiveRecord::Base delegate :name, to: :registrar, prefix: true before_create :generate_auth_info + after_create :attach_default_contacts validates :name_dirty, domain_name: true, uniqueness: true validates :period, numericality: { only_integer: true } @@ -106,6 +107,11 @@ class Domain < ActiveRecord::Base end while self.class.exists?(auth_info: auth_info) end + def attach_default_contacts + tech_contacts << owner_contact if tech_contacts_count.zero? + admin_contacts << owner_contact if admin_contacts_count.zero? && owner_contact.citizen? + end + def tech_contacts_count domain_contacts.select { |x| x.contact_type == DomainContact::TECH }.count end diff --git a/app/views/admin/domains/new.haml b/app/views/admin/domains/new.haml index 3f8c469a1..16cb74239 100644 --- a/app/views/admin/domains/new.haml +++ b/app/views/admin/domains/new.haml @@ -19,13 +19,13 @@ .col-md-6 .form-group.has-feedback = f.label :registrar - = text_field_tag(:registrar, params[:registrar], class: 'form-control js-registrar-typeahead', placeholder: t('shared.registrar_name'), autocomplete: 'off') + = text_field_tag(:domain_registrar, params[:registrar], class: 'form-control js-registrar-typeahead', placeholder: t('shared.registrar_name'), autocomplete: 'off') %span.glyphicon.glyphicon-ok.form-control-feedback.js-typeahead-ok.hidden %span.glyphicon.glyphicon-remove.form-control-feedback.js-typeahead-remove = f.hidden_field(:registrar_id, class: 'js-registrar-id') .form-group.has-feedback = f.label :owner_contact - = text_field_tag(:owner_contact, params[:owner_contact], class: 'form-control js-contact-typeahead', placeholder: t('shared.contact_code'), autocomplete: 'off') + = text_field_tag(:domain_owner_contact, params[:owner_contact], class: 'form-control js-contact-typeahead', placeholder: t('shared.contact_code'), autocomplete: 'off') %span.glyphicon.glyphicon-ok.form-control-feedback.js-typeahead-ok.hidden %span.glyphicon.glyphicon-remove.form-control-feedback.js-typeahead-remove = f.hidden_field(:owner_contact_id, class: 'js-contact-id') diff --git a/spec/features/domain_management_spec.rb b/spec/features/domain_management_spec.rb index b630a9468..a068487b4 100644 --- a/spec/features/domain_management_spec.rb +++ b/spec/features/domain_management_spec.rb @@ -2,6 +2,7 @@ require 'rails_helper' feature 'Domain management', type: :feature do background do + Fabricate(:registrar) Fabricate(:domain_validation_setting_group) Fabricate.times(4, :domain) end @@ -16,4 +17,43 @@ feature 'Domain management', type: :feature do expect(page).to have_link(x.owner_contact) end end + + scenario 'User adds a domain', js: true do + visit admin_domains_path + click_on 'Add' + fill_in('Domain name', with: 'example.ee') + fill_in('Period', with: 1) + fill_in('Registrar', with: 'zone', fill_options: { blur: false }) + # TODO: Wait for poltergeist to support blur option, then uncomment these lines: + # expect(page).to have_text('Zone Media OÜ (10577829)') + # click_on('Zone Media OÜ (10577829)') + # expect(find_field('Registrar').value).to eq('Zone Media OÜ (10577829)') + + # temporary solution: + + page.execute_script("$('#domain_registrar_id').val('1')") + + c = Contact.first + + fill_in('Registrant', with: c.code, fill_options: { blur: false }) + # TODO: Wait for poltergeist to support blur option, then uncomment these lines: + # expect(page).to have_text(c.code) + # click_on(c.code) + # expect(find_field('Registrar').value).to eq(c.code) + + # temporary solution: + page.execute_script("$('#domain_owner_contact_id').val('1')") + + click_on('Save') + + expect(page).to have_text('Domain details') + expect(page).to have_text('example.ee') + expect(page).to have_link('Zone Media OÜ') + expect(page).to have_link(c.name, count: 3) + expect(page).to have_text(c.code) + expect(page).to have_text(c.ident) + expect(page).to have_text(c.email) + expect(page).to have_text(c.phone) + expect(page).to have_text('Nameservers count must be between 1-13') + end end