mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
FEATURE: backend support for user-selectable components
* FEATURE: backend support for user-selectable components * fix problems with previewing default theme * rename preview_key => preview_theme_id * omit default theme from child themes dropdown and try a different fix * cache & freeze stylesheets arrays
This commit is contained in:
@ -33,4 +33,74 @@ RSpec.describe ApplicationController do
|
||||
end
|
||||
end
|
||||
|
||||
describe "#handle_theme" do
|
||||
let(:theme) { Fabricate(:theme, user_selectable: true) }
|
||||
let(:theme2) { Fabricate(:theme, user_selectable: true) }
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:admin) { Fabricate(:admin) }
|
||||
|
||||
before do
|
||||
sign_in(user)
|
||||
end
|
||||
|
||||
it "selects the theme the user has selected" do
|
||||
user.user_option.update_columns(theme_ids: [theme.id])
|
||||
|
||||
get "/"
|
||||
expect(response.status).to eq(200)
|
||||
expect(controller.theme_ids).to eq([theme.id])
|
||||
|
||||
theme.update_attribute(:user_selectable, false)
|
||||
|
||||
get "/"
|
||||
expect(response.status).to eq(200)
|
||||
expect(controller.theme_ids).to eq([SiteSetting.default_theme_id])
|
||||
end
|
||||
|
||||
it "can be overridden with a cookie" do
|
||||
user.user_option.update_columns(theme_ids: [theme.id])
|
||||
|
||||
cookies['theme_ids'] = "#{theme2.id}|#{user.user_option.theme_key_seq}"
|
||||
|
||||
get "/"
|
||||
expect(response.status).to eq(200)
|
||||
expect(controller.theme_ids).to eq([theme2.id])
|
||||
|
||||
theme2.update!(user_selectable: false)
|
||||
theme.add_child_theme!(theme2)
|
||||
cookies['theme_ids'] = "#{theme.id},#{theme2.id}|#{user.user_option.theme_key_seq}"
|
||||
|
||||
get "/"
|
||||
expect(response.status).to eq(200)
|
||||
expect(controller.theme_ids).to eq([theme.id, theme2.id])
|
||||
end
|
||||
|
||||
it "falls back to the default theme when the user has no cookies or preferences" do
|
||||
user.user_option.update_columns(theme_ids: [])
|
||||
cookies["theme_ids"] = nil
|
||||
theme2.set_default!
|
||||
|
||||
get "/"
|
||||
expect(response.status).to eq(200)
|
||||
expect(controller.theme_ids).to eq([theme2.id])
|
||||
end
|
||||
|
||||
it "can be overridden with preview_theme_id param" do
|
||||
sign_in(admin)
|
||||
cookies['theme_ids'] = "#{theme.id},#{theme2.id}|#{admin.user_option.theme_key_seq}"
|
||||
|
||||
get "/", params: { preview_theme_id: theme2.id }
|
||||
expect(response.status).to eq(200)
|
||||
expect(controller.theme_ids).to eq([theme2.id])
|
||||
end
|
||||
|
||||
it "cookie can fail back to user if out of sync" do
|
||||
user.user_option.update_columns(theme_ids: [theme.id])
|
||||
cookies['theme_ids'] = "#{theme2.id}|#{user.user_option.theme_key_seq - 1}"
|
||||
|
||||
get "/"
|
||||
expect(response.status).to eq(200)
|
||||
expect(controller.theme_ids).to eq([theme.id])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user