Merge pull request #5325 from consuldemocracy/settings_refactor

Refactor settings related code
This commit is contained in:
Senén Rodero
2024-01-30 17:04:24 +01:00
committed by GitHub
52 changed files with 507 additions and 276 deletions

View File

@@ -1,6 +0,0 @@
.admin .featured-settings-table {
td {
max-width: $global-width / 3;
}
}

View File

@@ -0,0 +1,13 @@
.admin {
.featured-settings-table {
td {
max-width: $global-width / 3;
}
}
.mixed-settings-table {
td {
width: 50%;
}
}
}

View File

@@ -0,0 +1,7 @@
<h2><%= t("admin.settings.index.general") %></h2>
<%= render Admin::Settings::TableComponent.new(setting_name: "setting") do %>
<% settings.each do |key| %>
<%= render Admin::Settings::RowComponent.new(key, tab: "#tab-configuration") %>
<% end %>
<% end %>

View File

@@ -0,0 +1,38 @@
class Admin::Settings::ConfigurationTabComponent < ApplicationComponent
def settings
%w[
official_level_1_name
official_level_2_name
official_level_3_name
official_level_4_name
official_level_5_name
max_ratio_anon_votes_on_debates
max_votes_for_debate_edit
max_votes_for_proposal_edit
comments_body_max_length
proposal_code_prefix
votes_for_proposal_success
months_to_archive_proposals
email_domain_for_officials
facebook_handle
instagram_handle
telegram_handle
twitter_handle
twitter_hashtag
youtube_handle
org_name
meta_title
meta_description
meta_keywords
proposal_notification_minimum_interval_in_days
direct_message_max_per_day
mailer_from_name
mailer_from_address
min_age_to_participate
hot_score_period_in_days
related_content_score_threshold
featured_proposals_number
postal_codes
]
end
end

View File

@@ -1,5 +1,6 @@
<%= form_tag admin_update_content_types_path, method: :put, id: "edit_#{dom_id(setting)}" do %>
<%= hidden_field_tag "id", setting.id, id: dom_id(setting, :id) %>
<%= hidden_field_tag :tab, tab if tab %>
<div class="small-12 medium-6 large-8 column">
<% group = setting.content_type_group %>

View File

@@ -0,0 +1,9 @@
class Admin::Settings::ContentTypesFormComponent < ApplicationComponent
attr_reader :setting, :tab
delegate :dom_id, to: :helpers
def initialize(setting, tab: nil)
@setting = setting
@tab = tab
end
end

View File

@@ -1,5 +1,5 @@
<%= form_for([:admin, feature], remote: remote?, html: { class: "featured-settings-form" }) do |f| %>
<%= f.hidden_field :tab, id: dom_id(feature, :tab), value: tab if tab %>
<%= form_for([:admin, feature], remote: remote?, authenticity_token: true, html: { class: "featured-settings-form" }) do |f| %>
<%= hidden_field_tag :tab, tab if tab %>
<%= f.hidden_field :describedby, id: dom_id(feature, :describedby), value: describedby if describedby %>
<%= f.hidden_field :value, id: dom_id(feature, :value), value: (enabled? ? "" : "active") %>
<%= f.button text, options %>

View File

@@ -0,0 +1,7 @@
<h2><%= t("admin.settings.index.feature_flags") %></h2>
<%= render Admin::Settings::TableComponent.new(setting_name: "feature", table_class: "featured-settings-table") do %>
<% settings.each do |key| %>
<%= render Admin::Settings::RowComponent.new(key, type: :feature, tab: "#tab-feature-flags") %>
<% end %>
<% end %>

View File

@@ -0,0 +1,31 @@
class Admin::Settings::FeaturesTabComponent < ApplicationComponent
def settings
%w[
feature.featured_proposals
feature.facebook_login
feature.google_login
feature.twitter_login
feature.wordpress_login
feature.public_stats
feature.signature_sheets
feature.user.recommendations
feature.user.recommendations_on_debates
feature.user.recommendations_on_proposals
feature.user.skip_verification
feature.community
feature.map
feature.allow_attached_documents
feature.allow_images
feature.help_page
feature.remote_translations
feature.translation_interface
feature.remote_census
feature.valuation_comment_notification
feature.graphql_api
feature.sdg
feature.machine_learning
feature.remove_investments_supports
feature.dashboard.notification_emails
]
end
end

View File

@@ -0,0 +1,12 @@
<h2><%= t("admin.settings.index.images_and_documents") %></h2>
<%= render Admin::Settings::TableComponent.new(setting_name: "setting") do %>
<% images_settings.each do |key| %>
<%= render Admin::Settings::RowComponent.new(key, tab: tab) %>
<% end %>
<%= render Admin::Settings::RowComponent.new("uploads.images.content_types", type: :content_type, tab: tab) %>
<% documents_settings.each do |key| %>
<%= render Admin::Settings::RowComponent.new(key, tab: tab) %>
<% end %>
<%= render Admin::Settings::RowComponent.new("uploads.documents.content_types", type: :content_type, tab: tab) %>
<% end %>

View File

@@ -0,0 +1,22 @@
class Admin::Settings::ImagesAndDocumentsTabComponent < ApplicationComponent
def tab
"#tab-images-and-documents"
end
def images_settings
%w[
uploads.images.title.min_length
uploads.images.title.max_length
uploads.images.min_width
uploads.images.min_height
uploads.images.max_size
]
end
def documents_settings
%w[
uploads.documents.max_amount
uploads.documents.max_size
]
end
end

View File

@@ -20,6 +20,7 @@
<%= hidden_field_tag :latitude, Setting["map.latitude"] %>
<%= hidden_field_tag :longitude, Setting["map.longitude"] %>
<%= hidden_field_tag :zoom, Setting["map.zoom"] %>
<%= hidden_field_tag :tab, tab if tab %>
<div class="small-12 medium-6 large-4 margin-top">
<%= submit_tag t("admin.settings.index.map.form.submit"),

View File

@@ -0,0 +1,7 @@
class Admin::Settings::MapFormComponent < ApplicationComponent
attr_reader :tab
def initialize(tab: nil)
@tab = tab
end
end

View File

@@ -0,0 +1,17 @@
<% if feature?(:map) %>
<h2><%= t("admin.settings.index.map.title") %></h2>
<%= render Admin::Settings::TableComponent.new(setting_name: "setting") do %>
<% settings.each do |key| %>
<%= render Admin::Settings::RowComponent.new(key, tab: tab) %>
<% end %>
<% end %>
<p><%= t("admin.settings.index.map.help") %></p>
<%= render Admin::Settings::MapFormComponent.new(tab: tab) %>
<% else %>
<div class="callout primary">
<%= t("admin.settings.index.map.how_to_enable") %>
</div>
<% end %>

View File

@@ -0,0 +1,13 @@
class Admin::Settings::MapTabComponent < ApplicationComponent
def tab
"#tab-map-configuration"
end
def settings
%w[
map.latitude
map.longitude
map.zoom
]
end
end

View File

@@ -0,0 +1,7 @@
<h2><%= t("admin.settings.index.participation_processes") %></h2>
<%= render Admin::Settings::TableComponent.new(setting_name: "feature", table_class: "featured-settings-table") do %>
<% settings.each do |key| %>
<%= render Admin::Settings::RowComponent.new(key, type: :feature, tab: "#tab-participation-processes") %>
<% end %>
<% end %>

View File

@@ -0,0 +1,11 @@
class Admin::Settings::ParticipationProcessesTabComponent < ApplicationComponent
def settings
%w[
process.debates
process.proposals
process.polls
process.budgets
process.legislation
]
end
end

View File

@@ -0,0 +1,7 @@
<h2><%= t("admin.settings.index.dashboard.title") %></h2>
<%= render Admin::Settings::TableComponent.new(setting_name: "setting") do %>
<% settings.each do |key| %>
<%= render Admin::Settings::RowComponent.new(key, tab: "#tab-proposals") %>
<% end %>
<% end %>

View File

@@ -0,0 +1,14 @@
class Admin::Settings::ProposalsDashboardTabComponent < ApplicationComponent
def settings
%w[
proposals.successful_proposal_id
proposals.poll_short_title
proposals.poll_description
proposals.poll_link
proposals.email_short_title
proposals.email_description
proposals.poster_short_title
proposals.poster_description
]
end
end

View File

@@ -0,0 +1,23 @@
<% if feature?(:remote_census) %>
<h2><%= t("admin.settings.index.remote_census.title") %></h2>
<%= render Admin::Settings::TableComponent.new(setting_name: "remote_census_general_name") do %>
<% general_settings.each do |key| %>
<%= render Admin::Settings::RowComponent.new(key, tab: tab) %>
<% end %>
<% end %>
<%= render Admin::Settings::TableComponent.new(setting_name: "remote_census_request_name") do %>
<% request_settings.each do |key| %>
<%= render Admin::Settings::RowComponent.new(key, tab: tab) %>
<% end %>
<% end %>
<%= render Admin::Settings::TableComponent.new(setting_name: "remote_census_response_name") do %>
<% response_settings.each do |key| %>
<%= render Admin::Settings::RowComponent.new(key, tab: tab) %>
<% end %>
<% end %>
<% else %>
<div class="callout primary">
<%= t("admin.settings.index.remote_census.how_to_enable") %>
</div>
<% end %>

View File

@@ -0,0 +1,34 @@
class Admin::Settings::RemoteCensusTabComponent < ApplicationComponent
def tab
"#tab-remote-census-configuration"
end
def general_settings
%w[
remote_census.general.endpoint
]
end
def request_settings
%w[
remote_census.request.method_name
remote_census.request.structure
remote_census.request.document_type
remote_census.request.document_number
remote_census.request.date_of_birth
remote_census.request.postal_code
]
end
def response_settings
%w[
remote_census.response.date_of_birth
remote_census.response.postal_code
remote_census.response.district
remote_census.response.gender
remote_census.response.name
remote_census.response.surname
remote_census.response.valid
]
end
end

View File

@@ -0,0 +1,18 @@
<tr>
<td>
<strong id="<%= dom_id(setting, :title) %>"><%= t("settings.#{setting.key}") %></strong>
<br>
<span id="<%= dom_id(setting, :description) %>" class="small">
<%= t("settings.#{setting.key}_description", default: t("admin.settings.no_description")) %>
</span>
</td>
<td>
<% if content_type_setting? %>
<%= render Admin::Settings::ContentTypesFormComponent.new(setting, tab: tab) %>
<% elsif featured_setting? %>
<%= render Admin::Settings::FeaturedSettingsFormComponent.new(setting, tab: tab) %>
<% else %>
<%= render Admin::Settings::TextFormComponent.new(setting, tab: tab) %>
<% end %>
</td>
</tr>

View File

@@ -0,0 +1,22 @@
class Admin::Settings::RowComponent < ApplicationComponent
attr_reader :key, :tab, :type
delegate :dom_id, to: :helpers
def initialize(key, type: :text, tab: nil)
@key = key
@type = type
@tab = tab
end
def setting
@setting ||= Setting.find_by!(key: key)
end
def content_type_setting?
type == :content_type
end
def featured_setting?
type == :feature
end
end

View File

@@ -0,0 +1,13 @@
<% if feature?(:sdg) %>
<h2><%= t("admin.settings.index.sdg.title") %></h2>
<%= render Admin::Settings::TableComponent.new(setting_name: "feature", table_class: "featured-settings-table") do %>
<% settings.each do |key| %>
<%= render Admin::Settings::RowComponent.new(key, type: :feature, tab: "#tab-sdg-configuration") %>
<% end %>
<% end %>
<% else %>
<div class="callout primary">
<%= t("admin.settings.index.sdg.how_to_enable") %>
</div>
<% end %>

View File

@@ -0,0 +1,11 @@
class Admin::Settings::SDGConfigurationTabComponent < ApplicationComponent
def settings
%w[
sdg.process.debates
sdg.process.proposals
sdg.process.polls
sdg.process.budgets
sdg.process.legislation
]
end
end

View File

@@ -0,0 +1,11 @@
<table class="<%= table_class %>">
<thead>
<tr>
<th><%= key_header %></th>
<th><%= value_header %></th>
</tr>
</thead>
<tbody>
<%= content %>
</tbody>
</table>

View File

@@ -0,0 +1,26 @@
class Admin::Settings::TableComponent < ApplicationComponent
attr_reader :setting_name, :table_class
def initialize(setting_name:, table_class: "mixed-settings-table")
@setting_name = setting_name
@table_class = table_class
end
def key_header
if setting_name == "feature"
t("admin.settings.setting")
elsif setting_name == "setting"
t("admin.settings.setting_name")
else
t("admin.settings.#{setting_name}")
end
end
def value_header
if setting_name == "feature"
t("admin.settings.index.features.enabled")
else
t("admin.settings.setting_value")
end
end
end

View File

@@ -1,5 +1,5 @@
<%= form_for([:admin, setting]) do |f| %>
<%= f.hidden_field :tab, id: dom_id(setting, :tab), value: tab if defined?(tab) %>
<%= hidden_field_tag :tab, tab if tab %>
<div class="small-12 medium-6 large-8 column">
<%= f.text_area :value,
label: false,

View File

@@ -0,0 +1,9 @@
class Admin::Settings::TextFormComponent < ApplicationComponent
attr_reader :setting, :tab
delegate :dom_id, to: :helpers
def initialize(setting, tab: nil)
@setting = setting
@tab = tab
end
end

View File

@@ -1,16 +1,5 @@
class Admin::SettingsController < Admin::BaseController
def index
all_settings = Setting.all.group_by(&:type)
@configuration_settings = all_settings["configuration"]
@feature_settings = all_settings["feature"]
@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"]
@sdg_settings = all_settings["sdg"]
end
def update
@@ -27,7 +16,7 @@ class Admin::SettingsController < Admin::BaseController
Setting["map.latitude"] = params[:latitude].to_f
Setting["map.longitude"] = params[:longitude].to_f
Setting["map.zoom"] = params[:zoom].to_i
redirect_to admin_settings_path, notice: t("admin.settings.index.map.flash.update")
redirect_to request_referer, notice: t("admin.settings.index.map.flash.update")
end
def update_content_types
@@ -37,7 +26,7 @@ class Admin::SettingsController < Admin::BaseController
Setting.mime_types[group][content_type]
end
setting.update! value: mime_type_values.join(" ")
redirect_to admin_settings_path, notice: t("admin.settings.flash.updated")
redirect_to request_referer, notice: t("admin.settings.flash.updated")
end
private
@@ -55,8 +44,6 @@ class Admin::SettingsController < Admin::BaseController
end
def request_referer
return request.referer + params[:setting][:tab] if params[:setting][:tab]
request.referer
request.referer + params[:tab].to_s
end
end

View File

@@ -9,8 +9,6 @@ class Admin::SiteCustomization::ContentBlocksController < Admin::SiteCustomizati
def index
@content_blocks = SiteCustomization::ContentBlock.order(:name, :locale)
@headings_content_blocks = Budget::ContentBlock.all
all_settings = Setting.all.group_by(&:type)
@html_settings = all_settings["html"]
end
def create

View File

@@ -15,12 +15,4 @@ module SettingsHelper
def setting
@all_settings ||= Setting.all.to_h { |s| [s.key, s.value.presence] }
end
def display_setting_name(setting_name)
if setting_name == "setting"
t("admin.settings.setting_name")
else
t("admin.settings.#{setting_name}")
end
end
end

View File

@@ -7,24 +7,10 @@ class Setting < ApplicationRecord
key.split(".").first
end
def type
if %w[feature process proposals map html homepage uploads sdg machine_learning].include? prefix
prefix
elsif %w[remote_census].include? prefix
key.rpartition(".").first
else
"configuration"
end
end
def enabled?
value.present?
end
def content_type?
key.split(".").last == "content_types"
end
def content_type_group
key.split(".").second
end

View File

@@ -1,3 +0,0 @@
<h2><%= t("admin.settings.index.general") %></h2>
<%= render "settings_table", settings: @configuration_settings, setting_name: "setting", tab: "#tab-configuration" %>

View File

@@ -1,25 +0,0 @@
<table class="featured-settings-table">
<thead>
<tr>
<th><%= t("admin.settings.setting") %></th>
<th><%= t("admin.settings.index.features.enabled") %></th>
</tr>
</thead>
<tbody>
<% features.each do |feature| %>
<tr>
<td>
<strong id="<%= dom_id(feature, :title) %>"><%= t("settings.#{feature.key}") %></strong>
<br>
<span class="small" id="<%= dom_id(feature, :description) %>">
<%= t("settings.#{feature.key}_description", default: t("admin.settings.no_description")) %>
</span>
</td>
<td>
<%= render Admin::Settings::FeaturedSettingsFormComponent.new(feature, tab: tab) %>
</td>
</tr>
<% end %>
</tbody>
</table>

View File

@@ -1,3 +0,0 @@
<h2><%= t("admin.settings.index.feature_flags") %></h2>
<%= render "featured_settings_table", features: @feature_settings, tab: "#tab-feature-flags" %>

View File

@@ -1,3 +0,0 @@
<h2><%= t("admin.settings.index.images_and_documents") %></h2>
<%= render "settings_table", settings: @uploads_settings, setting_name: "setting" %>

View File

@@ -1,13 +0,0 @@
<% if feature?(:map) %>
<h2><%= t("admin.settings.index.map.title") %></h2>
<%= render "settings_table", settings: @map_configuration_settings, setting_name: "setting", tab: "#tab-map-configuration" %>
<p><%= t("admin.settings.index.map.help") %></p>
<%= render "map_form" %>
<% else %>
<div class="callout primary">
<%= t("admin.settings.index.map.how_to_enable") %>
</div>
<% end %>

View File

@@ -1,3 +0,0 @@
<h2><%= t("admin.settings.index.participation_processes") %></h2>
<%= render "featured_settings_table", features: @participation_processes_settings, tab: "#tab-participation-processes" %>

View File

@@ -1,3 +0,0 @@
<h2><%= t("admin.settings.index.dashboard.title") %></h2>
<%= render "settings_table", settings: @proposals_settings, setting_name: "setting", tab: "#tab-proposals" %>

View File

@@ -1,11 +0,0 @@
<% if feature?(:remote_census) %>
<h2><%= t("admin.settings.index.remote_census.title") %></h2>
<%= render "settings_table", settings: @remote_census_general_settings, setting_name: "remote_census_general_name", tab: "#tab-remote-census-configuration" %>
<%= render "settings_table", settings: @remote_census_request_settings, setting_name: "remote_census_request_name", tab: "#tab-remote-census-configuration" %>
<%= render "settings_table", settings: @remote_census_response_settings, setting_name: "remote_census_response_name", tab: "#tab-remote-census-configuration" %>
<% else %>
<div class="callout primary">
<%= t("admin.settings.index.remote_census.how_to_enable") %>
</div>
<% end %>

View File

@@ -1,9 +0,0 @@
<% if feature?(:sdg) %>
<h2><%= t("admin.settings.index.sdg.title") %></h2>
<%= render "featured_settings_table", features: @sdg_settings, tab: "#tab-sdg-configuration" %>
<% else %>
<div class="callout primary">
<%= t("admin.settings.index.sdg.how_to_enable") %>
</div>
<% end %>

View File

@@ -1,32 +0,0 @@
<table>
<thead>
<tr>
<th><%= display_setting_name(setting_name) %></th>
<th><%= t("admin.settings.setting_value") %></th>
</tr>
</thead>
<tbody>
<% settings.each do |setting| %>
<tr>
<td class="small-6">
<strong><%= t("settings.#{setting.key}") %></strong>
<br>
<span id="<%= dom_id(setting, :description) %>" class="small">
<%= t("settings.#{setting.key}_description", default: t("admin.settings.no_description")) %>
</span>
</td>
<td class="small-6">
<% if setting.content_type? %>
<%= render "admin/settings/content_types_settings_form", setting: setting %>
<% else %>
<% if defined?(tab) %>
<%= render "admin/settings/settings_form", setting: setting, tab: tab %>
<% else %>
<%= render "admin/settings/settings_form", setting: setting %>
<% end %>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>

View File

@@ -3,34 +3,34 @@
<%= render "filter_subnav" %>
<div class="tabs-panel is-active" id="tab-configuration">
<%= render "configuration_settings_tab" %>
<%= render Admin::Settings::ConfigurationTabComponent.new %>
</div>
<div class="tabs-panel" id="tab-participation-processes">
<%= render "participation_processes_tab" %>
<%= render Admin::Settings::ParticipationProcessesTabComponent.new %>
</div>
<div class="tabs-panel" id="tab-feature-flags">
<%= render "features_tab" %>
<%= render Admin::Settings::FeaturesTabComponent.new %>
</div>
<div class="tabs-panel" id="tab-map-configuration">
<%= render "map_configuration_tab" %>
<%= render Admin::Settings::MapTabComponent.new %>
</div>
<div class="tabs-panel" id="tab-images-and-documents">
<%= render "images_and_documents_tab" %>
<%= render Admin::Settings::ImagesAndDocumentsTabComponent.new %>
</div>
<div class="tabs-panel" id="tab-proposals">
<%= render "proposals_dashboard" %>
<%= render Admin::Settings::ProposalsDashboardTabComponent.new %>
</div>
<div class="tabs-panel" id="tab-remote-census-configuration">
<%= render "remote_census_configuration_tab" %>
<%= render Admin::Settings::RemoteCensusTabComponent.new %>
</div>
<div class="tabs-panel" id="tab-sdg-configuration">
<%= render "sdg_configuration_tab" %>
<%= render Admin::Settings::SDGConfigurationTabComponent.new %>
</div>
</div>

View File

@@ -1,11 +1,11 @@
var form = $("<%= j render Admin::Settings::FeaturedSettingsFormComponent.new(
@setting,
tab: params[:setting][:tab],
tab: params[:tab],
describedby: params[:setting][:describedby]
) %>");
$("#" + form.attr("id")).html(form.html()).find("[type='submit']").focus();
<% if @setting.type == "feature" || @setting.type == "process" %>
<% if @setting.prefix == "feature" || @setting.prefix == "process" %>
$("#side_menu").html("<%= j render Admin::MenuComponent.new %>").foundation();
<% end %>

View File

@@ -6,7 +6,10 @@
<h2 class="inline-block"><%= t("admin.site_customization.content_blocks.index.title") %></h2>
<%= render "admin/settings/settings_table", settings: @html_settings, setting_name: "setting" %>
<%= render Admin::Settings::TableComponent.new(setting_name: "setting") do %>
<%= render Admin::Settings::RowComponent.new("html.per_page_code_body") %>
<%= render Admin::Settings::RowComponent.new("html.per_page_code_head") %>
<% end %>
<h3><%= t("admin.site_customization.content_blocks.information") %></h3>

View File

@@ -0,0 +1,7 @@
<noscript>
<style type="text/css">
.admin .tabs-content > .tabs-panel {
display: block;
}
</style>
</noscript>

View File

@@ -2,6 +2,7 @@
<html <%= common_html_attributes %>>
<head>
<%= render "layouts/common_head", default_title: "Admin" %>
<%= render "layouts/no_script" %>
<%= content_for :head %>
</head>

View File

@@ -0,0 +1,54 @@
require "rails_helper"
describe Admin::Settings::TableComponent do
describe "#key_header" do
it "returns correct table header for the setting name colums" do
render_inline Admin::Settings::TableComponent.new setting_name: "feature"
expect(page).to have_content("Feature")
render_inline Admin::Settings::TableComponent.new setting_name: "setting"
expect(page).to have_content("Setting")
render_inline Admin::Settings::TableComponent.new setting_name: "remote_census_general_name"
expect(page).to have_content("General Information")
render_inline Admin::Settings::TableComponent.new setting_name: "remote_census_request_name"
expect(page).to have_content("Request Data")
render_inline Admin::Settings::TableComponent.new setting_name: "remote_census_response_name"
expect(page).to have_content("Response Data")
end
end
describe "#value_header" do
it "returns correct table header for the setting interface column" do
render_inline Admin::Settings::TableComponent.new setting_name: "feature"
expect(page).to have_content("Enabled")
render_inline Admin::Settings::TableComponent.new setting_name: "setting"
expect(page).to have_content("Value")
end
end
describe "#table_class" do
it "returns the `mixed-settings-table` by default" do
render_inline Admin::Settings::TableComponent.new setting_name: "feature"
expect(page).to have_css(".mixed-settings-table")
end
it "returns the given table_class" do
render_inline Admin::Settings::TableComponent.new setting_name: "feature", table_class: "my-table-class"
expect(page).not_to have_css(".mixed-settings-table")
expect(page).to have_css(".my-table-class")
end
end
end

View File

@@ -24,13 +24,4 @@ RSpec.describe SettingsHelper do
expect(feature?("f4")).to be nil
end
end
describe "#display_setting_name" do
it "returns correct setting_name" do
expect(display_setting_name("setting")).to eq("Setting")
expect(display_setting_name("remote_census_general_name")).to eq("General Information")
expect(display_setting_name("remote_census_request_name")).to eq("Request Data")
expect(display_setting_name("remote_census_response_name")).to eq("Response Data")
end
end
end

View File

@@ -27,59 +27,6 @@ describe Setting do
end
end
describe "#type" do
it "returns the key prefix for 'process' settings" do
process_setting = Setting.create!(key: "process.whatever")
expect(process_setting.type).to eq "process"
end
it "returns the key prefix for 'feature' settings" do
feature_setting = Setting.create!(key: "feature.whatever")
expect(feature_setting.type).to eq "feature"
end
it "returns the key prefix for 'map' settings" do
map_setting = Setting.create!(key: "map.whatever")
expect(map_setting.type).to eq "map"
end
it "returns the key prefix for 'html' settings" do
html_setting = Setting.create!(key: "html.whatever")
expect(html_setting.type).to eq "html"
end
it "returns the key prefix for 'homepage' settings" do
homepage_setting = Setting.create!(key: "homepage.whatever")
expect(homepage_setting.type).to eq "homepage"
end
it "returns the key prefix for 'sdg' settings" do
sdg_setting = Setting.create!(key: "sdg.whatever")
expect(sdg_setting.type).to eq "sdg"
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"
end
end
describe "#enabled?" do
it "is true if value is present" do
setting = Setting.create!(key: "feature.whatever", value: 1)
@@ -101,16 +48,6 @@ describe Setting do
end
end
describe "#content_type?" do
it "returns true if the last part of the key is content_types" do
expect(Setting.create!(key: "key_name.content_types").content_type?).to be true
end
it "returns false if the last part of the key is not content_types" do
expect(Setting.create!(key: "key_name.whatever").content_type?).to be false
end
end
describe "#content_type_group" do
it "returns the group for content_types settings" do
images = Setting.create!(key: "update.images.content_types")

View File

@@ -2,24 +2,18 @@ require "rails_helper"
describe "Admin settings", :admin do
scenario "Index" do
create(:setting, key: "super.users.first")
create(:setting, key: "super.users.second")
create(:setting, key: "super.users.third")
visit admin_settings_path
expect(page).to have_content "First"
expect(page).to have_content "Second"
expect(page).to have_content "Third"
expect(page).to have_content "Level 1 public official"
expect(page).to have_content "Maximum ratio of anonymous votes per Debate"
expect(page).to have_content "Comments body max length"
end
scenario "Update" do
create(:setting, key: "super.users.first")
visit admin_settings_path
within "tr", text: "First" do
fill_in "First", with: "Super Users of level 1"
within "tr", text: "Level 1 public official" do
fill_in "Level 1 public official", with: "Super Users of level 1"
click_button "Update"
end
@@ -173,13 +167,11 @@ describe "Admin settings", :admin do
end
scenario "On #tab-remote-census-configuration" do
create(:setting, key: "remote_census.general.whatever")
visit admin_settings_path
find("#remote-census-tab").click
within "tr", text: "Whatever" do
fill_in "Whatever", with: "New value"
within "tr", text: "Endpoint" do
fill_in "Endpoint", with: "example.org/webservice"
click_button "Update"
end
@@ -189,13 +181,10 @@ describe "Admin settings", :admin do
end
scenario "On #tab-configuration" do
Setting.create!(key: "whatever")
visit admin_settings_path
find("#tab-configuration").click
within "tr", text: "Whatever" do
fill_in "Whatever", with: "New value"
within "tr", text: "Level 1 public official" do
fill_in "Level 1 public official", with: "Super Users of level 1"
click_button "Update"
end
@@ -209,29 +198,36 @@ describe "Admin settings", :admin do
end
scenario "On #tab-map-configuration" do
Setting.create!(key: "map.whatever")
visit admin_settings_path
click_link "Map configuration"
within "tr", text: "Whatever" do
fill_in "Whatever", with: "New value"
within "tr", text: "Latitude" do
fill_in "Latitude", with: "-3.636"
click_button "Update"
end
expect(page).to have_current_path(admin_settings_path)
expect(page).to have_css("div#tab-map-configuration.is-active")
end
scenario "On #tab-map-configuration when using the interactive map" do
visit admin_settings_path(anchor: "tab-map-configuration")
within "#map-form" do
click_button "Update"
end
expect(page).to have_content("Map configuration updated successfully.")
expect(page).to have_current_path(admin_settings_path)
expect(page).to have_css("div#tab-map-configuration.is-active")
end
end
scenario "On #tab-proposals" do
Setting.create!(key: "proposals.whatever")
visit admin_settings_path
find("#proposals-tab").click
within "tr", text: "Whatever" do
fill_in "Whatever", with: "New value"
within "tr", text: "Polls description" do
fill_in "Polls description", with: "Polls description"
click_button "Update"
end
@@ -240,22 +236,18 @@ describe "Admin settings", :admin do
end
scenario "On #tab-participation-processes" do
Setting.create!(key: "process.whatever")
visit admin_settings_path
find("#participation-processes-tab").click
within("tr", text: "Whatever") { click_button "No" }
within("tr", text: "Debates") { click_button "Yes" }
expect(page).to have_current_path(admin_settings_path)
expect(page).to have_css("div#tab-participation-processes.is-active")
end
scenario "On #tab-feature-flags" do
Setting.create!(key: "feature.whatever")
visit admin_settings_path
find("#features-tab").click
within("tr", text: "Whatever") { click_button "No" }
within("tr", text: "Featured proposals") { click_button "No" }
expect(page).to have_current_path(admin_settings_path)
expect(page).to have_css("div#tab-feature-flags.is-active")
@@ -263,20 +255,30 @@ describe "Admin settings", :admin do
scenario "On #tab-sdg-configuration" do
Setting["feature.sdg"] = true
Setting.create!(key: "sdg.whatever")
visit admin_settings_path
click_link "SDG configuration"
within("tr", text: "Whatever") do
click_button "No"
within("tr", text: "Related SDG in debates") do
click_button "Yes"
expect(page).to have_button "Yes"
expect(page).to have_button "No"
end
expect(page).to have_current_path(admin_settings_path)
expect(page).to have_css("h2", exact_text: "SDG configuration")
end
scenario "On #tab-images-and-documents" do
Setting["feature.sdg"] = true
visit admin_settings_path(anchor: "tab-images-and-documents")
within("tr", text: "Maximum number of documents") do
fill_in "Maximum number of documents", with: 5
click_button "Update"
end
expect(page).to have_current_path(admin_settings_path)
expect(page).to have_field("Maximum number of documents", with: 5)
end
end
describe "Skip verification" do