Replace best_in_place editor on admin settings page (#2789)
* Remove best_in_place * Replace best_in_place usage with rails helpers * Move admin/settings#index to #edit action * Remove click_to__edit from i18n
This commit is contained in:
parent
91ddd345f2
commit
2bd132d458
1
Gemfile
1
Gemfile
|
@ -13,7 +13,6 @@ gem 'hamlit-rails'
|
||||||
gem 'pg'
|
gem 'pg'
|
||||||
gem 'pghero'
|
gem 'pghero'
|
||||||
gem 'dotenv-rails'
|
gem 'dotenv-rails'
|
||||||
gem 'best_in_place', '~> 3.0.1'
|
|
||||||
|
|
||||||
gem 'aws-sdk', '>= 2.0'
|
gem 'aws-sdk', '>= 2.0'
|
||||||
gem 'paperclip', '~> 5.1'
|
gem 'paperclip', '~> 5.1'
|
||||||
|
|
|
@ -65,9 +65,6 @@ GEM
|
||||||
babel-source (>= 4.0, < 6)
|
babel-source (>= 4.0, < 6)
|
||||||
execjs (~> 2.0)
|
execjs (~> 2.0)
|
||||||
bcrypt (3.1.11)
|
bcrypt (3.1.11)
|
||||||
best_in_place (3.0.3)
|
|
||||||
actionpack (>= 3.2)
|
|
||||||
railties (>= 3.2)
|
|
||||||
better_errors (2.1.1)
|
better_errors (2.1.1)
|
||||||
coderay (>= 1.0.0)
|
coderay (>= 1.0.0)
|
||||||
erubis (>= 2.6.6)
|
erubis (>= 2.6.6)
|
||||||
|
@ -478,7 +475,6 @@ DEPENDENCIES
|
||||||
addressable
|
addressable
|
||||||
annotate
|
annotate
|
||||||
aws-sdk (>= 2.0)
|
aws-sdk (>= 2.0)
|
||||||
best_in_place (~> 3.0.1)
|
|
||||||
better_errors
|
better_errors
|
||||||
binding_of_caller
|
binding_of_caller
|
||||||
bullet
|
bullet
|
||||||
|
|
|
@ -2,38 +2,43 @@
|
||||||
|
|
||||||
module Admin
|
module Admin
|
||||||
class SettingsController < BaseController
|
class SettingsController < BaseController
|
||||||
|
ADMIN_SETTINGS = %w(
|
||||||
|
site_contact_username
|
||||||
|
site_contact_email
|
||||||
|
site_title
|
||||||
|
site_description
|
||||||
|
site_extended_description
|
||||||
|
open_registrations
|
||||||
|
closed_registrations_message
|
||||||
|
).freeze
|
||||||
BOOLEAN_SETTINGS = %w(open_registrations).freeze
|
BOOLEAN_SETTINGS = %w(open_registrations).freeze
|
||||||
|
|
||||||
def index
|
def edit
|
||||||
@settings = Setting.all_as_records
|
@settings = Setting.all_as_records
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@setting = Setting.where(var: params[:id]).first_or_initialize(var: params[:id])
|
settings_params.each do |key, value|
|
||||||
@setting.update(value: value_for_update)
|
setting = Setting.where(var: key).first_or_initialize(var: key)
|
||||||
|
setting.update(value: value_for_update(key, value))
|
||||||
respond_to do |format|
|
|
||||||
format.html { redirect_to admin_settings_path }
|
|
||||||
format.json { respond_with_bip(@setting) }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
flash[:notice] = 'Success!'
|
||||||
|
redirect_to edit_admin_settings_path
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def settings_params
|
def settings_params
|
||||||
params.require(:setting).permit(:value)
|
params.permit(ADMIN_SETTINGS)
|
||||||
end
|
end
|
||||||
|
|
||||||
def value_for_update
|
def value_for_update(key, value)
|
||||||
if updating_boolean_setting?
|
if BOOLEAN_SETTINGS.include?(key)
|
||||||
settings_params[:value] == 'true'
|
value == 'true'
|
||||||
else
|
else
|
||||||
settings_params[:value]
|
value
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def updating_boolean_setting?
|
|
||||||
BOOLEAN_SETTINGS.include?(params[:id])
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,6 +9,12 @@ code {
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.admin {
|
||||||
|
input, textarea {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.simple_form {
|
.simple_form {
|
||||||
.input {
|
.input {
|
||||||
margin-bottom: 15px;
|
margin-bottom: 15px;
|
||||||
|
|
58
app/views/admin/settings/edit.html.haml
Normal file
58
app/views/admin/settings/edit.html.haml
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
- content_for :page_title do
|
||||||
|
= t('admin.settings.title')
|
||||||
|
|
||||||
|
= form_tag(admin_settings_path, method: :put) do
|
||||||
|
%table.table
|
||||||
|
%thead
|
||||||
|
%tr
|
||||||
|
%th{width: '40%'}
|
||||||
|
= t('admin.settings.setting')
|
||||||
|
%th
|
||||||
|
%tbody
|
||||||
|
%tr
|
||||||
|
%td
|
||||||
|
%strong= t('admin.settings.contact_information.label')
|
||||||
|
%td= text_field_tag :site_contact_username,
|
||||||
|
@settings['site_contact_username'].value,
|
||||||
|
place_holder: t('admin.settings.contact_information.username')
|
||||||
|
%tr
|
||||||
|
%td
|
||||||
|
%strong= t('admin.accounts.email')
|
||||||
|
%td= text_field_tag :site_contact_email,
|
||||||
|
@settings['site_contact_email'].value,
|
||||||
|
place_holder: t('admin.settings.contact_information.email')
|
||||||
|
%tr
|
||||||
|
%td
|
||||||
|
%strong= t('admin.settings.site_title')
|
||||||
|
%td= text_field_tag :site_title,
|
||||||
|
@settings['site_title'].value
|
||||||
|
%tr
|
||||||
|
%td
|
||||||
|
%strong= t('admin.settings.site_description.title')
|
||||||
|
%p= t('admin.settings.site_description.desc_html')
|
||||||
|
%td= text_area_tag :site_description,
|
||||||
|
@settings['site_description'].value,
|
||||||
|
rows: 8
|
||||||
|
%tr
|
||||||
|
%td
|
||||||
|
%strong= t('admin.settings.site_description_extended.title')
|
||||||
|
%p= t('admin.settings.site_description_extended.desc_html')
|
||||||
|
%td= text_area_tag :site_extended_description,
|
||||||
|
@settings['site_extended_description'].value,
|
||||||
|
rows: 8
|
||||||
|
%tr
|
||||||
|
%td
|
||||||
|
%strong= t('admin.settings.registrations.open.title')
|
||||||
|
%td
|
||||||
|
= select_tag :open_registrations,
|
||||||
|
options_for_select({ t('admin.settings.registrations.open.disabled') => false, t('admin.settings.registrations.open.enabled') => true }, @settings['open_registrations'].value)
|
||||||
|
%tr
|
||||||
|
%td
|
||||||
|
%strong= t('admin.settings.registrations.closed_message.title')
|
||||||
|
%p= t('admin.settings.registrations.closed_message.desc_html')
|
||||||
|
%td= text_area_tag :closed_registrations_message,
|
||||||
|
@settings['closed_registrations_message'].value,
|
||||||
|
rows: 8
|
||||||
|
|
||||||
|
.simple_form.actions
|
||||||
|
= button_tag t('generic.save_changes'), type: :submit, class: :btn
|
|
@ -1,40 +0,0 @@
|
||||||
- content_for :page_title do
|
|
||||||
= t('admin.settings.title')
|
|
||||||
|
|
||||||
%table.table
|
|
||||||
%colgroup
|
|
||||||
%col{ width: '35%' }/
|
|
||||||
%thead
|
|
||||||
%tr
|
|
||||||
%th= t('admin.settings.setting')
|
|
||||||
%th= t('admin.settings.click_to_edit')
|
|
||||||
%tbody
|
|
||||||
%tr
|
|
||||||
%td{ rowspan: 2 }
|
|
||||||
%strong= t('admin.settings.contact_information.label')
|
|
||||||
%td= best_in_place @settings['site_contact_username'], :value, url: admin_setting_path(@settings['site_contact_username']), place_holder: t('admin.settings.contact_information.username')
|
|
||||||
%tr
|
|
||||||
%td= best_in_place @settings['site_contact_email'], :value, url: admin_setting_path(@settings['site_contact_email']), place_holder: t('admin.settings.contact_information.email')
|
|
||||||
%tr
|
|
||||||
%td
|
|
||||||
%strong= t('admin.settings.site_title')
|
|
||||||
%td= best_in_place @settings['site_title'], :value, url: admin_setting_path(@settings['site_title'])
|
|
||||||
%tr
|
|
||||||
%td
|
|
||||||
%strong= t('admin.settings.site_description.title')
|
|
||||||
%p= t('admin.settings.site_description.desc_html')
|
|
||||||
%td= best_in_place @settings['site_description'], :value, as: :textarea, url: admin_setting_path(@settings['site_description'])
|
|
||||||
%tr
|
|
||||||
%td
|
|
||||||
%strong= t('admin.settings.site_description_extended.title')
|
|
||||||
%p= t('admin.settings.site_description_extended.desc_html')
|
|
||||||
%td= best_in_place @settings['site_extended_description'], :value, as: :textarea, url: admin_setting_path(@settings['site_extended_description'])
|
|
||||||
%tr
|
|
||||||
%td
|
|
||||||
%strong= t('admin.settings.registrations.open.title')
|
|
||||||
%td= best_in_place @settings['open_registrations'], :value, as: :checkbox, collection: { false: t('admin.settings.registrations.open.disabled'), true: t('admin.settings.registrations.open.enabled')}, url: admin_setting_path(@settings['open_registrations'])
|
|
||||||
%tr
|
|
||||||
%td
|
|
||||||
%strong= t('admin.settings.registrations.closed_message.title')
|
|
||||||
%p= t('admin.settings.registrations.closed_message.desc_html')
|
|
||||||
%td= best_in_place @settings['closed_registrations_message'], :value, as: :textarea, url: admin_setting_path(@settings['closed_registrations_message'])
|
|
|
@ -145,7 +145,6 @@ de:
|
||||||
unresolved: Ungelöst
|
unresolved: Ungelöst
|
||||||
view: Ansehen
|
view: Ansehen
|
||||||
settings:
|
settings:
|
||||||
click_to_edit: Klicken zum Bearbeiten
|
|
||||||
contact_information:
|
contact_information:
|
||||||
email: Eine öffentliche E-Mail-Adresse angeben
|
email: Eine öffentliche E-Mail-Adresse angeben
|
||||||
label: Kontaktinformationen
|
label: Kontaktinformationen
|
||||||
|
|
|
@ -158,7 +158,6 @@ en:
|
||||||
unresolved: Unresolved
|
unresolved: Unresolved
|
||||||
view: View
|
view: View
|
||||||
settings:
|
settings:
|
||||||
click_to_edit: Click to edit
|
|
||||||
contact_information:
|
contact_information:
|
||||||
email: Enter a public e-mail address
|
email: Enter a public e-mail address
|
||||||
label: Contact information
|
label: Contact information
|
||||||
|
|
|
@ -156,7 +156,6 @@ fa:
|
||||||
unresolved: حلنشده
|
unresolved: حلنشده
|
||||||
view: نمایش
|
view: نمایش
|
||||||
settings:
|
settings:
|
||||||
click_to_edit: برای ویرایش کلیک کنید
|
|
||||||
contact_information:
|
contact_information:
|
||||||
email: یک نشانی ایمیل عمومی وارد کنید
|
email: یک نشانی ایمیل عمومی وارد کنید
|
||||||
label: اطلاعات تماس
|
label: اطلاعات تماس
|
||||||
|
|
|
@ -136,7 +136,6 @@ fr:
|
||||||
unresolved: Non résolus
|
unresolved: Non résolus
|
||||||
view: Voir
|
view: Voir
|
||||||
settings:
|
settings:
|
||||||
click_to_edit: Cliquez pour éditer
|
|
||||||
contact_information:
|
contact_information:
|
||||||
email: Entrez une adresse courriel publique
|
email: Entrez une adresse courriel publique
|
||||||
label: Informations de contact
|
label: Informations de contact
|
||||||
|
|
|
@ -157,7 +157,6 @@ he:
|
||||||
unresolved: לא פתור
|
unresolved: לא פתור
|
||||||
view: תצוגה
|
view: תצוגה
|
||||||
settings:
|
settings:
|
||||||
click_to_edit: לחיצה כדי לערוך
|
|
||||||
contact_information:
|
contact_information:
|
||||||
email: 'נא להקליד כתובת דוא"ל פומבית'
|
email: 'נא להקליד כתובת דוא"ל פומבית'
|
||||||
label: פרטי התקשרות
|
label: פרטי התקשרות
|
||||||
|
|
|
@ -156,7 +156,6 @@ id:
|
||||||
unresolved: Belum Terseleseikan
|
unresolved: Belum Terseleseikan
|
||||||
view: Tampilan
|
view: Tampilan
|
||||||
settings:
|
settings:
|
||||||
click_to_edit: Klik untuk mengubah
|
|
||||||
contact_information:
|
contact_information:
|
||||||
email: Masukkan alamat email
|
email: Masukkan alamat email
|
||||||
label: Informasi kontak
|
label: Informasi kontak
|
||||||
|
|
|
@ -144,7 +144,6 @@ io:
|
||||||
unresolved: Unresolved
|
unresolved: Unresolved
|
||||||
view: View
|
view: View
|
||||||
settings:
|
settings:
|
||||||
click_to_edit: Click to edit
|
|
||||||
contact_information:
|
contact_information:
|
||||||
email: Enter a public e-mail address
|
email: Enter a public e-mail address
|
||||||
label: Contact information
|
label: Contact information
|
||||||
|
|
|
@ -157,7 +157,6 @@ ja:
|
||||||
unresolved: 未解決
|
unresolved: 未解決
|
||||||
view: 表示
|
view: 表示
|
||||||
settings:
|
settings:
|
||||||
click_to_edit: クリックして編集
|
|
||||||
contact_information:
|
contact_information:
|
||||||
email: 公開するメールアドレスを入力
|
email: 公開するメールアドレスを入力
|
||||||
label: 連絡先情報
|
label: 連絡先情報
|
||||||
|
|
|
@ -41,7 +41,6 @@ nl:
|
||||||
unfollow: Ontvolgen
|
unfollow: Ontvolgen
|
||||||
admin:
|
admin:
|
||||||
settings:
|
settings:
|
||||||
click_to_edit: Klik om te bewerken
|
|
||||||
contact_information:
|
contact_information:
|
||||||
email: Vul een openbaar gebruikt e-mailadres in
|
email: Vul een openbaar gebruikt e-mailadres in
|
||||||
label: Contactgegevens
|
label: Contactgegevens
|
||||||
|
|
|
@ -146,7 +146,6 @@ oc:
|
||||||
unresolved: Pas resolguts
|
unresolved: Pas resolguts
|
||||||
view: Veire
|
view: Veire
|
||||||
settings:
|
settings:
|
||||||
click_to_edit: Clicatz per modificar
|
|
||||||
contact_information:
|
contact_information:
|
||||||
email: Picatz una adreça de corrièl
|
email: Picatz una adreça de corrièl
|
||||||
label: Informacions de contacte
|
label: Informacions de contacte
|
||||||
|
|
|
@ -158,7 +158,6 @@ pl:
|
||||||
unresolved: Nierozwiązane
|
unresolved: Nierozwiązane
|
||||||
view: Wyświetl
|
view: Wyświetl
|
||||||
settings:
|
settings:
|
||||||
click_to_edit: Naciśnij, aby edytować
|
|
||||||
contact_information:
|
contact_information:
|
||||||
email: Wprowadź publiczny adres e-mail
|
email: Wprowadź publiczny adres e-mail
|
||||||
label: Informacje kontaktowe
|
label: Informacje kontaktowe
|
||||||
|
|
|
@ -157,7 +157,6 @@ pt-BR:
|
||||||
unresolved: Unresolved
|
unresolved: Unresolved
|
||||||
view: View
|
view: View
|
||||||
settings:
|
settings:
|
||||||
click_to_edit: Clique para editar
|
|
||||||
contact_information:
|
contact_information:
|
||||||
email: Entre um endereço de email público
|
email: Entre um endereço de email público
|
||||||
label: Informação de contato
|
label: Informação de contato
|
||||||
|
|
|
@ -152,7 +152,6 @@ pt:
|
||||||
unresolved: Por resolver
|
unresolved: Por resolver
|
||||||
view: Ver
|
view: Ver
|
||||||
settings:
|
settings:
|
||||||
click_to_edit: Clique para editar
|
|
||||||
contact_information:
|
contact_information:
|
||||||
email: Inserir um endereço de email para tornar público
|
email: Inserir um endereço de email para tornar público
|
||||||
label: Informação de contacto
|
label: Informação de contacto
|
||||||
|
|
|
@ -139,7 +139,6 @@ ru:
|
||||||
unresolved: Неразрешенные
|
unresolved: Неразрешенные
|
||||||
view: Просмотреть
|
view: Просмотреть
|
||||||
settings:
|
settings:
|
||||||
click_to_edit: Нажмите для изменения
|
|
||||||
contact_information:
|
contact_information:
|
||||||
email: Введите публичный e-mail
|
email: Введите публичный e-mail
|
||||||
label: Контактная информация
|
label: Контактная информация
|
||||||
|
|
|
@ -157,7 +157,6 @@ th:
|
||||||
unresolved: Unresolved
|
unresolved: Unresolved
|
||||||
view: วิว
|
view: วิว
|
||||||
settings:
|
settings:
|
||||||
click_to_edit: คลิ๊กเพื่อแก้ไข
|
|
||||||
contact_information:
|
contact_information:
|
||||||
email: กรอกที่อยู่อีเมล์สาธารณะ
|
email: กรอกที่อยู่อีเมล์สาธารณะ
|
||||||
label: ข้อมูลที่ติดต่อ
|
label: ข้อมูลที่ติดต่อ
|
||||||
|
|
|
@ -154,7 +154,6 @@ zh-CN:
|
||||||
unresolved: 未处理
|
unresolved: 未处理
|
||||||
view: 查看
|
view: 查看
|
||||||
settings:
|
settings:
|
||||||
click_to_edit: 点击编辑
|
|
||||||
contact_information:
|
contact_information:
|
||||||
email: 输入一个公开的电邮地址
|
email: 输入一个公开的电邮地址
|
||||||
label: 联系数据
|
label: 联系数据
|
||||||
|
|
|
@ -141,7 +141,6 @@ zh-HK:
|
||||||
unresolved: 未處理
|
unresolved: 未處理
|
||||||
view: 檢視
|
view: 檢視
|
||||||
settings:
|
settings:
|
||||||
click_to_edit: 點擊編輯
|
|
||||||
contact_information:
|
contact_information:
|
||||||
email: 輸入一個公開的電郵地址
|
email: 輸入一個公開的電郵地址
|
||||||
label: 聯絡資料
|
label: 聯絡資料
|
||||||
|
|
|
@ -118,7 +118,6 @@ zh-TW:
|
||||||
unresolved: 未解決
|
unresolved: 未解決
|
||||||
view: 檢視
|
view: 檢視
|
||||||
settings:
|
settings:
|
||||||
click_to_edit: 點選以編輯
|
|
||||||
contact_information:
|
contact_information:
|
||||||
email: 請輸入輸入一個公開電子信箱
|
email: 請輸入輸入一個公開電子信箱
|
||||||
label: 聯絡資訊
|
label: 聯絡資訊
|
||||||
|
|
|
@ -23,7 +23,7 @@ SimpleNavigation::Configuration.run do |navigation|
|
||||||
admin.item :domain_blocks, safe_join([fa_icon('lock fw'), t('admin.domain_blocks.title')]), admin_domain_blocks_url, highlights_on: %r{/admin/domain_blocks}
|
admin.item :domain_blocks, safe_join([fa_icon('lock fw'), t('admin.domain_blocks.title')]), admin_domain_blocks_url, highlights_on: %r{/admin/domain_blocks}
|
||||||
admin.item :sidekiq, safe_join([fa_icon('diamond fw'), 'Sidekiq']), sidekiq_url, link_html: { target: 'sidekiq' }
|
admin.item :sidekiq, safe_join([fa_icon('diamond fw'), 'Sidekiq']), sidekiq_url, link_html: { target: 'sidekiq' }
|
||||||
admin.item :pghero, safe_join([fa_icon('database fw'), 'PgHero']), pghero_url, link_html: { target: 'pghero' }
|
admin.item :pghero, safe_join([fa_icon('database fw'), 'PgHero']), pghero_url, link_html: { target: 'pghero' }
|
||||||
admin.item :settings, safe_join([fa_icon('cogs fw'), t('admin.settings.title')]), admin_settings_url
|
admin.item :settings, safe_join([fa_icon('cogs fw'), t('admin.settings.title')]), edit_admin_settings_url
|
||||||
end
|
end
|
||||||
|
|
||||||
primary.item :logout, safe_join([fa_icon('sign-out fw'), t('auth.logout')]), destroy_user_session_url, link_html: { 'data-method' => 'delete' }
|
primary.item :logout, safe_join([fa_icon('sign-out fw'), t('auth.logout')]), destroy_user_session_url, link_html: { 'data-method' => 'delete' }
|
||||||
|
|
|
@ -76,7 +76,7 @@ Rails.application.routes.draw do
|
||||||
namespace :admin do
|
namespace :admin do
|
||||||
resources :pubsubhubbub, only: [:index]
|
resources :pubsubhubbub, only: [:index]
|
||||||
resources :domain_blocks, only: [:index, :new, :create, :show, :destroy]
|
resources :domain_blocks, only: [:index, :new, :create, :show, :destroy]
|
||||||
resources :settings, only: [:index, :update]
|
resource :settings, only: [:edit, :update]
|
||||||
resources :instances, only: [:index]
|
resources :instances, only: [:index]
|
||||||
|
|
||||||
resources :reports, only: [:index, :show, :update] do
|
resources :reports, only: [:index, :show, :update] do
|
||||||
|
|
|
@ -22,7 +22,7 @@ namespace :mastodon do
|
||||||
user = Account.find_local(ENV.fetch('USERNAME')).user
|
user = Account.find_local(ENV.fetch('USERNAME')).user
|
||||||
user.update(admin: true)
|
user.update(admin: true)
|
||||||
|
|
||||||
puts "Congrats! #{user.account.username} is now an admin. \\o/\nNavigate to #{admin_settings_url} to get started"
|
puts "Congrats! #{user.account.username} is now an admin. \\o/\nNavigate to #{edit_admin_settings_url} to get started"
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Manually confirms a user with associated user email address stored in USER_EMAIL environment variable.'
|
desc 'Manually confirms a user with associated user email address stored in USER_EMAIL environment variable.'
|
||||||
|
|
|
@ -1,51 +1,65 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe Admin::SettingsController, type: :controller do
|
RSpec.describe Admin::SettingsController, type: :controller do
|
||||||
render_views
|
render_views
|
||||||
|
|
||||||
|
before do
|
||||||
|
Rails.cache.clear
|
||||||
|
end
|
||||||
|
|
||||||
describe 'When signed in as an admin' do
|
describe 'When signed in as an admin' do
|
||||||
before do
|
before do
|
||||||
sign_in Fabricate(:user, admin: true), scope: :user
|
sign_in Fabricate(:user, admin: true), scope: :user
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'GET #index' do
|
describe 'GET #edit' do
|
||||||
it 'returns http success' do
|
it 'returns http success' do
|
||||||
get :index
|
get :edit
|
||||||
|
|
||||||
expect(response).to have_http_status(:success)
|
expect(response).to have_http_status(:success)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'PUT #update' do
|
describe 'PUT #update' do
|
||||||
|
|
||||||
describe 'for a record that doesnt exist' do
|
describe 'for a record that doesnt exist' do
|
||||||
after do
|
after do
|
||||||
Setting.new_setting_key = nil
|
Setting.new_setting_key = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'creates a settings value that didnt exist before' do
|
it 'cannot create a setting value for a non-admin key' do
|
||||||
expect(Setting.new_setting_key).to be_nil
|
expect(Setting.new_setting_key).to be_nil
|
||||||
|
|
||||||
patch :update, params: { id: 'new_setting_key', setting: { value: 'New key value' } }
|
patch :update, params: { new_setting_key: 'New key value' }
|
||||||
|
|
||||||
expect(response).to redirect_to(admin_settings_path)
|
expect(response).to redirect_to(edit_admin_settings_path)
|
||||||
expect(Setting.new_setting_key).to eq 'New key value'
|
expect(Setting.new_setting_key).to be_nil
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'creates a settings value that didnt exist before for eligible key' do
|
||||||
|
expect(Setting.site_extended_description).to be_blank
|
||||||
|
|
||||||
|
patch :update, params: { site_extended_description: 'New key value' }
|
||||||
|
|
||||||
|
expect(response).to redirect_to(edit_admin_settings_path)
|
||||||
|
expect(Setting.site_extended_description).to eq 'New key value'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'updates a settings value' do
|
it 'updates a settings value' do
|
||||||
Setting.site_title = 'Original'
|
Setting.site_title = 'Original'
|
||||||
patch :update, params: { id: 'site_title', setting: { value: 'New title' } }
|
patch :update, params: { site_title: 'New title' }
|
||||||
|
|
||||||
expect(response).to redirect_to(admin_settings_path)
|
expect(response).to redirect_to(edit_admin_settings_path)
|
||||||
expect(Setting.site_title).to eq 'New title'
|
expect(Setting.site_title).to eq 'New title'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'typecasts open_registrations to boolean' do
|
it 'typecasts open_registrations to boolean' do
|
||||||
Setting.open_registrations = false
|
Setting.open_registrations = false
|
||||||
patch :update, params: { id: 'open_registrations', setting: { value: 'true' } }
|
patch :update, params: { open_registrations: 'true' }
|
||||||
|
|
||||||
expect(response).to redirect_to(admin_settings_path)
|
expect(response).to redirect_to(edit_admin_settings_path)
|
||||||
expect(Setting.open_registrations).to eq true
|
expect(Setting.open_registrations).to eq true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Reference in a new issue