diff --git a/.rubocop.yml b/.rubocop.yml index e5fde5a60..4a286c388 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -17,6 +17,7 @@ AllCops: - vendor/**/* DisplayStyleGuide: true ExtraDetails: true + NewCops: enable # opt-in to new cops by default TargetRubyVersion: 2.7 #################### Bundler ########################### diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index b17b02073..956538c3d 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,19 +6,13 @@ require: # This configuration was generated by # `rubocop --auto-gen-config` -# on 2020-08-24 06:18:00 UTC using RuboCop version 0.89.1. +# on 2020-09-07 10:28:36 UTC using RuboCop version 0.90.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 3 -Performance/OpenStruct: - Exclude: - - 'spec/models/github_repo_spec.rb' - - 'spec/requests/github_repos_spec.rb' - -# Offense count: 4 +# Offense count: 2 # Configuration parameters: Include. # Include: app/models/**/*.rb Rails/UniqueValidationWithoutIndex: diff --git a/app/controllers/api/v0/listings_controller.rb b/app/controllers/api/v0/listings_controller.rb index 2ab1e3af0..72fe49e24 100644 --- a/app/controllers/api/v0/listings_controller.rb +++ b/app/controllers/api/v0/listings_controller.rb @@ -4,14 +4,15 @@ module Api include Pundit include ListingsToolkit + # actions `create` and `update` are defined in the module `ListingsToolkit`, + # we thus silence Rubocop lexical scope filter cop: https://rails.rubystyle.guide/#lexically-scoped-action-filter + # rubocop:disable Rails/LexicallyScopedActionFilter before_action :authenticate_with_api_key_or_current_user!, only: %i[create update] before_action :authenticate_with_api_key_or_current_user, only: %i[show] - - before_action :set_listing, only: %i[update] - before_action :set_cache_control_headers, only: %i[index show] - + before_action :set_listing, only: %i[update] skip_before_action :verify_authenticity_token, only: %i[create update] + # rubocop:enable Rails/LexicallyScopedActionFilter # Note: since this is used for selecting from the DB, we need to use the # actual column name for the listing category, prefixed with classified_. @@ -51,14 +52,6 @@ module Api set_surrogate_key_header @listing.record_key end - def create - super - end - - def update - super - end - private attr_accessor :user diff --git a/app/controllers/listings_controller.rb b/app/controllers/listings_controller.rb index 16dd4c6d0..27b9ec0ed 100644 --- a/app/controllers/listings_controller.rb +++ b/app/controllers/listings_controller.rb @@ -1,6 +1,5 @@ class ListingsController < ApplicationController include ListingsToolkit - before_action :check_limit, only: [:create] INDEX_JSON_OPTIONS = { only: %i[ @@ -22,11 +21,16 @@ class ListingsController < ApplicationController } }.freeze + # actions `create` and `update` are defined in the module `ListingsToolkit`, + # we thus silence Rubocop lexical scope filter cop: https://rails.rubystyle.guide/#lexically-scoped-action-filter + # rubocop:disable Rails/LexicallyScopedActionFilter + before_action :check_limit, only: [:create] before_action :set_listing, only: %i[edit update destroy] before_action :set_cache_control_headers, only: %i[index] before_action :raise_suspended, only: %i[new create update] before_action :authenticate_user!, only: %i[edit update new dashboard] after_action :verify_authorized, only: %i[edit update] + # rubocop:enable Rails/LexicallyScopedActionFilter def index published_listings = Listing.where(published: true) @@ -60,14 +64,6 @@ class ListingsController < ApplicationController @credits = current_user.credits.unspent end - def create - super - end - - def update - super - end - def edit authorize @listing @organizations = current_user.organizations diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index d1e81ea2d..842511056 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -173,7 +173,7 @@ module ApplicationHelper end def community_name - @community_name ||= SiteConfig.community_name # rubocop:disable Rails/HelperInstanceVariable + @community_name ||= SiteConfig.community_name end def community_qualified_name diff --git a/app/labor/markdown_parser.rb b/app/labor/markdown_parser.rb index c7adcc635..3fb28028d 100644 --- a/app/labor/markdown_parser.rb +++ b/app/labor/markdown_parser.rb @@ -8,6 +8,8 @@ class MarkdownParser WORDS_READ_PER_MINUTE = 275.0 + RAW_TAG_DELIMITERS = ["{", "}", "raw", "endraw", "----"].freeze + def initialize(content, source: nil, user: nil) @content = content @source = source @@ -176,7 +178,7 @@ class MarkdownParser end def possibly_raw_tag_syntax?(array) - array.any? { |string| ["{", "}", "raw", "endraw", "----"].include?(string) } + (RAW_TAG_DELIMITERS & array).any? end def unescape_raw_tag_in_codeblocks(html) diff --git a/app/liquid_tags/katex_tag.rb b/app/liquid_tags/katex_tag.rb index f824d3c8d..0f20d1384 100644 --- a/app/liquid_tags/katex_tag.rb +++ b/app/liquid_tags/katex_tag.rb @@ -2,10 +2,6 @@ class KatexTag < Liquid::Block PARTIAL = "liquids/katex".freeze KATEX_EXISTED = "katex_existed".freeze - def initialize(_tag_name, markup, _parse_context) - super - end - def render(context) block = Nokogiri::HTML(super).at("body").text diff --git a/app/models/comment.rb b/app/models/comment.rb index 23f07f38d..343b872da 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -180,7 +180,7 @@ class Comment < ApplicationRecord doc = Nokogiri::HTML.fragment(processed_html) doc.css("a").each do |anchor| unless anchor.to_s.include?(" @params[filter_key] } } else { term: { filter_key => @params[filter_key] } } diff --git a/app/services/slack/messengers/feedback.rb b/app/services/slack/messengers/feedback.rb index ccae1be60..177809f38 100644 --- a/app/services/slack/messengers/feedback.rb +++ b/app/services/slack/messengers/feedback.rb @@ -16,7 +16,7 @@ module Slack email: s|%s> TEXT - def initialize(user: nil, type:, category:, reported_url:, message:) + def initialize(type:, category:, reported_url:, message:, user: nil) @user = user @type = type @category = category diff --git a/app/services/suggester/users/sidebar.rb b/app/services/suggester/users/sidebar.rb index 58d9ec692..5441e6673 100644 --- a/app/services/suggester/users/sidebar.rb +++ b/app/services/suggester/users/sidebar.rb @@ -26,7 +26,7 @@ module Suggester @active_authors_for_given_tags ||= Article.published.tagged_with([given_tag], any: true) .where("public_reactions_count >= ?", minimum_reaction_count) .where("published_at > ?", 4.months.ago) - .where("user_id != ?", user.id) + .where.not(user_id: user.id) .where.not(user_id: user.following_by_type("User")) .pluck(:user_id) end diff --git a/app/views/api/v0/podcast_episodes/show.json.jbuilder b/app/views/api/v0/podcast_episodes/show.json.jbuilder deleted file mode 100644 index e69de29bb..000000000 diff --git a/config/environments/development.rb b/config/environments/development.rb index dee506203..0d1d5e018 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -131,12 +131,10 @@ Rails.application.configure do Bullet.add_whitelist(type: :n_plus_one_query, class_name: "User", association: :profile) # Check if there are any data update scripts to run during startup - if %w[c console runner s server].include?(ENV["COMMAND"]) - if DataUpdateScript.scripts_to_run? - message = "Data update scripts need to be run before you can start the application. " \ - "Please run 'rails data_updates:run'" - raise message - end + if %w[c console runner s server].include?(ENV["COMMAND"]) && DataUpdateScript.scripts_to_run? + message = "Data update scripts need to be run before you can start the application. " \ + "Please run 'rails data_updates:run'" + raise message end end end diff --git a/lib/data_update_scripts/20200810083831_remove_orphaned_ahoy_rows.rb b/lib/data_update_scripts/20200810083831_remove_orphaned_ahoy_rows.rb index 7d428d77c..cbcb15e72 100644 --- a/lib/data_update_scripts/20200810083831_remove_orphaned_ahoy_rows.rb +++ b/lib/data_update_scripts/20200810083831_remove_orphaned_ahoy_rows.rb @@ -3,7 +3,7 @@ module DataUpdateScripts def run # Delete all Ahoy::Events belonging to users that don't exist anymore ActiveRecord::Base.connection.execute( - <<~SQL, + <<~SQL.squish, DELETE FROM ahoy_events WHERE user_id IS NOT NULL AND user_id NOT IN (SELECT id FROM users); @@ -12,7 +12,7 @@ module DataUpdateScripts # Delete all Ahoy::Messages belonging to users that don't exist anymore ActiveRecord::Base.connection.execute( - <<~SQL, + <<~SQL.squish, DELETE FROM ahoy_messages WHERE user_id IS NOT NULL AND user_id NOT IN (SELECT id FROM users); @@ -21,7 +21,7 @@ module DataUpdateScripts # Delete all Ahoy::Visits belonging to users that don't exist anymore ActiveRecord::Base.connection.execute( - <<~SQL, + <<~SQL.squish, DELETE FROM ahoy_visits WHERE user_id IS NOT NULL AND user_id NOT IN (SELECT id FROM users); diff --git a/lib/data_update_scripts/20200813072205_remove_orphaned_display_ad_events.rb b/lib/data_update_scripts/20200813072205_remove_orphaned_display_ad_events.rb index b2c10b793..e8cf0259e 100644 --- a/lib/data_update_scripts/20200813072205_remove_orphaned_display_ad_events.rb +++ b/lib/data_update_scripts/20200813072205_remove_orphaned_display_ad_events.rb @@ -3,7 +3,7 @@ module DataUpdateScripts def run # Delete all DisplayAdEvents belonging to DisplayAds that don't exist anymore ActiveRecord::Base.connection.execute( - <<~SQL, + <<~SQL.squish, DELETE FROM display_ad_events WHERE display_ad_id NOT IN (SELECT id FROM display_ads); SQL @@ -11,7 +11,7 @@ module DataUpdateScripts # Delete all DisplayAdEvents belonging to Users that don't exist anymore ActiveRecord::Base.connection.execute( - <<~SQL, + <<~SQL.squish, DELETE FROM display_ad_events WHERE user_id NOT IN (SELECT id FROM users); SQL diff --git a/lib/data_update_scripts/20200818103028_nullify_orphaned_by_article_html_variant_trials.rb b/lib/data_update_scripts/20200818103028_nullify_orphaned_by_article_html_variant_trials.rb index ce4a2f0f0..b17a41724 100644 --- a/lib/data_update_scripts/20200818103028_nullify_orphaned_by_article_html_variant_trials.rb +++ b/lib/data_update_scripts/20200818103028_nullify_orphaned_by_article_html_variant_trials.rb @@ -3,7 +3,7 @@ module DataUpdateScripts def run # Nullify article_id for all HtmlVariantTrials linked to a non existing article ActiveRecord::Base.connection.execute( - <<~SQL, + <<~SQL.squish, UPDATE html_variant_trials SET article_id = NULL WHERE article_id IS NOT NULL AND article_id NOT IN (SELECT id FROM articles); diff --git a/lib/data_update_scripts/20200818170410_remove_orphaned_poll_votes.rb b/lib/data_update_scripts/20200818170410_remove_orphaned_poll_votes.rb index 3f7ebc58a..40deda9d9 100644 --- a/lib/data_update_scripts/20200818170410_remove_orphaned_poll_votes.rb +++ b/lib/data_update_scripts/20200818170410_remove_orphaned_poll_votes.rb @@ -3,7 +3,7 @@ module DataUpdateScripts def run # Delete all PollVotes belonging to Polls that don't exist anymore ActiveRecord::Base.connection.execute( - <<~SQL, + <<~SQL.squish, DELETE FROM poll_votes WHERE poll_id NOT IN (SELECT id FROM polls); SQL @@ -11,7 +11,7 @@ module DataUpdateScripts # Delete all PollVotes belonging to PollOptions that don't exist anymore ActiveRecord::Base.connection.execute( - <<~SQL, + <<~SQL.squish, DELETE FROM poll_votes WHERE poll_option_id NOT IN (SELECT id FROM poll_options); SQL @@ -19,7 +19,7 @@ module DataUpdateScripts # Delete all PollVotes belonging to Users that don't exist anymore ActiveRecord::Base.connection.execute( - <<~SQL, + <<~SQL.squish, DELETE FROM poll_votes WHERE user_id NOT IN (SELECT id FROM users); SQL diff --git a/lib/data_update_scripts/20200818170433_remove_orphaned_poll_skips.rb b/lib/data_update_scripts/20200818170433_remove_orphaned_poll_skips.rb index 1f9975b45..ecf226da3 100644 --- a/lib/data_update_scripts/20200818170433_remove_orphaned_poll_skips.rb +++ b/lib/data_update_scripts/20200818170433_remove_orphaned_poll_skips.rb @@ -3,7 +3,7 @@ module DataUpdateScripts def run # Delete all PollSkips belonging to Polls that don't exist anymore ActiveRecord::Base.connection.execute( - <<~SQL, + <<~SQL.squish, DELETE FROM poll_skips WHERE poll_id NOT IN (SELECT id FROM polls); SQL @@ -11,7 +11,7 @@ module DataUpdateScripts # Delete all PollSkips belonging to Users that don't exist anymore ActiveRecord::Base.connection.execute( - <<~SQL, + <<~SQL.squish, DELETE FROM poll_skips WHERE user_id NOT IN (SELECT id FROM users); SQL diff --git a/lib/data_update_scripts/20200818170505_remove_orphaned_poll_options.rb b/lib/data_update_scripts/20200818170505_remove_orphaned_poll_options.rb index d8ab7698b..82fc1e164 100644 --- a/lib/data_update_scripts/20200818170505_remove_orphaned_poll_options.rb +++ b/lib/data_update_scripts/20200818170505_remove_orphaned_poll_options.rb @@ -3,7 +3,7 @@ module DataUpdateScripts def run # Delete all PollOptions belonging to Polls that don't exist anymore ActiveRecord::Base.connection.execute( - <<~SQL, + <<~SQL.squish, DELETE FROM poll_options WHERE poll_id NOT IN (SELECT id FROM polls); SQL @@ -11,7 +11,7 @@ module DataUpdateScripts # Delete all PollOptions belonging to Polls that don't exist anymore ActiveRecord::Base.connection.execute( - <<~SQL, + <<~SQL.squish, DELETE FROM poll_options WHERE poll_id NOT IN (SELECT id FROM polls); SQL diff --git a/lib/data_update_scripts/20200818170523_remove_orphaned_polls.rb b/lib/data_update_scripts/20200818170523_remove_orphaned_polls.rb index c024fc1fe..a3b70232b 100644 --- a/lib/data_update_scripts/20200818170523_remove_orphaned_polls.rb +++ b/lib/data_update_scripts/20200818170523_remove_orphaned_polls.rb @@ -3,7 +3,7 @@ module DataUpdateScripts def run # Delete all Polls belonging to Articles that don't exist anymore ActiveRecord::Base.connection.execute( - <<~SQL, + <<~SQL.squish, DELETE FROM polls WHERE article_id NOT IN (SELECT id FROM articles); SQL diff --git a/lib/data_update_scripts/20200821103125_nullify_orphaned_articles_by_organization.rb b/lib/data_update_scripts/20200821103125_nullify_orphaned_articles_by_organization.rb index de2e59279..44108bda4 100644 --- a/lib/data_update_scripts/20200821103125_nullify_orphaned_articles_by_organization.rb +++ b/lib/data_update_scripts/20200821103125_nullify_orphaned_articles_by_organization.rb @@ -3,7 +3,7 @@ module DataUpdateScripts def run # Nullify organization_id for all Articles linked to a non existing Organization ActiveRecord::Base.connection.execute( - <<~SQL, + <<~SQL.squish, UPDATE articles SET organization_id = NULL WHERE organization_id IS NOT NULL diff --git a/lib/data_update_scripts/20200821103305_nullify_orphaned_collections_by_organization.rb b/lib/data_update_scripts/20200821103305_nullify_orphaned_collections_by_organization.rb index 3080cb066..ddd3da6a9 100644 --- a/lib/data_update_scripts/20200821103305_nullify_orphaned_collections_by_organization.rb +++ b/lib/data_update_scripts/20200821103305_nullify_orphaned_collections_by_organization.rb @@ -3,7 +3,7 @@ module DataUpdateScripts def run # Nullify organization_id for all Collections linked to a non existing Organization ActiveRecord::Base.connection.execute( - <<~SQL, + <<~SQL.squish, UPDATE collections SET organization_id = NULL WHERE organization_id IS NOT NULL diff --git a/lib/data_update_scripts/20200821103405_remove_orphaned_credits_by_organization.rb b/lib/data_update_scripts/20200821103405_remove_orphaned_credits_by_organization.rb index 8b25352b6..bb9380684 100644 --- a/lib/data_update_scripts/20200821103405_remove_orphaned_credits_by_organization.rb +++ b/lib/data_update_scripts/20200821103405_remove_orphaned_credits_by_organization.rb @@ -3,7 +3,7 @@ module DataUpdateScripts def run # Apparently we have a bunch of Credits that don't belong to either user or org ActiveRecord::Base.connection.execute( - <<~SQL, + <<~SQL.squish, DELETE FROM credits WHERE user_id IS NULL AND organization_id IS NULL @@ -12,7 +12,7 @@ module DataUpdateScripts # Delete all User less Credits belonging to Organizations that don't exist anymore ActiveRecord::Base.connection.execute( - <<~SQL, + <<~SQL.squish, DELETE FROM credits WHERE user_id IS NULL AND organization_id NOT IN (SELECT id FROM organizations); diff --git a/lib/data_update_scripts/20200821103718_remove_orphaned_display_ads_by_organization.rb b/lib/data_update_scripts/20200821103718_remove_orphaned_display_ads_by_organization.rb index a9732e97b..6fa8d990c 100644 --- a/lib/data_update_scripts/20200821103718_remove_orphaned_display_ads_by_organization.rb +++ b/lib/data_update_scripts/20200821103718_remove_orphaned_display_ads_by_organization.rb @@ -3,7 +3,7 @@ module DataUpdateScripts def run # Delete all DisplayAds belonging to Organizations that don't exist anymore ActiveRecord::Base.connection.execute( - <<~SQL, + <<~SQL.squish, DELETE FROM display_ads WHERE organization_id NOT IN (SELECT id FROM organizations); SQL diff --git a/lib/data_update_scripts/20200821103834_remove_orphaned_listings_by_organization.rb b/lib/data_update_scripts/20200821103834_remove_orphaned_listings_by_organization.rb index 5e980cb12..05bc2eb8e 100644 --- a/lib/data_update_scripts/20200821103834_remove_orphaned_listings_by_organization.rb +++ b/lib/data_update_scripts/20200821103834_remove_orphaned_listings_by_organization.rb @@ -3,7 +3,7 @@ module DataUpdateScripts def run # Delete all Listings belonging to Organizations that don't exist anymore ActiveRecord::Base.connection.execute( - <<~SQL, + <<~SQL.squish, DELETE FROM classified_listings WHERE organization_id IS NOT NULL AND organization_id NOT IN (SELECT id FROM organizations); diff --git a/lib/data_update_scripts/20200822082229_remove_orphaned_notifications_by_organization.rb b/lib/data_update_scripts/20200822082229_remove_orphaned_notifications_by_organization.rb index 89c81ea29..b2910f41c 100644 --- a/lib/data_update_scripts/20200822082229_remove_orphaned_notifications_by_organization.rb +++ b/lib/data_update_scripts/20200822082229_remove_orphaned_notifications_by_organization.rb @@ -3,7 +3,7 @@ module DataUpdateScripts def run # Delete all Notifications belonging to Organizations that don't exist anymore ActiveRecord::Base.connection.execute( - <<~SQL, + <<~SQL.squish, DELETE FROM notifications WHERE organization_id NOT IN (SELECT id FROM organizations); SQL diff --git a/lib/data_update_scripts/20200822083050_remove_orphaned_sponsorships_by_organization.rb b/lib/data_update_scripts/20200822083050_remove_orphaned_sponsorships_by_organization.rb index e9f173316..cf8a117fd 100644 --- a/lib/data_update_scripts/20200822083050_remove_orphaned_sponsorships_by_organization.rb +++ b/lib/data_update_scripts/20200822083050_remove_orphaned_sponsorships_by_organization.rb @@ -3,7 +3,7 @@ module DataUpdateScripts def run # Delete all Sponsorships belonging to Organizations that don't exist anymore ActiveRecord::Base.connection.execute( - <<~SQL, + <<~SQL.squish, DELETE FROM sponsorships WHERE organization_id NOT IN (SELECT id FROM organizations); SQL diff --git a/lib/data_update_scripts/20200825095213_remove_orphaned_buffer_updates_by_article.rb b/lib/data_update_scripts/20200825095213_remove_orphaned_buffer_updates_by_article.rb index 32d5e6570..3f21ace03 100644 --- a/lib/data_update_scripts/20200825095213_remove_orphaned_buffer_updates_by_article.rb +++ b/lib/data_update_scripts/20200825095213_remove_orphaned_buffer_updates_by_article.rb @@ -3,7 +3,7 @@ module DataUpdateScripts def run # Delete all BufferUpdates belonging to Articles that don't exist anymore ActiveRecord::Base.connection.execute( - <<~SQL, + <<~SQL.squish, DELETE FROM buffer_updates WHERE article_id NOT IN (SELECT id FROM articles); SQL diff --git a/lib/data_update_scripts/20200825095512_nullify_orphaned_comments_by_article.rb b/lib/data_update_scripts/20200825095512_nullify_orphaned_comments_by_article.rb index 424389d69..c13b598f6 100644 --- a/lib/data_update_scripts/20200825095512_nullify_orphaned_comments_by_article.rb +++ b/lib/data_update_scripts/20200825095512_nullify_orphaned_comments_by_article.rb @@ -3,7 +3,7 @@ module DataUpdateScripts def run # Nullify article_id for all Comments linked to a non existing Article ActiveRecord::Base.connection.execute( - <<~SQL, + <<~SQL.squish, UPDATE comments SET commentable_id = NULL, commentable_type = NULL WHERE commentable_type = 'Article' diff --git a/lib/data_update_scripts/20200825102635_remove_orphaned_notification_subscriptions_by_article.rb b/lib/data_update_scripts/20200825102635_remove_orphaned_notification_subscriptions_by_article.rb index 818b399a7..f0a4c3608 100644 --- a/lib/data_update_scripts/20200825102635_remove_orphaned_notification_subscriptions_by_article.rb +++ b/lib/data_update_scripts/20200825102635_remove_orphaned_notification_subscriptions_by_article.rb @@ -3,7 +3,7 @@ module DataUpdateScripts def run # Delete all NotificationSubscriptions belonging to Articles that don't exist anymore ActiveRecord::Base.connection.execute( - <<~SQL, + <<~SQL.squish, DELETE FROM notification_subscriptions WHERE notifiable_type = 'Article' AND notifiable_id NOT IN (SELECT id FROM articles); diff --git a/lib/data_update_scripts/20200825102956_remove_orphaned_notifications_by_article.rb b/lib/data_update_scripts/20200825102956_remove_orphaned_notifications_by_article.rb index 02a8cdf7e..ac8eed51e 100644 --- a/lib/data_update_scripts/20200825102956_remove_orphaned_notifications_by_article.rb +++ b/lib/data_update_scripts/20200825102956_remove_orphaned_notifications_by_article.rb @@ -3,7 +3,7 @@ module DataUpdateScripts def run # Delete all Notifications related to Articles that don't exist anymore ActiveRecord::Base.connection.execute( - <<~SQL, + <<~SQL.squish, DELETE FROM notifications WHERE notifiable_type = 'Article' AND notifiable_id NOT IN (SELECT id FROM articles); diff --git a/lib/data_update_scripts/20200825103119_remove_orphaned_profile_pins_by_article.rb b/lib/data_update_scripts/20200825103119_remove_orphaned_profile_pins_by_article.rb index c1b9200c0..905160265 100644 --- a/lib/data_update_scripts/20200825103119_remove_orphaned_profile_pins_by_article.rb +++ b/lib/data_update_scripts/20200825103119_remove_orphaned_profile_pins_by_article.rb @@ -3,7 +3,7 @@ module DataUpdateScripts def run # Delete all ProfilePins belonging to Articles that don't exist anymore ActiveRecord::Base.connection.execute( - <<~SQL, + <<~SQL.squish, DELETE FROM profile_pins WHERE pinnable_type = 'Article' AND pinnable_id NOT IN (SELECT id FROM articles); diff --git a/lib/data_update_scripts/20200825103244_remove_orphaned_rating_votes_by_article.rb b/lib/data_update_scripts/20200825103244_remove_orphaned_rating_votes_by_article.rb index 60dbf0aa4..8095f41ba 100644 --- a/lib/data_update_scripts/20200825103244_remove_orphaned_rating_votes_by_article.rb +++ b/lib/data_update_scripts/20200825103244_remove_orphaned_rating_votes_by_article.rb @@ -3,7 +3,7 @@ module DataUpdateScripts def run # Delete all RatingVotes belonging to Articles that don't exist anymore ActiveRecord::Base.connection.execute( - <<~SQL, + <<~SQL.squish, DELETE FROM rating_votes WHERE article_id NOT IN (SELECT id FROM articles); SQL diff --git a/lib/data_update_scripts/20200826092816_remove_orphaned_notes_by_user.rb b/lib/data_update_scripts/20200826092816_remove_orphaned_notes_by_user.rb index 75c00fd9a..c92d4244d 100644 --- a/lib/data_update_scripts/20200826092816_remove_orphaned_notes_by_user.rb +++ b/lib/data_update_scripts/20200826092816_remove_orphaned_notes_by_user.rb @@ -3,7 +3,7 @@ module DataUpdateScripts def run # Delete all Notes about users that don't exist anymore ActiveRecord::Base.connection.execute( - <<~SQL, + <<~SQL.squish, DELETE FROM notes WHERE noteable_type = 'User' AND noteable_id NOT IN (SELECT id FROM users); diff --git a/lib/data_update_scripts/20200826133748_nullify_orphaned_tweets_by_user.rb b/lib/data_update_scripts/20200826133748_nullify_orphaned_tweets_by_user.rb index 9a456353c..c56b8e5f1 100644 --- a/lib/data_update_scripts/20200826133748_nullify_orphaned_tweets_by_user.rb +++ b/lib/data_update_scripts/20200826133748_nullify_orphaned_tweets_by_user.rb @@ -3,7 +3,7 @@ module DataUpdateScripts def run # Nullify user_id for all Tweets linked to a non existing User ActiveRecord::Base.connection.execute( - <<~SQL, + <<~SQL.squish, UPDATE tweets SET user_id = NULL WHERE user_id IS NOT NULL diff --git a/lib/data_update_scripts/20200826140317_remove_orphaned_articles_by_user.rb b/lib/data_update_scripts/20200826140317_remove_orphaned_articles_by_user.rb index f136b6420..818473651 100644 --- a/lib/data_update_scripts/20200826140317_remove_orphaned_articles_by_user.rb +++ b/lib/data_update_scripts/20200826140317_remove_orphaned_articles_by_user.rb @@ -3,7 +3,7 @@ module DataUpdateScripts def run # Delete all Articles belonging to Users that don't exist anymore ActiveRecord::Base.connection.execute( - <<~SQL, + <<~SQL.squish, DELETE FROM articles WHERE user_id NOT IN (SELECT id FROM users); SQL diff --git a/lib/data_update_scripts/20200826140754_remove_orphaned_collections_by_user.rb b/lib/data_update_scripts/20200826140754_remove_orphaned_collections_by_user.rb index 2c56d4215..b4e1e9f35 100644 --- a/lib/data_update_scripts/20200826140754_remove_orphaned_collections_by_user.rb +++ b/lib/data_update_scripts/20200826140754_remove_orphaned_collections_by_user.rb @@ -3,7 +3,7 @@ module DataUpdateScripts def run # Delete all Collections belonging to Users that don't exist anymore ActiveRecord::Base.connection.execute( - <<~SQL, + <<~SQL.squish, DELETE FROM collections WHERE user_id NOT IN (SELECT id FROM users); SQL diff --git a/lib/data_update_scripts/20200826140924_remove_orphaned_credits_by_user.rb b/lib/data_update_scripts/20200826140924_remove_orphaned_credits_by_user.rb index b8090fdff..f2b7bc664 100644 --- a/lib/data_update_scripts/20200826140924_remove_orphaned_credits_by_user.rb +++ b/lib/data_update_scripts/20200826140924_remove_orphaned_credits_by_user.rb @@ -3,7 +3,7 @@ module DataUpdateScripts def run # Delete all Credits belonging to Users that don't exist anymore ActiveRecord::Base.connection.execute( - <<~SQL, + <<~SQL.squish, DELETE FROM credits WHERE user_id IS NOT NULL AND user_id NOT IN (SELECT id FROM users); diff --git a/lib/data_update_scripts/20200826141015_remove_orphaned_github_repos_by_user.rb b/lib/data_update_scripts/20200826141015_remove_orphaned_github_repos_by_user.rb index 66b899500..f93fa7cad 100644 --- a/lib/data_update_scripts/20200826141015_remove_orphaned_github_repos_by_user.rb +++ b/lib/data_update_scripts/20200826141015_remove_orphaned_github_repos_by_user.rb @@ -3,7 +3,7 @@ module DataUpdateScripts def run # Delete all Collections belonging to Users that don't exist anymore ActiveRecord::Base.connection.execute( - <<~SQL, + <<~SQL.squish, DELETE FROM github_repos WHERE user_id NOT IN (SELECT id FROM users); SQL diff --git a/lib/data_update_scripts/20200826141105_remove_orphaned_mentions_by_user.rb b/lib/data_update_scripts/20200826141105_remove_orphaned_mentions_by_user.rb index 0b2cde85e..9740fcb72 100644 --- a/lib/data_update_scripts/20200826141105_remove_orphaned_mentions_by_user.rb +++ b/lib/data_update_scripts/20200826141105_remove_orphaned_mentions_by_user.rb @@ -3,7 +3,7 @@ module DataUpdateScripts def run # Delete all Mentions belonging to Users that don't exist anymore ActiveRecord::Base.connection.execute( - <<~SQL, + <<~SQL.squish, DELETE FROM mentions WHERE user_id NOT IN (SELECT id FROM users); SQL diff --git a/lib/data_update_scripts/20200826141145_remove_orphaned_organization_memberships_by_user.rb b/lib/data_update_scripts/20200826141145_remove_orphaned_organization_memberships_by_user.rb index a4848d3fd..c9a31b0ab 100644 --- a/lib/data_update_scripts/20200826141145_remove_orphaned_organization_memberships_by_user.rb +++ b/lib/data_update_scripts/20200826141145_remove_orphaned_organization_memberships_by_user.rb @@ -3,7 +3,7 @@ module DataUpdateScripts def run # Delete all OrganizationMemberships belonging to Users that don't exist anymore ActiveRecord::Base.connection.execute( - <<~SQL, + <<~SQL.squish, DELETE FROM organization_memberships WHERE user_id NOT IN (SELECT id FROM users); SQL diff --git a/lib/data_update_scripts/20200826141447_nullify_orphaned_page_views_by_user.rb b/lib/data_update_scripts/20200826141447_nullify_orphaned_page_views_by_user.rb index 2479c4869..8d2bb182f 100644 --- a/lib/data_update_scripts/20200826141447_nullify_orphaned_page_views_by_user.rb +++ b/lib/data_update_scripts/20200826141447_nullify_orphaned_page_views_by_user.rb @@ -3,7 +3,7 @@ module DataUpdateScripts def run # Nullify all PageViews belonging to Users that don't exist anymore ActiveRecord::Base.connection.execute( - <<~SQL, + <<~SQL.squish, UPDATE page_views SET user_id = NULL WHERE user_id IS NOT NULL diff --git a/lib/data_update_scripts/20200826141550_nullify_orphaned_rating_votes_by_user.rb b/lib/data_update_scripts/20200826141550_nullify_orphaned_rating_votes_by_user.rb index 6294c3c58..7bb0c233c 100644 --- a/lib/data_update_scripts/20200826141550_nullify_orphaned_rating_votes_by_user.rb +++ b/lib/data_update_scripts/20200826141550_nullify_orphaned_rating_votes_by_user.rb @@ -3,7 +3,7 @@ module DataUpdateScripts def run # Nullify all RatingVotes belonging to Users that don't exist anymore ActiveRecord::Base.connection.execute( - <<~SQL, + <<~SQL.squish, UPDATE rating_votes SET user_id = NULL WHERE user_id IS NOT NULL diff --git a/lib/data_update_scripts/20200826141652_remove_orphaned_reactions_by_user.rb b/lib/data_update_scripts/20200826141652_remove_orphaned_reactions_by_user.rb index ea7435865..829b0bbd2 100644 --- a/lib/data_update_scripts/20200826141652_remove_orphaned_reactions_by_user.rb +++ b/lib/data_update_scripts/20200826141652_remove_orphaned_reactions_by_user.rb @@ -3,7 +3,7 @@ module DataUpdateScripts def run # Delete all Reactions belonging to Users that don't exist anymore ActiveRecord::Base.connection.execute( - <<~SQL, + <<~SQL.squish, DELETE FROM reactions WHERE user_id NOT IN (SELECT id FROM users); SQL diff --git a/lib/data_update_scripts/20200901085230_remove_draft_articles_with_duplicate_canonical_url.rb b/lib/data_update_scripts/20200901085230_remove_draft_articles_with_duplicate_canonical_url.rb index 7e1d6e3cd..358a8f97a 100644 --- a/lib/data_update_scripts/20200901085230_remove_draft_articles_with_duplicate_canonical_url.rb +++ b/lib/data_update_scripts/20200901085230_remove_draft_articles_with_duplicate_canonical_url.rb @@ -6,7 +6,7 @@ module DataUpdateScripts # This statement deletes all draft articles in excess found to be duplicate over canonical_url, # excluding those whose body_markdown is different from the other duplicate occurrences result = ActiveRecord::Base.connection.execute( - <<~SQL, + <<~SQL.squish, WITH duplicates_draft_articles AS (SELECT id FROM @@ -42,7 +42,7 @@ module DataUpdateScripts # with different bodies. # We thus select the oldest for removal preserving the most recent one result = ActiveRecord::Base.connection.execute( - <<~SQL, + <<~SQL.squish, WITH duplicates_draft_articles AS (SELECT id FROM diff --git a/spec/black_box/black_box_spec.rb b/spec/black_box/black_box_spec.rb index 137de39ac..51bbe9323 100644 --- a/spec/black_box/black_box_spec.rb +++ b/spec/black_box/black_box_spec.rb @@ -2,8 +2,6 @@ require "rails_helper" RSpec.describe BlackBox, type: :black_box do describe "#article_hotness_score" do - let!(:article) { build_stubbed(:article, published_at: Time.current) } - it "returns higher value for higher score" do article = build_stubbed(:article, score: 99, published_at: Time.current) lower_article = build_stubbed(:article, score: 70, published_at: Time.current) diff --git a/spec/labor/mailchimp_bot_spec.rb b/spec/labor/mailchimp_bot_spec.rb index 8f8d32c92..d36db9d81 100644 --- a/spec/labor/mailchimp_bot_spec.rb +++ b/spec/labor/mailchimp_bot_spec.rb @@ -1,6 +1,8 @@ require "rails_helper" +# [@forem/oss]: this should be probably refactored using a class_double but for now we silence Rubocop's complaint class FakeGibbonRequest < Gibbon::Request + # rubocop:disable Lint/UselessMethodDefinition def lists(*args) super end @@ -16,6 +18,7 @@ class FakeGibbonRequest < Gibbon::Request def community_mods(*args) super end + # rubocop:enable Lint/UselessMethodDefinition end RSpec.describe MailchimpBot, type: :labor do diff --git a/spec/labor/markdown_parser_spec.rb b/spec/labor/markdown_parser_spec.rb index 78ed28f5e..b02120bbd 100644 --- a/spec/labor/markdown_parser_spec.rb +++ b/spec/labor/markdown_parser_spec.rb @@ -8,6 +8,10 @@ RSpec.describe MarkdownParser, type: :labor do described_class.new(raw_markdown).finalize end + it "has the correct raw tag delimiters" do + expect(described_class::RAW_TAG_DELIMITERS).to match_array(["{", "}", "raw", "endraw", "----"]) + end + it "renders plain text as-is" do expect(basic_parsed_markdown.finalize).to include(random_word) end diff --git a/spec/models/profile_field_group_spec.rb b/spec/models/profile_field_group_spec.rb index bdcf1d652..647103664 100644 --- a/spec/models/profile_field_group_spec.rb +++ b/spec/models/profile_field_group_spec.rb @@ -1,17 +1,21 @@ require "rails_helper" RSpec.describe ProfileFieldGroup, type: :model do - let!(:group) { create(:profile_field_group) } subject { group } + let!(:group) { create(:profile_field_group) } + it { is_expected.to have_many(:profile_fields).dependent(:nullify) } it { is_expected.to validate_presence_of(:name) } it { is_expected.to validate_uniqueness_of(:name) } describe ".onboarding" do let!(:other_group) { create(:profile_field_group) } - let!(:profile_field1) { create(:profile_field, :onboarding, profile_field_group: group) } - let!(:profile_field2) { create(:profile_field, profile_field_group: other_group) } + + before do + create(:profile_field, :onboarding, profile_field_group: group) + create(:profile_field, profile_field_group: other_group) + end it "only returns groups that have fields for onboarding" do groups = described_class.onboarding diff --git a/spec/requests/admin/configs_spec.rb b/spec/requests/admin/configs_spec.rb index e43972e0a..d1264a707 100644 --- a/spec/requests/admin/configs_spec.rb +++ b/spec/requests/admin/configs_spec.rb @@ -610,7 +610,6 @@ RSpec.describe "/admin/config", type: :request do expect(SiteConfig.primary_brand_color_hex).not_to eq(hex) end - it "updates public to true" do is_public = true post "/admin/config", params: { site_config: { public: is_public }, diff --git a/spec/requests/github_repos_spec.rb b/spec/requests/github_repos_spec.rb index 29c87749b..96d580ce3 100644 --- a/spec/requests/github_repos_spec.rb +++ b/spec/requests/github_repos_spec.rb @@ -23,7 +23,7 @@ RSpec.describe "GithubRepos", type: :request do html_url: Faker::Internet.url, ) - [OpenStruct.new(repo1_params), OpenStruct.new(repo2_params)] + [OpenStruct.new(repo1_params), OpenStruct.new(repo2_params)] # rubocop:disable Performance/OpenStruct end let(:github_client) do instance_double( diff --git a/spec/requests/pages_spec.rb b/spec/requests/pages_spec.rb index 761d0db00..c4ec99b65 100644 --- a/spec/requests/pages_spec.rb +++ b/spec/requests/pages_spec.rb @@ -141,7 +141,7 @@ RSpec.describe "Pages", type: :request do context "when the welcome thread has an absolute URL stored as its path" do it "redirects to a page on the same domain as the app" do vulnerable_welcome_thread = create(:article, user: user, tags: "welcome") - vulnerable_welcome_thread.update_column(:path, 'https://attacker.com/hijacked/welcome') + vulnerable_welcome_thread.update_column(:path, "https://attacker.com/hijacked/welcome") get "/welcome" @@ -173,7 +173,7 @@ RSpec.describe "Pages", type: :request do context "when the challenge thread has an absolute URL stored as its path" do it "redirects to a page on the same domain as the app" do vulnerable_challenge_thread = create(:article, user: user, tags: "challenge") - vulnerable_challenge_thread.update_column(:path, 'https://attacker.com/hijacked/challenge') + vulnerable_challenge_thread.update_column(:path, "https://attacker.com/hijacked/challenge") get "/challenge" @@ -205,7 +205,7 @@ RSpec.describe "Pages", type: :request do context "when the staff thread has an absolute URL stored as its path" do it "redirects to a page on the same domain as the app" do vulnerable_staff_thread = create(:article, user: user, tags: "staff") - vulnerable_staff_thread.update_column(:path, 'https://attacker.com/hijacked/staff') + vulnerable_staff_thread.update_column(:path, "https://attacker.com/hijacked/staff") get "/checkin" diff --git a/spec/requests/profile_field_groups_request_spec.rb b/spec/requests/profile_field_groups_request_spec.rb index 35770f108..dcc3195e5 100644 --- a/spec/requests/profile_field_groups_request_spec.rb +++ b/spec/requests/profile_field_groups_request_spec.rb @@ -1,15 +1,19 @@ require "rails_helper" RSpec.describe "ProfileFieldGroups", type: :request do - describe "GET /api/profile_field_groups" do - - before { sign_in(create(:user)) } + let(:user) { create(:user) } + describe "GET /profile_field_groups" do let!(:group1) { create(:profile_field_group) } let!(:group2) { create(:profile_field_group) } let!(:field1) { create(:profile_field, :onboarding, label: "Field 1", profile_field_group: group1) } - let!(:field2) { create(:profile_field, label: "Field 2", profile_field_group: group1) } - let!(:field3) { create(:profile_field, label: "Field 3", profile_field_group: group2) } + + before do + sign_in user + + create(:profile_field, label: "Field 2", profile_field_group: group1) + create(:profile_field, label: "Field 3", profile_field_group: group2) + end it "returns a successful response" do get profile_field_groups_path diff --git a/spec/services/bulk_sql_delete_spec.rb b/spec/services/bulk_sql_delete_spec.rb index f8acf75aa..feb1f1dd3 100644 --- a/spec/services/bulk_sql_delete_spec.rb +++ b/spec/services/bulk_sql_delete_spec.rb @@ -2,7 +2,7 @@ require "rails_helper" describe BulkSqlDelete, type: :service do let(:sql) do - <<-SQL + <<-SQL.squish DELETE FROM notifications WHERE notifications.id IN ( SELECT notifications.id diff --git a/spec/support/sidekiq_test_helpers.rb b/spec/support/sidekiq_test_helpers.rb index c73d88ab1..102b1cae0 100644 --- a/spec/support/sidekiq_test_helpers.rb +++ b/spec/support/sidekiq_test_helpers.rb @@ -102,7 +102,7 @@ module SidekiqTestHelpers next false if Array(except).include?(job_class.constantize) end if queue - next false unless queue.to_s == job.fetch("queue") + next false unless queue.to_s == job.fetch("queue") # rubocop:disable Style/SoleNestedConditional end true end