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:
parent
4f88f2eb15
commit
e25218014e
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue