diff --git a/app/models/color_scheme.rb b/app/models/color_scheme.rb index 0e1f09c12c2..9f2f7eae5e6 100644 --- a/app/models/color_scheme.rb +++ b/app/models/color_scheme.rb @@ -43,12 +43,7 @@ class ColorScheme < ActiveRecord::Base alias_method :colors, :color_scheme_colors - before_save do - if self.id - self.version += 1 - end - end - + before_save :bump_version after_save :publish_discourse_stylesheet after_save :dump_hex_cache after_destroy :dump_hex_cache @@ -180,6 +175,12 @@ class ColorScheme < ActiveRecord::Base self.class.hex_cache.clear end + def bump_version + if self.id + self.version += 1 + end + end + end # == Schema Information diff --git a/app/models/remote_theme.rb b/app/models/remote_theme.rb index 664b23ff99a..f7b65bddebd 100644 --- a/app/models/remote_theme.rb +++ b/app/models/remote_theme.rb @@ -154,9 +154,10 @@ class RemoteTheme < ActiveRecord::Base end def update_theme_color_schemes(theme, schemes) - return if schemes.blank? + missing_scheme_names = Hash[*theme.color_schemes.pluck(:name, :id).flatten] schemes.each do |name, colors| + missing_scheme_names.delete(name) existing = theme.color_schemes.find_by(name: name) if existing existing.colors.each do |c| @@ -174,7 +175,13 @@ class RemoteTheme < ActiveRecord::Base end end end + + if missing_scheme_names.length > 0 + ColorScheme.where(id: missing_scheme_names.values).delete_all + # we may have stuff pointed at the incorrect scheme? + end end + end # == Schema Information diff --git a/app/models/theme.rb b/app/models/theme.rb index 8e6c152163f..024218ae93e 100644 --- a/app/models/theme.rb +++ b/app/models/theme.rb @@ -26,8 +26,16 @@ class Theme < ActiveRecord::Base end after_save do - changed_colors.each(&:save!) + color_schemes = {} + changed_colors.each do |color| + color.save! + color_schemes[color.color_scheme_id] ||= color.color_scheme + end + + color_schemes.values.each(&:save!) + changed_colors.clear + changed_fields.each(&:save!) changed_fields.clear diff --git a/spec/models/remote_theme_spec.rb b/spec/models/remote_theme_spec.rb index 6ecf04e10f8..31f772b94ec 100644 --- a/spec/models/remote_theme_spec.rb +++ b/spec/models/remote_theme_spec.rb @@ -18,10 +18,8 @@ describe RemoteTheme do repo_dir end - def about_json(options = {}) - options[:love] ||= "FAFAFA" - -<