From 9a154d59188f32ef4655b289c3f8eafae6e7f006 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Mon, 26 Jun 2017 02:14:08 +0300 Subject: [PATCH 01/11] Fix EPP code rspec matcher --- spec/support/matchers/epp/code.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/spec/support/matchers/epp/code.rb b/spec/support/matchers/epp/code.rb index db79488b3..042598c50 100644 --- a/spec/support/matchers/epp/code.rb +++ b/spec/support/matchers/epp/code.rb @@ -11,7 +11,11 @@ module Matchers end def failure_message - "Expected EPP code of #{expected}, got #{actual} (#{description})" + "Expected EPP code of #{expected}, got #{actual} (#{code_description})" + end + + def description + "should have EPP code of #{expected}" end private @@ -23,7 +27,7 @@ module Matchers xml_document.xpath('//xmlns:result').first['code'].to_i end - def description + def code_description xml_document.css('result msg').text end From 4a42b8b349f739dc8c24ec5805c2c29f51895d35 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 22 Aug 2017 14:13:00 +0300 Subject: [PATCH 02/11] Remove duplicate translation --- config/locales/en.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index 2627b112a..4518533ef 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -565,7 +565,6 @@ en: public_key: 'Public key' ds_key_tag: 'DS key tag' ds_algorithm: 'DS algorithm' - ds_digest_type: 'DS digest type' ds_digest: 'DS digest' statuses: 'Statuses' status: 'Status' From d61c9d43e35fc1dc3c017599dace6c1fd8f9ad84 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 22 Aug 2017 17:29:52 +0300 Subject: [PATCH 03/11] Extract admin settings translations --- app/views/admin/base/_menu.haml | 4 +- app/views/admin/settings/_setting_row.haml | 2 +- app/views/admin/settings/index.haml | 44 ++++++---------------- config/locales/admin/menu.en.yml | 1 + config/locales/admin/settings.en.yml | 11 ++++++ config/locales/en.yml | 32 ---------------- 6 files changed, 27 insertions(+), 67 deletions(-) create mode 100644 config/locales/admin/settings.en.yml diff --git a/app/views/admin/base/_menu.haml b/app/views/admin/base/_menu.haml index 4037ef23e..7c813e43e 100644 --- a/app/views/admin/base/_menu.haml +++ b/app/views/admin/base/_menu.haml @@ -11,7 +11,7 @@ - if can?(:access, :settings_menu) %li.dropdown %a.dropdown-toggle{"data-toggle" => "dropdown", href: "#"} - = t(:settings) + = t('.settings') %span.caret %ul.dropdown-menu{role: "menu"} %li.dropdown-header= t('.users') @@ -30,7 +30,7 @@ %li= link_to t('.contact_history'), admin_contact_versions_path %li.divider %li.dropdown-header= t(:system) - %li= link_to t(:settings), admin_settings_path + %li= link_to t('.settings'), admin_settings_path %li= link_to t('.zones'), admin_zones_path %li= link_to t('.blocked_domains'), admin_blocked_domains_path %li= link_to t('.reserved_domains'), admin_reserved_domains_path diff --git a/app/views/admin/settings/_setting_row.haml b/app/views/admin/settings/_setting_row.haml index ab0d8d991..7f11c2c63 100644 --- a/app/views/admin/settings/_setting_row.haml +++ b/app/views/admin/settings/_setting_row.haml @@ -1,6 +1,6 @@ - value = Setting.send(var) %tr{class: (@errors && @errors.has_key?(var.to_s) && "danger")} - %td= t(var) + %td= var.to_s.humanize - if [TrueClass, FalseClass].include?(value.class) %td = hidden_field_tag("[settings][#{var}]", '') diff --git a/app/views/admin/settings/index.haml b/app/views/admin/settings/index.haml index 8598fe072..d765aea6f 100644 --- a/app/views/admin/settings/index.haml +++ b/app/views/admin/settings/index.haml @@ -1,15 +1,11 @@ -= render 'shared/title', name: t(:settings) += render 'shared/title', name: t('.title') = form_tag [:admin, :settings] do .panel.panel-default - .panel-heading.clearfix - = t(:domain_validation_rules) + .panel-heading + = t('.domain_validation') .table-responsive %table.table.table-hover.table-bordered.table-condensed - %thead - %tr - %th{class: 'col-xs-6'}= t(:setting) - %th{class: 'col-xs-6'}= t(:value) %tbody = render 'setting_row', var: :admin_contacts_min_count = render 'setting_row', var: :admin_contacts_max_count @@ -26,14 +22,10 @@ = render 'setting_row', var: :expire_pending_confirmation .panel.panel-default - .panel-heading.clearfix - = t(:domain_expiring) + .panel-heading + = t('.domain_expiration') .table-responsive %table.table.table-hover.table-bordered.table-condensed - %thead - %tr - %th{class: 'col-xs-6'}= t(:setting) - %th{class: 'col-xs-6'}= t(:value) %tbody = render 'setting_row', var: :days_to_renew_domain_before_expire = render 'setting_row', var: :expire_warning_period @@ -41,14 +33,10 @@ = render 'setting_row', var: :expiration_reminder_mail .panel.panel-default - .panel-heading.clearfix - = t(:other) + .panel-heading + = t('.other') .table-responsive %table.table.table-hover.table-bordered.table-condensed - %thead - %tr - %th{class: 'col-xs-6'}= t(:setting) - %th{class: 'col-xs-6'}= t(:value) %tbody = render 'setting_row', var: :transfer_wait_time = render 'setting_row', var: :ds_digest_type @@ -61,14 +49,10 @@ = render 'setting_row', var: :address_processing .panel.panel-default - .panel-heading.clearfix - = t(:billing_settings) + .panel-heading + = t('.billing') .table-responsive %table.table.table-hover.table-bordered.table-condensed - %thead - %tr - %th{class: 'col-xs-6'}= t(:setting) - %th{class: 'col-xs-6'}= t(:value) %tbody = render 'setting_row', var: :invoice_number_min = render 'setting_row', var: :invoice_number_max @@ -91,14 +75,10 @@ = render 'setting_row', var: :registry_swift .panel.panel-default - .panel-heading.clearfix - = t(:registry_settings) + .panel-heading + = t('.contacts') .table-responsive %table.table.table-hover.table-bordered.table-condensed - %thead - %tr - %th{class: 'col-xs-6'}= t(:setting) - %th{class: 'col-xs-6'}= t(:value) %tbody = render 'setting_row', var: :registry_juridical_name = render 'setting_row', var: :registry_reg_no @@ -113,4 +93,4 @@ .row .col-md-12.text-right - %button.btn.btn-primary=t(:save) + %button.btn.btn-primary=t('.submit_btn') diff --git a/config/locales/admin/menu.en.yml b/config/locales/admin/menu.en.yml index 1570200be..2c31a5193 100644 --- a/config/locales/admin/menu.en.yml +++ b/config/locales/admin/menu.en.yml @@ -2,6 +2,7 @@ en: admin: base: menu: + settings: Settings users: Users api_users: API users admin_users: Admin users diff --git a/config/locales/admin/settings.en.yml b/config/locales/admin/settings.en.yml new file mode 100644 index 000000000..047a1eb6a --- /dev/null +++ b/config/locales/admin/settings.en.yml @@ -0,0 +1,11 @@ +en: + admin: + settings: + index: + title: Settings + domain_validation: Domain validation + other: Other + domain_expiration: Domain expiration + billing: Billing + contacts: Contacts + submit_btn: Save diff --git a/config/locales/en.yml b/config/locales/en.yml index 4518533ef..2511d086b 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -264,13 +264,11 @@ en: required_ident_attribute_missing: "Required ident attribute missing: %{key}" code: 'Code' - value: 'Value' action: 'Action' edit: 'Edit' save: 'Save' log_out: 'Log out (%{user})' system: 'System' - settings: 'Settings' domains: 'Domains' registrars: 'Registrars' valid_to: 'Valid to' @@ -418,8 +416,6 @@ en: authentication_error: 'Authentication error' - setting: 'Setting' - transfer_requested: 'Transfer requested.' message_was_not_found: 'Message was not found' host_obj_is_not_allowed: 'hostObj object is not allowed' @@ -427,12 +423,6 @@ en: only_one_parameter_allowed: 'Only one parameter allowed: %{param_1} or %{param_2}' exactly_one_parameter_required: 'Exactly one parameter required: %{params}' required_parameter_missing_choice: 'Required parameter missing: %{param_1} or %{param_2}' - transfer_wait_time: 'Transfer wait time' - ns_min_count: 'Nameserver minimum count' - ns_max_count: 'Nameserver maximum count' - dnskeys_min_count: 'DNS keys minimum count' - dnskeys_max_count: 'DNS keys maximum count' - ds_data_allowed: 'DS data allowed' ds_data_with_key_allowed: 'Allow DS data with key' key_data_allowed: 'Allow key data' ds_digest_type: 'DS digest type' @@ -620,7 +610,6 @@ en: index: 'Index' ident: 'Ident' email: 'E-mail' - value: 'Value' phone: 'Phone' org_name: Org name country: Country @@ -808,32 +797,11 @@ en: tech: Tech contact valid: Valid object_is_not_eligible_for_renewal: 'Object is not eligible for renewal' - domain_expiring: 'Domain expiring' - domain_validation_rules: 'Domain validation rules' bank_statement_desc: 'Import file row will match only when matching following attributes:
ref number
payment amount
invoice number (the first numerical value in comment field)
.' create_bank_statement: 'Create bank statement' create_bank_transaction: 'Create bank transaction' create_new_invoice: 'Create new invoice' ip_is_not_whitelisted: 'IP is not whitelisted' - billing_settings: 'Billing settings' - registry_settings: 'Registry settings' - registry_billing_email: 'Billing e-mail' - registry_invoice_contact: 'Invoice contact' - registry_vat_no: 'VAT no.' - registry_vat_prc: 'VAT prc.' - registry_bank: 'Bank' - registry_iban: 'IBAN' - registry_swift: 'SWIFT' - registry_juridical_name: 'Juridical name' - registry_reg_no: 'Reg no.' - registry_email: 'E-mail' - registry_phone: 'Phone' - registry_url: 'URL' - registry_street: 'Street' - registry_city: 'City' - registry_state: 'State / Province' - registry_zip: 'Postcode' - registry_country_code: 'Country' billing_failure_credit_balance_low: 'Billing failure - credit balance low' create: 'Create' activity_type: 'Activity type' From 44b3c41e3a9553e0c5fa58ed4a53de13b9225ba4 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 22 Aug 2017 17:39:48 +0300 Subject: [PATCH 04/11] Fix admin settings layout --- app/views/admin/settings/_setting_row.haml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/admin/settings/_setting_row.haml b/app/views/admin/settings/_setting_row.haml index 7f11c2c63..4cfd87b28 100644 --- a/app/views/admin/settings/_setting_row.haml +++ b/app/views/admin/settings/_setting_row.haml @@ -1,9 +1,9 @@ - value = Setting.send(var) %tr{class: (@errors && @errors.has_key?(var.to_s) && "danger")} - %td= var.to_s.humanize + %td.col-md-6= var.to_s.humanize - if [TrueClass, FalseClass].include?(value.class) - %td + %td.col-md-6 = hidden_field_tag("[settings][#{var}]", '') = check_box_tag("[settings][#{var}]", true, value) - else - %td= text_field_tag("[settings][#{var}]", value) + %td.col-md-6= text_field_tag("[settings][#{var}]", value) From 6e5b90b8097977245158c4b7bcb074ae2c680249 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 22 Aug 2017 17:52:43 +0300 Subject: [PATCH 05/11] Remove unused css --- app/assets/stylesheets/admin/admin.sass | 34 ---------------------- app/assets/stylesheets/shared/general.sass | 6 ---- 2 files changed, 40 deletions(-) diff --git a/app/assets/stylesheets/admin/admin.sass b/app/assets/stylesheets/admin/admin.sass index 0d11a771c..fe9b569ff 100644 --- a/app/assets/stylesheets/admin/admin.sass +++ b/app/assets/stylesheets/admin/admin.sass @@ -50,9 +50,6 @@ strong blockquote margin: 1em 40px -dfn - font-style: italic - mark background: #ff0 color: #000 @@ -94,12 +91,6 @@ sup sub bottom: -0.25em -.title-row - margin-bottom: 22px - -.app-nav - padding-top: 7px - .general-tab padding-top: 30px padding-right: 20px @@ -131,16 +122,6 @@ sub font-weight: bold color: #333 - -.subactions - h4 - margin-bottom: 20px - margin-top: 10px - min-height: 600px - -.sidebar - min-height: 400px - .content margin-right: 240px margin-left: 0 @@ -148,15 +129,6 @@ sub h4 margin: 0 -.top-actions - margin-top: 12px - margin-bottom: 16px - float: right - -.domify - td - vertical-align: middle !important - body.login padding-top: 40px padding-bottom: 40px @@ -196,12 +168,6 @@ body.login .form-control:focus z-index: 2 -.error-tab > a - color: #a94442 !important - -.edit-highlight - background-color: #E7E7E7 - .navbar-brand line-height: 12px padding-top: 20px diff --git a/app/assets/stylesheets/shared/general.sass b/app/assets/stylesheets/shared/general.sass index e6eb54ccf..fd8bc2905 100644 --- a/app/assets/stylesheets/shared/general.sass +++ b/app/assets/stylesheets/shared/general.sass @@ -1,12 +1,6 @@ body > .container min-height: 800px -.error-tab > a - color: #a94442 !important - -.edit-highlight - background-color: #E7E7E7 - .navbar-brand line-height: 12px padding-top: 20px From f658dcf8928d7e9f725daac03d90201dad613617 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 22 Aug 2017 17:56:15 +0300 Subject: [PATCH 06/11] Fix admin settings UI --- app/views/admin/settings/_setting_row.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/settings/_setting_row.haml b/app/views/admin/settings/_setting_row.haml index 4cfd87b28..ce2107ba8 100644 --- a/app/views/admin/settings/_setting_row.haml +++ b/app/views/admin/settings/_setting_row.haml @@ -6,4 +6,4 @@ = hidden_field_tag("[settings][#{var}]", '') = check_box_tag("[settings][#{var}]", true, value) - else - %td.col-md-6= text_field_tag("[settings][#{var}]", value) + %td.col-md-6= text_field_tag("[settings][#{var}]", value, class: 'form-control') From bb543c31bcfb450388fcca047ea0f5d84c0c7910 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 22 Aug 2017 22:51:09 +0300 Subject: [PATCH 07/11] Fix spec settings --- spec/support/settings.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/support/settings.rb b/spec/support/settings.rb index ff1aa50a4..bf7fbc5d5 100644 --- a/spec/support/settings.rb +++ b/spec/support/settings.rb @@ -6,7 +6,7 @@ RSpec.configure do |config| Setting.ds_algorithm = 2 Setting.ds_data_allowed = true Setting.ds_data_with_key_allowed = true - Setting.key_data_allowed = true + Setting.key_data_allowed = false Setting.dnskeys_min_count = 0 Setting.dnskeys_max_count = 9 From 4bbea0d58bf6d603496c80d5377bb801ce74609b Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 22 Aug 2017 22:52:17 +0300 Subject: [PATCH 08/11] Extract admin settings translations --- app/controllers/admin/settings_controller.rb | 2 +- app/views/admin/settings/index.haml | 6 ++++-- config/locales/admin/settings.en.yml | 5 ++++- config/locales/en.yml | 1 - spec/features/admin/settings/create_spec.rb | 13 +++++++++++++ 5 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 spec/features/admin/settings/create_spec.rb diff --git a/app/controllers/admin/settings_controller.rb b/app/controllers/admin/settings_controller.rb index 527e6f35b..d4df95649 100644 --- a/app/controllers/admin/settings_controller.rb +++ b/app/controllers/admin/settings_controller.rb @@ -14,7 +14,7 @@ module Admin Setting[k] = v end - flash[:notice] = I18n.t('records_updated') + flash[:notice] = t('.saved') redirect_to [:admin, :settings] else flash[:alert] = @errors.values.uniq.join(", ") diff --git a/app/views/admin/settings/index.haml b/app/views/admin/settings/index.haml index d765aea6f..94d0a2657 100644 --- a/app/views/admin/settings/index.haml +++ b/app/views/admin/settings/index.haml @@ -1,4 +1,6 @@ -= render 'shared/title', name: t('.title') +.page-header + .h1 + = t('.title') = form_tag [:admin, :settings] do .panel.panel-default @@ -93,4 +95,4 @@ .row .col-md-12.text-right - %button.btn.btn-primary=t('.submit_btn') + = submit_tag(t('.save_btn'), class: 'btn btn-success', name: nil) diff --git a/config/locales/admin/settings.en.yml b/config/locales/admin/settings.en.yml index 047a1eb6a..bb042db01 100644 --- a/config/locales/admin/settings.en.yml +++ b/config/locales/admin/settings.en.yml @@ -8,4 +8,7 @@ en: domain_expiration: Domain expiration billing: Billing contacts: Contacts - submit_btn: Save + save_btn: Save + + create: + saved: Settings have been successfully updated diff --git a/config/locales/en.yml b/config/locales/en.yml index 2511d086b..acc559c29 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -409,7 +409,6 @@ en: record_created: 'Record created' failed_to_create_record: 'Failed to create record' record_updated: 'Record updated' - records_updated: 'Records updated' failed_to_update_record: 'Failed to update record' record_deleted: 'Record deleted' failed_to_delete_record: 'Failed to delete record' diff --git a/spec/features/admin/settings/create_spec.rb b/spec/features/admin/settings/create_spec.rb new file mode 100644 index 000000000..d30e93e8e --- /dev/null +++ b/spec/features/admin/settings/create_spec.rb @@ -0,0 +1,13 @@ +require 'rails_helper' + +RSpec.feature 'Admin settings' do + background do + sign_in_to_admin_area + end + + it 'saves settings' do + visit admin_settings_path + click_link_or_button 'Save' + expect(page).to have_text(t('admin.settings.create.saved')) + end +end From b14cc88deda8c2e5bcc3e9b13ee4b7008d2d7eea Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 22 Aug 2017 22:52:43 +0300 Subject: [PATCH 09/11] Fix admin setting list HTML --- app/views/admin/settings/_setting_row.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/settings/_setting_row.haml b/app/views/admin/settings/_setting_row.haml index ce2107ba8..befd5b9d9 100644 --- a/app/views/admin/settings/_setting_row.haml +++ b/app/views/admin/settings/_setting_row.haml @@ -3,7 +3,7 @@ %td.col-md-6= var.to_s.humanize - if [TrueClass, FalseClass].include?(value.class) %td.col-md-6 - = hidden_field_tag("[settings][#{var}]", '') + = hidden_field_tag("[settings][#{var}]", '', id: nil) = check_box_tag("[settings][#{var}]", true, value) - else %td.col-md-6= text_field_tag("[settings][#{var}]", value, class: 'form-control') From 6d7701e52f698ff95918d95f7b40c3d05e21af4d Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 22 Aug 2017 23:09:34 +0300 Subject: [PATCH 10/11] Remove unused code --- app/controllers/admin/settings_controller.rb | 24 +------------------- config/routes.rb | 2 +- 2 files changed, 2 insertions(+), 24 deletions(-) diff --git a/app/controllers/admin/settings_controller.rb b/app/controllers/admin/settings_controller.rb index d4df95649..4940ff873 100644 --- a/app/controllers/admin/settings_controller.rb +++ b/app/controllers/admin/settings_controller.rb @@ -1,7 +1,6 @@ module Admin class SettingsController < BaseController load_and_authorize_resource - before_action :set_setting_group, only: [:show, :update] def index @settings = Setting.unscoped @@ -22,30 +21,9 @@ module Admin end end - def show; - end - - def update - if @setting_group.update(setting_group_params) - flash[:notice] = I18n.t('setting_updated') - redirect_to [:admin, @setting_group] - else - flash[:alert] = I18n.t('failed_to_update_setting') - render 'show' - end - end - private - def set_setting_group - @setting_group = SettingGroup.find(params[:id]) - end - - def setting_group_params - params.require(:setting_group).permit(settings_attributes: [:value, :id]) - end - - def casted_settings # rubocop:disable Metrics/MethodLength + def casted_settings settings = {} ints = [ diff --git a/config/routes.rb b/config/routes.rb index e9fb61989..b232c235f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -220,7 +220,7 @@ Rails.application.routes.draw do end end - resources :settings + resources :settings, only: %i[index create] resources :blocked_domains do member do From b632dbc2de743dcfb6c52532ca6b885dda642df2 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Wed, 23 Aug 2017 01:24:01 +0300 Subject: [PATCH 11/11] Move setting types from controller to model --- app/controllers/admin/settings_controller.rb | 43 +------------ app/models/setting.rb | 46 ++++++++++++++ spec/models/setting_spec.rb | 64 +++++++++++++++++--- spec/requests/admin/settings/create_spec.rb | 35 +++++++++++ 4 files changed, 141 insertions(+), 47 deletions(-) create mode 100644 spec/requests/admin/settings/create_spec.rb diff --git a/app/controllers/admin/settings_controller.rb b/app/controllers/admin/settings_controller.rb index 4940ff873..293c994b6 100644 --- a/app/controllers/admin/settings_controller.rb +++ b/app/controllers/admin/settings_controller.rb @@ -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 diff --git a/app/models/setting.rb b/app/models/setting.rb index cb52fd1b7..5ac62355e 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -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 diff --git a/spec/models/setting_spec.rb b/spec/models/setting_spec.rb index 84af99501..599693ae6 100644 --- a/spec/models/setting_spec.rb +++ b/spec/models/setting_spec.rb @@ -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 diff --git a/spec/requests/admin/settings/create_spec.rb b/spec/requests/admin/settings/create_spec.rb new file mode 100644 index 000000000..c9e7e443d --- /dev/null +++ b/spec/requests/admin/settings/create_spec.rb @@ -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