diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml
index 5a47cdb64..878928629 100644
--- a/config/locales/en/general.yml
+++ b/config/locales/en/general.yml
@@ -251,6 +251,7 @@ en:
other: You have %{count} new notifications
notifications: Notifications
no_notifications: "You don't have new notifications"
+ sdg: "SDG"
notifications:
index:
empty_notifications: You don't have new notifications.
@@ -874,9 +875,14 @@ en:
debates: "Most active debates"
proposals: "Most active proposals"
processes: "Open processes"
- see_all_debates: See all debates
- see_all_proposals: See all proposals
- see_all_processes: See all processes
+ see_all:
+ debates: See all debates
+ proposals: See all proposals
+ processes: See all processes
+ no_items:
+ debates: There are no debates right now
+ proposals: There are no proposals right now
+ processes: There are no open processes right now
process_label: Process
see_process: See process
cards:
diff --git a/config/locales/es/general.yml b/config/locales/es/general.yml
index 7f7b2b713..2a93e8bfb 100644
--- a/config/locales/es/general.yml
+++ b/config/locales/es/general.yml
@@ -251,6 +251,7 @@ es:
other: Tienes %{count} notificaciones nuevas
notifications: Notificaciones
no_notifications: "No tienes notificaciones nuevas"
+ sdg: "ODS"
notifications:
index:
empty_notifications: No tienes notificaciones nuevas.
@@ -874,9 +875,14 @@ es:
debates: "Debates más activos"
proposals: "Propuestas más activas"
processes: "Procesos abiertos"
- see_all_debates: Ver todos los debates
- see_all_proposals: Ver todas las propuestas
- see_all_processes: Ver todos los procesos
+ see_all:
+ debates: Ver todos los debates
+ proposals: Ver todas las propuestas
+ processes: Ver todos los procesos
+ no_items:
+ debates: Ahora mismo no hay debates
+ proposals: Ahora mismo no hay propuestas
+ processes: Ahora mismo no hay procesos abiertos
process_label: Proceso
see_process: Ver proceso
cards:
diff --git a/config/routes.rb b/config/routes.rb
index aeb715684..acbdf90d1 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -21,6 +21,7 @@ Rails.application.routes.draw do
draw :poll
draw :proposal
draw :related_content
+ draw :sdg
draw :sdg_management
draw :tag
draw :user
diff --git a/config/routes/sdg.rb b/config/routes/sdg.rb
new file mode 100644
index 000000000..52525c685
--- /dev/null
+++ b/config/routes/sdg.rb
@@ -0,0 +1,3 @@
+namespace :sdg do
+ resources :goals, param: :code, only: [:index, :show]
+end
diff --git a/db/sdg.rb b/db/sdg.rb
index 9dde1885b..f81741e77 100644
--- a/db/sdg.rb
+++ b/db/sdg.rb
@@ -1,4 +1,4 @@
-(1..17).each do |code|
+(1..17).to_a.shuffle.each do |code|
SDG::Goal.where(code: code).first_or_create!
end
diff --git a/spec/components/widgets/feeds/feed_component_spec.rb b/spec/components/widgets/feeds/feed_component_spec.rb
new file mode 100644
index 000000000..2e0d990e9
--- /dev/null
+++ b/spec/components/widgets/feeds/feed_component_spec.rb
@@ -0,0 +1,74 @@
+require "rails_helper"
+
+describe Widgets::Feeds::FeedComponent, type: :component do
+ it "renders a message when there are no items" do
+ feed = double(kind: "debates", items: [])
+ component = Widgets::Feeds::FeedComponent.new(feed)
+
+ render_inline component
+
+ expect(page).to have_content "no debates"
+ end
+
+ describe "#see_all_path" do
+ context "debates" do
+ let(:feed) { Widget::Feed.new(kind: "debates") }
+
+ it "points to the debates path for homepage debates feeds" do
+ component = Widgets::Feeds::FeedComponent.new(feed)
+
+ render_inline component
+
+ expect(component.see_all_path).to eq "/debates"
+ end
+
+ it "points to the debates filtered by goal for goal feeds" do
+ component = Widgets::Feeds::FeedComponent.new(SDG::Widget::Feed.new(feed, SDG::Goal[6]))
+
+ render_inline component
+
+ expect(component.see_all_path).to eq "/debates?advanced_search#{CGI.escape("[goal]")}=6"
+ end
+ end
+
+ context "proposals" do
+ let(:feed) { Widget::Feed.new(kind: "proposals") }
+
+ it "points to the proposals path for homepage proposals feeds" do
+ component = Widgets::Feeds::FeedComponent.new(feed)
+
+ render_inline component
+
+ expect(component.see_all_path).to eq "/proposals"
+ end
+
+ it "points to the proposals filtered by goal for goal feeds" do
+ component = Widgets::Feeds::FeedComponent.new(SDG::Widget::Feed.new(feed, SDG::Goal[6]))
+
+ render_inline component
+
+ expect(component.see_all_path).to eq "/proposals?advanced_search#{CGI.escape("[goal]")}=6"
+ end
+ end
+
+ context "processes" do
+ let(:feed) { Widget::Feed.new(kind: "processes") }
+
+ it "points to the legislation processes path for homepage processes feeds" do
+ component = Widgets::Feeds::FeedComponent.new(feed)
+
+ render_inline component
+
+ expect(component.see_all_path).to eq "/legislation/processes"
+ end
+
+ it "points to the legislation processes path for goal processes feeds" do
+ component = Widgets::Feeds::FeedComponent.new(SDG::Widget::Feed.new(feed, SDG::Goal[6]))
+
+ render_inline component
+
+ expect(component.see_all_path).to eq "/legislation/processes"
+ end
+ end
+ end
+end
diff --git a/spec/controllers/sdg/goals_spec.rb b/spec/controllers/sdg/goals_spec.rb
new file mode 100644
index 000000000..f72c283dd
--- /dev/null
+++ b/spec/controllers/sdg/goals_spec.rb
@@ -0,0 +1,13 @@
+require 'rails_helper'
+
+describe SDG::GoalsController do
+ context "featured disabled" do
+ before do
+ Setting["feature.sdg"] = false
+ end
+
+ it "raises feature disabled" do
+ expect { get :index }.to raise_exception(FeatureFlags::FeatureDisabled)
+ end
+ end
+end
diff --git a/spec/models/abilities/administrator_spec.rb b/spec/models/abilities/administrator_spec.rb
index f237964dc..873768d87 100644
--- a/spec/models/abilities/administrator_spec.rb
+++ b/spec/models/abilities/administrator_spec.rb
@@ -107,7 +107,6 @@ describe Abilities::Administrator do
it { should be_able_to(:create, LocalCensusRecords::Import) }
it { should be_able_to(:show, LocalCensusRecords::Import) }
- it { should be_able_to(:read, SDG::Goal) }
it { should be_able_to(:read, SDG::Target) }
it { should be_able_to(:read, SDG::Manager) }
diff --git a/spec/models/abilities/common_spec.rb b/spec/models/abilities/common_spec.rb
index 336116012..b060f5944 100644
--- a/spec/models/abilities/common_spec.rb
+++ b/spec/models/abilities/common_spec.rb
@@ -305,7 +305,6 @@ describe Abilities::Common do
it { should be_able_to(:disable_recommendations, Proposal) }
end
- it { should_not be_able_to(:read, SDG::Goal) }
it { should_not be_able_to(:read, SDG::Target) }
it { should_not be_able_to(:read, SDG::Manager) }
diff --git a/spec/models/abilities/everyone_spec.rb b/spec/models/abilities/everyone_spec.rb
index a5399e25b..81b82dcd5 100644
--- a/spec/models/abilities/everyone_spec.rb
+++ b/spec/models/abilities/everyone_spec.rb
@@ -53,7 +53,7 @@ describe Abilities::Everyone do
it { should_not be_able_to(:summary, create(:legislation_process, :open)) }
it { should_not be_able_to(:summary, create(:legislation_process, :past, :not_published)) }
- it { should_not be_able_to(:read, SDG::Goal) }
+ it { should be_able_to(:read, SDG::Goal) }
it { should_not be_able_to(:read, SDG::Target) }
it { should_not be_able_to(:read, SDG::Manager) }
diff --git a/spec/models/abilities/moderator_spec.rb b/spec/models/abilities/moderator_spec.rb
index 762583534..1b2bd4f48 100644
--- a/spec/models/abilities/moderator_spec.rb
+++ b/spec/models/abilities/moderator_spec.rb
@@ -109,7 +109,6 @@ describe Abilities::Moderator do
it { should_not be_able_to(:comment_as_administrator, legislation_question) }
end
- it { should_not be_able_to(:read, SDG::Goal) }
it { should_not be_able_to(:read, SDG::Target) }
it { should_not be_able_to(:read, SDG::Manager) }
diff --git a/spec/models/abilities/organization_spec.rb b/spec/models/abilities/organization_spec.rb
index 2553b3f18..874a5ce40 100644
--- a/spec/models/abilities/organization_spec.rb
+++ b/spec/models/abilities/organization_spec.rb
@@ -23,7 +23,6 @@ describe "Abilities::Organization" do
it { should be_able_to(:create, Comment) }
it { should_not be_able_to(:vote, Comment) }
- it { should_not be_able_to(:read, SDG::Goal) }
it { should_not be_able_to(:read, SDG::Target) }
it { should_not be_able_to(:read, SDG::Manager) }
diff --git a/spec/models/abilities/sdg/manager.rb b/spec/models/abilities/sdg/manager.rb
index f8a4e598e..11800ca04 100644
--- a/spec/models/abilities/sdg/manager.rb
+++ b/spec/models/abilities/sdg/manager.rb
@@ -7,7 +7,6 @@ describe "Abilities::SDG::Manager" do
let(:user) { sdg_manager.user }
let(:sdg_manager) { create(:sdg_manager) }
- it { should be_able_to(:read, SDG::Goal) }
it { should be_able_to(:read, SDG::Target) }
it { should be_able_to(:manage, SDG::LocalTarget) }
diff --git a/spec/models/abilities/valuator_spec.rb b/spec/models/abilities/valuator_spec.rb
index 634dd7e92..328c1cb48 100644
--- a/spec/models/abilities/valuator_spec.rb
+++ b/spec/models/abilities/valuator_spec.rb
@@ -40,7 +40,6 @@ describe Abilities::Valuator do
it { should_not be_able_to(:comment_valuation, assigned_investment) }
end
- it { should_not be_able_to(:read, SDG::Goal) }
it { should_not be_able_to(:read, SDG::Target) }
it { should_not be_able_to(:read, SDG::Manager) }
diff --git a/spec/routing/sdg_routes_spec.rb b/spec/routing/sdg_routes_spec.rb
new file mode 100644
index 000000000..d3dbcb398
--- /dev/null
+++ b/spec/routing/sdg_routes_spec.rb
@@ -0,0 +1,19 @@
+require "rails_helper"
+
+describe "SDG routes" do
+ it "maps goals to their code" do
+ expect(get("/sdg/goals/1")).to route_to(
+ controller: "sdg/goals",
+ action: "show",
+ code: "1"
+ )
+ end
+
+ it "requires using the code instead of the ID" do
+ expect(get(sdg_goal_path(SDG::Goal[2].code))).to route_to(
+ controller: "sdg/goals",
+ action: "show",
+ code: "2"
+ )
+ end
+end
diff --git a/spec/system/admin/homepage/homepage_spec.rb b/spec/system/admin/homepage/homepage_spec.rb
index 0e3eff79a..b6349376a 100644
--- a/spec/system/admin/homepage/homepage_spec.rb
+++ b/spec/system/admin/homepage/homepage_spec.rb
@@ -92,9 +92,6 @@ describe "Homepage", :admin do
expect(page).to have_content "Most active debates"
expect(page).to have_css(".debate", count: 3)
end
-
- expect(page).to have_css("#feed_proposals.medium-8")
- expect(page).to have_css("#feed_debates.medium-4")
end
scenario "Processes", :js do
@@ -109,7 +106,7 @@ describe "Homepage", :admin do
visit root_path
expect(page).to have_content "Open processes"
- expect(page).to have_css(".legislation_process", count: 3)
+ expect(page).to have_css(".legislation-process", count: 3)
end
xscenario "Deactivate"
diff --git a/spec/system/sdg/goals_spec.rb b/spec/system/sdg/goals_spec.rb
new file mode 100644
index 000000000..3231a6f80
--- /dev/null
+++ b/spec/system/sdg/goals_spec.rb
@@ -0,0 +1,88 @@
+require "rails_helper"
+
+describe "SDG Goals", :js do
+ before do
+ Setting["feature.sdg"] = true
+ end
+
+ describe "SDG navigation link" do
+ scenario "is not present when the feature is disabled" do
+ Setting["feature.sdg"] = false
+
+ visit root_path
+
+ within("#navigation_bar") { expect(page).not_to have_link "SDG" }
+ end
+
+ scenario "routes to the goals index" do
+ visit root_path
+ within("#navigation_bar") { click_link "SDG" }
+
+ expect(page).to have_current_path sdg_goals_path
+ end
+ end
+
+ describe "Index" do
+ scenario "has links to SDGs" do
+ visit sdg_goals_path
+
+ click_link "7. Affordable and Clean Energy"
+
+ expect(page).to have_current_path sdg_goal_path(7)
+ end
+ end
+
+ describe "Show" do
+ before do
+ goal = SDG::Goal[15]
+
+ create(:debate, title: "Solar panels", sdg_goals: [SDG::Goal[7]])
+ create(:debate, title: "Hunting ground", sdg_goals: [goal])
+ create(:proposal, title: "Animal farm", sdg_goals: [goal])
+ create(:proposal, title: "Sea farm", sdg_goals: [SDG::Goal[14]])
+ create(:legislation_process, title: "Bullfighting regulations", sdg_goals: [goal])
+ create(:legislation_process, title: "Tax regulations", sdg_goals: [SDG::Goal[10]])
+ end
+
+ scenario "shows the SDG and its related content" do
+ visit sdg_goal_path(15)
+
+ within(".sdg-goal header") { expect(page).to have_content "Life on Land" }
+
+ within ".feed-proposals" do
+ expect(page).to have_content "Animal farm"
+ expect(page).not_to have_content "Sea farm"
+ end
+
+ within ".feed-debates" do
+ expect(page).to have_content "Hunting ground"
+ expect(page).not_to have_content "Solar panels"
+ end
+
+ within ".feed-processes" do
+ expect(page).to have_content "BULLFIGHTING REGULATIONS"
+ expect(page).not_to have_content "TAX REGULATIONS"
+ end
+ end
+
+ scenario "has links to debates and proposals filtered by goal" do
+ visit sdg_goal_path(15)
+
+ click_link "See all debates"
+
+ within "#debates" do
+ expect(page).to have_content "Hunting ground"
+ expect(page).not_to have_content "Solar panels"
+ end
+
+ go_back
+
+ click_link "See all proposals"
+
+ within "#proposals" do
+ expect(page).to have_content "Animal farm"
+ expect(page).not_to have_content "Sea farm"
+ end
+ end
+ end
+end