* Add: #406 ユーザーのカスタムCSS * Fix lint * Fix lint * カスタムCSSの保存先を変更 * キャッシュを考慮して別URLに変更
This commit is contained in:
parent
5ffd7593f1
commit
665c632d66
28 changed files with 283 additions and 4 deletions
|
@ -203,6 +203,45 @@ RSpec.describe Auth::SessionsController do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with custom css' do
|
||||
let(:params) { {} }
|
||||
|
||||
before do
|
||||
user.settings['web.use_custom_css'] = true
|
||||
user.save!
|
||||
|
||||
post :create, params: { user: { email: user.email, password: user.password }.merge(params) }
|
||||
end
|
||||
|
||||
context 'when does not reset custom css' do
|
||||
let(:params) { { disable_css: '0' } }
|
||||
|
||||
it 'custom css is enabled' do
|
||||
expect(response).to redirect_to(root_path)
|
||||
expect(controller.current_user).to eq user
|
||||
expect(user.reload.setting_use_custom_css).to be true
|
||||
end
|
||||
end
|
||||
|
||||
context 'when reset custom css' do
|
||||
let(:params) { { disable_css: '1' } }
|
||||
|
||||
it 'custom css is disabled' do
|
||||
expect(response).to redirect_to(root_path)
|
||||
expect(controller.current_user).to eq user
|
||||
expect(user.reload.setting_use_custom_css).to be false
|
||||
end
|
||||
end
|
||||
|
||||
context 'when does not specify about custom css' do
|
||||
it 'custom css is enabled' do
|
||||
expect(response).to redirect_to(root_path)
|
||||
expect(controller.current_user).to eq user
|
||||
expect(user.reload.setting_use_custom_css).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when using two-factor authentication' do
|
||||
|
|
48
spec/requests/user_custom_css_spec.rb
Normal file
48
spec/requests/user_custom_css_spec.rb
Normal file
|
@ -0,0 +1,48 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'User custom CSS' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:custom_css) { '* { display: none !important; }' }
|
||||
|
||||
describe 'GET /user_custom.css' do
|
||||
context 'without sign in' do
|
||||
it 'returns 422' do
|
||||
get '/user_custom.css'
|
||||
|
||||
expect(response).to have_http_status(401)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with sign in but custom css is not enabled' do
|
||||
before do
|
||||
user.update!(custom_css_text: custom_css)
|
||||
sign_in user
|
||||
end
|
||||
|
||||
it 'returns custom css' do
|
||||
get '/user_custom.css'
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response.content_type).to include 'text/css'
|
||||
expect(response.body.strip).to eq custom_css
|
||||
end
|
||||
end
|
||||
|
||||
context 'with sign in and custom css is enabled' do
|
||||
before do
|
||||
user.update!(custom_css_text: custom_css, settings: { 'web.use_custom_css': true })
|
||||
sign_in user
|
||||
end
|
||||
|
||||
it 'returns custom css' do
|
||||
get '/user_custom.css'
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response.content_type).to include 'text/css'
|
||||
expect(response.body.strip).to eq custom_css
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue