diff --git a/app/controllers/admin/settings/mascots_controller.rb b/app/controllers/admin/settings/mascots_controller.rb deleted file mode 100644 index cd4e66f0a..000000000 --- a/app/controllers/admin/settings/mascots_controller.rb +++ /dev/null @@ -1,34 +0,0 @@ -module Admin - module Settings - class MascotsController < Admin::ApplicationController - def create - errors = upsert_config(settings_params) - - if errors.none? - Audit::Logger.log(:internal, current_user, params.dup) - redirect_to admin_config_path, notice: "Site configuration was successfully updated." - else - redirect_to admin_config_path, alert: "😭 #{errors.to_sentence}" - end - end - - def settings_params - params - .require(:settings_mascot) - .permit(*::Settings::Mascot.keys) - end - - def upsert_config(configs) - errors = [] - configs.each do |key, value| - ::Settings::Mascot.public_send("#{key}=", value) if value.present? - rescue ActiveRecord::RecordInvalid => e - errors << e.message - next - end - - errors - end - end - end -end diff --git a/app/controllers/chat_channels_controller.rb b/app/controllers/chat_channels_controller.rb index 91e153160..07bcfd855 100644 --- a/app/controllers/chat_channels_controller.rb +++ b/app/controllers/chat_channels_controller.rb @@ -57,10 +57,10 @@ class ChatChannelsController < ApplicationController flash[:error] = chat_channel.errors.full_messages.to_sentence else if chat_channel_params[:discoverable].to_i.zero? - ChatChannelMembership.create(user_id: Settings::Mascot.mascot_user_id, chat_channel_id: chat_channel.id, + ChatChannelMembership.create(user_id: SiteConfig.mascot_user_id, chat_channel_id: chat_channel.id, role: "member", status: "active") else - ChatChannelMembership.find_by(user_id: Settings::Mascot.mascot_user_id)&.destroy + ChatChannelMembership.find_by(user_id: SiteConfig.mascot_user_id)&.destroy end flash[:settings_notice] = "Channel settings updated." end @@ -76,10 +76,10 @@ class ChatChannelsController < ApplicationController message: "Channel settings updation failed. Try again later." }, success: :bad_request else if chat_channel_params[:discoverable] - ChatChannelMembership.create(user_id: Settings::Mascot.mascot_user_id, chat_channel_id: @chat_channel.id, + ChatChannelMembership.create(user_id: SiteConfig.mascot_user_id, chat_channel_id: @chat_channel.id, role: "member", status: "active") else - ChatChannelMembership.find_by(user_id: Settings::Mascot.mascot_user_id)&.destroy + ChatChannelMembership.find_by(user_id: SiteConfig.mascot_user_id)&.destroy end render json: { success: true, message: "Channel settings updated.", data: {} }, success: :ok end diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 4c009ddfb..154626e34 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -110,7 +110,7 @@ class CommentsController < ApplicationController response_template = ResponseTemplate.find(params[:response_template][:id]) authorize response_template, :moderator_create? - moderator = User.find(Settings::Mascot.mascot_user_id) + moderator = User.find(SiteConfig.mascot_user_id) @comment = Comment.new(permitted_attributes(Comment)) @comment.user_id = moderator.id @comment.body_markdown = response_template.content diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 1d77c55e7..1c52df701 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -68,7 +68,7 @@ class SearchController < ApplicationController def chat_channels user_ids = if chat_channel_params[:user_id].present? - [current_user.id, Settings::Mascot.mascot_user_id, chat_channel_params[:user_id]].reject(&:blank?) + [current_user.id, SiteConfig.mascot_user_id, chat_channel_params[:user_id]].reject(&:blank?) else [current_user.id] end diff --git a/app/lib/constants/settings/mascot.rb b/app/lib/constants/settings/mascot.rb deleted file mode 100644 index 4c325a70d..000000000 --- a/app/lib/constants/settings/mascot.rb +++ /dev/null @@ -1,32 +0,0 @@ -module Constants - module Settings - module Mascot - DETAILS = { - footer_image_url: { - description: "Special cute mascot image used in the footer.", - placeholder: ::Constants::SiteConfig::IMAGE_PLACEHOLDER - }, - footer_image_width: { - description: "The footer mascot width will resized to this value, defaults to 52", - placeholder: "" - }, - footer_image_height: { - description: "The footer mascot height will be resized to this value, defaults to 120", - placeholder: "" - }, - image_description: { - description: "Used as the alt text for the mascot image", - placeholder: "" - }, - image_url: { - description: "Used as the mascot image.", - placeholder: ::Constants::SiteConfig::IMAGE_PLACEHOLDER - }, - mascot_user_id: { - description: "User ID of the Mascot account", - placeholder: "1" - } - }.freeze - end - end -end diff --git a/app/lib/constants/site_config.rb b/app/lib/constants/site_config.rb index c6a8affdf..be896d296 100644 --- a/app/lib/constants/site_config.rb +++ b/app/lib/constants/site_config.rb @@ -70,6 +70,14 @@ module Constants description: "Community Moderators Newsletter ID", placeholder: "" }, + mascot_image_url: { + description: "Used as the mascot image.", + placeholder: ::Constants::SiteConfig::IMAGE_PLACEHOLDER + }, + mascot_user_id: { + description: "User ID of the Mascot account", + placeholder: "1" + }, meta_keywords: { description: "", placeholder: "List of valid keywords: comma separated, letters only e.g. engineering, development" diff --git a/app/models/article.rb b/app/models/article.rb index e6ce90c9f..f308daee5 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -178,7 +178,7 @@ class Article < ApplicationRecord .where(user_id: User.with_role(:super_admin) .union(User.with_role(:admin)) .union(id: [Settings::Community.staff_user_id, - Settings::Mascot.mascot_user_id].compact) + SiteConfig.mascot_user_id].compact) .select(:id)).order(published_at: :desc).tagged_with(tag_name) } @@ -788,7 +788,7 @@ class Article < ApplicationRecord return unless SiteConfig.spam_trigger_terms.any? { |term| Regexp.new(term.downcase).match?(title.downcase) } Reaction.create( - user_id: Settings::Mascot.mascot_user_id, + user_id: SiteConfig.mascot_user_id, reactable_id: id, reactable_type: "Article", category: "vomit", @@ -798,7 +798,7 @@ class Article < ApplicationRecord user.add_role(:suspended) Note.create( - author_id: Settings::Mascot.mascot_user_id, + author_id: SiteConfig.mascot_user_id, noteable_id: user_id, noteable_type: "User", reason: "automatic_suspend", diff --git a/app/models/comment.rb b/app/models/comment.rb index d861f5a4c..7a0e2edbe 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -274,7 +274,7 @@ class Comment < ApplicationRecord user.registered_at > 5.days.ago Reaction.create( - user_id: Settings::Mascot.mascot_user_id, + user_id: SiteConfig.mascot_user_id, reactable_id: id, reactable_type: "Comment", category: "vomit", @@ -284,7 +284,7 @@ class Comment < ApplicationRecord user.add_role(:suspended) Note.create( - author_id: Settings::Mascot.mascot_user_id, + author_id: SiteConfig.mascot_user_id, noteable_id: user_id, noteable_type: "User", reason: "automatic_suspend", diff --git a/app/models/reaction.rb b/app/models/reaction.rb index 62a95af05..cbba6b6eb 100644 --- a/app/models/reaction.rb +++ b/app/models/reaction.rb @@ -130,7 +130,7 @@ class Reaction < ApplicationRecord end def negative_reaction_from_untrusted_user? - return if user&.any_admin? || user&.id == Settings::Mascot.mascot_user_id + return if user&.any_admin? || user&.id == SiteConfig.mascot_user_id negative? && !user.trusted end diff --git a/app/models/settings/mascot.rb b/app/models/settings/mascot.rb index 42d297915..f994ce408 100644 --- a/app/models/settings/mascot.rb +++ b/app/models/settings/mascot.rb @@ -6,10 +6,6 @@ module Settings # the cache, or call Settings::Mascot.clear_cache cache_prefix { "v1" } - field :footer_image_height, type: :integer, default: 120 - field :footer_image_url, type: :string, validates: { url: true } - field :footer_image_width, type: :integer, default: 52 - field :image_description, type: :string, default: "The community mascot" field :image_url, type: :string, default: proc { URL.local_image("mascot.png") }, diff --git a/app/models/site_config.rb b/app/models/site_config.rb index 59de94b07..6e6e99788 100644 --- a/app/models/site_config.rb +++ b/app/models/site_config.rb @@ -103,10 +103,6 @@ class SiteConfig < RailsSettings::Base type: :string, default: proc { URL.local_image("mascot.png") }, validates: { url: true } - field :mascot_image_description, type: :string, default: "The community mascot" - field :mascot_footer_image_url, type: :string, validates: { url: true } - field :mascot_footer_image_width, type: :integer, default: 52 - field :mascot_footer_image_height, type: :integer, default: 120 # Meta keywords field :meta_keywords, type: :hash, default: { diff --git a/app/models/user.rb b/app/models/user.rb index 8b27e6e0b..2cbe3edd2 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -310,7 +310,7 @@ class User < ApplicationRecord end def self.mascot_account - find_by(id: Settings::Mascot.mascot_user_id) + find_by(id: SiteConfig.mascot_user_id) end def tag_line diff --git a/app/services/authentication/providers/apple.rb b/app/services/authentication/providers/apple.rb index 193b36fb6..ea2a05d10 100644 --- a/app/services/authentication/providers/apple.rb +++ b/app/services/authentication/providers/apple.rb @@ -18,7 +18,7 @@ module Authentication } if Rails.env.test? - user_data[:profile_image] = Settings::Mascot.image_url + user_data[:profile_image] = SiteConfig.mascot_image_url else user_data[:remote_profile_image_url] = Users::ProfileImageGenerator.call end diff --git a/app/services/users/create_mascot_account.rb b/app/services/users/create_mascot_account.rb index 4be3bd84f..db1c8f701 100644 --- a/app/services/users/create_mascot_account.rb +++ b/app/services/users/create_mascot_account.rb @@ -4,7 +4,7 @@ module Users email: "mascot@forem.com", username: "mascot", name: "Mascot", - profile_image: Settings::Mascot.image_url, + profile_image: SiteConfig.mascot_image_url, confirmed_at: Time.current, registered_at: Time.current, password: SecureRandom.hex @@ -15,10 +15,10 @@ module Users end def call - raise "Mascot already set" if Settings::Mascot.mascot_user_id + raise "Mascot already set" if SiteConfig.mascot_user_id mascot = User.create!(mascot_params) - Settings::Mascot.mascot_user_id = mascot.id + SiteConfig.mascot_user_id = mascot.id end def mascot_params diff --git a/app/views/admin/configs/show.html.erb b/app/views/admin/configs/show.html.erb index b1f9ad78e..857e48a17 100644 --- a/app/views/admin/configs/show.html.erb +++ b/app/views/admin/configs/show.html.erb @@ -739,7 +739,7 @@ <% end %> - <%= form_for(Settings::Mascot.new, url: admin_settings_mascots_path, html: { data: { testid: "mascotSectionForm" } }) do |f| %> + <%= form_for(SiteConfig.new, url: admin_config_path, html: { data: { testid: "mascotSectionForm" } }) do |f| %>
<%= render partial: "admin/shared/card_header", locals: { @@ -751,67 +751,29 @@
- <%= admin_config_label :mascot_user_id, "Mascot user ID", model: Settings::Mascot %> - <%= admin_config_description Constants::Settings::Mascot::DETAILS[:mascot_user_id][:description] %> + <%= admin_config_label :mascot_user_id, "Mascot user ID" %> + <%= admin_config_description Constants::SiteConfig::DETAILS[:mascot_user_id][:description] %> <%= f.text_field :mascot_user_id, class: "crayons-textfield", - value: Settings::Mascot.mascot_user_id, + value: SiteConfig.mascot_user_id, min: 1, - placeholder: Constants::Settings::Mascot::DETAILS[:mascot_user_id][:placeholder] %> + placeholder: Constants::SiteConfig::DETAILS[:mascot_user_id][:placeholder] %>
- <%= admin_config_label :image_url, "Mascot Image URL", model: Settings::Mascot %> - <%= admin_config_description Constants::Settings::Mascot::DETAILS[:image_url][:description] %> - <%= f.text_field :image_url, + <%= admin_config_label :mascot_image_url, "Mascot Image URL" %> + <%= admin_config_description Constants::SiteConfig::DETAILS[:mascot_image_url][:description] %> + <%= f.text_field :mascot_image_url, class: "crayons-textfield", - value: Settings::Mascot.image_url, - placeholder: Constants::Settings::Mascot::DETAILS[:image_url][:placeholder] %> + value: SiteConfig.mascot_image_url, + placeholder: Constants::SiteConfig::DETAILS[:mascot_image_url][:placeholder] %>
- <%= Settings::Mascot.image_description %> + Mascot image
- -
- <%= admin_config_label :footer_image_url, model: Settings::Mascot %> - <%= admin_config_description Constants::Settings::Mascot::DETAILS[:footer_image_url][:description] %> - <%= f.text_field :footer_image_url, - class: "crayons-textfield", - value: Settings::Mascot.footer_image_url, - placeholder: Constants::Settings::Mascot::DETAILS[:footer_image_url][:placeholder] %> - -
- <%= Settings::Mascot.image_description %> -
-
- -
- <%= admin_config_label :footer_image_width, model: Settings::Mascot %> - <%= admin_config_description Constants::Settings::Mascot::DETAILS[:footer_image_width][:description] %> - <%= f.text_field :footer_image_width, - class: "form-control", - value: Settings::Mascot.footer_image_width %> -
- -
- <%= admin_config_label :footer_image_height, model: Settings::Mascot %> - <%= admin_config_description Constants::Settings::Mascot::DETAILS[:footer_image_height][:description] %> - <%= f.text_field :footer_image_height, - class: "form-control", - value: Settings::Mascot.footer_image_height %> -
- -
- <%= admin_config_label :image_description, model: Settings::Mascot %> - <%= admin_config_description Constants::Settings::Mascot::DETAILS[:image_description][:description] %> - <%= f.text_field :image_description, - class: "form-control", - value: Settings::Mascot.image_description %> -
- - <%= render "form_submission", f: f %> + <%= render "form_submission", f: f %>
diff --git a/app/views/admin/feedback_messages/_abuse_reports.html.erb b/app/views/admin/feedback_messages/_abuse_reports.html.erb index ce17b4532..b3eecf806 100644 --- a/app/views/admin/feedback_messages/_abuse_reports.html.erb +++ b/app/views/admin/feedback_messages/_abuse_reports.html.erb @@ -31,7 +31,7 @@ data-reaction-url-value="<%= admin_reaction_path(reaction.id) %>"> 🤢 @<%= reaction.user.username %> - <% if reaction.user_id == Settings::Mascot.mascot_user_id %> + <% if reaction.user_id == SiteConfig.mascot_user_id %> (auto-generated) <% end %> diff --git a/app/views/comments/_comment_avatar.html.erb b/app/views/comments/_comment_avatar.html.erb index 289838706..bd9e77d2e 100644 --- a/app/views/comments/_comment_avatar.html.erb +++ b/app/views/comments/_comment_avatar.html.erb @@ -1,6 +1,6 @@ <% if comment.deleted %> - <%= image_tag(Images::Optimizer.call(Settings::Mascot.image_url, width: 32, height: 32, crop: "imagga_scale"), class: "crayons-avatar__image overflow-hidden", alt: "Sloan, the sloth mascot", loading: "lazy") %> + <%= image_tag(Images::Optimizer.call(SiteConfig.mascot_image_url, width: 32, height: 32, crop: "imagga_scale"), class: "crayons-avatar__image overflow-hidden", alt: "Sloan, the sloth mascot", loading: "lazy") %> <% else %> diff --git a/app/views/comments/deleted_commentable_comment.html.erb b/app/views/comments/deleted_commentable_comment.html.erb index 533f3590d..795a9b2a1 100644 --- a/app/views/comments/deleted_commentable_comment.html.erb +++ b/app/views/comments/deleted_commentable_comment.html.erb @@ -14,7 +14,7 @@ <% if decorated_comment.low_quality %>
- <%= image_tag(Images::Optimizer.call(Settings::Mascot.image_url, width: 50, height: 50, crop: "imagga_scale"), class: "sloan", alt: "Sloan, the sloth mascot", loading: "lazy") %> + <%= image_tag(Images::Optimizer.call(SiteConfig.mascot_image_url, width: 50, height: 50, crop: "imagga_scale"), class: "sloan", alt: "Sloan, the sloth mascot", loading: "lazy") %> Comment marked as low quality/non-constructive by the community. View Code of Conduct
<% end %> diff --git a/app/views/dashboards/show.html.erb b/app/views/dashboards/show.html.erb index da3a539d9..86a642de2 100644 --- a/app/views/dashboards/show.html.erb +++ b/app/views/dashboards/show.html.erb @@ -55,9 +55,9 @@ <% else %>
- <% if Settings::Mascot.image_url.present? %> - <% image_url = Images::Optimizer.call(Settings::Mascot.image_url, width: 300, crop: "imagga_scale") %> - <%= image_tag(image_url, class: "sloan mb-7", alt: Settings::Mascot.image_description.to_s) %> + <% if SiteConfig.mascot_image_url.present? %> + <% image_url = Images::Optimizer.call(SiteConfig.mascot_image_url, width: 300, crop: "imagga_scale") %> + <%= image_tag(image_url, class: "sloan mb-7", alt: "Mascot image") %> <% end %>

This is where you can manage your posts, but you haven't written anything yet.

Write your first post now

diff --git a/app/views/layouts/_footer.html.erb b/app/views/layouts/_footer.html.erb index a85191613..78ac82812 100644 --- a/app/views/layouts/_footer.html.erb +++ b/app/views/layouts/_footer.html.erb @@ -25,13 +25,5 @@
<%= inline_svg_tag("logo-forem.svg", aria: true, class: "crayons-icon crayons-icon--default", title: "Forem logo") %>
- <% if Settings::Mascot.footer_image_url.present? %> - <%= image_tag(Images::Optimizer.call(Settings::Mascot.footer_image_url, width: 100), - class: "crayons-footer__mascot", - alt: Settings::Mascot.image_description, - width: Settings::Mascot.footer_image_width, - height: Settings::Mascot.footer_image_height, - loading: "lazy") %> - <% end %>
diff --git a/config/routes/admin.rb b/config/routes/admin.rb index 7d2549595..6c16a6bc4 100644 --- a/config/routes/admin.rb +++ b/config/routes/admin.rb @@ -19,7 +19,6 @@ namespace :admin do resources :campaigns, only: [:create] resources :communities, only: [:create] resources :mandatory_settings, only: [:create] - resources :mascots, only: [:create] resources :rate_limits, only: [:create] resources :user_experiences, only: [:create] end diff --git a/cypress/integration/adminFlows/config/mascotSection.js b/cypress/integration/adminFlows/config/mascotSection.js index 214fd2f6a..301c37a0d 100644 --- a/cypress/integration/adminFlows/config/mascotSection.js +++ b/cypress/integration/adminFlows/config/mascotSection.js @@ -16,9 +16,9 @@ describe('Mascot Section', () => { cy.get('@mascotSectionForm').findByText('Mascot').click(); cy.get('@mascotSectionForm') - .get('#settings_mascot_image_url') + .findByLabelText('Mascot Image URL') .clear() - .type('example.com/image.png'); + .type('notanimage'); cy.get('@mascotSectionForm') .findByPlaceholderText('Confirmation text') @@ -33,7 +33,7 @@ describe('Mascot Section', () => { cy.url().should('contains', '/admin/customization/config'); cy.findByText( - '😭 Validation failed: Image url is not a valid URL', + '😭 Validation failed: Mascot image url is not a valid URL', ).should('be.visible'); }); }); @@ -45,7 +45,7 @@ describe('Mascot Section', () => { cy.get('@mascotSectionForm').findByText('Mascot').click(); cy.get('@mascotSectionForm') - .get('#settings_mascot_image_url') + .findByLabelText('Mascot Image URL') .clear() .type('https://example.com/image.png'); @@ -66,8 +66,8 @@ describe('Mascot Section', () => { ); // Page reloaded so need to get a new reference to the form. - cy.get('#new_settings_mascot').as('mascotSectionForm'); - cy.get('#settings_mascot_image_url').should( + cy.findByTestId('mascotSectionForm').as('mascotSectionForm'); + cy.findByLabelText('Mascot Image URL').should( 'have.value', 'https://example.com/image.png', ); diff --git a/lib/data_update_scripts/20210420050256_move_mascot_settings.rb b/lib/data_update_scripts/20210420050256_move_mascot_settings.rb deleted file mode 100644 index 2a914324e..000000000 --- a/lib/data_update_scripts/20210420050256_move_mascot_settings.rb +++ /dev/null @@ -1,20 +0,0 @@ -module DataUpdateScripts - class MoveMascotSettings - SETTINGS = %w[ - footer_image_height - footer_image_url - footer_image_width - image_description - image_url - ].freeze - - def run - SETTINGS.each do |setting| - if (value = SiteConfig.public_send("mascot_#{setting}")) - Settings::Mascot.public_send("#{setting}=", value) - end - end - Settings::Mascot.mascot_user_id = SiteConfig.mascot_user_id - end - end -end diff --git a/lib/data_update_scripts/20210504060704_move_mascot_settings_backto_site_config.rb b/lib/data_update_scripts/20210504060704_move_mascot_settings_backto_site_config.rb new file mode 100644 index 000000000..49ca52dd9 --- /dev/null +++ b/lib/data_update_scripts/20210504060704_move_mascot_settings_backto_site_config.rb @@ -0,0 +1,17 @@ +module DataUpdateScripts + class MoveMascotSettingsBacktoSiteConfig + def run + return unless Database.table_available?("settings_mascots") + + # Remove obsolete data update script + DataUpdateScript.delete_by(file_name: "20210420050256_move_mascot_settings") + + # Migrate back explicitly set values + mascot_image_url = Settings::Mascot.image_url + SiteConfig.mascot_image_url = mascot_image_url if mascot_image_url + + mascot_user_id = Settings::Mascot.mascot_user_id + SiteConfig.mascot_user_id = mascot_user_id if mascot_user_id + end + end +end diff --git a/spec/lib/data_update_scripts/move_mascot_settings_spec.rb b/spec/lib/data_update_scripts/move_mascot_settings_spec.rb deleted file mode 100644 index 5b12ceaf4..000000000 --- a/spec/lib/data_update_scripts/move_mascot_settings_spec.rb +++ /dev/null @@ -1,28 +0,0 @@ -require "rails_helper" -require Rails.root.join( - "lib/data_update_scripts/20210420050256_move_mascot_settings.rb", -) - -describe DataUpdateScripts::MoveMascotSettings do - before do - allow(SiteConfig).to receive(:mascot_footer_image_url) - .and_return("https://example.com/mascot.png") - end - - it "moves renamed settings" do - allow(SiteConfig).to receive(:mascot_image_description).and_return("Bla") - - expect do - described_class.new.run - end - .to change(Settings::Mascot, :image_description) - .and change(Settings::Mascot, :footer_image_url) - end - - it "moves the non-renamed./spec/lib/data_update_scripts/move_mascot_settings_spec.rb setting" do - allow(SiteConfig).to receive(:mascot_user_id).and_return(42) - expect do - described_class.new.run - end.to change(Settings::Mascot, :mascot_user_id).to(42) - end -end diff --git a/spec/models/article_spec.rb b/spec/models/article_spec.rb index d25568d0a..c39d58609 100644 --- a/spec/models/article_spec.rb +++ b/spec/models/article_spec.rb @@ -55,7 +55,7 @@ RSpec.describe Article, type: :model do describe "::admin_published_with" do it "includes mascot-published articles" do - allow(Settings::Mascot).to receive(:mascot_user_id).and_return(3) + allow(SiteConfig).to receive(:mascot_user_id).and_return(3) user = create(:user, id: 3) create(:article, user: user, tags: "challenge") expect(described_class.admin_published_with("challenge").count).to eq(1) @@ -989,7 +989,7 @@ RSpec.describe Article, type: :model do describe "spam" do before do - allow(Settings::Mascot).to receive(:mascot_user_id).and_return(user.id) + allow(SiteConfig).to receive(:mascot_user_id).and_return(user.id) allow(SiteConfig).to receive(:spam_trigger_terms).and_return( ["yahoomagoo gogo", "testtestetest", "magoo.+magee"], ) diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb index de6a1c385..4baa70d72 100644 --- a/spec/models/comment_spec.rb +++ b/spec/models/comment_spec.rb @@ -414,7 +414,7 @@ RSpec.describe Comment, type: :model do describe "spam" do before do - allow(Settings::Mascot).to receive(:mascot_user_id).and_return(user.id) + allow(SiteConfig).to receive(:mascot_user_id).and_return(user.id) allow(SiteConfig).to receive(:spam_trigger_terms).and_return(["yahoomagoo gogo", "anothertestterm"]) end diff --git a/spec/models/reaction_spec.rb b/spec/models/reaction_spec.rb index d5dfe6a9a..96216f1fe 100644 --- a/spec/models/reaction_spec.rb +++ b/spec/models/reaction_spec.rb @@ -44,13 +44,13 @@ RSpec.describe Reaction, type: :model do end it "does not allow vomit reaction for users without trusted role" do - allow(Settings::Mascot).to receive(:mascot_user_id).and_return(user.id + 1) + allow(SiteConfig).to receive(:mascot_user_id).and_return(user.id + 1) reaction.category = "vomit" expect(reaction).not_to be_valid end it "does not allow thumbsdown reaction for users without trusted role" do - allow(Settings::Mascot).to receive(:mascot_user_id).and_return(user.id + 1) + allow(SiteConfig).to receive(:mascot_user_id).and_return(user.id + 1) reaction.category = "thumbsdown" expect(reaction).not_to be_valid end diff --git a/spec/models/site_config_spec.rb b/spec/models/site_config_spec.rb index d4547b590..5e8439de7 100644 --- a/spec/models/site_config_spec.rb +++ b/spec/models/site_config_spec.rb @@ -5,7 +5,7 @@ RSpec.describe SiteConfig, type: :model do describe "validating URLs" do let(:url_fields) do %w[ - main_social_image logo_png mascot_image_url mascot_footer_image_url onboarding_background_image + main_social_image logo_png mascot_image_url onboarding_background_image ] end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index ddcf21998..eb179c696 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -815,7 +815,7 @@ RSpec.describe User, type: :model do end it "returns the user if the account exists" do - allow(Settings::Mascot).to receive(:mascot_user_id).and_return(user.id) + allow(SiteConfig).to receive(:mascot_user_id).and_return(user.id) expect(described_class.mascot_account).to eq(user) end diff --git a/spec/requests/admin/configs_spec.rb b/spec/requests/admin/configs_spec.rb index 55fad2477..42a21de6e 100644 --- a/spec/requests/admin/configs_spec.rb +++ b/spec/requests/admin/configs_spec.rb @@ -406,66 +406,22 @@ RSpec.describe "/admin/customization/config", type: :request do describe "Mascot" do it "updates the mascot_user_id" do expected_mascot_user_id = 2 - post admin_settings_mascots_path, params: { - settings_mascot: { mascot_user_id: expected_mascot_user_id }, + post admin_config_path, params: { + site_config: { mascot_user_id: expected_mascot_user_id }, confirmation: confirmation_message } - expect(Settings::Mascot.mascot_user_id).to eq(expected_mascot_user_id) + expect(SiteConfig.mascot_user_id).to eq(expected_mascot_user_id) end it "updates image_url" do - expected_default_image_url = Settings::Mascot.get_default(:image_url) + expected_default_image_url = SiteConfig.get_default(:mascot_image_url) expected_image_url = "https://dummyimage.com/300x300.png" expect do - post admin_settings_mascots_path, params: { - settings_mascot: { image_url: expected_image_url }, + post admin_config_path, params: { + site_config: { mascot_image_url: expected_image_url }, confirmation: confirmation_message } - end.to change(Settings::Mascot, :image_url).from(expected_default_image_url).to(expected_image_url) - end - - it "updates footer_image_url" do - expected_image_url = "https://dummyimage.com/300x300.png" - post admin_settings_mascots_path, params: { - settings_mascot: { footer_image_url: expected_image_url }, - confirmation: confirmation_message - } - expect(Settings::Mascot.footer_image_url).to eq(expected_image_url) - end - - it "updates the footer_image_width" do - expected_default_footer_image_width = Settings::Mascot.get_default(:footer_image_width) - expected_footer_image_width = 1002 - - expect(Settings::Mascot.footer_image_width).to eq(expected_default_footer_image_width) - - post admin_settings_mascots_path, params: { - settings_mascot: { footer_image_width: expected_footer_image_width }, - confirmation: confirmation_message - } - expect(Settings::Mascot.footer_image_width).to eq(expected_footer_image_width) - end - - it "updates the footer_image_height" do - expected_default_footer_image_height = Settings::Mascot.get_default(:footer_image_height) - expected_footer_image_height = 3002 - - expect(Settings::Mascot.footer_image_height).to eq(expected_default_footer_image_height) - - post admin_settings_mascots_path, params: { - settings_mascot: { footer_image_height: expected_footer_image_height }, - confirmation: confirmation_message - } - expect(Settings::Mascot.footer_image_height).to eq(expected_footer_image_height) - end - - it "updates image_description" do - description = "Hey hey #{rand(100)}" - post admin_settings_mascots_path, params: { - settings_mascot: { image_description: description }, - confirmation: confirmation_message - } - expect(Settings::Mascot.image_description).to eq(description) + end.to change(SiteConfig, :mascot_image_url).from(expected_default_image_url).to(expected_image_url) end end diff --git a/spec/requests/comments_create_spec.rb b/spec/requests/comments_create_spec.rb index d77db3ddd..e86527902 100644 --- a/spec/requests/comments_create_spec.rb +++ b/spec/requests/comments_create_spec.rb @@ -161,7 +161,7 @@ RSpec.describe "CommentsCreate", type: :request do end def reply_and_mention_comment_author_as_moderator(comment) - allow(Settings::Mascot).to receive(:mascot_user_id) + allow(SiteConfig).to receive(:mascot_user_id) .and_return(moderator_replier.id) sign_in moderator_replier diff --git a/spec/requests/registrations_spec.rb b/spec/requests/registrations_spec.rb index 40eda788a..c1e78907d 100644 --- a/spec/requests/registrations_spec.rb +++ b/spec/requests/registrations_spec.rb @@ -370,14 +370,14 @@ RSpec.describe "Registrations", type: :request do end it "creates mascot user" do - expect(Settings::Mascot.mascot_user_id).to be_nil + expect(SiteConfig.mascot_user_id).to be_nil post "/users", params: { user: { name: "test #{rand(10)}", username: "haha_#{rand(10)}", email: "yoooo#{rand(100)}@yo.co", password: "PaSSw0rd_yo000", password_confirmation: "PaSSw0rd_yo000" } } - expect(Settings::Mascot.mascot_user_id).to eq User.last.id + expect(SiteConfig.mascot_user_id).to eq User.last.id mascot_account = User.mascot_account expect(mascot_account.username).to eq Users::CreateMascotAccount::MASCOT_PARAMS[:username] diff --git a/spec/services/users/create_mascot_account_spec.rb b/spec/services/users/create_mascot_account_spec.rb index a0f7280b9..02621a532 100644 --- a/spec/services/users/create_mascot_account_spec.rb +++ b/spec/services/users/create_mascot_account_spec.rb @@ -6,7 +6,7 @@ RSpec.describe Users::CreateMascotAccount, type: :service do end context "when a mascot user doesn't exist" do - before { allow(Settings::Mascot).to receive(:mascot_user_id).and_return(nil) } + before { allow(SiteConfig).to receive(:mascot_user_id).and_return(nil) } it "creates a mascot account" do expect do @@ -21,7 +21,7 @@ RSpec.describe Users::CreateMascotAccount, type: :service do context "when a mascot user already exists" do before do - allow(Settings::Mascot).to receive(:mascot_user_id).and_return(2) + allow(SiteConfig).to receive(:mascot_user_id).and_return(2) allow(User).to receive(:create) end diff --git a/spec/views/dashboards/show.html.erb_spec.rb b/spec/views/dashboards/show.html.erb_spec.rb index cbb118d16..e5ed8eff6 100644 --- a/spec/views/dashboards/show.html.erb_spec.rb +++ b/spec/views/dashboards/show.html.erb_spec.rb @@ -7,7 +7,7 @@ RSpec.describe "dashboards/show.html.erb", type: :view do stub_template "dashboards/_actions.html.erb" => "stubbed content" allow(Images::Optimizer).to receive(:imgproxy_enabled?).and_return(true) - allow(Settings::Mascot).to receive(:image_url).and_return("https://i.imgur.com/fKYKgo4.png") + allow(SiteConfig).to receive(:mascot_image_url).and_return("https://i.imgur.com/fKYKgo4.png") end context "when using Imgproxy" do