FIX: Correctly cache hash of extra translations
This commit is contained in:
parent
c1e9a70d59
commit
f4a471f0eb
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue