From 4cf57239a0ab34ef26f1b7df3db0ca3467dfa380 Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Thu, 30 Apr 2015 15:16:21 +0300 Subject: [PATCH] Cleaned up rspec create settings and refactored whois_record --- Guardfile | 4 +- app/models/domain.rb | 13 +- app/models/registrar.rb | 2 - app/models/whois_record.rb | 95 +++++++------- spec/epp/contact_spec.rb | 1 - spec/epp/domain_spec.rb | 1 - spec/epp/keyrelay_spec.rb | 1 - spec/epp/poll_spec.rb | 2 - spec/features/admin/admin_user_spec.rb | 2 - spec/features/admin/api_user_spec.rb | 2 - spec/features/admin/contact_spec.rb | 2 - spec/features/admin/epp_log_spec.rb | 2 - spec/features/admin/invoice_spec.rb | 2 - spec/features/admin/repp_log_spec.rb | 2 - spec/features/admin/zonefile_setting_spec.rb | 2 - spec/features/registrar/contact_spec.rb | 1 - spec/features/registrar/domain_spec.rb | 1 - spec/features/registrar/invoices_spec.rb | 1 - spec/features/registrar/root_spec.rb | 1 - spec/features/registrar/sessions_spec.rb | 1 - spec/features/sessions_spec.rb | 1 - spec/features/setting_management_spec.rb | 2 - spec/models/dnskey_spec.rb | 4 - spec/models/domain_spec.rb | 75 ----------- spec/models/epp_domain_spec.rb | 4 - spec/models/setting_spec.rb | 1 - spec/models/whois_record_spec.rb | 127 +++++++++++++++++++ spec/models/zonefile_setting_spec.rb | 1 - spec/rails_helper.rb | 27 ++++ spec/requests/v1/contact_spec.rb | 1 - spec/requests/v1/domain_spec.rb | 1 - spec/support/general.rb | 26 ---- 32 files changed, 210 insertions(+), 198 deletions(-) create mode 100644 spec/models/whois_record_spec.rb delete mode 100644 spec/support/general.rb diff --git a/Guardfile b/Guardfile index 31958aa77..ab7619ed7 100644 --- a/Guardfile +++ b/Guardfile @@ -9,8 +9,8 @@ group :red_green_refactor, halt_on_fail: true do # watch(%r{^(config|lib)/.*}) # end - guard :rspec, cmd: 'spring rspec --fail-fast', notification: false do - # guard :rspec, cmd: 'spring rspec', notification: false do + # guard :rspec, cmd: 'spring rspec --fail-fast', notification: false do + guard :rspec, cmd: 'spring rspec', notification: false do watch(%r{^spec/.+_spec\.rb$}) watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } watch('spec/spec_helper.rb') { "spec" } diff --git a/app/models/domain.rb b/app/models/domain.rb index a094f48ae..d0ae261b3 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -54,7 +54,6 @@ class Domain < ActiveRecord::Base end after_save :manage_automatic_statuses after_save :update_whois_record - after_save :update_whois_server validates :name_dirty, domain_name: true, uniqueness: true validates :period, numericality: { only_integer: true } @@ -123,6 +122,7 @@ class Domain < ActiveRecord::Base def included includes( + :registrant, :registrar, :nameservers, :whois_record, @@ -244,15 +244,6 @@ class Domain < ActiveRecord::Base end def update_whois_record - self.whois_record = WhoisRecord.create if whois_record.blank? - whois_record.update - end - - def update_whois_server - if whois_record.present? - whois_record.update_whois_server - else - logger.info "NO WHOIS BODY for domain: #{name}" - end + whois_record.blank? ? create_whois_record : whois_record.save end end diff --git a/app/models/registrar.rb b/app/models/registrar.rb index 1723ebdd2..ea36daef5 100644 --- a/app/models/registrar.rb +++ b/app/models/registrar.rb @@ -37,8 +37,6 @@ class Registrar < ActiveRecord::Base end end - after_save :touch_domains_version - validates :email, :billing_email, format: /@/, allow_blank: true class << self diff --git a/app/models/whois_record.rb b/app/models/whois_record.rb index 928896236..d8384edfd 100644 --- a/app/models/whois_record.rb +++ b/app/models/whois_record.rb @@ -1,32 +1,33 @@ class WhoisRecord < ActiveRecord::Base belongs_to :domain - def update_whois_server - return logger.info "NO WHOIS NAME for whois record id: #{id}" if name.blank? - wd = Whois::Record.find_or_initialize_by(name: name) - wd.body = body - wd.json = json - wd.save + validates :domain, :name, :body, :json, presence: true + + before_validation :populate + def populate + return if domain.blank? + self.json = generate_json + self.name = json['name'] + self.body = generated_body end # rubocop:disable Metrics/MethodLength - def h - @h ||= HashWithIndifferentAccess.new - end + def generate_json + h = HashWithIndifferentAccess.new + return h if domain.blank? - def update @disclosed = [] h[:name] = domain.name h[:registrant] = domain.registrant.name h[:status] = domain.domain_statuses.map(&:human_value).join(', ') - h[:registered] = domain.registered_at and domain.registered_at.to_s(:db) - h[:updated_at] = domain.updated_at and domain.updated_at.to_s(:db) - h[:valid_to] = domain.valid_to and domain.valid_to.to_s(:db) + h[:registered] = domain.registered_at.try(:to_s, :iso8601) + h[:updated_at] = domain.updated_at.try(:to_s, :iso8601) + h[:valid_to] = domain.valid_to.try(:to_s, :iso8601) h[:registrar] = domain.registrar.name h[:registrar_phone] = domain.registrar.phone h[:registrar_address] = domain.registrar.address - h[:registrar_update_at] = domain.registrar.updated_at.to_s(:db) + h[:registrar_update_at] = domain.registrar.updated_at.try(:to_s, :iso8601) h[:admin_contacts] = [] domain.admin_contacts.each do |ac| @disclosed << [:email, ac.email] @@ -34,7 +35,7 @@ class WhoisRecord < ActiveRecord::Base name: ac.name, email: ac.email, registrar: ac.registrar.name, - created_at: ac.created_at.to_s(:db) + created_at: ac.created_at.try(:to_s, :iso8601) } end h[:tech_contacts] = [] @@ -44,23 +45,18 @@ class WhoisRecord < ActiveRecord::Base name: tc.name, email: tc.email, registrar: tc.registrar.name, - created_at: tc.created_at.to_s(:db) + created_at: tc.created_at.try(:to_s, :iso8601) } end h[:nameservers] = [] domain.nameservers.each do |ns| h[:nameservers] << { hostname: ns.hostname, - updated_at: ns.updated_at.to_s(:db) + updated_at: ns.updated_at.try(:to_s, :iso8601) } end - h[:disclosed] = @disclosed - - self.name = h[:name] - self.body = generated_body - self.json = h - save + h end def generated_body @@ -68,21 +64,21 @@ class WhoisRecord < ActiveRecord::Base Estonia .ee Top Level Domain WHOIS server Domain: - name: #{h[:name]} - registrant: #{h[:registrant]} - status: #{h[:status]} - registered: #{h[:registered]} - changed: #{h[:updated_at]} - expire: #{h[:valid_to]} + name: #{json['name']} + registrant: #{json['registrant']} + status: #{json['status']} + registered: #{Time.zone.parse(json['registered'])} + changed: #{Time.zone.parse(json['updated_at'])} + expire: #{Time.zone.parse(json['valid_to'])} outzone: delete: -#{contacts_body(h[:admin_contacts], h[:tech_contacts])} +#{contacts_body(json['admin_contacts'], json['tech_contacts'])} Registrar: - name: #{h[:registrar]} - phone: #{h[:registrar_phone]} - address: #{h[:registrar_address]} - changed: #{h[:registrar_update_at]} -#{nameservers_body(h[:nameservers])} + name: #{json['registrar']} + phone: #{json['registrar_phone']} + address: #{json['registrar_address']} + changed: #{Time.zone.parse(json['registrar_update_at'])} +#{nameservers_body(json['nameservers'])} Estonia .ee Top Level Domain WHOIS server More information at http://internet.ee EOS @@ -90,34 +86,47 @@ More information at http://internet.ee # rubocop:enable Metrics/MethodLength def contacts_body(admins, techs) + admins ||= [] + techs ||= [] + out = '' out << (admins.size > 1 ? "\nAdministrative contacts" : "\nAdministrative contact") admins.each do |c| - out << "\n name: #{c[:name]}" + out << "\n name: #{c['name']}" out << "\n email: Not Disclosed - Visit www.internet.ee for webbased WHOIS" - out << "\n registrar: #{c[:registrar]}" - out << "\n created: #{c[:created_at]}" + out << "\n registrar: #{c['registrar']}" + out << "\n created: #{Time.zone.parse(c['created_at'])}" out << "\n" end out << (techs.size > 1 ? "\nTechnical contacts" : "\nTechnical contact:") techs.each do |c| - out << "\n name: #{c[:name]}" + out << "\n name: #{c['name']}" out << "\n email: Not Disclosed - Visit www.internet.ee for webbased WHOIS" - out << "\n registrar: #{c[:registrar]}" - out << "\n created: #{c[:created_at]}" + out << "\n registrar: #{c['registrar']}" + out << "\n created: #{Time.zone.parse(c['created_at'])}" out << "\n" end out end def nameservers_body(nservers) + nservers ||= [] + out = "\nName servers:" nservers.each do |ns| - out << "\n nserver: #{ns[:hostname]}" - out << "\n changed: #{ns[:updated_at]}" + out << "\n nserver: #{ns['hostname']}" + out << "\n changed: #{Time.zone.parse(ns['updated_at'])}" out << "\n" end out end + + def update_whois_server + return logger.info "NO WHOIS NAME for whois record id: #{id}" if name.blank? + wd = Whois::Record.find_or_initialize_by(name: name) + wd.body = body + wd.json = json + wd.save + end end diff --git a/spec/epp/contact_spec.rb b/spec/epp/contact_spec.rb index cb5f4555e..7efcf04f9 100644 --- a/spec/epp/contact_spec.rb +++ b/spec/epp/contact_spec.rb @@ -2,7 +2,6 @@ require 'rails_helper' describe 'EPP Contact', epp: true do before :all do - create_settings @registrar1 = Fabricate(:registrar1) @registrar2 = Fabricate(:registrar2) @epp_xml = EppXml::Contact.new(cl_trid: 'ABC-12345') diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb index 95fe3c821..c7dd22f6a 100644 --- a/spec/epp/domain_spec.rb +++ b/spec/epp/domain_spec.rb @@ -2,7 +2,6 @@ require 'rails_helper' describe 'EPP Domain', epp: true do before(:all) do - create_settings @epp_xml = EppXml.new(cl_trid: 'ABC-12345') @registrar1 = Fabricate(:registrar1) @registrar2 = Fabricate(:registrar2) diff --git a/spec/epp/keyrelay_spec.rb b/spec/epp/keyrelay_spec.rb index da5bdf570..451c5f7cc 100644 --- a/spec/epp/keyrelay_spec.rb +++ b/spec/epp/keyrelay_spec.rb @@ -2,7 +2,6 @@ require 'rails_helper' describe 'EPP Keyrelay', epp: true do before(:all) do - create_settings @registrar1 = Fabricate(:registrar1) @registrar2 = Fabricate(:registrar2) @domain = Fabricate(:domain, registrar: @registrar2) diff --git a/spec/epp/poll_spec.rb b/spec/epp/poll_spec.rb index b1639c546..cf585ff69 100644 --- a/spec/epp/poll_spec.rb +++ b/spec/epp/poll_spec.rb @@ -18,8 +18,6 @@ describe 'EPP Poll', epp: true do login_as :registrar1 @uniq_no = proc { @i ||= 0; @i += 1 } - - create_settings end it 'returns no messages in poll' do diff --git a/spec/features/admin/admin_user_spec.rb b/spec/features/admin/admin_user_spec.rb index 2e9219341..2a08245af 100644 --- a/spec/features/admin/admin_user_spec.rb +++ b/spec/features/admin/admin_user_spec.rb @@ -1,8 +1,6 @@ require 'rails_helper' feature 'Admin users', type: :feature do - background { create_settings } - before :all do @admin_user = Fabricate(:admin_user, username: 'user1', identity_code: '37810013087') end diff --git a/spec/features/admin/api_user_spec.rb b/spec/features/admin/api_user_spec.rb index a8a752154..36ba2a767 100644 --- a/spec/features/admin/api_user_spec.rb +++ b/spec/features/admin/api_user_spec.rb @@ -1,8 +1,6 @@ require 'rails_helper' feature 'Api users', type: :feature do - background { create_settings } - before :all do @user = Fabricate(:admin_user, username: 'user1', identity_code: '37810013087') @api_user = Fabricate(:api_user) diff --git a/spec/features/admin/contact_spec.rb b/spec/features/admin/contact_spec.rb index afd67c296..18fcd19cf 100644 --- a/spec/features/admin/contact_spec.rb +++ b/spec/features/admin/contact_spec.rb @@ -1,8 +1,6 @@ require 'rails_helper' feature 'Admin contact', type: :feature do - background { create_settings } - before :all do @user = Fabricate(:admin_user, username: 'user1', identity_code: '37810013087') @contact = Fabricate(:contact, name: 'Mr John') diff --git a/spec/features/admin/epp_log_spec.rb b/spec/features/admin/epp_log_spec.rb index 6c260ecd5..9aeebde2b 100644 --- a/spec/features/admin/epp_log_spec.rb +++ b/spec/features/admin/epp_log_spec.rb @@ -1,8 +1,6 @@ require 'rails_helper' feature 'EPP log', type: :feature do - background { create_settings } - before :all do @user = Fabricate(:admin_user, username: 'user1', identity_code: '37810013087') @contact = Fabricate(:contact, name: 'Mr John') diff --git a/spec/features/admin/invoice_spec.rb b/spec/features/admin/invoice_spec.rb index f2a58d0a8..176ba2b66 100644 --- a/spec/features/admin/invoice_spec.rb +++ b/spec/features/admin/invoice_spec.rb @@ -1,8 +1,6 @@ require 'rails_helper' feature 'Invoice', type: :feature do - background { create_settings } - before :all do @user = Fabricate(:admin_user, username: 'user1', identity_code: '37810013087') Fabricate(:invoice) diff --git a/spec/features/admin/repp_log_spec.rb b/spec/features/admin/repp_log_spec.rb index 95a73c4e5..7f1cf4af3 100644 --- a/spec/features/admin/repp_log_spec.rb +++ b/spec/features/admin/repp_log_spec.rb @@ -1,8 +1,6 @@ require 'rails_helper' feature 'Repp log', type: :feature do - background { create_settings } - before :all do @user = Fabricate(:admin_user, username: 'user1', identity_code: '37810013087') end diff --git a/spec/features/admin/zonefile_setting_spec.rb b/spec/features/admin/zonefile_setting_spec.rb index d7653c75a..afcdc2a7c 100644 --- a/spec/features/admin/zonefile_setting_spec.rb +++ b/spec/features/admin/zonefile_setting_spec.rb @@ -1,8 +1,6 @@ require 'rails_helper' feature 'Zonefile settings', type: :feature do - background { create_settings } - before :all do @user = Fabricate(:admin_user, username: 'user1', identity_code: '37810013087') end diff --git a/spec/features/registrar/contact_spec.rb b/spec/features/registrar/contact_spec.rb index 1650b1a9c..150103559 100644 --- a/spec/features/registrar/contact_spec.rb +++ b/spec/features/registrar/contact_spec.rb @@ -2,7 +2,6 @@ require 'rails_helper' feature 'Contact', type: :feature do before :all do - create_settings @user = Fabricate(:api_user) end diff --git a/spec/features/registrar/domain_spec.rb b/spec/features/registrar/domain_spec.rb index 647fcee4f..c72f50b84 100644 --- a/spec/features/registrar/domain_spec.rb +++ b/spec/features/registrar/domain_spec.rb @@ -2,7 +2,6 @@ require 'rails_helper' feature 'Domains', type: :feature do before :all do - create_settings @user = Fabricate(:api_user) end diff --git a/spec/features/registrar/invoices_spec.rb b/spec/features/registrar/invoices_spec.rb index 2deb54f73..88deed70b 100644 --- a/spec/features/registrar/invoices_spec.rb +++ b/spec/features/registrar/invoices_spec.rb @@ -2,7 +2,6 @@ require 'rails_helper' feature 'Invoices', type: :feature do before :all do - create_settings @user = Fabricate(:api_user) @invoice = Fabricate(:invoice, buyer: @user.registrar) end diff --git a/spec/features/registrar/root_spec.rb b/spec/features/registrar/root_spec.rb index 0d6b751fb..a00b80b3c 100644 --- a/spec/features/registrar/root_spec.rb +++ b/spec/features/registrar/root_spec.rb @@ -2,7 +2,6 @@ require 'rails_helper' feature 'Root', type: :feature do before :all do - create_settings Fabricate(:api_user) end diff --git a/spec/features/registrar/sessions_spec.rb b/spec/features/registrar/sessions_spec.rb index 97b50bec9..26f73851c 100644 --- a/spec/features/registrar/sessions_spec.rb +++ b/spec/features/registrar/sessions_spec.rb @@ -2,7 +2,6 @@ require 'rails_helper' feature 'Sessions', type: :feature do before :all do - create_settings Fabricate(:api_user) end diff --git a/spec/features/sessions_spec.rb b/spec/features/sessions_spec.rb index c22698976..20ff66a38 100644 --- a/spec/features/sessions_spec.rb +++ b/spec/features/sessions_spec.rb @@ -2,7 +2,6 @@ require 'rails_helper' feature 'Sessions', type: :feature do before :all do - create_settings Fabricate(:ee_user) @registrar1 = Fabricate(:registrar1) @registrar2 = Fabricate(:registrar2) diff --git a/spec/features/setting_management_spec.rb b/spec/features/setting_management_spec.rb index 8888afae3..7f18ff5fa 100644 --- a/spec/features/setting_management_spec.rb +++ b/spec/features/setting_management_spec.rb @@ -3,8 +3,6 @@ require 'rails_helper' feature 'Setting management', type: :feature do let(:user) { Fabricate(:admin_user, username: 'user1', identity_code: '37810013087') } - background { create_settings } - scenario 'User changes a setting' do sign_in user visit admin_settings_path diff --git a/spec/models/dnskey_spec.rb b/spec/models/dnskey_spec.rb index dff7d84b2..911713da5 100644 --- a/spec/models/dnskey_spec.rb +++ b/spec/models/dnskey_spec.rb @@ -1,10 +1,6 @@ require 'rails_helper' describe Dnskey do - before :all do - create_settings - end - it { should belong_to(:domain) } context 'with invalid attribute' do diff --git a/spec/models/domain_spec.rb b/spec/models/domain_spec.rb index ac8dc8c10..fadcb98e0 100644 --- a/spec/models/domain_spec.rb +++ b/spec/models/domain_spec.rb @@ -1,10 +1,6 @@ require 'rails_helper' describe Domain do - before :all do - create_settings - end - it { should belong_to(:registrar) } it { should have_many(:nameservers) } it { should belong_to(:registrant) } @@ -81,77 +77,6 @@ describe Domain do @domain.whois_record.json.present?.should == true end - it 'should have whois record present by default' do - @domain.name = 'yeah.ee' - @domain.updated_at = Time.zone.parse('2020.02.02 02:00') - @domain.registered_at = Time.zone.parse('2000.01.01 9:00') - @domain.valid_to = Time.zone.parse('2016.04.21 0:00') - registrar = Fabricate(:registrar, - name: 'First Registrar Ltd', - created_at: Time.zone.parse('1995.01.01'), - updated_at: Time.zone.parse('1996.01.01')) - @domain.registrant = Fabricate(:contact, - name: 'Jarren Jakubowski0', - created_at: Time.zone.parse('2005.01.01')) - @domain.admin_contacts = [Fabricate(:contact, - name: 'First Admin', - registrar: registrar, - created_at: Time.zone.parse('2016.01.01'))] - @domain.tech_contacts = [Fabricate(:contact, - name: 'First Tech', - registrar: registrar, - created_at: Time.zone.parse('2016.01.01'))] - @domain.registrar = registrar - ns1 = Fabricate(:nameserver, hostname: 'test.ee') - ns1.updated_at = Time.zone.parse('1980.01.01') - ns2 = Fabricate(:nameserver, hostname: 'test1.ee') - ns2.updated_at = Time.zone.parse('1970.01.01') - @domain.nameservers = [ns1, ns2] - - @domain.update_whois_record - @domain.whois_record.body.should == <<-EOS -Estonia .ee Top Level Domain WHOIS server - -Domain: - name: yeah.ee - registrant: Jarren Jakubowski0 - status: ok (paid and in zone) - registered: 2000-01-01 09:00:00 UTC - changed: 2020-02-02 02:00:00 UTC - expire: 2016-04-21 00:00:00 UTC - outzone: - delete: - -Administrative contact - name: First Admin - email: Not Disclosed - Visit www.internet.ee for webbased WHOIS - registrar: First Registrar Ltd - created: 2016-01-01 00:00:00 - -Technical contact: - name: First Tech - email: Not Disclosed - Visit www.internet.ee for webbased WHOIS - registrar: First Registrar Ltd - created: 2016-01-01 00:00:00 - -Registrar: - name: First Registrar Ltd - phone: - address: Street 999, Town, County, Postal - changed: 1996-01-01 00:00:00 - -Name servers: - nserver: test.ee - changed: 1980-01-01 00:00:00 - - nserver: test1.ee - changed: 1970-01-01 00:00:00 - -Estonia .ee Top Level Domain WHOIS server -More information at http://internet.ee - EOS - end - context 'with versioning' do it 'should not have one version' do with_versioning do diff --git a/spec/models/epp_domain_spec.rb b/spec/models/epp_domain_spec.rb index 3cd640005..9dab00c8a 100644 --- a/spec/models/epp_domain_spec.rb +++ b/spec/models/epp_domain_spec.rb @@ -3,9 +3,5 @@ require 'rails_helper' describe Epp::Domain do context 'with sufficient settings' do let(:domain) { Fabricate(:epp_domain) } - - before(:each) do - create_settings - end end end diff --git a/spec/models/setting_spec.rb b/spec/models/setting_spec.rb index 9459fc999..84af99501 100644 --- a/spec/models/setting_spec.rb +++ b/spec/models/setting_spec.rb @@ -2,7 +2,6 @@ require 'rails_helper' describe Setting do it 'returns value' do - create_settings expect(Setting.ns_min_count).to eq(2) Setting.ns_min_count = '2' expect(Setting.ns_min_count).to eq('2') diff --git a/spec/models/whois_record_spec.rb b/spec/models/whois_record_spec.rb new file mode 100644 index 000000000..964603d95 --- /dev/null +++ b/spec/models/whois_record_spec.rb @@ -0,0 +1,127 @@ +require 'rails_helper' + +describe WhoisRecord do + context 'with invalid attribute' do + before :all do + @whois_record = WhoisRecord.new + end + + it 'should not be valid' do + @whois_record.valid? + @whois_record.errors.full_messages.should match_array([ + "Body is missing", + "Domain is missing", + "Json is missing", + "Name is missing" + ]) + end + + it 'should not support versions' do + @whois_record.respond_to?(:versions).should == false + end + + it 'should not have whois body' do + @whois_record.body.should == nil + end + end + + context 'with valid attributes' do + before :all do + @whois_record = Fabricate(:domain).whois_record + end + + it 'should be valid' do + @whois_record.valid? + @whois_record.errors.full_messages.should match_array([]) + end + + it 'should be valid twice' do + @whois_record = Fabricate(:domain).whois_record + @whois_record.valid? + @whois_record.errors.full_messages.should match_array([]) + end + + it 'should have whois body by default' do + @whois_record.body.present?.should == true + end + + it 'should have whois json by default' do + @whois_record.json.present?.should == true + end + + it 'should have whois record present by default' do + @domain = Fabricate(:domain, name: 'yeah.ee') + @domain.updated_at = Time.zone.parse('2020.02.02 02:00') + @domain.valid_to = Time.zone.parse('2016.04.21 0:00') + registrar = Fabricate(:registrar, + name: 'First Registrar Ltd', + created_at: Time.zone.parse('1995.01.01'), + updated_at: Time.zone.parse('1996.01.01')) + @domain.registrant = Fabricate(:contact, + name: 'Jarren Jakubowski0', + created_at: Time.zone.parse('2005.01.01')) + @domain.admin_contacts = [Fabricate(:contact, + name: 'First Admin', + registrar: registrar, + created_at: Time.zone.parse('2016.01.01'))] + @domain.tech_contacts = [Fabricate(:contact, + name: 'First Tech', + registrar: registrar, + created_at: Time.zone.parse('2016.01.01'))] + @domain.registrar = registrar + ns1 = Fabricate(:nameserver, hostname: 'test.ee') + ns1.updated_at = Time.zone.parse('1980.01.01') + ns2 = Fabricate(:nameserver, hostname: 'test1.ee') + ns2.updated_at = Time.zone.parse('1970.01.01') + @domain.nameservers = [ns1, ns2] + + @domain.save + + # load some very dynamic attributes + registered = @domain.whois_record.json['registered'] + changed = @domain.whois_record.json['updated_at'] + + @domain.whois_record.body.should == <<-EOS +Estonia .ee Top Level Domain WHOIS server + +Domain: + name: yeah.ee + registrant: Jarren Jakubowski0 + status: ok (paid and in zone) + registered: #{Time.zone.parse(registered)} + changed: #{Time.zone.parse(changed)} + expire: 2016-04-21 00:00:00 UTC + outzone: + delete: + +Administrative contact + name: First Admin + email: Not Disclosed - Visit www.internet.ee for webbased WHOIS + registrar: First Registrar Ltd + created: 2016-01-01 00:00:00 UTC + +Technical contact: + name: First Tech + email: Not Disclosed - Visit www.internet.ee for webbased WHOIS + registrar: First Registrar Ltd + created: 2016-01-01 00:00:00 UTC + +Registrar: + name: First Registrar Ltd + phone: + address: Street 999, Town, County, Postal + changed: 1996-01-01 00:00:00 UTC + +Name servers: + nserver: test.ee + changed: 1980-01-01 00:00:00 UTC + + nserver: test1.ee + changed: 1970-01-01 00:00:00 UTC + +Estonia .ee Top Level Domain WHOIS server +More information at http://internet.ee + EOS + end + end +end diff --git a/spec/models/zonefile_setting_spec.rb b/spec/models/zonefile_setting_spec.rb index 2239fa4c8..9604a1cd0 100644 --- a/spec/models/zonefile_setting_spec.rb +++ b/spec/models/zonefile_setting_spec.rb @@ -1,7 +1,6 @@ require 'rails_helper' describe ZonefileSetting do - before { create_settings } it 'generates the zonefile' do ZonefileSetting.where({ origin: 'ee', diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index cd28b925b..eca52cf12 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -26,6 +26,28 @@ Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f } # If you are not using ActiveRecord, you can remove this line. ActiveRecord::Migration.maintain_test_schema! +# create general settings +def create_settings + Setting.ds_algorithm = 2 + Setting.ds_data_allowed = true + Setting.ds_data_with_key_allowed = true + Setting.key_data_allowed = true + + Setting.dnskeys_min_count = 0 + Setting.dnskeys_max_count = 9 + Setting.ns_min_count = 2 + Setting.ns_max_count = 11 + + Setting.transfer_wait_time = 0 + + Setting.admin_contacts_min_count = 1 + Setting.admin_contacts_max_count = 10 + Setting.tech_contacts_min_count = 0 + Setting.tech_contacts_max_count = 10 + + Setting.client_side_status_editing_enabled = true +end + RSpec.configure do |config| config.filter_run focus: true config.run_all_when_everything_filtered = true @@ -45,21 +67,26 @@ RSpec.configure do |config| config.before(:all) do DatabaseCleaner.clean_with(:truncation) + create_settings end config.before(:all, epp: true) do DatabaseCleaner.strategy = nil + create_settings end config.before(:each, js: true) do DatabaseCleaner.strategy = :truncation + create_settings end config.before(:each, type: :request) do DatabaseCleaner.strategy = :truncation + create_settings end config.before(:each, type: :model) do + create_settings DatabaseCleaner.strategy = :transaction DatabaseCleaner.start end diff --git a/spec/requests/v1/contact_spec.rb b/spec/requests/v1/contact_spec.rb index bd5f8567b..6db06c28d 100644 --- a/spec/requests/v1/contact_spec.rb +++ b/spec/requests/v1/contact_spec.rb @@ -2,7 +2,6 @@ require 'rails_helper' describe Repp::ContactV1 do before :all do - create_settings @api_user = Fabricate(:gitlab_api_user) Fabricate.times(2, :contact, registrar: @api_user.registrar) Fabricate.times(2, :contact) diff --git a/spec/requests/v1/domain_spec.rb b/spec/requests/v1/domain_spec.rb index e4a10680a..a7502ad0e 100644 --- a/spec/requests/v1/domain_spec.rb +++ b/spec/requests/v1/domain_spec.rb @@ -2,7 +2,6 @@ require 'rails_helper' describe Repp::DomainV1 do before :all do - create_settings @registrar1 = Fabricate(:registrar1) @api_user = Fabricate(:gitlab_api_user, registrar: @registrar1) Fabricate.times(2, :domain, registrar: @api_user.registrar) diff --git a/spec/support/general.rb b/spec/support/general.rb deleted file mode 100644 index 5831ebf83..000000000 --- a/spec/support/general.rb +++ /dev/null @@ -1,26 +0,0 @@ -module General - def create_settings - Setting.ds_algorithm = 2 - Setting.ds_data_allowed = true - Setting.ds_data_with_key_allowed = true - Setting.key_data_allowed = true - - Setting.dnskeys_min_count = 0 - Setting.dnskeys_max_count = 9 - Setting.ns_min_count = 2 - Setting.ns_max_count = 11 - - Setting.transfer_wait_time = 0 - - Setting.admin_contacts_min_count = 1 - Setting.admin_contacts_max_count = 10 - Setting.tech_contacts_min_count = 0 - Setting.tech_contacts_max_count = 10 - - Setting.client_side_status_editing_enabled = true - end -end - -RSpec.configure do |c| - c.include General -end