mirror of
https://github.com/internetee/registry.git
synced 2025-05-18 02:09:39 +02:00
Move setting types from controller to model
This commit is contained in:
parent
6d7701e52f
commit
b632dbc2de
4 changed files with 141 additions and 47 deletions
|
@ -26,48 +26,11 @@ module Admin
|
|||
def casted_settings
|
||||
settings = {}
|
||||
|
||||
ints = [
|
||||
:admin_contacts_min_count,
|
||||
:admin_contacts_max_count,
|
||||
:tech_contacts_min_count,
|
||||
:tech_contacts_max_count,
|
||||
:orphans_contacts_in_months,
|
||||
:ds_digest_type,
|
||||
:dnskeys_min_count,
|
||||
:dnskeys_max_count,
|
||||
:ns_min_count,
|
||||
:ns_max_count,
|
||||
:transfer_wait_time,
|
||||
:invoice_number_min,
|
||||
:invoice_number_max,
|
||||
:days_to_keep_business_registry_cache,
|
||||
:days_to_keep_invoices_active,
|
||||
:days_to_keep_overdue_invoices_active,
|
||||
:days_to_renew_domain_before_expire,
|
||||
:expire_warning_period,
|
||||
:redemption_grace_period,
|
||||
:expire_pending_confirmation
|
||||
]
|
||||
|
||||
floats = [:registry_vat_prc, :minimum_deposit]
|
||||
|
||||
booleans = [
|
||||
:ds_data_allowed,
|
||||
:key_data_allowed,
|
||||
:client_side_status_editing_enabled,
|
||||
:registrar_ip_whitelist_enabled,
|
||||
:api_ip_whitelist_enabled,
|
||||
:request_confrimation_on_registrant_change_enabled,
|
||||
:request_confirmation_on_domain_deletion_enabled,
|
||||
:nameserver_required,
|
||||
:address_processing
|
||||
]
|
||||
|
||||
params[:settings].each do |k, v|
|
||||
settings[k] = v
|
||||
settings[k] = v.to_i if ints.include?(k.to_sym)
|
||||
settings[k] = v.to_f if floats.include?(k.to_sym)
|
||||
settings[k] = (v == 'true' ? true : false) if booleans.include?(k.to_sym)
|
||||
settings[k] = v.to_i if Setting.integer_settings.include?(k.to_sym)
|
||||
settings[k] = v.to_f if Setting.float_settings.include?(k.to_sym)
|
||||
settings[k] = (v == 'true' ? true : false) if Setting.boolean_settings.include?(k.to_sym)
|
||||
end
|
||||
|
||||
settings
|
||||
|
|
|
@ -20,4 +20,50 @@ class Setting < RailsSettings::CachedSettings
|
|||
|
||||
return errors
|
||||
end
|
||||
|
||||
def self.integer_settings
|
||||
%i[
|
||||
admin_contacts_min_count
|
||||
admin_contacts_max_count
|
||||
tech_contacts_min_count
|
||||
tech_contacts_max_count
|
||||
orphans_contacts_in_months
|
||||
ds_digest_type
|
||||
dnskeys_min_count
|
||||
dnskeys_max_count
|
||||
ns_min_count
|
||||
ns_max_count
|
||||
transfer_wait_time
|
||||
invoice_number_min
|
||||
invoice_number_max
|
||||
days_to_keep_business_registry_cache
|
||||
days_to_keep_invoices_active
|
||||
days_to_keep_overdue_invoices_active
|
||||
days_to_renew_domain_before_expire
|
||||
expire_warning_period
|
||||
redemption_grace_period
|
||||
expire_pending_confirmation
|
||||
]
|
||||
end
|
||||
|
||||
def self.float_settings
|
||||
%i[
|
||||
registry_vat_prc
|
||||
minimum_deposit
|
||||
]
|
||||
end
|
||||
|
||||
def self.boolean_settings
|
||||
%i[
|
||||
ds_data_allowed
|
||||
key_data_allowed
|
||||
client_side_status_editing_enabled
|
||||
registrar_ip_whitelist_enabled
|
||||
api_ip_whitelist_enabled
|
||||
request_confrimation_on_registrant_change_enabled
|
||||
request_confirmation_on_domain_deletion_enabled
|
||||
nameserver_required
|
||||
address_processing
|
||||
]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,11 +1,61 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe Setting do
|
||||
it 'returns value' do
|
||||
expect(Setting.ns_min_count).to eq(2)
|
||||
Setting.ns_min_count = '2'
|
||||
expect(Setting.ns_min_count).to eq('2')
|
||||
Setting.ns_min_count = true
|
||||
expect(Setting.ns_min_count).to eq(true)
|
||||
RSpec.describe Setting do
|
||||
describe 'integer_settings', db: false do
|
||||
it 'returns integer settings' do
|
||||
settings = %i[
|
||||
admin_contacts_min_count
|
||||
admin_contacts_max_count
|
||||
tech_contacts_min_count
|
||||
tech_contacts_max_count
|
||||
orphans_contacts_in_months
|
||||
ds_digest_type
|
||||
dnskeys_min_count
|
||||
dnskeys_max_count
|
||||
ns_min_count
|
||||
ns_max_count
|
||||
transfer_wait_time
|
||||
invoice_number_min
|
||||
invoice_number_max
|
||||
days_to_keep_business_registry_cache
|
||||
days_to_keep_invoices_active
|
||||
days_to_keep_overdue_invoices_active
|
||||
days_to_renew_domain_before_expire
|
||||
expire_warning_period
|
||||
redemption_grace_period
|
||||
expire_pending_confirmation
|
||||
]
|
||||
|
||||
expect(described_class.integer_settings).to eq(settings)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'float_settings', db: false do
|
||||
it 'returns float settings' do
|
||||
settings = %i[
|
||||
registry_vat_prc
|
||||
minimum_deposit
|
||||
]
|
||||
|
||||
expect(described_class.float_settings).to eq(settings)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'boolean_settings', db: false do
|
||||
it 'returns boolean settings' do
|
||||
settings = %i[
|
||||
ds_data_allowed
|
||||
key_data_allowed
|
||||
client_side_status_editing_enabled
|
||||
registrar_ip_whitelist_enabled
|
||||
api_ip_whitelist_enabled
|
||||
request_confrimation_on_registrant_change_enabled
|
||||
request_confirmation_on_domain_deletion_enabled
|
||||
nameserver_required
|
||||
address_processing
|
||||
]
|
||||
|
||||
expect(described_class.boolean_settings).to eq(settings)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
35
spec/requests/admin/settings/create_spec.rb
Normal file
35
spec/requests/admin/settings/create_spec.rb
Normal file
|
@ -0,0 +1,35 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Admin settings saving' do
|
||||
before do
|
||||
sign_in_to_admin_area
|
||||
end
|
||||
|
||||
it 'saves integer setting' do
|
||||
allow(Setting).to receive(:integer_settings) { %i[test_setting] }
|
||||
post admin_settings_path, settings: { test_setting: '1' }
|
||||
expect(Setting.test_setting).to eq(1)
|
||||
end
|
||||
|
||||
it 'saves float setting' do
|
||||
allow(Setting).to receive(:float_settings) { %i[test_setting] }
|
||||
post admin_settings_path, settings: { test_setting: '1.2' }
|
||||
expect(Setting.test_setting).to eq(1.2)
|
||||
end
|
||||
|
||||
it 'saves boolean setting' do
|
||||
allow(Setting).to receive(:boolean_settings) { %i[test_setting] }
|
||||
post admin_settings_path, settings: { test_setting: 'true' }
|
||||
expect(Setting.test_setting).to be true
|
||||
end
|
||||
|
||||
it 'saves string setting' do
|
||||
post admin_settings_path, settings: { test_setting: 'test' }
|
||||
expect(Setting.test_setting).to eq('test')
|
||||
end
|
||||
|
||||
it 'redirects to :index' do
|
||||
post admin_settings_path, settings: { test: 'test' }
|
||||
expect(response).to redirect_to admin_settings_path
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue