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:
Ben Halpern 2020-12-29 14:03:17 -05:00 committed by GitHub
parent ba5f25931f
commit 183a672113
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View file

@ -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]

View file

@ -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