FIX: Correctly cache hash of extra translations

FIX: Correctly cache hash of extra translations

diff --git a/app/controllers/extra_locales_controller.rb b/app/controllers/extra_locales_controller.rb
index 1baadeb..9083af9 100644
--- a/app/controllers/extra_locales_controller.rb
+++ b/app/controllers/extra_locales_controller.rb
@@ -23,7 +23,7 @@ class ExtraLocalesController < ApplicationController
 
   def self.bundle_js_hash(bundle)
     @bundle_js_hash ||= {}
-    @bundle_js_hash[bundle] = Digest::MD5.hexdigest(bundle_js(bundle))
+    @bundle_js_hash["#{bundle}_#{I18n.locale}"] ||= Digest::MD5.hexdigest(bundle_js(bundle))
   end
 
   def self.url(bundle)
diff --git a/spec/requests/extra_locales_controller_spec.rb b/spec/requests/extra_locales_controller_spec.rb
index 9615bf3..c2aaee6 100644
--- a/spec/requests/extra_locales_controller_spec.rb
+++ b/spec/requests/extra_locales_controller_spec.rb
@@ -54,4 +54,31 @@ describe ExtraLocalesController do
       end
     end
   end
+
+  describe ".bundle_js_hash" do
+    it "doesn't call bundle_js more than once for the same locale and bundle" do
+      I18n.locale = :de
+      ExtraLocalesController.expects(:bundle_js).with("admin").returns("admin_js DE").once
+      expected_hash_de = Digest::MD5.hexdigest("admin_js DE")
+
+      expect(ExtraLocalesController.bundle_js_hash("admin")).to eq(expected_hash_de)
+      expect(ExtraLocalesController.bundle_js_hash("admin")).to eq(expected_hash_de)
+
+      I18n.locale = :fr
+      ExtraLocalesController.expects(:bundle_js).with("admin").returns("admin_js FR").once
+      expected_hash_fr = Digest::MD5.hexdigest("admin_js FR")
+
+      expect(ExtraLocalesController.bundle_js_hash("admin")).to eq(expected_hash_fr)
+      expect(ExtraLocalesController.bundle_js_hash("admin")).to eq(expected_hash_fr)
+
+      I18n.locale = :de
+      expect(ExtraLocalesController.bundle_js_hash("admin")).to eq(expected_hash_de)
+
+      ExtraLocalesController.expects(:bundle_js).with("wizard").returns("wizard_js DE").once
+      expected_hash_de = Digest::MD5.hexdigest("wizard_js DE")
+
+      expect(ExtraLocalesController.bundle_js_hash("wizard")).to eq(expected_hash_de)
+      expect(ExtraLocalesController.bundle_js_hash("wizard")).to eq(expected_hash_de)
+    end
+  end
 end

GitHub sha: f4a471f0