mirror of
https://github.com/discourse/discourse.git
synced 2025-04-26 08:44:26 +08:00

This test file fails locally if `tmp/theme-transpiler.js` does not exists. Since the test file stubs the production env, we have to ensure that `DiscourseJsProcessor::Transpiler.build_production_theme_transpiler` is run first to mirror the production environment where the theme transpiler file is built as part of assets precompilation. ### Review notes: Example failure: https://github.com/discourse/discourse/actions/runs/14529161497/job/40766003075 To repro locally, run the following steps: 1. In your Discourse directory, run `rm -rf tmp` 2. `rspec spec/requests/qunit_controller_spec.rb`
36 lines
1.1 KiB
Ruby
36 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe QunitController do
|
|
def production_sign_in(user)
|
|
# We need to call sign_in before stubbing the method because SessionController#become
|
|
# checks for the current env when the file is loaded.
|
|
# We need to make sure become is called once before stubbing, or the method
|
|
# wont'be available for future tests if this one runs first.
|
|
sign_in(user) if user
|
|
Rails.env.stubs(:production?).returns(true)
|
|
end
|
|
|
|
# rubocop:disable RSpec/BeforeAfterAll
|
|
before(:all) { DiscourseJsProcessor::Transpiler.build_production_theme_transpiler }
|
|
|
|
after(:all) { File.delete(DiscourseJsProcessor::Transpiler::TRANSPILER_PATH) }
|
|
|
|
it "hides page for regular users in production" do
|
|
production_sign_in(Fabricate(:user))
|
|
get "/theme-qunit"
|
|
expect(response.status).to eq(404)
|
|
end
|
|
|
|
it "hides page for anon in production" do
|
|
production_sign_in(nil)
|
|
get "/theme-qunit"
|
|
expect(response.status).to eq(404)
|
|
end
|
|
|
|
it "shows page for admin in production" do
|
|
production_sign_in(Fabricate(:admin))
|
|
get "/theme-qunit"
|
|
expect(response.status).to eq(200)
|
|
end
|
|
end
|