2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-03-04 01:15:08 +08:00
discourse/spec/fabricators/optimized_image_fabricator.rb
Régis Hanol 4805d78ade
DEV: Prevent test "leakage" in cooked post processor specs (#33493)
Since we use the id of the upload record to determine part of its URL
 (aka, the /1X/, /2X/, etc.. part) we have to be careful making sure the
 id are "synced" accross all ways to generate ids.

 It's especially hard when using fabricators & sequences, using the `n`
 parameter of the sequence was "out of sync" of whatever was stored in
 the test databases.

 The main fix is to use `Upload.maximum(:id)` instead of `n` to retrieve
 the "next" id value.

 This ensured the optimized_images (aka thumbnails) were correctly
 created in test (as opposed to before where they were silently not
 created because the "orginal" image wasn't found).

 This made is so we can use `upload.thumbnail(width, height).url`
 instead of hardcoding the URLs in the specs so it can correctly work
 even when the `Upload id` is over 1000.
2025-07-07 15:26:41 +02:00

15 lines
354 B
Ruby

# frozen_string_literal: true
Fabricator(:optimized_image) do
upload
sha1 "86f7e437faa5a7fce15d1ddcb9eaeaea377667b8"
extension ".png"
width 100
height 200
filesize 654
version OptimizedImage::VERSION
after_build do |optimized_image, _|
optimized_image.url ||= Discourse.store.get_path_for_optimized_image(optimized_image)
end
end