diff --git a/spec/models/contact_spec.rb b/spec/models/contact_spec.rb index a5a680439..b54c5a47f 100644 --- a/spec/models/contact_spec.rb +++ b/spec/models/contact_spec.rb @@ -2,6 +2,25 @@ require 'rails_helper' describe Contact do before :example do + 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 + Fabricate(:zonefile_setting, origin: 'ee') @api_user = Fabricate(:api_user) end @@ -363,3 +382,25 @@ describe Contact, '.destroy_orphans' do Contact.count.should == cc end end + +RSpec.describe Contact, db: false do + describe '::names' do + before :example do + expect(described_class).to receive(:pluck).with(:name).and_return('names') + end + + it 'returns names' do + expect(described_class.names).to eq('names') + end + end + + describe '::emails' do + before :example do + expect(described_class).to receive(:pluck).with(:email).and_return('emails') + end + + it 'returns emails' do + expect(described_class.emails).to eq('emails') + end + end +end diff --git a/spec/models/dnskey_spec.rb b/spec/models/dnskey_spec.rb index ef0f52475..5267f3eac 100644 --- a/spec/models/dnskey_spec.rb +++ b/spec/models/dnskey_spec.rb @@ -2,6 +2,25 @@ require 'rails_helper' describe Dnskey do before :example do + 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 + Fabricate(:zonefile_setting, origin: 'ee') end diff --git a/spec/models/domain_spec.rb b/spec/models/domain_spec.rb index 9d9c6439e..1d6a63fb8 100644 --- a/spec/models/domain_spec.rb +++ b/spec/models/domain_spec.rb @@ -2,6 +2,25 @@ require 'rails_helper' RSpec.describe Domain do before :example do + 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 + Fabricate(:zonefile_setting, origin: 'ee') Fabricate(:zonefile_setting, origin: 'pri.ee') Fabricate(:zonefile_setting, origin: 'med.ee') @@ -842,6 +861,9 @@ RSpec.describe Domain do end RSpec.describe Domain, db: false do + it { is_expected.to alias_attribute(:on_hold_time, :outzone_at) } + it { is_expected.to alias_attribute(:delete_time, :delete_at) } + describe '#set_server_hold' do let(:domain) { described_class.new } @@ -858,4 +880,77 @@ RSpec.describe Domain, db: false do expect(domain.outzone_at).to eq(Time.zone.parse('05.07.2010')) end end + + describe '#admin_contact_names' do + let(:domain) { described_class.new } + + before :example do + expect(Contact).to receive(:names).and_return('names') + end + + it 'returns admin contact names' do + expect(domain.admin_contact_names).to eq('names') + end + end + + describe '#admin_contact_emails' do + let(:domain) { described_class.new } + + before :example do + expect(Contact).to receive(:emails).and_return('emails') + end + + it 'returns admin contact emails' do + expect(domain.admin_contact_emails).to eq('emails') + end + end + + describe '#tech_contact_names' do + let(:domain) { described_class.new } + + before :example do + expect(Contact).to receive(:names).and_return('names') + end + + it 'returns technical contact names' do + expect(domain.tech_contact_names).to eq('names') + end + end + + describe '#nameserver_hostnames' do + let(:domain) { described_class.new } + + before :example do + expect(Nameserver).to receive(:hostnames).and_return('hostnames') + end + + it 'returns name server hostnames' do + expect(domain.nameserver_hostnames).to eq('hostnames') + end + end + + describe '#registered?' do + before :example do + travel_to Time.zone.parse('05.07.2010 00:00:01') + end + + context 'when :valid_to is in the future' do + let(:domain) { described_class.new(valid_to: Time.zone.parse('06.07.2010')) } + + specify { expect(domain).to be_registered } + end + + context 'when :valid_to is the same as current time' do + let(:domain) { described_class.new(valid_to: Time.zone.parse('05.07.2010 00:00:01')) } + + + specify { expect(domain).to be_registered } + end + + context 'when :valid_to is in the past' do + let(:domain) { described_class.new(valid_to: Time.zone.parse('04.07.2010 23:59:59')) } + + specify { expect(domain).to_not be_registered } + end + end end diff --git a/spec/models/domain_transfer_spec.rb b/spec/models/domain_transfer_spec.rb index e46b46aca..3609b2f7d 100644 --- a/spec/models/domain_transfer_spec.rb +++ b/spec/models/domain_transfer_spec.rb @@ -2,6 +2,25 @@ require 'rails_helper' describe DomainTransfer do before :example do + 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 + Fabricate(:zonefile_setting, origin: 'ee') end diff --git a/spec/models/keyrelay_spec.rb b/spec/models/keyrelay_spec.rb index 5243cbf6c..73e26a098 100644 --- a/spec/models/keyrelay_spec.rb +++ b/spec/models/keyrelay_spec.rb @@ -2,6 +2,25 @@ require 'rails_helper' describe Keyrelay do before :example do + 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 + Fabricate(:zonefile_setting, origin: 'ee') end diff --git a/spec/models/nameserver_spec.rb b/spec/models/nameserver_spec.rb index 586f83390..1844bc0f9 100644 --- a/spec/models/nameserver_spec.rb +++ b/spec/models/nameserver_spec.rb @@ -2,6 +2,25 @@ require 'rails_helper' describe Nameserver do before :example do + 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 + Fabricate(:zonefile_setting, origin: 'ee') end @@ -92,3 +111,15 @@ describe Nameserver do end end end + +RSpec.describe Nameserver do + describe '::hostnames', db: false do + before :example do + expect(described_class).to receive(:pluck).with(:hostname).and_return('hostnames') + end + + it 'returns names' do + expect(described_class.hostnames).to eq('hostnames') + end + end +end diff --git a/spec/models/registrant_verification_spec.rb b/spec/models/registrant_verification_spec.rb index fc9b8ab82..5997797c7 100644 --- a/spec/models/registrant_verification_spec.rb +++ b/spec/models/registrant_verification_spec.rb @@ -2,6 +2,25 @@ require 'rails_helper' describe RegistrantVerification do before :example do + 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 + Fabricate(:zonefile_setting, origin: 'ee') end context 'with invalid attribute' do diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 2e6927569..3403af964 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -15,33 +15,10 @@ require 'support/matchers/alias_attribute' require 'support/matchers/active_job' require 'support/capybara' require 'support/database_cleaner' -require 'support/request' require 'support/paper_trail' 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.include ActionView::TestCase::Behavior, type: :presenter config.include ActiveSupport::Testing::TimeHelpers @@ -52,27 +29,6 @@ RSpec.configure do |config| end config.use_transactional_fixtures = false - - config.before(:all) do - create_settings - end - - config.before(:all, epp: true) do - create_settings - end - - config.before(:each, js: true) do - create_settings - end - - config.before(:each, type: :request) do - create_settings - end - - config.before(:each, type: :model) do - create_settings - end - config.infer_spec_type_from_file_location! config.expect_with :rspec do |c| diff --git a/spec/support/request.rb b/spec/support/request.rb deleted file mode 100644 index fedf1ae04..000000000 --- a/spec/support/request.rb +++ /dev/null @@ -1,104 +0,0 @@ -module Request - def get_with_auth(path, params, epp_user) - get path, params, env_with_auth(epp_user) - end - - def delete_with_auth(path, epp_user) - delete path, params, env_with_auth(epp_user) - end - - def post_with_auth(path, params, epp_user) - post path, params, env_with_auth(epp_user) - end - - def patch_with_auth(path, params, epp_user) - patch path, params, env_with_auth(epp_user) - end - - def env - { - 'Accept' => 'application/json', - 'Content-Type' => 'application/json' - } - end - - def env_with_auth(epp_user) - env.merge({ - 'HTTP_AUTHORIZATION' => ActionController::HttpAuthentication::Basic.encode_credentials( - epp_user.username, epp_user.password - ) - }) - end -end - -module Autodoc - class Document - def route_info_doc - return unless example.metadata[:route_info_doc] - route = request.env["rack.routing_args"][:route_info] - return unless route.route_params.is_a?(Hash) - return if route.route_params.empty? - - rows = [ - "| Field name | Required | Type | Allowed values | Description |", - "| ---------- | -------- | ---- | -------------- | ----------- |" - ] - - route.route_params.each do |name, desc| - details = [] - details << "| #{name} " - details << "| #{desc[:required]} " - details << "| #{desc[:type]} " - details << "| #{ranges_from_array(desc[:values])} " - details << "| #{desc[:desc]} |" - rows << details.join - end - - pretty_table(rows).join("\n") - end - - def pretty_table(rows) - # longest_in_col = 0 - matrix_array = [] - rows.each do |x| - matrix_array << x.split('|') + [''] # [''] is because split loses last | - end - - new_arr = [] - matrix_array.transpose.each do |col| - new_col = [] - longest = col.max_by(&:size).size - - col.each do |r| - new_col << r.center(longest) - end - new_arr << new_col - end - - matrix_array = [] - new_arr.transpose.each do |x| - matrix_array << x.join('|') - end - - matrix_array - end - - def ranges_from_array(a) - return unless a - ranges = a.sort.uniq.reduce([]) do |spans, n| - return a if n.is_a?(String) - if spans.empty? || spans.last.last != n - 1 - spans + [n..n] - else - spans[0..-2] + [spans.last.first..n] - end - end - - ranges - end - end -end - -RSpec.configure do |c| - c.include Request, type: :request -end