discourse/spec/models/theme_svg_sprite_spec.rb
Daniel Waterworth 84f590ab83
DEV: Store theme sprites in the DB (#20501)
Let's avoid fetching sprites from the CDN during page rendering.
2023-03-14 13:11:45 -05:00

48 lines
1.2 KiB
Ruby

# frozen_string_literal: true
RSpec.describe ThemeSvgSprite do
fab!(:theme) { Fabricate(:theme) }
describe "#refetch!" do
context "when an upload exists" do
before do
fname = "custom-theme-icon-sprite.svg"
upload = UploadCreator.new(file_from_fixtures(fname), fname, for_theme: true).create_for(-1)
theme.set_field(
target: :common,
name: SvgSprite.theme_sprite_variable_name,
upload_id: upload.id,
type: :theme_upload_var,
)
theme.save!
end
it "fetches values from the store and puts them in the table" do
expect(ThemeSvgSprite.count).to eq(1)
sprite = ThemeSvgSprite.first
original_content = sprite.sprite
expect(original_content).not_to be_empty
sprite.update!(sprite: "INVALID")
ThemeSvgSprite.refetch!
sprite.reload
expect(sprite.sprite).to eq(original_content)
expect(ThemeSvgSprite.count).to eq(1)
end
end
# It needs to do this since the cache is based on values in this table
it "expires the svg sprite cache" do
SvgSprite.expects(:expire_cache)
ThemeSvgSprite.refetch!
end
end
end