diff --git a/Gemfile.lock b/Gemfile.lock index f19fb2d149a..3dc4aeed419 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -484,7 +484,7 @@ GEM sprockets (>= 3.0.0) sshkey (3.0.0) stackprof (0.2.25) - syntax_tree (6.1.1) + syntax_tree (6.2.0) prettier_print (>= 1.2.0) syntax_tree-disable_ternary (1.0.0) test-prof (1.3.0) diff --git a/app/controllers/admin/api_controller.rb b/app/controllers/admin/api_controller.rb index 6238287c067..aaa5929e5aa 100644 --- a/app/controllers/admin/api_controller.rb +++ b/app/controllers/admin/api_controller.rb @@ -14,7 +14,6 @@ class Admin::ApiController < Admin::AdminController ApiKey .where(hidden: false) .includes(:user, :api_key_scopes) - # Sort revoked keys by revoked_at and active keys by created_at .order("revoked_at DESC NULLS FIRST, created_at DESC") .offset(offset) .limit(limit) diff --git a/app/jobs/scheduled/clean_up_uploads.rb b/app/jobs/scheduled/clean_up_uploads.rb index 71320a2db10..7ae69f3c466 100644 --- a/app/jobs/scheduled/clean_up_uploads.rb +++ b/app/jobs/scheduled/clean_up_uploads.rb @@ -33,11 +33,11 @@ module Jobs .where( "uploads.retain_hours IS NULL OR uploads.created_at < current_timestamp - interval '1 hour' * uploads.retain_hours", ) - .where("uploads.created_at < ?", grace_period.hour.ago) - # Don't remove any secure uploads. + .where("uploads.created_at < ?", grace_period.hour.ago) # Don't remove any secure uploads. .where("uploads.access_control_post_id IS NULL") - .joins("LEFT JOIN upload_references ON upload_references.upload_id = uploads.id") - # Don't remove any uploads linked to an UploadReference. + .joins( + "LEFT JOIN upload_references ON upload_references.upload_id = uploads.id", + ) # Don't remove any uploads linked to an UploadReference. .where("upload_references.upload_id IS NULL") .with_no_non_post_relations diff --git a/app/models/api_key.rb b/app/models/api_key.rb index c8611418b74..e86d27d2a95 100644 --- a/app/models/api_key.rb +++ b/app/models/api_key.rb @@ -12,10 +12,10 @@ class ApiKey < ActiveRecord::Base scope :revoked, -> { where("revoked_at IS NOT NULL") } scope :with_key, - ->(key) { + ->(key) do hashed = self.hash_key(key) where(key_hash: hashed) - } + end validates :description, length: { maximum: 255 } diff --git a/app/models/bookmark.rb b/app/models/bookmark.rb index 239824566ba..911fe9f1ff9 100644 --- a/app/models/bookmark.rb +++ b/app/models/bookmark.rb @@ -130,14 +130,14 @@ class Bookmark < ActiveRecord::Base scope :with_reminders, -> { where("reminder_at IS NOT NULL") } scope :pending_reminders, - ->(before_time = Time.now.utc) { + ->(before_time = Time.now.utc) do with_reminders.where("reminder_at <= ?", before_time).where(reminder_last_sent_at: nil) - } + end scope :pending_reminders_for_user, ->(user) { pending_reminders.where(user: user) } scope :for_user_in_topic, - ->(user_id, topic_id) { + ->(user_id, topic_id) do joins( "LEFT JOIN posts ON posts.id = bookmarks.bookmarkable_id AND bookmarks.bookmarkable_type = 'Post'", ).joins( @@ -149,7 +149,7 @@ class Bookmark < ActiveRecord::Base user_id: user_id, topic_id: topic_id, ) - } + end def self.count_per_day(opts = nil) opts ||= {} diff --git a/app/models/category.rb b/app/models/category.rb index 0c13d560e02..69d1cf35078 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -170,7 +170,7 @@ class Category < ActiveRecord::Base scope :latest, -> { order("topic_count DESC") } scope :secured, - ->(guardian = nil) { + ->(guardian = nil) do ids = guardian.secure_category_ids if guardian if ids.present? @@ -181,13 +181,13 @@ class Category < ActiveRecord::Base else where("NOT categories.read_restricted").references(:categories) end - } + end TOPIC_CREATION_PERMISSIONS ||= [:full] POST_CREATION_PERMISSIONS ||= %i[create_post full] scope :topic_create_allowed, - ->(guardian) { + ->(guardian) do scoped = scoped_to_permissions(guardian, TOPIC_CREATION_PERMISSIONS) if !SiteSetting.allow_uncategorized_topics && !guardian.is_staff? @@ -195,7 +195,7 @@ class Category < ActiveRecord::Base end scoped - } + end scope :post_create_allowed, ->(guardian) { scoped_to_permissions(guardian, POST_CREATION_PERMISSIONS) } diff --git a/app/models/email_token.rb b/app/models/email_token.rb index 7a04e7c2296..5cfcfc446d8 100644 --- a/app/models/email_token.rb +++ b/app/models/email_token.rb @@ -10,12 +10,12 @@ class EmailToken < ActiveRecord::Base scope :unconfirmed, -> { where(confirmed: false) } scope :active, - -> { + -> do where(expired: false).where( "created_at >= ?", SiteSetting.email_token_valid_hours.hours.ago, ) - } + end after_initialize do if self.token_hash.blank? diff --git a/app/models/external_upload_stub.rb b/app/models/external_upload_stub.rb index 10004f29069..baa9bbfb9c1 100644 --- a/app/models/external_upload_stub.rb +++ b/app/models/external_upload_stub.rb @@ -17,22 +17,22 @@ class ExternalUploadStub < ActiveRecord::Base } scope :expired_created, - -> { + -> do where( "status = ? AND created_at <= ?", ExternalUploadStub.statuses[:created], CREATED_EXPIRY_HOURS.hours.ago, ) - } + end scope :expired_uploaded, - -> { + -> do where( "status = ? AND created_at <= ?", ExternalUploadStub.statuses[:uploaded], UPLOADED_EXPIRY_HOURS.hours.ago, ) - } + end before_create do self.unique_identifier = SecureRandom.uuid diff --git a/app/models/notification.rb b/app/models/notification.rb index 91c506a28dd..4fe1d393b73 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -25,14 +25,14 @@ class Notification < ActiveRecord::Base } scope :unread_type, ->(user, type, limit = 30) { unread_types(user, [type], limit) } scope :unread_types, - ->(user, types, limit = 30) { + ->(user, types, limit = 30) do where(user_id: user.id, read: false, notification_type: types) .visible .includes(:topic) .limit(limit) - } + end scope :prioritized, - ->(deprioritized_types = []) { + ->(deprioritized_types = []) do scope = order("notifications.high_priority AND NOT notifications.read DESC") if deprioritized_types.present? scope = @@ -46,11 +46,11 @@ class Notification < ActiveRecord::Base scope = scope.order("NOT notifications.read DESC") end scope.order("notifications.created_at DESC") - } + end scope :for_user_menu, - ->(user_id, limit: 30) { + ->(user_id, limit: 30) do where(user_id: user_id).visible.prioritized.includes(:topic).limit(limit) - } + end attr_accessor :skip_send_email diff --git a/app/models/post.rb b/app/models/post.rb index bf391920499..473e306911a 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -89,13 +89,13 @@ class Post < ActiveRecord::Base register_custom_field_type(NOTICE, :json) scope :private_posts_for_user, - ->(user) { + ->(user) do where( "topics.id IN (#{Topic::PRIVATE_MESSAGES_SQL_USER}) OR topics.id IN (#{Topic::PRIVATE_MESSAGES_SQL_GROUP})", user_id: user.id, ) - } + end scope :by_newest, -> { order("created_at DESC, id DESC") } scope :by_post_number, -> { order("post_number ASC") } @@ -111,7 +111,7 @@ class Post < ActiveRecord::Base ->(guardian) { where("posts.post_type IN (?)", Topic.visible_post_types(guardian&.user)) } scope :for_mailing_list, - ->(user, since) { + ->(user, since) do q = created_since(since).joins( "INNER JOIN (#{Topic.for_digest(user, Time.at(0)).select(:id).to_sql}) AS digest_topics ON digest_topics.id = posts.topic_id", @@ -120,10 +120,10 @@ class Post < ActiveRecord::Base q = q.where.not(post_type: Post.types[:whisper]) unless user.staff? q - } + end scope :raw_match, - ->(pattern, type = "string") { + ->(pattern, type = "string") do type = type&.downcase case type @@ -132,10 +132,10 @@ class Post < ActiveRecord::Base when "regex" where("raw ~* ?", "(?n)#{pattern}") end - } + end scope :have_uploads, - -> { + -> do where( " ( @@ -151,7 +151,7 @@ class Post < ActiveRecord::Base )", "%/uploads/#{RailsMultisite::ConnectionManagement.current_db}/%", ) - } + end delegate :username, to: :user diff --git a/app/models/remote_theme.rb b/app/models/remote_theme.rb index 85f7f47ed28..774ab344400 100644 --- a/app/models/remote_theme.rb +++ b/app/models/remote_theme.rb @@ -34,11 +34,11 @@ class RemoteTheme < ActiveRecord::Base has_one :theme, autosave: false scope :joined_remotes, - -> { + -> do joins("JOIN themes ON themes.remote_theme_id = remote_themes.id").where.not( remote_url: "", ) - } + end validates_format_of :minimum_discourse_version, :maximum_discourse_version, diff --git a/app/models/tag.rb b/app/models/tag.rb index 3076504e540..ac32eee2a70 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -22,18 +22,18 @@ class Tag < ActiveRecord::Base validates :description, length: { maximum: 1000 } scope :where_name, - ->(name) { + ->(name) do name = Array(name).map(&:downcase) where("lower(tags.name) IN (?)", name) - } + end # tags that have never been used and don't belong to a tag group scope :unused, - -> { + -> do where(staff_topic_count: 0, pm_topic_count: 0, target_tag_id: nil).joins( "LEFT JOIN tag_group_memberships tgm ON tags.id = tgm.tag_id", ).where("tgm.tag_id IS NULL") - } + end scope :used_tags_in_regular_topics, ->(guardian) { where("tags.#{Tag.topic_count_column(guardian)} > 0") } diff --git a/app/models/tag_user.rb b/app/models/tag_user.rb index 21a01e5c925..5b55a261dd2 100644 --- a/app/models/tag_user.rb +++ b/app/models/tag_user.rb @@ -5,7 +5,7 @@ class TagUser < ActiveRecord::Base belongs_to :user scope :notification_level_visible, - ->(notification_levels = TagUser.notification_levels.values) { + ->(notification_levels = TagUser.notification_levels.values) do select("tag_users.*") .distinct .joins( @@ -24,7 +24,7 @@ class TagUser < ActiveRecord::Base everyone_group_id: Group::AUTO_GROUPS[:everyone], notification_levels: notification_levels, ) - } + end def self.notification_levels NotificationLevels.all diff --git a/app/models/theme.rb b/app/models/theme.rb index a644266c5a1..e471e14d36a 100644 --- a/app/models/theme.rb +++ b/app/models/theme.rb @@ -75,7 +75,7 @@ class Theme < ActiveRecord::Base scope :user_selectable, -> { where("user_selectable OR id = ?", SiteSetting.default_theme_id) } scope :include_relations, - -> { + -> do includes( :child_themes, :parent_themes, @@ -88,7 +88,7 @@ class Theme < ActiveRecord::Base :theme_translation_overrides, theme_fields: :upload, ) - } + end def notify_color_change(color, scheme: nil) scheme ||= color.color_scheme diff --git a/app/models/theme_field.rb b/app/models/theme_field.rb index 8173d49e492..c3d02c7fa63 100644 --- a/app/models/theme_field.rb +++ b/app/models/theme_field.rb @@ -19,7 +19,7 @@ class ThemeField < ActiveRecord::Base end scope :find_by_theme_ids, - ->(theme_ids) { + ->(theme_ids) do return none unless theme_ids.present? where(theme_id: theme_ids).joins( @@ -27,10 +27,10 @@ class ThemeField < ActiveRecord::Base SELECT #{theme_ids.map.with_index { |id, idx| "#{id.to_i} AS theme_id, #{idx} AS theme_sort_column" }.join(" UNION ALL SELECT ")} ) as X ON X.theme_id = theme_fields.theme_id", ).order("theme_sort_column") - } + end scope :filter_locale_fields, - ->(locale_codes) { + ->(locale_codes) do return none unless locale_codes.present? where(target_id: Theme.targets[:translations], name: locale_codes).joins( @@ -41,20 +41,20 @@ class ThemeField < ActiveRecord::Base *locale_codes.map.with_index { |code, index| [code, index] }, ), ).order("Y.locale_sort_column") - } + end scope :find_first_locale_fields, - ->(theme_ids, locale_codes) { + ->(theme_ids, locale_codes) do find_by_theme_ids(theme_ids) .filter_locale_fields(locale_codes) .reorder("X.theme_sort_column", "Y.locale_sort_column") .select("DISTINCT ON (X.theme_sort_column) *") - } + end scope :svg_sprite_fields, - -> { + -> do where(type_id: ThemeField.theme_var_type_ids, name: SvgSprite.theme_sprite_variable_name) - } + end def self.types @types ||= diff --git a/app/models/topic.rb b/app/models/topic.rb index 9457847360a..fab6c594b0d 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -317,13 +317,13 @@ class Topic < ActiveRecord::Base SQL scope :private_messages_for_user, - ->(user) { + ->(user) do private_messages.where( "topics.id IN (#{PRIVATE_MESSAGES_SQL_USER}) OR topics.id IN (#{PRIVATE_MESSAGES_SQL_GROUP})", user_id: user.id, ) - } + end scope :listable_topics, -> { where("topics.archetype <> ?", Archetype.private_message) } diff --git a/app/models/topic_timer.rb b/app/models/topic_timer.rb index 22abd8b3c96..9d4b5c3105e 100644 --- a/app/models/topic_timer.rb +++ b/app/models/topic_timer.rb @@ -23,9 +23,9 @@ class TopicTimer < ActiveRecord::Base scope :scheduled_bump_topics, -> { where(status_type: TopicTimer.types[:bump], deleted_at: nil).pluck(:topic_id) } scope :pending_timers, - ->(before_time = Time.now.utc) { + ->(before_time = Time.now.utc) do where("execute_at <= :before_time AND deleted_at IS NULL", before_time: before_time) - } + end before_save do self.created_at ||= Time.zone.now if execute_at diff --git a/app/models/user.rb b/app/models/user.rb index 2b11ce613c5..a4a868fda44 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -103,7 +103,7 @@ class User < ActiveRecord::Base has_many :badges, through: :user_badges has_many :default_featured_user_badges, - -> { + -> do max_featured_rank = ( if SiteSetting.max_favorite_badges > 0 @@ -113,7 +113,7 @@ class User < ActiveRecord::Base end ) for_enabled_badges.grouped_with_count.where("featured_rank <= ?", max_featured_rank) - }, + end, class_name: "UserBadge" has_many :topics_allowed, through: :topic_allowed_users, source: :topic @@ -249,18 +249,18 @@ class User < ActiveRecord::Base ->(email) { joins(:user_emails).where("lower(user_emails.email) IN (?)", email) } scope :with_primary_email, - ->(email) { + ->(email) do joins(:user_emails).where( "lower(user_emails.email) IN (?) AND user_emails.primary", email, ) - } + end scope :human_users, -> { where("users.id > 0") } # excluding fake users like the system user or anonymous users scope :real, - -> { + -> do human_users.where( "NOT EXISTS( SELECT 1 @@ -268,7 +268,7 @@ class User < ActiveRecord::Base WHERE a.user_id = users.id )", ) - } + end # TODO-PERF: There is no indexes on any of these # and NotifyMailingListSubscribers does a select-all-and-loop @@ -281,16 +281,16 @@ class User < ActiveRecord::Base scope :not_staged, -> { where(staged: false) } scope :filter_by_username, - ->(filter) { + ->(filter) do if filter.is_a?(Array) where("username_lower ~* ?", "(#{filter.join("|")})") else where("username_lower ILIKE ?", "%#{filter}%") end - } + end scope :filter_by_username_or_email, - ->(filter) { + ->(filter) do if filter.is_a?(String) && filter =~ /.+@.+/ # probably an email so try the bypass if user_id = UserEmail.where("lower(email) = ?", filter.downcase).pick(:user_id) @@ -311,10 +311,10 @@ class User < ActiveRecord::Base filter: "%#{filter}%", ) end - } + end scope :watching_topic, - ->(topic) { + ->(topic) do joins( DB.sql_fragment( "LEFT JOIN category_users ON category_users.user_id = users.id AND category_users.category_id = :category_id", @@ -333,7 +333,7 @@ class User < ActiveRecord::Base .where( "category_users.notification_level > 0 OR topic_users.notification_level > 0 OR tag_users.notification_level > 0", ) - } + end module NewTopicDuration ALWAYS = -1 diff --git a/app/models/user_badge.rb b/app/models/user_badge.rb index 618632656c1..20d456d26a9 100644 --- a/app/models/user_badge.rb +++ b/app/models/user_badge.rb @@ -10,15 +10,15 @@ class UserBadge < ActiveRecord::Base BOOLEAN_ATTRIBUTES = %w[is_favorite] scope :grouped_with_count, - -> { + -> do group(:badge_id, :user_id) .select_for_grouping .order("MAX(featured_rank) ASC") .includes(:user, :granted_by, { badge: :badge_type }, post: :topic) - } + end scope :select_for_grouping, - -> { + -> do select( UserBadge.attribute_names.map do |name| operation = BOOLEAN_ATTRIBUTES.include?(name) ? "BOOL_OR" : "MAX" @@ -26,7 +26,7 @@ class UserBadge < ActiveRecord::Base end, 'COUNT(*) AS "count"', ) - } + end scope :for_enabled_badges, -> { where("user_badges.badge_id IN (SELECT id FROM badges WHERE enabled)") } diff --git a/app/models/user_custom_field.rb b/app/models/user_custom_field.rb index 92255cc5648..fde4b371c6a 100644 --- a/app/models/user_custom_field.rb +++ b/app/models/user_custom_field.rb @@ -4,11 +4,11 @@ class UserCustomField < ActiveRecord::Base belongs_to :user scope :searchable, - -> { + -> do joins( "INNER JOIN user_fields ON user_fields.id = REPLACE(user_custom_fields.name, 'user_field_', '')::INTEGER AND user_fields.searchable IS TRUE AND user_custom_fields.name like 'user_field_%'", ) - } + end end # == Schema Information diff --git a/app/models/watched_word.rb b/app/models/watched_word.rb index e03bd95fd20..0ceccd5272d 100644 --- a/app/models/watched_word.rb +++ b/app/models/watched_word.rb @@ -27,12 +27,12 @@ class WatchedWord < ActiveRecord::Base after_destroy -> { WordWatcher.clear_cache! } scope :for, - ->(word:) { + ->(word:) do where( "(word ILIKE :word AND case_sensitive = 'f') OR (word LIKE :word AND case_sensitive = 't')", word: word, ) - } + end def self.actions @actions ||= diff --git a/plugins/chat/app/models/chat/channel.rb b/plugins/chat/app/models/chat/channel.rb index 8e585bb0b09..652b12edf7b 100644 --- a/plugins/chat/app/models/chat/channel.rb +++ b/plugins/chat/app/models/chat/channel.rb @@ -48,17 +48,17 @@ module Chat before_validation :generate_auto_slug scope :with_categories, - -> { + -> do joins( "LEFT JOIN categories ON categories.id = chat_channels.chatable_id AND chat_channels.chatable_type = 'Category'", ) - } + end scope :public_channels, - -> { + -> do with_categories.where(chatable_type: public_channel_chatable_types).where( "categories.id IS NOT NULL", ) - } + end delegate :empty?, to: :chat_messages, prefix: true diff --git a/plugins/chat/app/models/chat/message.rb b/plugins/chat/app/models/chat/message.rb index c3a5ea2cce8..d151a8cc3fa 100644 --- a/plugins/chat/app/models/chat/message.rb +++ b/plugins/chat/app/models/chat/message.rb @@ -30,11 +30,11 @@ module Chat dependent: :destroy, foreign_key: :chat_message_id has_many :bookmarks, - -> { + -> do unscope(where: :bookmarkable_type).where( bookmarkable_type: Chat::Message.polymorphic_name, ) - }, + end, as: :bookmarkable, dependent: :destroy has_many :upload_references, @@ -53,21 +53,21 @@ module Chat foreign_key: :chat_message_id scope :in_public_channel, - -> { + -> do joins(:chat_channel).where( chat_channel: { chatable_type: Chat::Channel.public_channel_chatable_types, }, ) - } + end scope :in_dm_channel, - -> { + -> do joins(:chat_channel).where( chat_channel: { chatable_type: Chat::Channel.direct_channel_chatable_types, }, ) - } + end scope :created_before, ->(date) { where("chat_messages.created_at < ?", date) } scope :uncooked, -> { where("cooked_version <> ? or cooked_version IS NULL", BAKED_VERSION) } diff --git a/plugins/chat/app/models/chat/thread.rb b/plugins/chat/app/models/chat/thread.rb index 1b852f7bec4..7531dfbd658 100644 --- a/plugins/chat/app/models/chat/thread.rb +++ b/plugins/chat/app/models/chat/thread.rb @@ -17,11 +17,11 @@ module Chat class_name: "Chat::Message" has_many :chat_messages, - -> { + -> do where("deleted_at IS NULL").order( "chat_messages.created_at ASC, chat_messages.id ASC", ) - }, + end, foreign_key: :thread_id, primary_key: :id, class_name: "Chat::Message" diff --git a/spec/lib/backup_restore/s3_backup_store_spec.rb b/spec/lib/backup_restore/s3_backup_store_spec.rb index 297572e131f..1d94b55932b 100644 --- a/spec/lib/backup_restore/s3_backup_store_spec.rb +++ b/spec/lib/backup_restore/s3_backup_store_spec.rb @@ -25,27 +25,27 @@ RSpec.describe BackupRestore::S3BackupStore do @s3_client.stub_responses( :list_objects_v2, - ->(context) { + ->(context) do check_context(context) { contents: objects_with_prefix(context) } - }, + end, ) @s3_client.stub_responses( :delete_object, - ->(context) { + ->(context) do check_context(context) expect do @objects.delete_if { |obj| obj[:key] == context.params[:key] } end.to change { @objects } - }, + end, ) @s3_client.stub_responses( :head_object, - ->(context) { + ->(context) do check_context(context) if object = @objects.find { |obj| obj[:key] == context.params[:key] } @@ -53,12 +53,12 @@ RSpec.describe BackupRestore::S3BackupStore do else { status_code: 404, headers: {}, body: "" } end - }, + end, ) @s3_client.stub_responses( :get_object, - ->(context) { + ->(context) do check_context(context) if object = @objects.find { |obj| obj[:key] == context.params[:key] } @@ -66,12 +66,12 @@ RSpec.describe BackupRestore::S3BackupStore do else { status_code: 404, headers: {}, body: "" } end - }, + end, ) @s3_client.stub_responses( :put_object, - ->(context) { + ->(context) do check_context(context) @objects << { @@ -79,7 +79,7 @@ RSpec.describe BackupRestore::S3BackupStore do size: context.params[:body].size, last_modified: Time.zone.now, } - }, + end, ) SiteSetting.s3_backup_bucket = "s3-backup-bucket" diff --git a/spec/lib/inline_oneboxer_spec.rb b/spec/lib/inline_oneboxer_spec.rb index cf821f0118b..ad32b243fc0 100644 --- a/spec/lib/inline_oneboxer_spec.rb +++ b/spec/lib/inline_oneboxer_spec.rb @@ -130,9 +130,9 @@ RSpec.describe InlineOneboxer do topic = Fabricate(:topic, title: "Inline oneboxer") Fabricate(:post, topic: topic) # OP Fabricate(:post, topic: topic) - lookup = ->(number) { + lookup = ->(number) do InlineOneboxer.lookup("#{topic.url}/#{number}", skip_cache: true)[:title] - } + end posts = topic.reload.posts.order("post_number ASC") expect(lookup.call(0)).to eq("Inline oneboxer") diff --git a/spec/lib/middleware/request_tracker_spec.rb b/spec/lib/middleware/request_tracker_spec.rb index 30705a0b897..8edb6319a71 100644 --- a/spec/lib/middleware/request_tracker_spec.rb +++ b/spec/lib/middleware/request_tracker_spec.rb @@ -667,10 +667,10 @@ RSpec.describe Middleware::RequestTracker do end let(:logger) do - ->(env, data) { + ->(env, data) do @env = env @data = data - } + end end before { Middleware::RequestTracker.register_detailed_request_logger(logger) } diff --git a/spec/lib/new_post_manager_spec.rb b/spec/lib/new_post_manager_spec.rb index 429bcc3e891..16a8a6ce7fc 100644 --- a/spec/lib/new_post_manager_spec.rb +++ b/spec/lib/new_post_manager_spec.rb @@ -382,9 +382,9 @@ RSpec.describe NewPostManager do result end - @queue_handler = ->(manager) { + @queue_handler = ->(manager) do manager.args[:raw] =~ /queue me/ ? manager.enqueue("default") : nil - } + end NewPostManager.add_handler(&@counter_handler) NewPostManager.add_handler(&@queue_handler) diff --git a/spec/lib/plugin/instance_spec.rb b/spec/lib/plugin/instance_spec.rb index a501619faa4..1e7c6e5feff 100644 --- a/spec/lib/plugin/instance_spec.rb +++ b/spec/lib/plugin/instance_spec.rb @@ -771,12 +771,12 @@ RSpec.describe Plugin::Instance do to: Notification.types[:code_review_commit_approved], threshold: 1, consolidation_window: 1.minute, - unconsolidated_query_blk: ->(notifications, _data) { + unconsolidated_query_blk: ->(notifications, _data) do notifications.where("(data::json ->> 'consolidated') IS NULL") - }, - consolidated_query_blk: ->(notifications, _data) { + end, + consolidated_query_blk: ->(notifications, _data) do notifications.where("(data::json ->> 'consolidated') IS NOT NULL") - }, + end, ).set_mutations( set_data_blk: ->(notification) { notification.data_hash.merge(consolidated: true) }, ) diff --git a/spec/lib/post_destroyer_spec.rb b/spec/lib/post_destroyer_spec.rb index 672190e6ec2..15550b1aeb8 100644 --- a/spec/lib/post_destroyer_spec.rb +++ b/spec/lib/post_destroyer_spec.rb @@ -391,11 +391,11 @@ RSpec.describe PostDestroyer do user_stat = post2.user.user_stat called = 0 - topic_destroyed = ->(topic, user) { + topic_destroyed = ->(topic, user) do expect(topic).to eq(post2.topic) expect(user).to eq(post2.user) called += 1 - } + end DiscourseEvent.on(:topic_destroyed, &topic_destroyed) @@ -414,11 +414,11 @@ RSpec.describe PostDestroyer do expect(user_stat.reload.topic_count).to eq(1) called = 0 - topic_recovered = ->(topic, user) { + topic_recovered = ->(topic, user) do expect(topic).to eq(post2.topic) expect(user).to eq(post2.user) called += 1 - } + end DiscourseEvent.on(:topic_recovered, &topic_recovered) diff --git a/spec/lib/s3_inventory_spec.rb b/spec/lib/s3_inventory_spec.rb index 92172aef965..1aaf094de18 100644 --- a/spec/lib/s3_inventory_spec.rb +++ b/spec/lib/s3_inventory_spec.rb @@ -16,7 +16,7 @@ RSpec.describe "S3Inventory" do client.stub_responses( :list_objects, - ->(context) { + ->(context) do expect(context.params[:prefix]).to eq( "#{S3Inventory::INVENTORY_PREFIX}/#{S3Inventory::INVENTORY_VERSION}/bucket/original/hive", ) @@ -48,7 +48,7 @@ RSpec.describe "S3Inventory" do ], next_marker: "eyJNYXJrZXIiOiBudWxsLCAiYm90b190cnVuY2F0ZV9hbW91bnQiOiAyfQ==", } - }, + end, ) inventory.stubs(:cleanup!) diff --git a/spec/models/report_spec.rb b/spec/models/report_spec.rb index 3efcf065fb8..19fe0f58d45 100644 --- a/spec/models/report_spec.rb +++ b/spec/models/report_spec.rb @@ -206,14 +206,14 @@ RSpec.describe Report do if arg == :flag user = Fabricate(:user) topic = Fabricate(:topic, user: user) - builder = ->(dt) { + builder = ->(dt) do PostActionCreator.create( user, Fabricate(:post, topic: topic, user: user), :spam, created_at: dt, ) - } + end elsif arg == :signup builder = ->(dt) { Fabricate(:user, created_at: dt) } else diff --git a/spec/models/topic_user_spec.rb b/spec/models/topic_user_spec.rb index 79f762026c4..5cfb63fb02f 100644 --- a/spec/models/topic_user_spec.rb +++ b/spec/models/topic_user_spec.rb @@ -590,10 +590,10 @@ RSpec.describe TopicUser do called = 0 visits = [] - user_first_visit = ->(topic_id, user_id) { + user_first_visit = ->(topic_id, user_id) do visits << "#{topic_id}-#{user_id}" called += 1 - } + end DiscourseEvent.on(:topic_first_visited_by_user, &user_first_visit) diff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rb index 106ee53adad..fc9aa061680 100644 --- a/spec/requests/topics_controller_spec.rb +++ b/spec/requests/topics_controller_spec.rb @@ -309,11 +309,11 @@ RSpec.describe TopicsController do begin called = false - assert = ->(original_topic, destination_topic) { + assert = ->(original_topic, destination_topic) do called = true expect(original_topic).to eq(topic) expect(destination_topic).to eq(dest_topic) - } + end DiscourseEvent.on(:topic_merged, &assert) diff --git a/spec/services/user_silencer_spec.rb b/spec/services/user_silencer_spec.rb index 574010d3120..c4f66015f94 100644 --- a/spec/services/user_silencer_spec.rb +++ b/spec/services/user_silencer_spec.rb @@ -70,10 +70,10 @@ RSpec.describe UserSilencer do context "with a plugin hook" do before do - @override_silence_message = ->(opts) { + @override_silence_message = ->(opts) do opts[:silence_message_params][:message_title] = "override title" opts[:silence_message_params][:message_raw] = "override raw" - } + end DiscourseEvent.on(:user_silenced, &@override_silence_message) end