From cbe84450acb02232de3f22c9a3b5498c8d282e8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Thu, 12 Nov 2020 14:26:03 +0100 Subject: [PATCH] Add Goals seeds and translations Extracted from the official United Nations Sustainable Development Goals website [1]. [1] https://www.un.org/sustainabledevelopment/sustainable-development-goals/ --- app/models/sdg/goal.rb | 2 +- config/locales/en/sdg.yml | 48 ++++++++++++++++++++++++ config/locales/es/sdg.yml | 48 ++++++++++++++++++++++++ db/dev_seeds.rb | 1 + db/dev_seeds/sdg.rb | 3 ++ db/sdg.rb | 3 ++ db/seeds.rb | 3 ++ spec/models/sdg/goal_spec.rb | 22 ++++++++--- spec/system/sdg_management/goals_spec.rb | 2 - 9 files changed, 124 insertions(+), 8 deletions(-) create mode 100644 db/dev_seeds/sdg.rb create mode 100644 db/sdg.rb diff --git a/app/models/sdg/goal.rb b/app/models/sdg/goal.rb index 7ff570cc8..eb83d4ecb 100644 --- a/app/models/sdg/goal.rb +++ b/app/models/sdg/goal.rb @@ -1,5 +1,5 @@ class SDG::Goal < ApplicationRecord - validates :code, presence: true, uniqueness: true + validates :code, presence: true, uniqueness: true, inclusion: { in: 1..17 } def title I18n.t("sdg.goals.goal_#{code}.title") diff --git a/config/locales/en/sdg.yml b/config/locales/en/sdg.yml index 44eb51fee..b969a39bf 100644 --- a/config/locales/en/sdg.yml +++ b/config/locales/en/sdg.yml @@ -4,3 +4,51 @@ en: goal_1: title: "No Poverty" description: "End poverty in all its forms, everywhere." + goal_2: + title: "Zero Hunger" + description: "Zero Hunger" + goal_3: + title: "Good Health and Well-Being" + description: "Ensure healthy lives and promote well-being for all at all ages." + goal_4: + title: "Quality Education" + description: "Quality Education" + goal_5: + title: "Gender Equality" + description: "Achieve gender equality and empower all women and girls." + goal_6: + title: "Clean Water and Sanitation" + description: "Ensure access to water and sanitation for all." + goal_7: + title: "Affordable and Clean Energy" + description: "Ensure access to affordable, reliable, sustainable and modern energy." + goal_8: + title: "Decent Work and Economic Growth" + description: "Promote inclusive and sustainable economic growth, employment and decent work for all." + goal_9: + title: "Industry, Innovation and Infrastructure" + description: "Build resilient infrastructure, promote sustainable industrialization and foster innovation." + goal_10: + title: "Reduced Inequalities" + description: "Reduce inequality within and among countries." + goal_11: + title: "Sustainable Cities and Communities" + description: "Make cities inclusive, safe, resilient and sustainable." + goal_12: + title: "Responsible Consumption and Production" + description: "Ensure sustainable consumption and production patterns." + goal_13: + title: "Climate Action" + description: "Take urgent action to combat climate change and its impacts." + goal_14: + title: "Life Below Water" + description: "Conserve and sustainably use the oceans, seas and marine resources." + goal_15: + title: "Life on Land" + description: "Sustainably manage forests, combat desertification, halt and reverse land degradation, halt biodiversity loss." + goal_16: + title: "Peace, Justice and Strong Institution" + description: "Promote just, peaceful and inclusive societies." + goal_17: + title: "Partnerships For the Goals" + description: "Revitalize the global partnership for Sustainable Development." diff --git a/config/locales/es/sdg.yml b/config/locales/es/sdg.yml index 4f13d07ab..6fb2ce9d9 100644 --- a/config/locales/es/sdg.yml +++ b/config/locales/es/sdg.yml @@ -4,3 +4,51 @@ es: goal_1: title: "Fin de la pobreza" description: "Poner fin a la pobreza en todas sus formas en todo el mundo." + goal_2: + title: "Hambre Cero" + description: "Poner fin al hambre." + goal_3: + title: "Salud y Bienestar" + description: "Garantizar una vida sana y promover el bienestar para todos en todas las edades." + goal_4: + title: "Educación de Calidad" + description: "Garantizar una educación inclusiva, equitativa y de calidad y promover oportunidades de aprendizaje durante toda la vida para todos." + goal_5: + title: "Igualdad de Género" + description: "Lograr la igualdad entre los géneros y empoderar a todas las mujeres y las niñas." + goal_6: + title: "Agua Limpia y Saneamiento" + description: "Garantizar la disponibilidad de agua y su gestión sostenible y el saneamiento para todos." + goal_7: + title: "Energía Sostenible y No Contaminante" + description: "Garantizar el acceso a una energía asequible, segura, sostenible y moderna." + goal_8: + title: "Trabajo Decente y Crecimiento Económico" + description: "Promover el crecimiento económico inclusivo y sostenible, el empleo y el trabajo decente para todos." + goal_9: + title: "Industria, Innovación e Infraestructuras" + description: "Construir infraestructuras resilientes, promover la industrialización sostenible y fomentar la innovación." + goal_10: + title: "Reducción de las Desigualdades" + description: "Reducir la desigualdad en y entre los países." + goal_11: + title: "Ciudades y Comunidades Sostenibles" + description: "Lograr que las ciudades sean más inclusivas, seguras, resilientes y sostenibles." + goal_12: + title: "Producción y Consumo Responsables" + description: "Garantizar modalidades de consumo y producción sostenibles" + goal_13: + title: "Acción Por el Clima" + description: "Adoptar medidas urgentes para combatir el cambio climático y sus efectos." + goal_14: + title: "Vida Submarina" + description: "Conservar y utilizar sosteniblemente los océanos, los mares y los recursos marinos." + goal_15: + title: "Vida de Ecosistemas Terrestres" + description: "Gestionar sosteniblemente los bosques, luchar contra la desertificación, detener e invertir la degradación de las tierras, detener la pérdida de biodiversidad." + goal_16: + title: "Paz, Justicia e Instituciones Sólidas" + description: "Promover sociedades justas, pacíficas e inclusivas." + goal_17: + title: "Alianzas para Lograr los Objetivos" + description: "Revitalizar la Alianza Mundial para el Desarrollo Sostenible." diff --git a/db/dev_seeds.rb b/db/dev_seeds.rb index a63ccd86d..7b8755b30 100644 --- a/db/dev_seeds.rb +++ b/db/dev_seeds.rb @@ -43,5 +43,6 @@ require_relative "dev_seeds/admin_notifications" require_relative "dev_seeds/legislation_proposals" require_relative "dev_seeds/milestones" require_relative "dev_seeds/pages" +require_relative "dev_seeds/sdg" log "All dev seeds created successfuly 👍" diff --git a/db/dev_seeds/sdg.rb b/db/dev_seeds/sdg.rb new file mode 100644 index 000000000..01336730e --- /dev/null +++ b/db/dev_seeds/sdg.rb @@ -0,0 +1,3 @@ +section "Creating Sustainable Development Goals" do + load Rails.root.join("db", "sdg.rb") +end diff --git a/db/sdg.rb b/db/sdg.rb new file mode 100644 index 000000000..f581c4899 --- /dev/null +++ b/db/sdg.rb @@ -0,0 +1,3 @@ +(1..17).each do |code| + SDG::Goal.where(code: code).first_or_create! +end diff --git a/db/seeds.rb b/db/seeds.rb index 167c83d15..dba4e37cb 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -16,3 +16,6 @@ WebSection.where(name: "help_page").first_or_create! # Default custom pages load Rails.root.join("db", "pages.rb") + +# Sustainable Development Goals +load Rails.root.join("db", "sdg.rb") diff --git a/spec/models/sdg/goal_spec.rb b/spec/models/sdg/goal_spec.rb index e9693e5a4..831ce85d6 100644 --- a/spec/models/sdg/goal_spec.rb +++ b/spec/models/sdg/goal_spec.rb @@ -1,12 +1,24 @@ require "rails_helper" describe SDG::Goal do - it "is valid" do - expect(build(:sdg_goal)).to be_valid - end + describe "validations" do + it "is valid with an existent code" do + goal = SDG::Goal.where(code: "1").first_or_initialize - it "is not valid without a code" do - expect(build(:sdg_goal, code: nil)).not_to be_valid + expect(goal).to be_valid + end + + it "is not valid without a code" do + expect(build(:sdg_goal, code: nil)).not_to be_valid + end + + it "is not valid with a nonexistent code" do + [0, 18].each do |code| + goal = SDG::Goal.where(code: code).first_or_initialize + + expect(goal).not_to be_valid + end + end end it "translates title" do diff --git a/spec/system/sdg_management/goals_spec.rb b/spec/system/sdg_management/goals_spec.rb index 227135237..6ceca8107 100644 --- a/spec/system/sdg_management/goals_spec.rb +++ b/spec/system/sdg_management/goals_spec.rb @@ -5,8 +5,6 @@ describe "Goals", :js do describe "Index" do scenario "Visit the index" do - SDG::Goal.where(code: "1").first_or_create! - visit sdg_management_root_path within("#side_menu") do