mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 23:54:16 +08:00
9667485951
Until now, we have allowed testing themes in production environments via `/theme-qunit`. This was made possible by hacking the ember-cli build so that it would create the `tests.js` bundle in production. However, this is fundamentally problematic because a number of test-specific things are still optimized out of the Ember build in production mode. It also makes asset compilation significantly slower, and makes it more difficult for us to update our build pipeline (e.g. to introduce Embroider). This commit removes the ability to run qunit tests in production builds of the JS app when the Embdroider flag is enabled. If a production instance of Discourse exists exclusively for the development of themes (e.g. discourse.theme-creator.io) then they can add `EMBER_ENV: development` to their `app.yml` file. This will build the entire app in development mode, and has a significant performance impact. This must not be used for real production sites. This commit also refactors many of the request specs into system specs. This means that the tests are guaranteed to have Ember assets built, and is also a better end-to-end test than simply checking for the presence of certain `<script>` tags in the HTML.
31 lines
933 B
Ruby
31 lines
933 B
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
|
|
|
|
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
|