Add SDG::RelatedListSelectorComponent to Polls

Allow to relate SDG and Targets to Polls
This commit is contained in:
taitus
2021-01-21 18:17:47 +01:00
parent 6e0158db17
commit 920631c5b3
3 changed files with 43 additions and 1 deletions

View File

@@ -76,7 +76,7 @@ class Admin::Poll::PollsController < Admin::Poll::BaseController
end end
def poll_params 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] geozone_ids: [], image_attributes: image_attributes]
params.require(:poll).permit(*attributes, *report_attributes, translation_params(Poll)) params.require(:poll).permit(*attributes, *report_attributes, translation_params(Poll))

View File

@@ -55,6 +55,10 @@
</div> </div>
</div> </div>
<div class="row">
<%= render SDG::RelatedListSelectorComponent.new(f) %>
</div>
<div class="row"> <div class="row">
<div class="clear"> <div class="clear">
<div class="small-12 medium-4 large-2 column"> <div class="small-12 medium-4 large-2 column">

View File

@@ -521,4 +521,42 @@ describe "Admin polls", :admin do
end end
end 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 end