FIX: theme CSS should recompile when theme uploads change

This commit is contained in:
OsamaSayegh 2018-06-13 16:54:26 +03:00 committed by Sam
parent c34100d1e7
commit 2427c0a17c
2 changed files with 44 additions and 1 deletions

View File

@ -256,7 +256,7 @@ class Stylesheet::Manager
raise "attempting to look up theme digest for invalid field"
end
Digest::SHA1.hexdigest(scss.to_s + color_scheme_digest.to_s + settings_digest + plugins_digest)
Digest::SHA1.hexdigest(scss.to_s + color_scheme_digest.to_s + settings_digest + plugins_digest + uploads_digest)
end
# this protects us from situations where new versions of a plugin removed a file
@ -274,6 +274,10 @@ class Stylesheet::Manager
Digest::SHA1.hexdigest((theme&.included_settings || {}).to_json)
end
def uploads_digest
Digest::SHA1.hexdigest(ThemeField.joins(:upload).where(id: theme&.all_theme_variables).pluck(:sha1).join(","))
end
def color_scheme_digest
cs = theme&.color_scheme

View File

@ -87,6 +87,45 @@ describe Stylesheet::Manager do
expect(digest1).not_to eq(digest2)
end
let(:image) { file_from_fixtures("logo.png") }
let(:image2) { file_from_fixtures("logo-dev.png") }
it 'can correctly account for theme uploads in digest' do
theme = Theme.create!(
name: 'parent',
user_id: -1
)
upload = UploadCreator.new(image, "logo.png").create_for(-1)
field = ThemeField.create!(
theme_id: theme.id,
target_id: Theme.targets[:common],
name: "logo",
value: "",
upload_id: upload.id,
type_id: ThemeField.types[:theme_upload_var]
)
manager = Stylesheet::Manager.new(:desktop_theme, theme.key)
digest1 = manager.digest
field.destroy!
upload = UploadCreator.new(image2, "logo.png").create_for(-1)
field = ThemeField.create!(
theme_id: theme.id,
target_id: Theme.targets[:common],
name: "logo",
value: "",
upload_id: upload.id,
type_id: ThemeField.types[:theme_upload_var]
)
manager = Stylesheet::Manager.new(:desktop_theme, theme.key)
digest2 = manager.digest
expect(digest1).not_to eq(digest2)
end
end
describe 'color_scheme_digest' do