From 920631c5b3e77a8630b59180a1ae3b9710a7f3cc Mon Sep 17 00:00:00 2001 From: taitus Date: Thu, 21 Jan 2021 18:17:47 +0100 Subject: [PATCH] Add SDG::RelatedListSelectorComponent to Polls Allow to relate SDG and Targets to Polls --- .../admin/poll/polls_controller.rb | 2 +- app/views/admin/poll/polls/_form.html.erb | 4 ++ spec/system/admin/poll/polls_spec.rb | 38 +++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/app/controllers/admin/poll/polls_controller.rb b/app/controllers/admin/poll/polls_controller.rb index 75fae91ff..8bf2b75f7 100644 --- a/app/controllers/admin/poll/polls_controller.rb +++ b/app/controllers/admin/poll/polls_controller.rb @@ -76,7 +76,7 @@ class Admin::Poll::PollsController < Admin::Poll::BaseController end def poll_params - attributes = [:name, :starts_at, :ends_at, :geozone_restricted, :budget_id, + attributes = [:name, :starts_at, :ends_at, :geozone_restricted, :budget_id, :sdg_related_list, geozone_ids: [], image_attributes: image_attributes] params.require(:poll).permit(*attributes, *report_attributes, translation_params(Poll)) diff --git a/app/views/admin/poll/polls/_form.html.erb b/app/views/admin/poll/polls/_form.html.erb index 4011ab4ec..cb542612d 100644 --- a/app/views/admin/poll/polls/_form.html.erb +++ b/app/views/admin/poll/polls/_form.html.erb @@ -55,6 +55,10 @@ +
+ <%= render SDG::RelatedListSelectorComponent.new(f) %> +
+
diff --git a/spec/system/admin/poll/polls_spec.rb b/spec/system/admin/poll/polls_spec.rb index c60ade14b..5d5baf257 100644 --- a/spec/system/admin/poll/polls_spec.rb +++ b/spec/system/admin/poll/polls_spec.rb @@ -521,4 +521,42 @@ describe "Admin polls", :admin do end end end + + context "SDG related list" do + before do + Setting["feature.sdg"] = true + Setting["sdg.process.polls"] = true + end + + scenario "create poll with sdg related list", :js do + visit new_admin_poll_path + fill_in "Name", with: "Upcoming poll with SDG related content" + fill_in "Start Date", with: 1.week.from_now + fill_in "Closing Date", with: 2.weeks.from_now + fill_in "Summary", with: "Upcoming poll's summary. This poll..." + fill_in "Description", with: "Upcomming poll's description. This poll..." + + click_sdg_goal(17) + click_button "Create poll" + visit admin_polls_path + + within("tr", text: "Upcoming poll with SDG related content") do + expect(page).to have_css "td", exact_text: "17" + end + end + + scenario "edit poll with sdg related list", :js do + poll = create(:poll, name: "Upcoming poll with SDG related content") + poll.sdg_goals = [SDG::Goal[1], SDG::Goal[17]] + visit edit_admin_poll_path(poll) + + remove_sdg_goal_or_target_tag(1) + click_button "Update poll" + visit admin_polls_path + + within("tr", text: "Upcoming poll with SDG related content") do + expect(page).to have_css "td", exact_text: "17" + end + end + end end