Routine rubocop fixes (#10237)
This commit is contained in:
parent
5aefa6279a
commit
2d881ef571
56 changed files with 98 additions and 104 deletions
|
|
@ -17,6 +17,7 @@ AllCops:
|
|||
- vendor/**/*
|
||||
DisplayStyleGuide: true
|
||||
ExtraDetails: true
|
||||
NewCops: enable # opt-in to new cops by default
|
||||
TargetRubyVersion: 2.7
|
||||
|
||||
#################### Bundler ###########################
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -180,7 +180,7 @@ class Comment < ApplicationRecord
|
|||
doc = Nokogiri::HTML.fragment(processed_html)
|
||||
doc.css("a").each do |anchor|
|
||||
unless anchor.to_s.include?("<img") || anchor.attr("class")&.include?("ltag")
|
||||
anchor.content = strip_url(anchor.content) unless anchor.to_s.include?("<img")
|
||||
anchor.content = strip_url(anchor.content) unless anchor.to_s.include?("<img") # rubocop:disable Style/SoleNestedConditional
|
||||
end
|
||||
end
|
||||
self.processed_html = doc.to_html.html_safe # rubocop:disable Rails/OutputSafety
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@ class Notification < ApplicationRecord
|
|||
end
|
||||
|
||||
def fast_destroy_old_notifications(destroy_before_timestamp = 3.months.ago)
|
||||
sql = <<-SQL
|
||||
sql = <<-SQL.squish
|
||||
DELETE FROM notifications
|
||||
WHERE notifications.id IN (
|
||||
SELECT notifications.id
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ module Search
|
|||
viewable_by
|
||||
].freeze
|
||||
|
||||
TERMS_FILTER_KEYS = %i[viewable_by status].freeze
|
||||
|
||||
QUERY_KEYS = %i[
|
||||
channel_text
|
||||
].freeze
|
||||
|
|
@ -43,7 +45,7 @@ module Search
|
|||
FILTER_KEYS.filter_map do |filter_key|
|
||||
next if @params[filter_key].blank? || @params[filter_key] == "all"
|
||||
|
||||
if %i[viewable_by status].include? filter_key
|
||||
if TERMS_FILTER_KEYS.include?(filter_key)
|
||||
{ terms: { filter_key => @params[filter_key] } }
|
||||
else
|
||||
{ term: { filter_key => @params[filter_key] } }
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ module Slack
|
|||
email: <mailto:%<email>s|%<email>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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 },
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue