From 6b0626a5e2ac8748c71f97acf2cb053101aee860 Mon Sep 17 00:00:00 2001 From: Julianna Tetreault <32834804+juliannatetreault@users.noreply.github.com> Date: Tue, 29 Dec 2020 15:03:52 -0700 Subject: [PATCH] Adds collective_noun Fields Back to SiteConfig Model (#12055) [deploy] * Adds collective_noun and collective_noun_disabled back to SiteConfig model * Adds a script that appends collective_noun conditionally and matching spec * Adds a conditional to determine if collective_noun should be appended * Refactors data_update script logic to be cleaner * Refactors spec to use method stubs * Adds a comment to the SiteConfig model about collective_noun fields * Adds an additional check to the scripts return statement --- app/models/site_config.rb | 4 ++++ ...ppend_collective_noun_to_community_name.rb | 9 ++++++++ ..._collective_noun_to_community_name_spec.rb | 23 +++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 lib/data_update_scripts/20201228194641_append_collective_noun_to_community_name.rb create mode 100644 spec/lib/data_update_scripts/append_collective_noun_to_community_name_spec.rb diff --git a/app/models/site_config.rb b/app/models/site_config.rb index d45701121..34b67ae3d 100644 --- a/app/models/site_config.rb +++ b/app/models/site_config.rb @@ -55,6 +55,10 @@ class SiteConfig < RailsSettings::Base # Community Content field :community_name, type: :string, default: ApplicationConfig["COMMUNITY_NAME"] || "New Forem" field :community_emoji, type: :string, default: "🌱" + # collective_noun and collective_noun_disabled have been added back temporarily for + # a data_update script, but will be removed in a future PR! + field :collective_noun, type: :string, default: "Community" + field :collective_noun_disabled, type: :boolean, default: false field :community_description, type: :string field :community_member_label, type: :string, default: "user" field :tagline, type: :string diff --git a/lib/data_update_scripts/20201228194641_append_collective_noun_to_community_name.rb b/lib/data_update_scripts/20201228194641_append_collective_noun_to_community_name.rb new file mode 100644 index 000000000..8a3b90350 --- /dev/null +++ b/lib/data_update_scripts/20201228194641_append_collective_noun_to_community_name.rb @@ -0,0 +1,9 @@ +module DataUpdateScripts + class AppendCollectiveNounToCommunityName + def run + return if SiteConfig.collective_noun_disabled || SiteConfig.collective_noun.blank? + + SiteConfig.community_name = "#{SiteConfig.community_name} #{SiteConfig.collective_noun}" + end + end +end diff --git a/spec/lib/data_update_scripts/append_collective_noun_to_community_name_spec.rb b/spec/lib/data_update_scripts/append_collective_noun_to_community_name_spec.rb new file mode 100644 index 000000000..705881d8d --- /dev/null +++ b/spec/lib/data_update_scripts/append_collective_noun_to_community_name_spec.rb @@ -0,0 +1,23 @@ +require "rails_helper" +require Rails.root.join( + "lib/data_update_scripts/20201228194641_append_collective_noun_to_community_name.rb", +) + +describe DataUpdateScripts::AppendCollectiveNounToCommunityName do + context "when collective_noun_disabled is false" do + it "appends the collective_noun to the community_name" do + allow(SiteConfig).to receive(:collective_noun).and_return("Club") + described_class.new.run + expect(SiteConfig.collective_noun_disabled).to eq(false) + expect(SiteConfig.community_name).to eq("DEV(local) Club") + end + end + + context "when collective_noun_disabled is true" do + it "does not append the collective_noun to the community_name" do + allow(SiteConfig).to receive(:collective_noun_disabled).and_return(true) + described_class.new.run + expect(SiteConfig.community_name).to eq("DEV(local)") + end + end +end