FIX: add theme field errors (#12880)

* FIX: add theme field errors

Expose theme field errors on theme pages
Previously these errors were not being displayed on themes.
This commit is contained in:
Jeff Wong 2021-04-28 12:00:37 -10:00 committed by GitHub
parent 4f88f2eb15
commit e25218014e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 1 deletions

View File

@ -79,6 +79,10 @@ class ThemeSerializer < BasicThemeSerializer
def initialize(theme, options = {})
super
@errors = []
object.theme_fields.each do |o|
@errors << o.error if o.error
end
end
def child_themes

View File

@ -0,0 +1,9 @@
# frozen_string_literal: true
Fabricator(:theme_field) do
theme
target_id { 0 }
name { sequence(:name) { |i| "scss_#{i + 1}" } }
value { ".test {color: blue;}" }
error { nil }
end

View File

@ -4,7 +4,7 @@ require 'rails_helper'
RSpec.describe ThemeSerializer do
describe "load theme settings" do
it 'should add error message when having invalid format' do
it 'should add error message when settings format is invalid' do
theme = Fabricate(:theme)
Theme.any_instance.stubs(:settings).raises(ThemeSettingsParser::InvalidYaml, I18n.t("themes.settings_errors.invalid_yaml"))
serialized = ThemeSerializer.new(theme).as_json[:theme]
@ -12,5 +12,14 @@ RSpec.describe ThemeSerializer do
expect(serialized[:errors].count).to eq(1)
expect(serialized[:errors][0]).to eq(I18n.t("themes.settings_errors.invalid_yaml"))
end
it 'should add errors messages from theme fields' do
error = "error when compiling theme field"
theme = Fabricate(:theme)
theme_field = Fabricate(:theme_field, error: error, theme: theme)
serialized = ThemeSerializer.new(theme.reload).as_json[:theme]
expect(serialized[:errors].count).to eq(1)
expect(serialized[:errors][0]).to eq(error)
end
end
end