Skip to content

A platform for community discussion. Free, open, simple.

FIX: error customizing text for badges from plugins

Neil Lalonde9d781d495903
diff --git a/app/models/badge.rb b/app/models/badge.rb
index 7ff7ce07105..5608444957b 100644
--- a/app/models/badge.rb
+++ b/app/models/badge.rb
@@ -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?
diff --git a/spec/models/badge_spec.rb b/spec/models/badge_spec.rb
index 221569de084..73cd39ef0ee 100644
--- a/spec/models/badge_spec.rb
+++ b/spec/models/badge_spec.rb
@@ -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