FIX: error customizing text for badges from plugins

This commit is contained in:
Neil Lalonde 2020-04-28 14:33:58 -04:00
parent 22f11efad0
commit 9d781d4959
No known key found for this signature in database
GPG Key ID: FF871CA9037D0A91
2 changed files with 9 additions and 1 deletions

View File

@ -181,7 +181,7 @@ class Badge < ActiveRecord::Base
def self.find_system_badge_id_from_translation_key(translation_key)
return unless translation_key.starts_with?('badges.')
badge_name_klass = translation_key.split('.').second.camelize
"Badge::#{badge_name_klass}".constantize
Badge.const_defined?(badge_name_klass) ? "Badge::#{badge_name_klass}".constantize : nil
end
def awarded_for_trust_level?

View File

@ -113,6 +113,14 @@ describe Badge do
expect(Badge.find_system_badge_id_from_translation_key(translation_key)).to eq(nil)
end
end
context "when translation key doesn't match its class" do
let(:translation_key) { "badges.licensed.long_description" }
it "returns nil" do
expect(Badge.find_system_badge_id_from_translation_key(translation_key)).to eq(nil)
end
end
end
context "First Quote" do