diff --git a/spec/components/budgets/budget_component_spec.rb b/spec/components/budgets/budget_component_spec.rb index 02d94bc6a..7e46693d0 100644 --- a/spec/components/budgets/budget_component_spec.rb +++ b/spec/components/budgets/budget_component_spec.rb @@ -36,4 +36,43 @@ describe Budgets::BudgetComponent do end end end + + describe "budget image" do + it "does not show a background image when the budget has no image" do + render_inline Budgets::BudgetComponent.new(budget) + + expect(page).to have_css ".budget-header" + expect(page).not_to have_css ".with-background-image" + expect(page).not_to have_css ".budget-header[style*='background-image:']" + end + + it "shows a background image when the bugdet image is defined" do + budget = create(:budget, :with_image) + + render_inline Budgets::BudgetComponent.new(budget) + + expect(page).to have_css ".budget-header.with-background-image" + expect(page).to have_css ".budget-header[style*='background-image:'][style*='clippy.jpg']" + end + + it "quotes the background image filename so it works with filenames with brackets" do + budget.update!(image: create(:image, attachment: fixture_file_upload("clippy(with_brackets).jpg"))) + + render_inline Budgets::BudgetComponent.new(budget) + + expect(page).to have_css ".budget-header.with-background-image" + expect(page).to have_css ".budget-header[style*='background-image:']"\ + "[style*='url(\\''][style*='clippy(with_brackets).jpg\\'']" + end + + it "escapes single quotes in the background image filename" do + budget.update!(image: create(:image, attachment: fixture_file_upload("clippy_with_'quotes'.jpg"))) + + render_inline Budgets::BudgetComponent.new(budget) + + expect(page).to have_css ".budget-header.with-background-image" + expect(page).to have_css ".budget-header[style*='background-image:']"\ + "[style*='url(\\''][style*='clippy_with_\\\\\'quotes\\\\\'.jpg']" + end + end end diff --git a/spec/factories/budgets.rb b/spec/factories/budgets.rb index 2e57a920b..57beb8737 100644 --- a/spec/factories/budgets.rb +++ b/spec/factories/budgets.rb @@ -65,6 +65,10 @@ FactoryBot.define do voting_style { "approval" } end + trait :with_image do + after(:create) { |budget| create(:image, imageable: budget) } + end + trait :with_winner do after(:create) { |budget| create(:budget_investment, :winner, budget: budget) } end diff --git a/spec/fixtures/files/clippy(with_brackets).jpg b/spec/fixtures/files/clippy(with_brackets).jpg new file mode 100644 index 000000000..1edb6659b Binary files /dev/null and b/spec/fixtures/files/clippy(with_brackets).jpg differ diff --git a/spec/fixtures/files/clippy_with_'quotes'.jpg b/spec/fixtures/files/clippy_with_'quotes'.jpg new file mode 100644 index 000000000..1edb6659b Binary files /dev/null and b/spec/fixtures/files/clippy_with_'quotes'.jpg differ