Fix crash voting on a heading with a content block

When voting investment projects, the sidebar was rendered without the
`@heading_content_blocks` being set. That resulted in a 500 error when
the heading had content blocks.

By extracting the logic to a component, we make sure the heading content
blocks are properly set every time this code is rendered, no matter
which controller is rendering the view.
This commit is contained in:
Javi Martín
2022-11-28 13:23:53 +01:00
parent 937a86e345
commit 236796406a
7 changed files with 75 additions and 16 deletions

View File

@@ -160,13 +160,16 @@ describe "Ballots" do
end
end
scenario "the Map shoud be visible before and after" do
scenario "map and content block shoud be visible before and after" do
create(:budget_investment, :selected, heading: new_york, price: 10000, title: "More bridges")
create(:heading_content_block, heading: new_york, body: "<li>New Block</li>")
new_york.update!(allow_custom_content: true)
visit budget_investments_path(budget, heading_id: new_york)
within("#sidebar") do
expect(page).to have_content "OpenStreetMap"
expect(page).to have_content "New Block"
end
add_to_ballot("More bridges")
@@ -174,6 +177,7 @@ describe "Ballots" do
within("#sidebar") do
expect(page).to have_content "More bridges"
expect(page).to have_content "OpenStreetMap"
expect(page).to have_content "New Block"
end
within(".budget-investment", text: "More bridges") do
@@ -183,6 +187,7 @@ describe "Ballots" do
within("#sidebar") do
expect(page).not_to have_content "More bridges"
expect(page).to have_content "OpenStreetMap"
expect(page).to have_content "New Block"
end
end
end