FIX: ColorScheme color missing was returning "nil"

This commit is contained in:
Sam 2018-05-28 11:46:00 +10:00
parent c677877e4f
commit 5a32a70d6c
2 changed files with 6 additions and 4 deletions

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'distributed_cache'
class ColorScheme < ActiveRecord::Base
@ -108,12 +110,12 @@ class ColorScheme < ActiveRecord::Base
def self.lookup_hex_for_name(name)
enabled_color_scheme = Theme.where(key: SiteSetting.default_theme_key).first&.color_scheme
(enabled_color_scheme || base).colors.find { |c| c.name == name }.try(:hex) || :nil
(enabled_color_scheme || base).colors.find { |c| c.name == name }.try(:hex) || "nil"
end
def self.hex_for_name(name)
hex_cache[name] ||= lookup_hex_for_name(name)
hex_cache[name] == :nil ? nil : hex_cache[name]
hex_cache[name] == "nil" ? nil : hex_cache[name]
end
def colors=(arr)

View File

@ -62,11 +62,11 @@ describe ColorScheme do
end
it "returns nil for a missing attribute" do
expect(described_class.hex_for_name('undefined')).to eq nil
expect(ColorScheme.hex_for_name('undefined')).to eq nil
end
it "returns the base color for an attribute" do
expect(described_class.hex_for_name('second_one')).to eq base_colors[:second_one]
expect(ColorScheme.hex_for_name('second_one')).to eq base_colors[:second_one]
end
end
end