Add tests for budget images with brackets / quotes

This commit is contained in:
karim-semmoud
2023-06-13 11:38:27 +02:00
committed by Javi Martín
parent 5630a24d7a
commit 3a623c070f
4 changed files with 43 additions and 0 deletions

View File

@@ -36,4 +36,43 @@ describe Budgets::BudgetComponent do
end end
end 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 end

View File

@@ -65,6 +65,10 @@ FactoryBot.define do
voting_style { "approval" } voting_style { "approval" }
end end
trait :with_image do
after(:create) { |budget| create(:image, imageable: budget) }
end
trait :with_winner do trait :with_winner do
after(:create) { |budget| create(:budget_investment, :winner, budget: budget) } after(:create) { |budget| create(:budget_investment, :winner, budget: budget) }
end end

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB