2021-04-12 20:02:58 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-28 10:27:38 +08:00
|
|
|
RSpec.describe QunitController do
|
2023-09-11 16:12:37 +08:00
|
|
|
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
|
2021-04-29 04:12:08 +08:00
|
|
|
|
2023-09-11 16:12:37 +08:00
|
|
|
it "hides page for regular users in production" do
|
|
|
|
production_sign_in(Fabricate(:user))
|
|
|
|
get "/theme-qunit"
|
|
|
|
expect(response.status).to eq(404)
|
|
|
|
end
|
2021-04-29 04:12:08 +08:00
|
|
|
|
2023-09-11 16:12:37 +08:00
|
|
|
it "hides page for anon in production" do
|
|
|
|
production_sign_in(nil)
|
|
|
|
get "/theme-qunit"
|
|
|
|
expect(response.status).to eq(404)
|
|
|
|
end
|
2021-04-29 04:12:08 +08:00
|
|
|
|
2023-09-11 16:12:37 +08:00
|
|
|
it "shows page for admin in production" do
|
|
|
|
production_sign_in(Fabricate(:admin))
|
|
|
|
get "/theme-qunit"
|
|
|
|
expect(response.status).to eq(200)
|
2021-04-12 20:02:58 +08:00
|
|
|
end
|
|
|
|
end
|