Files
grecia/spec/components/budgets/investments/content_blocks_component_spec.rb
Javi Martín 236796406a 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.
2022-11-28 13:28:22 +01:00

47 lines
1.5 KiB
Ruby

require "rails_helper"
describe Budgets::Investments::ContentBlocksComponent do
it "is not rendered without a heading" do
render_inline Budgets::Investments::ContentBlocksComponent.new(nil)
expect(page).not_to be_rendered
end
it "is not rendered with a heading without custom blocks" do
heading = Budget::Heading.new(allow_custom_content: true)
render_inline Budgets::Investments::ContentBlocksComponent.new(heading)
expect(page).not_to be_rendered
end
it "is not rendered with a heading with custom blocks in other languages" do
heading = create(:budget_heading, allow_custom_content: true)
create(:heading_content_block, heading: heading, locale: :es)
render_inline Budgets::Investments::ContentBlocksComponent.new(heading)
expect(page).not_to be_rendered
end
it "is not rendered with a heading not allowing custom content" do
heading = create(:budget_heading, allow_custom_content: false)
create(:heading_content_block, heading: heading, locale: :en)
render_inline Budgets::Investments::ContentBlocksComponent.new(heading)
expect(page).not_to be_rendered
end
it "renders content blocks for the current language" do
heading = create(:budget_heading, allow_custom_content: true)
create(:heading_content_block, heading: heading, locale: :en, body: "<li>Heading block</li>")
render_inline Budgets::Investments::ContentBlocksComponent.new(heading)
page.find("ul") do |list|
expect(page).to have_css "li", exact_text: "Heading block"
end
end
end