Cleaned up rspec create settings and refactored whois_record

This commit is contained in:
Priit Tark 2015-04-30 15:16:21 +03:00
parent acab58b71c
commit 4cf57239a0
32 changed files with 210 additions and 198 deletions

View file

@ -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')

View file

@ -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)

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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')

View file

@ -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')

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -2,7 +2,6 @@ require 'rails_helper'
feature 'Contact', type: :feature do
before :all do
create_settings
@user = Fabricate(:api_user)
end

View file

@ -2,7 +2,6 @@ require 'rails_helper'
feature 'Domains', type: :feature do
before :all do
create_settings
@user = Fabricate(:api_user)
end

View file

@ -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

View file

@ -2,7 +2,6 @@ require 'rails_helper'
feature 'Root', type: :feature do
before :all do
create_settings
Fabricate(:api_user)
end

View file

@ -2,7 +2,6 @@ require 'rails_helper'
feature 'Sessions', type: :feature do
before :all do
create_settings
Fabricate(:api_user)
end

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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')

View file

@ -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

View file

@ -1,7 +1,6 @@
require 'rails_helper'
describe ZonefileSetting do
before { create_settings }
it 'generates the zonefile' do
ZonefileSetting.where({
origin: 'ee',

View file

@ -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

View file

@ -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)

View file

@ -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)

View file

@ -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