mirror of
https://github.com/discourse/discourse.git
synced 2024-11-29 04:03:57 -06:00
586454bcf1
* DEV: Add a dedicated Admin::StaffController base controller The current parent(Admin:AdminController) for all admin-related controllers uses a filter that allows only staff(admin, moderator) users. This refactor makes Admin::AdminController filter for only admins as the name suggests and introduces a base controller dedicated for staff-related endpoints. * DEV: Set staff-only controllers parent to Admin::StaffController Refactor staff-only controllers to inherit newly introduced Admin::StaffController abstract controller. This conveys the purpose of the parent controller better unlike the previously used parent controller.
74 lines
2.2 KiB
Ruby
74 lines
2.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe Admin::EmailStylesController do
|
|
fab!(:admin) { Fabricate(:admin) }
|
|
let(:default_html) { File.read("#{Rails.root}/app/views/email/default_template.html") }
|
|
let(:default_css) { "" }
|
|
|
|
before do
|
|
sign_in(admin)
|
|
end
|
|
|
|
after do
|
|
SiteSetting.remove_override!(:email_custom_template)
|
|
SiteSetting.remove_override!(:email_custom_css)
|
|
end
|
|
|
|
it "is a subclass of AdminController" do
|
|
expect(Admin::EmailStylesController < Admin::AdminController).to eq(true)
|
|
end
|
|
|
|
describe 'show' do
|
|
it 'returns default values' do
|
|
get '/admin/customize/email_style.json'
|
|
expect(response.status).to eq(200)
|
|
|
|
json = response.parsed_body['email_style']
|
|
expect(json['html']).to eq(default_html)
|
|
expect(json['css']).to eq(default_css)
|
|
end
|
|
|
|
it 'returns customized values' do
|
|
SiteSetting.email_custom_template = "For you: %{email_content}"
|
|
SiteSetting.email_custom_css = ".user-name { font-size: 24px; }"
|
|
get '/admin/customize/email_style.json'
|
|
expect(response.status).to eq(200)
|
|
|
|
json = response.parsed_body['email_style']
|
|
expect(json['html']).to eq("For you: %{email_content}")
|
|
expect(json['css']).to eq(".user-name { font-size: 24px; }")
|
|
end
|
|
end
|
|
|
|
describe 'update' do
|
|
let(:valid_params) do
|
|
{
|
|
html: 'For you: %{email_content}',
|
|
css: '.user-name { color: purple; }'
|
|
}
|
|
end
|
|
|
|
it 'changes the settings' do
|
|
SiteSetting.email_custom_css = ".user-name { font-size: 24px; }"
|
|
put '/admin/customize/email_style.json', params: { email_style: valid_params }
|
|
expect(response.status).to eq(200)
|
|
expect(SiteSetting.email_custom_template).to eq(valid_params[:html])
|
|
expect(SiteSetting.email_custom_css).to eq(valid_params[:css])
|
|
end
|
|
|
|
it 'reports errors' do
|
|
put '/admin/customize/email_style.json', params: {
|
|
email_style: valid_params.merge(html: 'No email content')
|
|
}
|
|
expect(response.status).to eq(422)
|
|
json = response.parsed_body
|
|
expect(json['errors']).to include(
|
|
I18n.t(
|
|
'email_style.html_missing_placeholder',
|
|
placeholder: '%{email_content}'
|
|
)
|
|
)
|
|
end
|
|
end
|
|
end
|