From 637675a1f58bf0318ac1017c76f3f6bf1778fe5c Mon Sep 17 00:00:00 2001 From: taitus Date: Wed, 10 Apr 2019 14:04:56 +0200 Subject: [PATCH] Add content to the Remote Census Configuration tab - Render remote census configuration content on settings index. - Update type method from Setting On Admin::SettingsController#index we are using 'all_settings' to group all settings by 'type' method. 'type' method return the first part of key when split by '.' To allow use by example: all_settings["remote_census.general"] and recover only settings related with this key we have added new 'elsif' on 'type' method. --- app/controllers/admin/settings_controller.rb | 3 +++ app/models/setting.rb | 2 ++ .../_remote_census_configuration_tab.html.erb | 5 +++++ app/views/admin/settings/index.html.erb | 4 ++++ spec/models/setting_spec.rb | 15 +++++++++++++++ 5 files changed, 29 insertions(+) create mode 100644 app/views/admin/settings/_remote_census_configuration_tab.html.erb diff --git a/app/controllers/admin/settings_controller.rb b/app/controllers/admin/settings_controller.rb index f24b6c63e..d21f6de23 100644 --- a/app/controllers/admin/settings_controller.rb +++ b/app/controllers/admin/settings_controller.rb @@ -14,6 +14,9 @@ class Admin::SettingsController < Admin::BaseController @participation_processes_settings = all_settings["process"] @map_configuration_settings = all_settings["map"] @proposals_settings = all_settings["proposals"] + @remote_census_general_settings = all_settings["remote_census.general"] + @remote_census_request_settings = all_settings["remote_census.request"] + @remote_census_response_settings = all_settings["remote_census.response"] @uploads_settings = all_settings["uploads"] end diff --git a/app/models/setting.rb b/app/models/setting.rb index ea773ecbb..61a6ebf30 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -10,6 +10,8 @@ class Setting < ApplicationRecord def type if %w[feature process proposals map html homepage uploads].include? prefix prefix + elsif %w[remote_census].include? prefix + key.rpartition(".").first else "configuration" end diff --git a/app/views/admin/settings/_remote_census_configuration_tab.html.erb b/app/views/admin/settings/_remote_census_configuration_tab.html.erb new file mode 100644 index 000000000..f16af9d80 --- /dev/null +++ b/app/views/admin/settings/_remote_census_configuration_tab.html.erb @@ -0,0 +1,5 @@ +

<%= t("admin.settings.index.remote_census.title") %>

+ + <%= render "settings_table", settings: @remote_census_general_settings %> + <%= render "settings_table", settings: @remote_census_request_settings %> + <%= render "settings_table", settings: @remote_census_response_settings %> diff --git a/app/views/admin/settings/index.html.erb b/app/views/admin/settings/index.html.erb index a000cffc5..56d727887 100644 --- a/app/views/admin/settings/index.html.erb +++ b/app/views/admin/settings/index.html.erb @@ -25,4 +25,8 @@
<%= render "proposals_dashboard" %>
+ +
+ <%= render "remote_census_configuration_tab" %> +
diff --git a/spec/models/setting_spec.rb b/spec/models/setting_spec.rb index fde1615cd..19d7b5374 100644 --- a/spec/models/setting_spec.rb +++ b/spec/models/setting_spec.rb @@ -53,6 +53,21 @@ describe Setting do expect(homepage_setting.type).to eq "homepage" end + it "returns the key prefix for 'remote_census.general' settings" do + remote_census_general_setting = Setting.create(key: "remote_census.general.whatever") + expect(remote_census_general_setting.type).to eq "remote_census.general" + end + + it "returns the key prefix for 'remote_census_request' settings" do + remote_census_request_setting = Setting.create(key: "remote_census.request.whatever") + expect(remote_census_request_setting.type).to eq "remote_census.request" + end + + it "returns the key prefix for 'remote_census_response' settings" do + remote_census_response_setting = Setting.create(key: "remote_census.response.whatever") + expect(remote_census_response_setting.type).to eq "remote_census.response" + end + it "returns 'configuration' for the rest of the settings" do configuration_setting = Setting.create(key: "whatever") expect(configuration_setting.type).to eq "configuration"