FIX: error customizing text for badges from plugins

FIX: error customizing text for badges from plugins

diff --git a/app/models/badge.rb b/app/models/badge.rb
index 7ff7ce0..5608444 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 221569d..73cd39e 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

GitHub sha: 9d781d49