Create tag model if config updated (#12026)
* Create tag model if config updated * Guard unless tags are part of request
This commit is contained in:
parent
ba5f25931f
commit
183a672113
2 changed files with 19 additions and 0 deletions
|
|
@ -42,6 +42,7 @@ module SiteConfigs
|
|||
|
||||
@success = true
|
||||
upsert_configs
|
||||
after_upsert_tasks
|
||||
self
|
||||
end
|
||||
|
||||
|
|
@ -63,6 +64,10 @@ module SiteConfigs
|
|||
end
|
||||
end
|
||||
|
||||
def after_upsert_tasks
|
||||
create_tags_if_not_created
|
||||
end
|
||||
|
||||
def clean_up_params
|
||||
PARAMS_TO_BE_CLEANED.each do |param|
|
||||
@configs[param] = @configs[param]&.downcase&.delete(" ") if @configs[param]
|
||||
|
|
@ -112,6 +117,14 @@ module SiteConfigs
|
|||
SiteConfig.public_send("#{entry}_key").blank? || SiteConfig.public_send("#{entry}_secret").blank?
|
||||
end
|
||||
|
||||
def create_tags_if_not_created
|
||||
# Bulk create tags if they should exist.
|
||||
# This is an acts-as-taggable-on as used on saving of an Article, etc.
|
||||
return unless (@configs.keys & %w[suggested_tags sidebar_tags]).any?
|
||||
|
||||
Tag.find_or_create_all_with_like_by_name(SiteConfig.suggested_tags + SiteConfig.sidebar_tags)
|
||||
end
|
||||
|
||||
# Validations
|
||||
def brand_contrast_too_low
|
||||
hex = @configs[:primary_brand_color_hex]
|
||||
|
|
|
|||
|
|
@ -801,6 +801,12 @@ RSpec.describe "/admin/config", type: :request do
|
|||
confirmation: confirmation_message }
|
||||
expect(SiteConfig.sidebar_tags).to eq(%w[hey haha hoho bobofofo])
|
||||
end
|
||||
|
||||
it "creates tags if they do not exist" do
|
||||
post "/admin/config", params: { site_config: { sidebar_tags: "bobofogololo, spla, bla" },
|
||||
confirmation: confirmation_message }
|
||||
expect(Tag.find_by(name: "bobofogololo")).to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe "User Experience" do
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue