2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-03-04 01:15:08 +08:00
discourse/spec/lib/ember_cli_spec.rb
David Taylor 2dff6d24af
FIX: Ensure ember version in cache key is coupled to compiler (#34694)
During in-container updates, the old version of the application
continues running while an update is applied. That means that it's
possible for the `node_modules/ember-source` version to be different to
the version currently loaded in the transpiler. That means it's
theoretically possible for theme assets to be built with the old
compiler, and then stored against the new version.

This commit removes that race condition by adding an `ember_version`
method to the JS transpiler. This is guaranteed to give us an accurate
version number for the template-compiler currently being used for
themes.

This commit also bumps the BASE_COMPILER_VERSION to force a recompile on
any sites affected by this race condition.
2025-09-02 22:29:02 +01:00

44 lines
1.2 KiB
Ruby

# frozen_string_literal: true
describe EmberCli do
describe "cache" do
after { EmberCli.clear_cache! }
def simulate_request_cache_clearance
# this method is defined by ActiveSupport::CurrentAttributes
# and is called before/after every web request
EmberCli.reset
end
context "in development" do
before { Rails.env.stubs(:development?).returns(true) }
it "cache works, and is cleared before/after each web request" do
EmberCli.cache[:foo] = "bar"
expect(EmberCli.cache[:foo]).to eq("bar")
simulate_request_cache_clearance
expect(EmberCli.cache[:foo]).to eq(nil)
end
end
context "in production" do
before { Rails.env.stubs(:development?).returns(false) }
it "cache works, and can be cleared" do
EmberCli.cache[:foo] = "bar"
expect(EmberCli.cache[:foo]).to eq("bar")
simulate_request_cache_clearance
# In production, persists across requests
expect(EmberCli.cache[:foo]).to eq("bar")
# But still can be manually cleared
EmberCli.clear_cache!
expect(EmberCli.cache[:foo]).to eq(nil)
end
end
end
end