mirror of
https://github.com/discourse/discourse.git
synced 2026-03-04 01:15:08 +08:00
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.
15 lines
354 B
Ruby
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
|