From f1ec04a0c9b3a04e0e0296521e0b977e7ee1f54c Mon Sep 17 00:00:00 2001 From: rhymes Date: Thu, 16 Jul 2020 15:51:11 +0200 Subject: [PATCH] Rubocop: move dot in multi-line calls to leading position (#9262) --- .rubocop.yml | 4 +- app/controllers/api/v0/articles_controller.rb | 32 +++---- app/controllers/api/v0/comments_controller.rb | 16 ++-- .../api/v0/followers_controller.rb | 12 +-- app/controllers/api/v0/listings_controller.rb | 6 +- .../api/v0/podcast_episodes_controller.rb | 8 +- app/controllers/api/v0/tags_controller.rb | 6 +- app/controllers/api/v0/videos_controller.rb | 10 +- .../buffered_articles_controller.rb | 4 +- .../chat_channel_memberships_controller.rb | 8 +- app/controllers/chat_channels_controller.rb | 64 ++++++------- app/controllers/dashboards_controller.rb | 24 ++--- app/controllers/followings_controller.rb | 24 ++--- .../internal/articles_controller.rb | 92 +++++++++---------- .../internal/comments_controller.rb | 22 ++--- .../internal/feedback_messages_controller.rb | 32 +++---- .../internal/listings_controller.rb | 4 +- .../internal/moderator_actions_controller.rb | 10 +- .../internal/permissions_controller.rb | 10 +- .../internal/podcasts_controller.rb | 8 +- .../privileged_reactions_controller.rb | 12 +-- app/controllers/internal/users_controller.rb | 14 +-- .../internal/webhook_endpoints_controller.rb | 6 +- app/controllers/listings_controller.rb | 18 ++-- app/controllers/moderations_controller.rb | 6 +- .../notification_subscriptions_controller.rb | 4 +- app/controllers/organizations_controller.rb | 4 +- app/controllers/page_views_controller.rb | 8 +- app/controllers/pages_controller.rb | 10 +- .../podcast_episodes_controller.rb | 6 +- app/controllers/reactions_controller.rb | 10 +- app/controllers/sitemaps_controller.rb | 6 +- app/controllers/social_previews_controller.rb | 8 +- app/controllers/stories_controller.rb | 62 ++++++------- app/controllers/tags_controller.rb | 4 +- app/controllers/videos_controller.rb | 10 +- app/labor/article_suggester.rb | 24 ++--- app/labor/assign_tag_moderator.rb | 6 +- app/labor/badge_rewarder.rb | 18 ++-- app/labor/cache_buster.rb | 12 +-- app/labor/email_logic.rb | 32 +++---- app/labor/reading_list.rb | 10 +- app/labor/sticky_article_collection.rb | 38 ++++---- app/liquid_tags/codepen_tag.rb | 4 +- app/liquid_tags/codesandbox_tag.rb | 4 +- app/liquid_tags/gist_tag.rb | 4 +- .../github_tag/github_readme_tag.rb | 6 +- app/liquid_tags/soundcloud_tag.rb | 4 +- app/models/article.rb | 62 ++++++------- app/models/buffer_update.rb | 6 +- app/models/chat_channel.rb | 4 +- app/models/comment.rb | 6 +- app/models/email_message.rb | 4 +- app/models/event.rb | 8 +- app/models/follow.rb | 4 +- app/models/github_repo.rb | 8 +- app/models/html_variant.rb | 8 +- app/models/message.rb | 30 +++--- app/models/podcast.rb | 6 +- app/models/podcast_episode.rb | 24 ++--- app/models/sponsorship.rb | 8 +- app/models/tag.rb | 10 +- app/models/user.rb | 6 +- app/queries/internal/moderators_query.rb | 4 +- app/serializers/search/listing_serializer.rb | 6 +- app/services/analytics_service.rb | 14 +-- app/services/article_api_index_service.rb | 56 +++++------ app/services/articles/feed.rb | 28 +++--- app/services/exporter/comments.rb | 4 +- app/services/mentions/create_all.rb | 4 +- app/services/notifications/moderation.rb | 6 +- .../notifications/new_comment/send.rb | 6 +- .../notifications/new_follower/send.rb | 4 +- app/services/notifications/reactions/send.rb | 8 +- app/services/rss_reader/assembler.rb | 8 +- app/services/suggester/users/recent.rb | 22 ++--- app/services/suggester/users/sidebar.rb | 12 +-- .../follows/create_chat_channel_worker.rb | 6 +- .../follows/send_email_notification_worker.rb | 6 +- .../record_daily_notifications_worker.rb | 6 +- .../metrics/record_daily_usage_worker.rb | 14 +-- app/workers/search/bulk_index_worker.rb | 8 +- .../users/record_field_test_event_worker.rb | 8 +- config/sitemap.rb | 4 +- spec/decorators/article_decorator_spec.rb | 4 +- spec/decorators/listing_decorator_spec.rb | 16 ++-- spec/helpers/articles_helper_spec.rb | 4 +- spec/initializers/application_config_spec.rb | 4 +- spec/labor/mailchimp_bot_spec.rb | 40 ++++---- spec/labor/markdown_fixer_spec.rb | 24 ++--- spec/labor/markdown_parser_spec.rb | 4 +- spec/lib/html_css_to_image_spec.rb | 44 ++++----- spec/liquid_tags/link_tag_spec.rb | 4 +- spec/liquid_tags/listing_tag_spec.rb | 4 +- spec/models/chat_channel_membership_spec.rb | 4 +- spec/models/feedback_message_spec.rb | 8 +- spec/models/user_spec.rb | 86 ++++++++--------- spec/models/user_subscription_spec.rb | 4 +- spec/policies/comment_policy_spec.rb | 12 +-- spec/rails_helper.rb | 28 +++--- spec/requests/api/v0/articles_spec.rb | 8 +- spec/requests/api/v0/listings_spec.rb | 20 ++-- spec/requests/api_secrets_create_spec.rb | 8 +- spec/requests/chat_channels_spec.rb | 8 +- spec/requests/comments_create_spec.rb | 10 +- spec/requests/email_subscriptions_spec.rb | 4 +- spec/requests/follows_create_spec.rb | 12 +-- .../internal/privileged_reactions_spec.rb | 8 +- spec/requests/listings_spec.rb | 12 +-- spec/requests/page_views_spec.rb | 4 +- spec/requests/social_previews_spec.rb | 8 +- spec/requests/twitch_stream_updates_spec.rb | 18 ++-- spec/requests/user/user_organization_spec.rb | 8 +- spec/requests/user/user_settings_spec.rb | 4 +- spec/services/bulk_sql_delete_spec.rb | 4 +- spec/services/payments/customer_spec.rb | 4 +- spec/services/rate_limit_checker_spec.rb | 24 ++--- spec/services/slack/announcer_spec.rb | 6 +- .../streams/twitch_access_token/get_spec.rb | 8 +- .../streams/twitch_webhook/register_spec.rb | 24 ++--- .../user_blocks/channel_handler_spec.rb | 8 +- .../internal/admin_awards_badges_spec.rb | 4 +- .../search/display_comments_search_spec.rb | 4 +- .../user/user_edits_integrations_spec.rb | 4 +- .../record_daily_notifications_worker_spec.rb | 6 +- .../webhook/dispatch_event_worker_spec.rb | 8 +- 126 files changed, 849 insertions(+), 851 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 786e0d655..8b6257a1b 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -37,9 +37,7 @@ Layout/ClassStructure: Layout/DotPosition: Description: 'Checks the position of the dot in multi-line method calls.' StyleGuide: '#consistent-multi-line-chains' - # TODO: [@thepracticaldev/oss] enable leading? - EnforcedStyle: trailing - + EnforcedStyle: leading Layout/EmptyLinesAroundAttributeAccessor: Description: "Keep blank lines around attribute accessors." diff --git a/app/controllers/api/v0/articles_controller.rb b/app/controllers/api/v0/articles_controller.rb index 49fdc0fc1..d00ca5b41 100644 --- a/app/controllers/api/v0/articles_controller.rb +++ b/app/controllers/api/v0/articles_controller.rb @@ -41,20 +41,20 @@ module Api end def show - @article = Article.published. - includes(:user). - select(SHOW_ATTRIBUTES_FOR_SERIALIZATION). - find(params[:id]). - decorate + @article = Article.published + .includes(:user) + .select(SHOW_ATTRIBUTES_FOR_SERIALIZATION) + .find(params[:id]) + .decorate set_surrogate_key_header @article.record_key end def show_by_slug - @article = Article.published. - select(SHOW_ATTRIBUTES_FOR_SERIALIZATION). - find_by!(path: "/#{params[:username]}/#{params[:slug]}"). - decorate + @article = Article.published + .select(SHOW_ATTRIBUTES_FOR_SERIALIZATION) + .find_by!(path: "/#{params[:username]}/#{params[:slug]}") + .decorate set_surrogate_key_header @article.record_key render "show" @@ -95,13 +95,13 @@ module Api @user.articles.published end - @articles = @articles. - includes(:organization). - select(ME_ATTRIBUTES_FOR_SERIALIZATION). - order(published_at: :desc, created_at: :desc). - page(params[:page]). - per(num). - decorate + @articles = @articles + .includes(:organization) + .select(ME_ATTRIBUTES_FOR_SERIALIZATION) + .order(published_at: :desc, created_at: :desc) + .page(params[:page]) + .per(num) + .decorate end private diff --git a/app/controllers/api/v0/comments_controller.rb b/app/controllers/api/v0/comments_controller.rb index 2431f87db..b25283497 100644 --- a/app/controllers/api/v0/comments_controller.rb +++ b/app/controllers/api/v0/comments_controller.rb @@ -11,19 +11,19 @@ module Api def index article = Article.find(params[:a_id]) - @comments = article.comments. - includes(:user). - select(ATTRIBUTES_FOR_SERIALIZATION). - arrange + @comments = article.comments + .includes(:user) + .select(ATTRIBUTES_FOR_SERIALIZATION) + .arrange set_surrogate_key_header article.record_key, Comment.table_key, edge_cache_keys(@comments) end def show - tree_with_root_comment = Comment.subtree_of(params[:id].to_i(26)). - includes(:user). - select(ATTRIBUTES_FOR_SERIALIZATION). - arrange + tree_with_root_comment = Comment.subtree_of(params[:id].to_i(26)) + .includes(:user) + .select(ATTRIBUTES_FOR_SERIALIZATION) + .arrange # being only one tree we know that the root comment is the first (and only) key @comment = tree_with_root_comment.keys.first diff --git a/app/controllers/api/v0/followers_controller.rb b/app/controllers/api/v0/followers_controller.rb index fe6c867bf..083a7512b 100644 --- a/app/controllers/api/v0/followers_controller.rb +++ b/app/controllers/api/v0/followers_controller.rb @@ -10,12 +10,12 @@ module Api private_constant :USERS_ATTRIBUTES_FOR_SERIALIZATION def users - @follows = Follow.followable_user(@user.id). - includes(:follower). - select(USERS_ATTRIBUTES_FOR_SERIALIZATION). - order(created_at: :desc). - page(params[:page]). - per(@follows_limit) + @follows = Follow.followable_user(@user.id) + .includes(:follower) + .select(USERS_ATTRIBUTES_FOR_SERIALIZATION) + .order(created_at: :desc) + .page(params[:page]) + .per(@follows_limit) end private diff --git a/app/controllers/api/v0/listings_controller.rb b/app/controllers/api/v0/listings_controller.rb index 27cdd1cb3..2ab1e3af0 100644 --- a/app/controllers/api/v0/listings_controller.rb +++ b/app/controllers/api/v0/listings_controller.rb @@ -22,9 +22,9 @@ module Api private_constant :ATTRIBUTES_FOR_SERIALIZATION def index - @listings = Listing.published. - select(ATTRIBUTES_FOR_SERIALIZATION). - includes(:user, :organization, :taggings, :listing_category) + @listings = Listing.published + .select(ATTRIBUTES_FOR_SERIALIZATION) + .includes(:user, :organization, :taggings, :listing_category) if params[:category].present? @listings = @listings.in_category(params[:category]) diff --git a/app/controllers/api/v0/podcast_episodes_controller.rb b/app/controllers/api/v0/podcast_episodes_controller.rb index b79c43c19..5486d12c1 100644 --- a/app/controllers/api/v0/podcast_episodes_controller.rb +++ b/app/controllers/api/v0/podcast_episodes_controller.rb @@ -15,10 +15,10 @@ module Api relation = PodcastEpisode.includes(:podcast).reachable end - @podcast_episodes = relation. - select(:id, :slug, :title, :podcast_id). - order(published_at: :desc). - page(page).per(num) + @podcast_episodes = relation + .select(:id, :slug, :title, :podcast_id) + .order(published_at: :desc) + .page(page).per(num) set_surrogate_key_header PodcastEpisode.table_key, @podcast_episodes.map(&:record_key) end diff --git a/app/controllers/api/v0/tags_controller.rb b/app/controllers/api/v0/tags_controller.rb index 7ef69dd8b..fe8e7a08a 100644 --- a/app/controllers/api/v0/tags_controller.rb +++ b/app/controllers/api/v0/tags_controller.rb @@ -11,9 +11,9 @@ module Api per_page = (params[:per_page] || 10).to_i num = [per_page, 1000].min - @tags = Tag.select(ATTRIBUTES_FOR_SERIALIZATION). - order(taggings_count: :desc). - page(page).per(num) + @tags = Tag.select(ATTRIBUTES_FOR_SERIALIZATION) + .order(taggings_count: :desc) + .page(page).per(num) set_surrogate_key_header Tag.table_key, @tags.map(&:record_key) end diff --git a/app/controllers/api/v0/videos_controller.rb b/app/controllers/api/v0/videos_controller.rb index 972cae38e..9a7b5d969 100644 --- a/app/controllers/api/v0/videos_controller.rb +++ b/app/controllers/api/v0/videos_controller.rb @@ -13,11 +13,11 @@ module Api per_page = (params[:per_page] || 24).to_i num = [per_page, 1000].min - @video_articles = Article.with_video. - includes([:user]). - select(INDEX_ATTRIBUTES_FOR_SERIALIZATION). - order(hotness_score: :desc). - page(page).per(num) + @video_articles = Article.with_video + .includes([:user]) + .select(INDEX_ATTRIBUTES_FOR_SERIALIZATION) + .order(hotness_score: :desc) + .page(page).per(num) set_surrogate_key_header "videos", Article.table_key, @video_articles.map(&:record_key) end diff --git a/app/controllers/buffered_articles_controller.rb b/app/controllers/buffered_articles_controller.rb index 0831d9a3a..f1faac952 100644 --- a/app/controllers/buffered_articles_controller.rb +++ b/app/controllers/buffered_articles_controller.rb @@ -9,8 +9,8 @@ class BufferedArticlesController < ApplicationController def buffered_articles_urls relation = if Rails.env.production? - Article.where("last_buffered > ?", 24.hours.ago). - or(Article.where("published_at > ?", 20.minutes.ago)) + Article.where("last_buffered > ?", 24.hours.ago) + .or(Article.where("published_at > ?", 20.minutes.ago)) else Article.all end diff --git a/app/controllers/chat_channel_memberships_controller.rb b/app/controllers/chat_channel_memberships_controller.rb index b71764206..991534b05 100644 --- a/app/controllers/chat_channel_memberships_controller.rb +++ b/app/controllers/chat_channel_memberships_controller.rb @@ -163,10 +163,10 @@ class ChatChannelMembershipsController < ApplicationController "joined", ) - NotifyMailer. - with(membership: @chat_channel_membership, inviter: @chat_channel_membership.user). - channel_invite_email. - deliver_later + NotifyMailer + .with(membership: @chat_channel_membership, inviter: @chat_channel_membership.user) + .channel_invite_email + .deliver_later notice = "Accepted request of #{@chat_channel_membership.user.username} to join #{channel_name}." end diff --git a/app/controllers/chat_channels_controller.rb b/app/controllers/chat_channels_controller.rb index a6991d857..c614afddc 100644 --- a/app/controllers/chat_channels_controller.rb +++ b/app/controllers/chat_channels_controller.rb @@ -26,11 +26,11 @@ class ChatChannelsController < ApplicationController end def show - @chat_messages = @chat_channel.messages. - includes(:user). - order(created_at: :desc). - offset(params[:message_offset]). - limit(50) + @chat_messages = @chat_channel.messages + .includes(:user) + .order(created_at: :desc) + .offset(params[:message_offset]) + .limit(50) end def create @@ -147,9 +147,9 @@ class ChatChannelsController < ApplicationController skip_authorization @chat_channel = - ChatChannel. - select(CHANNEL_ATTRIBUTES_FOR_SERIALIZATION). - find_by(id: params[:id]) + ChatChannel + .select(CHANNEL_ATTRIBUTES_FOR_SERIALIZATION) + .find_by(id: params[:id]) return if @chat_channel&.has_member?(current_user) @@ -169,12 +169,12 @@ class ChatChannelsController < ApplicationController def render_unopened_json_response @chat_channels_memberships = if session_current_user_id - ChatChannelMembership.where(user_id: session_current_user_id). - where(has_unopened_messages: true). - where(show_global_badge_notification: true). - where.not(status: %w[removed_from_channel left_channel]). - includes(%i[chat_channel user]). - order("chat_channel_memberships.updated_at DESC") + ChatChannelMembership.where(user_id: session_current_user_id) + .where(has_unopened_messages: true) + .where(show_global_badge_notification: true) + .where.not(status: %w[removed_from_channel left_channel]) + .includes(%i[chat_channel user]) + .order("chat_channel_memberships.updated_at DESC") else [] end @@ -183,10 +183,10 @@ class ChatChannelsController < ApplicationController def render_pending_json_response @chat_channels_memberships = if current_user - current_user. - chat_channel_memberships.includes(:chat_channel). - where(status: "pending"). - order("chat_channel_memberships.updated_at DESC") + current_user + .chat_channel_memberships.includes(:chat_channel) + .where(status: "pending") + .order("chat_channel_memberships.updated_at DESC") else [] end @@ -194,25 +194,25 @@ class ChatChannelsController < ApplicationController end def render_unopened_ids_response - @unopened_ids = ChatChannelMembership.where(user_id: session_current_user_id).includes(:chat_channel). - where(has_unopened_messages: true).where.not(status: %w[removed_from_channel - left_channel]).pluck(:chat_channel_id) + @unopened_ids = ChatChannelMembership.where(user_id: session_current_user_id).includes(:chat_channel) + .where(has_unopened_messages: true).where.not(status: %w[removed_from_channel + left_channel]).pluck(:chat_channel_id) render json: { unopened_ids: @unopened_ids } end def render_joining_request_json_response - requested_memberships_id = current_user. - chat_channel_memberships. - includes(:chat_channel). - where(chat_channels: { discoverable: true }, role: "mod"). - pluck(:chat_channel_id). - map { |membership_id| ChatChannel.find_by(id: membership_id).requested_memberships }. - flatten. - map(&:id) + requested_memberships_id = current_user + .chat_channel_memberships + .includes(:chat_channel) + .where(chat_channels: { discoverable: true }, role: "mod") + .pluck(:chat_channel_id) + .map { |membership_id| ChatChannel.find_by(id: membership_id).requested_memberships } + .flatten + .map(&:id) - @chat_channels_memberships = ChatChannelMembership. - includes(%i[user chat_channel]). - where(id: requested_memberships_id) + @chat_channels_memberships = ChatChannelMembership + .includes(%i[user chat_channel]) + .where(id: requested_memberships_id) render "index.json" end diff --git a/app/controllers/dashboards_controller.rb b/app/controllers/dashboards_controller.rb index 1ba4e9540..0749b879b 100644 --- a/app/controllers/dashboards_controller.rb +++ b/app/controllers/dashboards_controller.rb @@ -35,28 +35,28 @@ class DashboardsController < ApplicationController end def following_tags - @followed_tags = @user.follows_by_type("ActsAsTaggableOn::Tag"). - order("points DESC").includes(:followable).limit(@follows_limit) + @followed_tags = @user.follows_by_type("ActsAsTaggableOn::Tag") + .order("points DESC").includes(:followable).limit(@follows_limit) end def following_users - @follows = @user.follows_by_type("User"). - order("created_at DESC").includes(:followable).limit(@follows_limit) + @follows = @user.follows_by_type("User") + .order("created_at DESC").includes(:followable).limit(@follows_limit) end def following_organizations - @followed_organizations = @user.follows_by_type("Organization"). - order("created_at DESC").includes(:followable).limit(@follows_limit) + @followed_organizations = @user.follows_by_type("Organization") + .order("created_at DESC").includes(:followable).limit(@follows_limit) end def following_podcasts - @followed_podcasts = @user.follows_by_type("Podcast"). - order("created_at DESC").includes(:followable).limit(@follows_limit) + @followed_podcasts = @user.follows_by_type("Podcast") + .order("created_at DESC").includes(:followable).limit(@follows_limit) end def followers - @follows = Follow.followable_user(@user.id). - includes(:follower).order("created_at DESC").limit(@follows_limit) + @follows = Follow.followable_user(@user.id) + .includes(:follower).order("created_at DESC").limit(@follows_limit) end def pro @@ -73,8 +73,8 @@ class DashboardsController < ApplicationController def subscriptions authorize @source - @subscriptions = @source.user_subscriptions. - includes(:subscriber).order(created_at: :desc).page(params[:page]).per(100) + @subscriptions = @source.user_subscriptions + .includes(:subscriber).order(created_at: :desc).page(params[:page]).per(100) end private diff --git a/app/controllers/followings_controller.rb b/app/controllers/followings_controller.rb index 04ba1da71..03dcc2b05 100644 --- a/app/controllers/followings_controller.rb +++ b/app/controllers/followings_controller.rb @@ -6,30 +6,30 @@ class FollowingsController < ApplicationController TAGS_ATTRIBUTES_FOR_SERIALIZATION = [*ATTRIBUTES_FOR_SERIALIZATION, :points].freeze def users - relation = current_user.follows_by_type("User"). - select(ATTRIBUTES_FOR_SERIALIZATION). - order(created_at: :desc) + relation = current_user.follows_by_type("User") + .select(ATTRIBUTES_FOR_SERIALIZATION) + .order(created_at: :desc) @follows = load_follows_and_paginate(relation) end def tags - relation = current_user.follows_by_type("ActsAsTaggableOn::Tag"). - select(TAGS_ATTRIBUTES_FOR_SERIALIZATION). - order(points: :desc) + relation = current_user.follows_by_type("ActsAsTaggableOn::Tag") + .select(TAGS_ATTRIBUTES_FOR_SERIALIZATION) + .order(points: :desc) @followed_tags = load_follows_and_paginate(relation) end def organizations - relation = current_user.follows_by_type("Organization"). - select(ATTRIBUTES_FOR_SERIALIZATION). - order(created_at: :desc) + relation = current_user.follows_by_type("Organization") + .select(ATTRIBUTES_FOR_SERIALIZATION) + .order(created_at: :desc) @followed_organizations = load_follows_and_paginate(relation) end def podcasts - relation = current_user.follows_by_type("Podcast"). - select(ATTRIBUTES_FOR_SERIALIZATION). - order(created_at: :desc) + relation = current_user.follows_by_type("Podcast") + .select(ATTRIBUTES_FOR_SERIALIZATION) + .order(created_at: :desc) @followed_podcasts = load_follows_and_paginate(relation) end diff --git a/app/controllers/internal/articles_controller.rb b/app/controllers/internal/articles_controller.rb index 555d74dea..f990e5a20 100644 --- a/app/controllers/internal/articles_controller.rb +++ b/app/controllers/internal/articles_controller.rb @@ -52,70 +52,70 @@ module Internal private def articles_not_buffered(days_ago) - Article.published. - where(last_buffered: nil). - where("published_at > ? OR crossposted_at > ?", days_ago.days.ago, days_ago.days.ago). - includes(:user). - limited_columns_internal_select. - order("public_reactions_count DESC"). - page(params[:page]). - per(50) + Article.published + .where(last_buffered: nil) + .where("published_at > ? OR crossposted_at > ?", days_ago.days.ago, days_ago.days.ago) + .includes(:user) + .limited_columns_internal_select + .order("public_reactions_count DESC") + .page(params[:page]) + .per(50) end def articles_top(months_ago) - Article.published. - where("published_at > ?", months_ago). - includes(user: [:notes]). - limited_columns_internal_select. - order("public_reactions_count DESC"). - page(params[:page]). - per(50) + Article.published + .where("published_at > ?", months_ago) + .includes(user: [:notes]) + .limited_columns_internal_select + .order("public_reactions_count DESC") + .page(params[:page]) + .per(50) end def articles_satellite - Article.published.where(last_buffered: nil). - includes(:user, :buffer_updates). - tagged_with(Tag.bufferized_tags, any: true). - limited_columns_internal_select. - order("hotness_score DESC"). - page(params[:page]). - per(60) + Article.published.where(last_buffered: nil) + .includes(:user, :buffer_updates) + .tagged_with(Tag.bufferized_tags, any: true) + .limited_columns_internal_select + .order("hotness_score DESC") + .page(params[:page]) + .per(60) end def articles_boosted_additional - Article.boosted_via_additional_articles. - includes(:user, :buffer_updates). - limited_columns_internal_select. - order("published_at DESC"). - page(params[:page]). - per(100) + Article.boosted_via_additional_articles + .includes(:user, :buffer_updates) + .limited_columns_internal_select + .order("published_at DESC") + .page(params[:page]) + .per(100) end def articles_chronological - Article.published. - includes(user: [:notes]). - limited_columns_internal_select. - order("published_at DESC"). - page(params[:page]). - per(50) + Article.published + .includes(user: [:notes]) + .limited_columns_internal_select + .order("published_at DESC") + .page(params[:page]) + .per(50) end def articles_mixed - Article.published. - includes(user: [:notes]). - limited_columns_internal_select. - order("hotness_score DESC"). - page(params[:page]). - per(30) + Article.published + .includes(user: [:notes]) + .limited_columns_internal_select + .order("hotness_score DESC") + .page(params[:page]) + .per(30) end def articles_featured - Article.published.or(Article.where(published_from_feed: true)). - where(featured: true). - where("featured_number > ?", Time.current.to_i). - includes(:user, :buffer_updates). - limited_columns_internal_select. - order("featured_number DESC") + Article.published.or(Article.where(published_from_feed: true)) + .where(featured: true) + .where("featured_number > ?", Time.current.to_i) + .includes(:user, :buffer_updates) + .limited_columns_internal_select + .order("featured_number DESC") end def article_params diff --git a/app/controllers/internal/comments_controller.rb b/app/controllers/internal/comments_controller.rb index ececd7569..1a2d7cb5f 100644 --- a/app/controllers/internal/comments_controller.rb +++ b/app/controllers/internal/comments_controller.rb @@ -4,18 +4,18 @@ module Internal def index @comments = if params[:state]&.start_with?("toplast-") - Comment. - includes(:user). - includes(:commentable). - order("public_reactions_count DESC"). - where("created_at > ?", params[:state].split("-").last.to_i.days.ago). - page(params[:page] || 1).per(50) + Comment + .includes(:user) + .includes(:commentable) + .order("public_reactions_count DESC") + .where("created_at > ?", params[:state].split("-").last.to_i.days.ago) + .page(params[:page] || 1).per(50) else - Comment. - includes(:user). - includes(:commentable). - order("created_at DESC"). - page(params[:page] || 1).per(50) + Comment + .includes(:user) + .includes(:commentable) + .order("created_at DESC") + .page(params[:page] || 1).per(50) end end diff --git a/app/controllers/internal/feedback_messages_controller.rb b/app/controllers/internal/feedback_messages_controller.rb index d57dc1b97..8f9a8c6c2 100644 --- a/app/controllers/internal/feedback_messages_controller.rb +++ b/app/controllers/internal/feedback_messages_controller.rb @@ -3,29 +3,29 @@ module Internal layout "internal" def index - @q = FeedbackMessage.includes(:reporter, :offender, :affected). - order(created_at: :desc). - ransack(params[:q]) + @q = FeedbackMessage.includes(:reporter, :offender, :affected) + .order(created_at: :desc) + .ransack(params[:q]) @feedback_messages = @q.result.page(params[:page] || 1).per(5) @feedback_type = params[:state] || "abuse-reports" @status = params[:status] || "Open" @email_messages = EmailMessage.find_for_reports(@feedback_messages) - @new_articles = Article.published.select(:title, :user_id, :path).includes(:user). - order(created_at: :desc). - where("score > ? AND score < ?", -10, 8). - limit(120) + @new_articles = Article.published.select(:title, :user_id, :path).includes(:user) + .order(created_at: :desc) + .where("score > ? AND score < ?", -10, 8) + .limit(120) @possible_spam_users = User.registered.where( "github_created_at > ? OR twitter_created_at > ? OR length(name) > ?", 50.hours.ago, 50.hours.ago, 30 - ). - where("created_at > ?", 48.hours.ago). - order(created_at: :desc). - select(:username, :name, :id). - where.not("username LIKE ?", "%spam_%"). - limit(150) + ) + .where("created_at > ?", 48.hours.ago) + .order(created_at: :desc) + .select(:username, :name, :id) + .where.not("username LIKE ?", "%spam_%") + .limit(150) @vomits = get_vomits end @@ -81,9 +81,9 @@ module Internal private def get_vomits - q = Reaction.includes(:user, :reactable). - select(:id, :user_id, :reactable_type, :reactable_id). - order(updated_at: :desc) + q = Reaction.includes(:user, :reactable) + .select(:id, :user_id, :reactable_type, :reactable_id) + .order(updated_at: :desc) if params[:status] == "Open" || params[:status].blank? q.where(category: "vomit", status: "valid") elsif params[:status] == "Resolved" diff --git a/app/controllers/internal/listings_controller.rb b/app/controllers/internal/listings_controller.rb index b79feb72f..c9c8a62e5 100644 --- a/app/controllers/internal/listings_controller.rb +++ b/app/controllers/internal/listings_controller.rb @@ -8,8 +8,8 @@ module Internal def index @listings = - Listing.includes(%i[user listing_category]). - page(params[:page]).order("bumped_at DESC").per(50) + Listing.includes(%i[user listing_category]) + .page(params[:page]).order("bumped_at DESC").per(50) @listings = @listings.published unless include_unpublished? @listings = @listings.in_category(params[:filter]) if params[:filter].present? diff --git a/app/controllers/internal/moderator_actions_controller.rb b/app/controllers/internal/moderator_actions_controller.rb index 9bf79b663..8b2323a51 100644 --- a/app/controllers/internal/moderator_actions_controller.rb +++ b/app/controllers/internal/moderator_actions_controller.rb @@ -3,11 +3,11 @@ module Internal layout "internal" def index - @q = AuditLog. - includes(:user). - where(category: "moderator.audit.log"). - order(created_at: :desc). - ransack(params[:q]) + @q = AuditLog + .includes(:user) + .where(category: "moderator.audit.log") + .order(created_at: :desc) + .ransack(params[:q]) @moderator_actions = @q.result.page(params[:page] || 1).per(25) end end diff --git a/app/controllers/internal/permissions_controller.rb b/app/controllers/internal/permissions_controller.rb index 9b9367584..8407a9e52 100644 --- a/app/controllers/internal/permissions_controller.rb +++ b/app/controllers/internal/permissions_controller.rb @@ -3,11 +3,11 @@ module Internal layout "internal" def index - @users = User.with_role(:admin). - union(User.with_role(:super_admin)). - union(User.with_role(:single_resource_admin, :any)). - page(params[:page]). - per(50) + @users = User.with_role(:admin) + .union(User.with_role(:super_admin)) + .union(User.with_role(:single_resource_admin, :any)) + .page(params[:page]) + .per(50) end end end diff --git a/app/controllers/internal/podcasts_controller.rb b/app/controllers/internal/podcasts_controller.rb index ae2dd5354..942ebe7c3 100644 --- a/app/controllers/internal/podcasts_controller.rb +++ b/app/controllers/internal/podcasts_controller.rb @@ -6,10 +6,10 @@ module Internal before_action :find_user, only: %i[remove_admin add_admin] def index - @podcasts = Podcast.left_outer_joins(:podcast_episodes). - select("podcasts.*, count(podcast_episodes) as episodes_count"). - group("podcasts.id").order("podcasts.created_at DESC"). - page(params[:page]).per(50) + @podcasts = Podcast.left_outer_joins(:podcast_episodes) + .select("podcasts.*, count(podcast_episodes) as episodes_count") + .group("podcasts.id").order("podcasts.created_at DESC") + .page(params[:page]).per(50) return if params[:search].blank? diff --git a/app/controllers/internal/privileged_reactions_controller.rb b/app/controllers/internal/privileged_reactions_controller.rb index 09ba37614..2906d2b8e 100644 --- a/app/controllers/internal/privileged_reactions_controller.rb +++ b/app/controllers/internal/privileged_reactions_controller.rb @@ -5,12 +5,12 @@ module Internal PRIVILEGED_REACTION_CATEGORIES = %i[thumbsup thumbsdown vomit].freeze def index - @q = Reaction. - includes(:user, - :reactable). - where("category IN (?)", PRIVILEGED_REACTION_CATEGORIES). - order("reactions.created_at DESC"). - ransack(params[:q]) + @q = Reaction + .includes(:user, + :reactable) + .where("category IN (?)", PRIVILEGED_REACTION_CATEGORIES) + .order("reactions.created_at DESC") + .ransack(params[:q]) @privileged_reactions = @q.result.page(params[:page] || 1).per(25) end end diff --git a/app/controllers/internal/users_controller.rb b/app/controllers/internal/users_controller.rb index acfe76eb1..8f30eb027 100644 --- a/app/controllers/internal/users_controller.rb +++ b/app/controllers/internal/users_controller.rb @@ -21,13 +21,13 @@ module Internal @user = User.find(params[:id]) @organizations = @user.organizations.order(:name) @notes = @user.notes.order(created_at: :desc).limit(10) - @organization_memberships = @user.organization_memberships. - joins(:organization). - order("organizations.name ASC"). - includes(:organization) - @last_email_verification_date = @user.email_authorizations. - where.not(verified_at: nil). - order("created_at DESC").first&.verified_at || "Never" + @organization_memberships = @user.organization_memberships + .joins(:organization) + .order("organizations.name ASC") + .includes(:organization) + @last_email_verification_date = @user.email_authorizations + .where.not(verified_at: nil) + .order("created_at DESC").first&.verified_at || "Never" end def update diff --git a/app/controllers/internal/webhook_endpoints_controller.rb b/app/controllers/internal/webhook_endpoints_controller.rb index 5be28045c..5e806f2b5 100644 --- a/app/controllers/internal/webhook_endpoints_controller.rb +++ b/app/controllers/internal/webhook_endpoints_controller.rb @@ -3,9 +3,9 @@ module Internal layout "internal" def index - @endpoints = Webhook::Endpoint.includes(:user). - page(params[:page]).per(50). - order("created_at desc") + @endpoints = Webhook::Endpoint.includes(:user) + .page(params[:page]).per(50) + .order("created_at desc") end end end diff --git a/app/controllers/listings_controller.rb b/app/controllers/listings_controller.rb index df000e03a..3157533dc 100644 --- a/app/controllers/listings_controller.rb +++ b/app/controllers/listings_controller.rb @@ -38,10 +38,10 @@ class ListingsController < ApplicationController @listings = if params[:category].blank? - published_listings. - order("bumped_at DESC"). - includes(:user, :organization, :taggings). - limit(12) + published_listings + .order("bumped_at DESC") + .includes(:user, :organization, :taggings) + .limit(12) else Listing.none end @@ -74,13 +74,13 @@ class ListingsController < ApplicationController end def dashboard - listings = current_user.listings. - includes(:organization, :taggings) + listings = current_user.listings + .includes(:organization, :taggings) @listings_json = listings.to_json(DASHBOARD_JSON_OPTIONS) - organizations_ids = current_user.organization_memberships. - where(type_of_user: "admin"). - pluck(:organization_id) + organizations_ids = current_user.organization_memberships + .where(type_of_user: "admin") + .pluck(:organization_id) orgs = Organization.where(id: organizations_ids) @orgs_json = orgs.to_json(only: %i[id name slug unspent_credits_count]) org_listings = Listing.where(organization_id: organizations_ids) diff --git a/app/controllers/moderations_controller.rb b/app/controllers/moderations_controller.rb index 0f68e4e6a..921d5cc21 100644 --- a/app/controllers/moderations_controller.rb +++ b/app/controllers/moderations_controller.rb @@ -12,9 +12,9 @@ class ModerationsController < ApplicationController skip_authorization return unless current_user&.trusted - articles = Article.published. - where("score > -5 AND score < 5"). - order("published_at DESC").limit(70) + articles = Article.published + .where("score > -5 AND score < 5") + .order("published_at DESC").limit(70) articles = articles.cached_tagged_with(params[:tag]) if params[:tag].present? if params[:state] == "new-authors" articles = articles.where("nth_published_by_author > 0 AND nth_published_by_author < 4 AND published_at > ?", diff --git a/app/controllers/notification_subscriptions_controller.rb b/app/controllers/notification_subscriptions_controller.rb index e2c804b01..83582322e 100644 --- a/app/controllers/notification_subscriptions_controller.rb +++ b/app/controllers/notification_subscriptions_controller.rb @@ -2,8 +2,8 @@ class NotificationSubscriptionsController < ApplicationController def show result = if current_user NotificationSubscription.where(user_id: current_user.id, notifiable_id: params[:notifiable_id], - notifiable_type: params[:notifiable_type]). - first&.to_json(only: %i[config]) || { config: "not_subscribed" } + notifiable_type: params[:notifiable_type]) + .first&.to_json(only: %i[config]) || { config: "not_subscribed" } end respond_to do |format| format.json { render json: result } diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index 7649c3917..c040571e2 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -87,8 +87,8 @@ class OrganizationsController < ApplicationController end def organization_params - params.require(:organization).permit(permitted_params). - transform_values do |value| + params.require(:organization).permit(permitted_params) + .transform_values do |value| if value.class.name == "String" ActionController::Base.helpers.strip_tags(value) else diff --git a/app/controllers/page_views_controller.rb b/app/controllers/page_views_controller.rb index 19f8e1b2c..c2350db04 100644 --- a/app/controllers/page_views_controller.rb +++ b/app/controllers/page_views_controller.rb @@ -56,12 +56,12 @@ class PageViewsController < ApplicationMetalController organic_count) end - organic_count_past_week_count = page_views_from_google_com. - where("created_at > ?", 1.week.ago).sum(:counts_for_number_of_views) + organic_count_past_week_count = page_views_from_google_com + .where("created_at > ?", 1.week.ago).sum(:counts_for_number_of_views) @article.update_column(:organic_page_views_past_week_count, organic_count_past_week_count) - organic_count_past_month_count = page_views_from_google_com. - where("created_at > ?", 1.month.ago).sum(:counts_for_number_of_views) + organic_count_past_month_count = page_views_from_google_com + .where("created_at > ?", 1.month.ago).sum(:counts_for_number_of_views) @article.update_column(:organic_page_views_past_month_count, organic_count_past_month_count) end end diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index 26c424065..bb2a64508 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -94,11 +94,11 @@ class PagesController < ApplicationController def checkin daily_thread = - Article. - published. - where(user: User.find_by(username: "codenewbiestaff")). - order("articles.published_at" => :desc). - first + Article + .published + .where(user: User.find_by(username: "codenewbiestaff")) + .order("articles.published_at" => :desc) + .first if daily_thread redirect_to daily_thread.path diff --git a/app/controllers/podcast_episodes_controller.rb b/app/controllers/podcast_episodes_controller.rb index da0426df0..ddf5c7abf 100644 --- a/app/controllers/podcast_episodes_controller.rb +++ b/app/controllers/podcast_episodes_controller.rb @@ -6,9 +6,9 @@ class PodcastEpisodesController < ApplicationController @podcast_index = true @podcasts = Podcast.available.order("title asc") - @podcast_episodes = PodcastEpisodeDecorator.decorate_collection(PodcastEpisode. - available. - includes(:podcast).order("published_at desc").first(20)) + @podcast_episodes = PodcastEpisodeDecorator.decorate_collection(PodcastEpisode + .available + .includes(:podcast).order("published_at desc").first(20)) if params[:q].blank? surrogate_keys = ["podcast_episodes_all"] + @podcast_episodes.map(&:record_key) diff --git a/app/controllers/reactions_controller.rb b/app/controllers/reactions_controller.rb index 3ba7cba2a..e73e86545 100644 --- a/app/controllers/reactions_controller.rb +++ b/app/controllers/reactions_controller.rb @@ -13,8 +13,8 @@ class ReactionsController < ApplicationController id = params[:article_id] reactions = if session_current_user_id - Reaction.public_category. - where( + Reaction.public_category + .where( reactable_id: id, reactable_type: "Article", user_id: session_current_user_id, @@ -25,9 +25,9 @@ class ReactionsController < ApplicationController result = { article_reaction_counts: Reaction.count_for_article(id) } else - comments = Comment. - where(commentable_id: params[:commentable_id], commentable_type: params[:commentable_type]). - select(%i[id public_reactions_count]) + comments = Comment + .where(commentable_id: params[:commentable_id], commentable_type: params[:commentable_type]) + .select(%i[id public_reactions_count]) reaction_counts = comments.map do |comment| { id: comment.id, count: comment.public_reactions_count } diff --git a/app/controllers/sitemaps_controller.rb b/app/controllers/sitemaps_controller.rb index 578696693..612394a4a 100644 --- a/app/controllers/sitemaps_controller.rb +++ b/app/controllers/sitemaps_controller.rb @@ -12,9 +12,9 @@ class SitemapsController < ApplicationController not_found end - @articles = Article.published. - where("published_at > ? AND published_at < ? AND score > ?", date, date.end_of_month, 3). - pluck(:path, :last_comment_at) + @articles = Article.published + .where("published_at > ? AND published_at < ? AND score > ?", date, date.end_of_month, 3) + .pluck(:path, :last_comment_at) set_surrogate_controls(date) set_cache_control_headers(@max_age, diff --git a/app/controllers/social_previews_controller.rb b/app/controllers/social_previews_controller.rb index 2324ede0b..ae715bbd8 100644 --- a/app/controllers/social_previews_controller.rb +++ b/app/controllers/social_previews_controller.rb @@ -8,10 +8,10 @@ class SocialPreviewsController < ApplicationController @tag_badges = Badge.where(id: Tag.where(name: @article.decorate.cached_tag_list_array).pluck(:badge_id)) not_found unless @article.published - template = @article.tags. - where.not(social_preview_template: nil). - where.not(social_preview_template: "article"). - select(:social_preview_template).first&.social_preview_template + template = @article.tags + .where.not(social_preview_template: nil) + .where.not(social_preview_template: "article") + .select(:social_preview_template).first&.social_preview_template # make sure that the template exists template = "article" unless Tag.social_preview_templates.include?(template) diff --git a/app/controllers/stories_controller.rb b/app/controllers/stories_controller.rb index e96588f71..7b6764799 100644 --- a/app/controllers/stories_controller.rb +++ b/app/controllers/stories_controller.rb @@ -63,15 +63,15 @@ class StoriesController < ApplicationController def assign_hero_html return if SiteConfig.campaign_hero_html_variant_name.blank? - @hero_area = HtmlVariant.relevant.select(:name, :html). - find_by(group: "campaign", name: SiteConfig.campaign_hero_html_variant_name) + @hero_area = HtmlVariant.relevant.select(:name, :html) + .find_by(group: "campaign", name: SiteConfig.campaign_hero_html_variant_name) @hero_html = @hero_area&.html end def get_latest_campaign_articles - campaign_articles_scope = Article.tagged_with(SiteConfig.campaign_featured_tags, any: true). - where("published_at > ? AND score > ?", 4.weeks.ago, 0). - order("hotness_score DESC") + campaign_articles_scope = Article.tagged_with(SiteConfig.campaign_featured_tags, any: true) + .where("published_at > ? AND score > ?", 4.weeks.ago, 0) + .order("hotness_score DESC") requires_approval = SiteConfig.campaign_articles_require_approval? campaign_articles_scope = campaign_articles_scope.where(approved: true) if requires_approval @@ -143,8 +143,8 @@ class StoriesController < ApplicationController cached_tagged_count end @number_of_articles = user_signed_in? ? 5 : SIGNED_OUT_RECORD_COUNT - @stories = Articles::Feed.new(number_of_articles: @number_of_articles, tag: @tag, page: @page). - published_articles_by_tag + @stories = Articles::Feed.new(number_of_articles: @number_of_articles, tag: @tag, page: @page) + .published_articles_by_tag @stories = @stories.where(approved: true) if @tag_model&.requires_approval @@ -194,17 +194,17 @@ class StoriesController < ApplicationController def handle_podcast_index @podcast_index = true @list_of = "podcast-episodes" - @podcast_episodes = @podcast.podcast_episodes. - reachable.order("published_at DESC").limit(30).decorate + @podcast_episodes = @podcast.podcast_episodes + .reachable.order("published_at DESC").limit(30).decorate set_surrogate_key_header "podcast_episodes" render template: "podcast_episodes/index" end def handle_organization_index @user = @organization - @stories = ArticleDecorator.decorate_collection(@organization.articles.published. - limited_column_select. - order("published_at DESC").page(@page).per(8)) + @stories = ArticleDecorator.decorate_collection(@organization.articles.published + .limited_column_select + .order("published_at DESC").page(@page).per(8)) @organization_article_index = true set_organization_json_ld set_surrogate_key_header "articles-org-#{@organization.id}" @@ -288,9 +288,9 @@ class StoriesController < ApplicationController # we need to make sure that articles that were cross posted after their # original publication date appear in the correct order in the collection, # considering non cross posted articles with a more recent publication date - @collection_articles = @article.collection.articles. - published. - order(Arel.sql("COALESCE(crossposted_at, published_at) ASC")) + @collection_articles = @article.collection.articles + .published + .order(Arel.sql("COALESCE(crossposted_at, published_at) ASC")) end @comments_to_show_count = @article.cached_tag_list_array.include?("discuss") ? 50 : 30 @@ -313,21 +313,21 @@ class StoriesController < ApplicationController def assign_user_comments comment_count = params[:view] == "comments" ? 250 : 8 @comments = if @user.comments_count.positive? - @user.comments.where(deleted: false). - order("created_at DESC").includes(:commentable).limit(comment_count) + @user.comments.where(deleted: false) + .order("created_at DESC").includes(:commentable).limit(comment_count) else [] end end def assign_user_stories - @pinned_stories = Article.published.where(id: @user.profile_pins.select(:pinnable_id)). - limited_column_select. - order("published_at DESC").decorate - @stories = ArticleDecorator.decorate_collection(@user.articles.published. - limited_column_select. - where.not(id: @pinned_stories.pluck(:id)). - order("published_at DESC").page(@page).per(user_signed_in? ? 2 : SIGNED_OUT_RECORD_COUNT)) + @pinned_stories = Article.published.where(id: @user.profile_pins.select(:pinnable_id)) + .limited_column_select + .order("published_at DESC").decorate + @stories = ArticleDecorator.decorate_collection(@user.articles.published + .limited_column_select + .where.not(id: @pinned_stories.pluck(:id)) + .order("published_at DESC").page(@page).per(user_signed_in? ? 2 : SIGNED_OUT_RECORD_COUNT)) end def assign_user_github_repositories @@ -336,8 +336,8 @@ class StoriesController < ApplicationController def stories_by_timeframe if %w[week month year infinity].include?(params[:timeframe]) - @stories.where("published_at > ?", Timeframer.new(params[:timeframe]).datetime). - order("public_reactions_count DESC") + @stories.where("published_at > ?", Timeframer.new(params[:timeframe]).datetime) + .order("public_reactions_count DESC") elsif params[:timeframe] == "latest" @stories.where("score > ?", -20).order("published_at DESC") else @@ -349,11 +349,11 @@ class StoriesController < ApplicationController return unless user_signed_in? num_hours = Rails.env.production? ? 24 : 2400 - @podcast_episodes = PodcastEpisode. - includes(:podcast). - order("published_at desc"). - where("published_at > ?", num_hours.hours.ago). - select(:slug, :title, :podcast_id, :image) + @podcast_episodes = PodcastEpisode + .includes(:podcast) + .order("published_at desc") + .where("published_at > ?", num_hours.hours.ago) + .select(:slug, :title, :podcast_id, :image) end def assign_listings diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index af196f2eb..d7759ee8c 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -37,8 +37,8 @@ class TagsController < ApplicationController def onboarding skip_authorization - @tags = Tag.where(name: SiteConfig.suggested_tags). - select(ATTRIBUTES_FOR_SERIALIZATION) + @tags = Tag.where(name: SiteConfig.suggested_tags) + .select(ATTRIBUTES_FOR_SERIALIZATION) set_surrogate_key_header Tag.table_key, @tags.map(&:record_key) end diff --git a/app/controllers/videos_controller.rb b/app/controllers/videos_controller.rb index 9e76e68f1..2816c0b1c 100644 --- a/app/controllers/videos_controller.rb +++ b/app/controllers/videos_controller.rb @@ -6,11 +6,11 @@ class VideosController < ApplicationController def new; end def index - @video_articles = Article.with_video. - includes([:user]). - select(:id, :video, :path, :title, :video_thumbnail_url, :user_id, :video_duration_in_seconds). - order("hotness_score DESC"). - page(params[:page].to_i).per(24) + @video_articles = Article.with_video + .includes([:user]) + .select(:id, :video, :path, :title, :video_thumbnail_url, :user_id, :video_duration_in_seconds) + .order("hotness_score DESC") + .page(params[:page].to_i).per(24) set_surrogate_key_header "videos", Article.table_key, @video_articles.map(&:record_key) end diff --git a/app/labor/article_suggester.rb b/app/labor/article_suggester.rb index cd79eec17..aedc60237 100644 --- a/app/labor/article_suggester.rb +++ b/app/labor/article_suggester.rb @@ -28,21 +28,21 @@ class ArticleSuggester def other_suggestions(max: 4, ids_to_ignore: []) ids_to_ignore << article.id - Article.published. - where.not(id: ids_to_ignore). - where.not(user_id: article.user_id). - order("hotness_score DESC"). - offset(rand(0..offset)). - first(max) + Article.published + .where.not(id: ids_to_ignore) + .where.not(user_id: article.user_id) + .order("hotness_score DESC") + .offset(rand(0..offset)) + .first(max) end def suggestions_by_tag(max: 4) - Article.published.tagged_with(cached_tag_list_array, any: true). - where.not(user_id: article.user_id). - where("organic_page_views_past_month_count > 5"). - order("hotness_score DESC"). - offset(rand(0..offset)). - first(max) + Article.published.tagged_with(cached_tag_list_array, any: true) + .where.not(user_id: article.user_id) + .where("organic_page_views_past_month_count > 5") + .order("hotness_score DESC") + .offset(rand(0..offset)) + .first(max) end def offset diff --git a/app/labor/assign_tag_moderator.rb b/app/labor/assign_tag_moderator.rb index 23674d024..f47ad5368 100644 --- a/app/labor/assign_tag_moderator.rb +++ b/app/labor/assign_tag_moderator.rb @@ -18,9 +18,9 @@ module AssignTagModerator add_trusted_role(user) add_to_chat_channels(user, tag) - NotifyMailer.with(user: user, tag: tag, channel_slug: chat_channel_slug(tag)). - tag_moderator_confirmation_email. - deliver_now + NotifyMailer.with(user: user, tag: tag, channel_slug: chat_channel_slug(tag)) + .tag_moderator_confirmation_email + .deliver_now end end diff --git a/app/labor/badge_rewarder.rb b/app/labor/badge_rewarder.rb index c2b9fc9dc..4efb3a696 100644 --- a/app/labor/badge_rewarder.rb +++ b/app/labor/badge_rewarder.rb @@ -53,12 +53,12 @@ module BadgeRewarder def self.award_tag_badges Tag.where.not(badge_id: nil).find_each do |tag| past_winner_user_ids = BadgeAchievement.where(badge_id: tag.badge_id).pluck(:user_id) - winning_article = Article.where("score > 100"). - published. - where.not(user_id: past_winner_user_ids). - order(score: :desc). - where("published_at > ?", 7.5.days.ago). # More than seven days, to have some wiggle room. - cached_tagged_with(tag).first + winning_article = Article.where("score > 100") + .published + .where.not(user_id: past_winner_user_ids) + .order(score: :desc) + .where("published_at > ?", 7.5.days.ago) # More than seven days, to have some wiggle room. + .cached_tagged_with(tag).first if winning_article award_badges( [winning_article.user.username], @@ -89,9 +89,9 @@ module BadgeRewarder def self.award_streak_badge(num_weeks) # No credit for super low quality - article_user_ids = Article.published. - where("published_at > ? AND score > ?", 1.week.ago, MINIMUM_QUALITY). - pluck(:user_id) + article_user_ids = Article.published + .where("published_at > ? AND score > ?", 1.week.ago, MINIMUM_QUALITY) + .pluck(:user_id) message = if num_weeks == LONGEST_STREAK_WEEKS LONGEST_STREAK_MESSAGE else diff --git a/app/labor/cache_buster.rb b/app/labor/cache_buster.rb index abdf29163..41bd93d59 100644 --- a/app/labor/cache_buster.rb +++ b/app/labor/cache_buster.rb @@ -76,8 +76,8 @@ module CacheBuster bust("/videos?i=i") end TIMEFRAMES.each do |timestamp, interval| - if Article.published.where("published_at > ?", timestamp). - order("public_reactions_count DESC").limit(3).pluck(:id).include?(article.id) + if Article.published.where("published_at > ?", timestamp) + .order("public_reactions_count DESC").limit(3).pluck(:id).include?(article.id) bust("/top/#{interval}") bust("/top/#{interval}?i=i") bust("/top/#{interval}/?i=i") @@ -99,8 +99,8 @@ module CacheBuster bust("/t/#{tag}/latest?i=i") end TIMEFRAMES.each do |timestamp, interval| - if Article.published.where("published_at > ?", timestamp).tagged_with(tag). - order("public_reactions_count DESC").limit(3).pluck(:id).include?(article.id) + if Article.published.where("published_at > ?", timestamp).tagged_with(tag) + .order("public_reactions_count DESC").limit(3).pluck(:id).include?(article.id) bust("/top/#{interval}") bust("/top/#{interval}?i=i") bust("/top/#{interval}/?i=i") @@ -110,8 +110,8 @@ module CacheBuster end end if rand(2) == 1 && - Article.published.tagged_with(tag). - order("hotness_score DESC").limit(2).pluck(:id).include?(article.id) + Article.published.tagged_with(tag) + .order("hotness_score DESC").limit(2).pluck(:id).include?(article.id) bust("/t/#{tag}") bust("/t/#{tag}?i=i") end diff --git a/app/labor/email_logic.rb b/app/labor/email_logic.rb index 557aff0ad..86b652136 100644 --- a/app/labor/email_logic.rb +++ b/app/labor/email_logic.rb @@ -33,23 +33,23 @@ class EmailLogic experience_level_rating_min = experience_level_rating - 3.6 experience_level_rating_max = experience_level_rating + 3.6 - @user.followed_articles. - where("published_at > ?", fresh_date). - where(published: true, email_digest_eligible: true). - where.not(user_id: @user.id). - where("score > ?", 12). - where("experience_level_rating > ? AND experience_level_rating < ?", - experience_level_rating_min, experience_level_rating_max). - order("score DESC"). - limit(8) + @user.followed_articles + .where("published_at > ?", fresh_date) + .where(published: true, email_digest_eligible: true) + .where.not(user_id: @user.id) + .where("score > ?", 12) + .where("experience_level_rating > ? AND experience_level_rating < ?", + experience_level_rating_min, experience_level_rating_max) + .order("score DESC") + .limit(8) else - Article.published. - where("published_at > ?", fresh_date). - where(featured: true, email_digest_eligible: true). - where.not(user_id: @user.id). - where("score > ?", 25). - order("score DESC"). - limit(8) + Article.published + .where("published_at > ?", fresh_date) + .where(featured: true, email_digest_eligible: true) + .where.not(user_id: @user.id) + .where("score > ?", 25) + .order("score DESC") + .limit(8) end @ready_to_receive_email = false if articles.length < 3 diff --git a/app/labor/reading_list.rb b/app/labor/reading_list.rb index c20696179..978ed0902 100644 --- a/app/labor/reading_list.rb +++ b/app/labor/reading_list.rb @@ -6,11 +6,11 @@ class ReadingList end def get - Article. - joins(:reactions). - includes(:user). - where(reactions: reaction_criteria). - order("reactions.created_at DESC") + Article + .joins(:reactions) + .includes(:user) + .where(reactions: reaction_criteria) + .order("reactions.created_at DESC") end def cached_ids_of_articles diff --git a/app/labor/sticky_article_collection.rb b/app/labor/sticky_article_collection.rb index ea2b42dea..990e77be0 100644 --- a/app/labor/sticky_article_collection.rb +++ b/app/labor/sticky_article_collection.rb @@ -9,11 +9,11 @@ class StickyArticleCollection end def user_stickies - author.articles.published. - limited_column_select. - tagged_with(article_tags, any: true). - where.not(id: article.id).order("published_at DESC"). - limit(3) + author.articles.published + .limited_column_select + .tagged_with(article_tags, any: true) + .where.not(id: article.id).order("published_at DESC") + .limit(3) end def suggested_stickies @@ -21,25 +21,25 @@ class StickyArticleCollection end def tag_articles - @tag_articles ||= Article.published.tagged_with(article_tags, any: true). - includes(:user). - where("public_reactions_count > ? OR comments_count > ?", reaction_count_num, comment_count_num). - where.not(id: article.id).where.not(user_id: article.user_id). - where("featured_number > ?", 5.days.ago.to_i). - order(Arel.sql("RANDOM()")). - limit(3) + @tag_articles ||= Article.published.tagged_with(article_tags, any: true) + .includes(:user) + .where("public_reactions_count > ? OR comments_count > ?", reaction_count_num, comment_count_num) + .where.not(id: article.id).where.not(user_id: article.user_id) + .where("featured_number > ?", 5.days.ago.to_i) + .order(Arel.sql("RANDOM()")) + .limit(3) end def more_articles return [] if tag_articles.size > 6 - Article.published.tagged_with(%w[career productivity discuss explainlikeimfive], any: true). - includes(:user). - where("comments_count > ?", comment_count_num). - where.not(id: article.id).where.not(user_id: article.user_id). - where("featured_number > ?", 5.days.ago.to_i). - order(Arel.sql("RANDOM()")). - limit(10 - tag_articles.size) + Article.published.tagged_with(%w[career productivity discuss explainlikeimfive], any: true) + .includes(:user) + .where("comments_count > ?", comment_count_num) + .where.not(id: article.id).where.not(user_id: article.user_id) + .where("featured_number > ?", 5.days.ago.to_i) + .order(Arel.sql("RANDOM()")) + .limit(10 - tag_articles.size) end def article_tags diff --git a/app/liquid_tags/codepen_tag.rb b/app/liquid_tags/codepen_tag.rb index 469043534..a4b98ef8d 100644 --- a/app/liquid_tags/codepen_tag.rb +++ b/app/liquid_tags/codepen_tag.rb @@ -1,8 +1,8 @@ class CodepenTag < LiquidTagBase PARTIAL = "liquids/codepen".freeze URL_REGEXP = - /\A(http|https):\/\/(codepen\.io|codepen\.io\/team)\/[a-zA-Z0-9_\-]{1,30}\/pen\/([a-zA-Z]{5,7})\/{0,1}\z/. - freeze + /\A(http|https):\/\/(codepen\.io|codepen\.io\/team)\/[a-zA-Z0-9_\-]{1,30}\/pen\/([a-zA-Z]{5,7})\/{0,1}\z/ + .freeze def initialize(_tag_name, link, _parse_context) super diff --git a/app/liquid_tags/codesandbox_tag.rb b/app/liquid_tags/codesandbox_tag.rb index dabe5889e..b2985d6b6 100644 --- a/app/liquid_tags/codesandbox_tag.rb +++ b/app/liquid_tags/codesandbox_tag.rb @@ -4,8 +4,8 @@ class CodesandboxTag < LiquidTagBase /\A(initialpath=([a-zA-Z0-9\-_\/.@%])+)\Z| \A(module=([a-zA-Z0-9\-_\/.@%])+)\Z| \A(runonclick=((0|1){1}))\Z| - \Aview=(editor|split|preview)\Z/x. - freeze + \Aview=(editor|split|preview)\Z/x + .freeze def initialize(_tag_name, id, _parse_context) super diff --git a/app/liquid_tags/gist_tag.rb b/app/liquid_tags/gist_tag.rb index 855906ae9..f2d11fb40 100644 --- a/app/liquid_tags/gist_tag.rb +++ b/app/liquid_tags/gist_tag.rb @@ -1,8 +1,8 @@ class GistTag < LiquidTagBase PARTIAL = "liquids/gist".freeze VALID_LINK_REGEXP = - /\Ahttps:\/\/gist\.github\.com\/([a-zA-Z0-9](-?[a-zA-Z0-9]){0,38})\/([a-zA-Z0-9]){1,32}(\/[a-zA-Z0-9]+)?\Z/. - freeze + /\Ahttps:\/\/gist\.github\.com\/([a-zA-Z0-9](-?[a-zA-Z0-9]){0,38})\/([a-zA-Z0-9]){1,32}(\/[a-zA-Z0-9]+)?\Z/ + .freeze def initialize(_tag_name, link, _parse_context) super diff --git a/app/liquid_tags/github_tag/github_readme_tag.rb b/app/liquid_tags/github_tag/github_readme_tag.rb index 50dd0750e..4bbdb2e45 100644 --- a/app/liquid_tags/github_tag/github_readme_tag.rb +++ b/app/liquid_tags/github_tag/github_readme_tag.rb @@ -67,9 +67,9 @@ class GithubTag end def sanitize_input(input) - ActionController::Base.helpers.strip_tags(input). - gsub(GITHUB_DOMAIN_REGEXP, ""). - strip + ActionController::Base.helpers.strip_tags(input) + .gsub(GITHUB_DOMAIN_REGEXP, "") + .strip end def raise_error diff --git a/app/liquid_tags/soundcloud_tag.rb b/app/liquid_tags/soundcloud_tag.rb index 851707244..3f2408da4 100644 --- a/app/liquid_tags/soundcloud_tag.rb +++ b/app/liquid_tags/soundcloud_tag.rb @@ -31,8 +31,8 @@ class SoundcloudTag < LiquidTagBase end def valid_link?(link) - (link =~ /\Ahttps:\/\/soundcloud\.com\/([a-zA-Z0-9_\-]){3,25}\/(sets\/)?([a-zA-Z0-9_\-]){3,255}\Z/)&. - zero? + (link =~ /\Ahttps:\/\/soundcloud\.com\/([a-zA-Z0-9_\-]){3,25}\/(sets\/)?([a-zA-Z0-9_\-]){3,255}\Z/) + &.zero? end def raise_error diff --git a/app/models/article.rb b/app/models/article.rb index 942a37bb1..5f7624a03 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -100,17 +100,17 @@ class Article < ApplicationRecord scope :unpublished, -> { where(published: false) } scope :admin_published_with, lambda { |tag_name| - published. - where(user_id: SiteConfig.staff_user_id). - order(published_at: :desc). - tagged_with(tag_name) + published + .where(user_id: SiteConfig.staff_user_id) + .order(published_at: :desc) + .tagged_with(tag_name) } scope :user_published_with, lambda { |user_id, tag_name| - published. - where(user_id: user_id). - order(published_at: :desc). - tagged_with(tag_name) + published + .where(user_id: user_id) + .order(published_at: :desc) + .tagged_with(tag_name) } scope :cached_tagged_with, ->(tag) { where("cached_tag_list ~* ?", "^#{tag},| #{tag},|, #{tag}$|^#{tag}$") } @@ -118,10 +118,10 @@ class Article < ApplicationRecord scope :cached_tagged_by_approval_with, ->(tag) { cached_tagged_with(tag).where(approved: true) } scope :active_help, lambda { - published. - cached_tagged_with("help"). - order(created_at: :desc). - where("published_at > ? AND comments_count < ? AND score > ?", 12.hours.ago, 6, -4) + published + .cached_tagged_with("help") + .order(created_at: :desc) + .where("published_at > ? AND comments_count < ? AND score > ?", 12.hours.ago, 6, -4) } scope :limited_column_select, lambda { @@ -175,17 +175,17 @@ class Article < ApplicationRecord } scope :feed, lambda { - published.includes(:taggings). - select( + published.includes(:taggings) + .select( :id, :published_at, :processed_html, :user_id, :organization_id, :title, :path, :cached_tag_list ) } scope :with_video, lambda { - published. - where.not(video: [nil, ""]). - where.not(video_thumbnail_url: [nil, ""]). - where("score > ?", -4) + published + .where.not(video: [nil, ""]) + .where.not(video_thumbnail_url: [nil, ""]) + .where("score > ?", -4) } scope :eager_load_serialized_data, -> { includes(:user, :organization, :tags) } @@ -201,11 +201,11 @@ class Article < ApplicationRecord stories = if time_ago == "latest" stories.order("published_at DESC").where("score > ?", -5) elsif time_ago - stories.order("comments_count DESC"). - where("published_at > ? AND score > ?", time_ago, -5) + stories.order("comments_count DESC") + .where("published_at > ? AND score > ?", time_ago, -5) else - stories.order("last_comment_at DESC"). - where("published_at > ? AND score > ?", (tags.present? ? 5 : 2).days.ago, -5) + stories.order("last_comment_at DESC") + .where("published_at > ? AND score > ?", (tags.present? ? 5 : 2).days.ago, -5) end stories = tags.size == 1 ? stories.cached_tagged_with(tags.first) : stories.tagged_with(tags) stories.pluck(:path, :title, :comments_count, :created_at) @@ -218,11 +218,11 @@ class Article < ApplicationRecord # Time ago sometimes is given as nil and should then be the default. I know, sloppy. time_ago = 75.days.ago if time_ago.nil? - relation = Article.published. - order(organic_page_views_past_month_count: :desc). - where("score > ?", 8). - where("published_at > ?", time_ago). - limit(20) + relation = Article.published + .order(organic_page_views_past_month_count: :desc) + .where("score > ?", 8) + .where("published_at > ?", time_ago) + .limit(20) fields = %i[path title comments_count created_at] if tag @@ -233,10 +233,10 @@ class Article < ApplicationRecord end def self.search_optimized(tag = nil) - relation = Article.published. - order(updated_at: :desc). - where.not(search_optimized_title_preamble: nil). - limit(20) + relation = Article.published + .order(updated_at: :desc) + .where.not(search_optimized_title_preamble: nil) + .limit(20) fields = %i[path search_optimized_title_preamble comments_count created_at] if tag diff --git a/app/models/buffer_update.rb b/app/models/buffer_update.rb index ceb7bedc5..94d5c8b1c 100644 --- a/app/models/buffer_update.rb +++ b/app/models/buffer_update.rb @@ -59,9 +59,9 @@ class BufferUpdate < ApplicationRecord def validate_body_text_recent_uniqueness return if persisted? - relation = BufferUpdate. - where(body_text: body_text, article_id: article_id, tag_id: tag_id, social_service_name: social_service_name). - where("created_at > ?", 2.minutes.ago) + relation = BufferUpdate + .where(body_text: body_text, article_id: article_id, tag_id: tag_id, social_service_name: social_service_name) + .where("created_at > ?", 2.minutes.ago) return unless relation.any? diff --git a/app/models/chat_channel.rb b/app/models/chat_channel.rb index b24dcc811..82cc4f3b1 100644 --- a/app/models/chat_channel.rb +++ b/app/models/chat_channel.rb @@ -179,8 +179,8 @@ class ChatChannel < ApplicationRecord end def channel_human_names - active_memberships. - order("last_opened_at DESC").limit(5).includes(:user).map do |membership| + active_memberships + .order("last_opened_at DESC").limit(5).includes(:user).map do |membership| membership.user.name end end diff --git a/app/models/comment.rb b/app/models/comment.rb index d00747d19..2ea894334 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -80,9 +80,9 @@ class Comment < ApplicationRecord end def parent_type - parent_or_root_article.class.name.downcase. - gsub("article", "post"). - gsub("podcastepisode", "episode") + parent_or_root_article.class.name.downcase + .gsub("article", "post") + .gsub("podcastepisode", "episode") end def id_code_generated diff --git a/app/models/email_message.rb b/app/models/email_message.rb index 2b9b9712c..6c730dafd 100644 --- a/app/models/email_message.rb +++ b/app/models/email_message.rb @@ -9,7 +9,7 @@ class EmailMessage < Ahoy::Message end def self.find_for_reports(feedback_message_ids) - select(:to, :subject, :content, :utm_campaign, :feedback_message_id). - where(feedback_message_id: feedback_message_ids) + select(:to, :subject, :content, :utm_campaign, :feedback_message_id) + .where(feedback_message_id: feedback_message_ids) end end diff --git a/app/models/event.rb b/app/models/event.rb index 296141cd1..c852a9c9f 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -12,13 +12,13 @@ class Event < ApplicationRecord before_validation :evaluate_markdown scope :in_the_future_and_published, lambda { - where("starts_at > ?", Time.current). - where(published: true) + where("starts_at > ?", Time.current) + .where(published: true) } scope :in_the_past_and_published, lambda { - where("starts_at < ?", Time.current). - where(published: true) + where("starts_at < ?", Time.current) + .where(published: true) } private diff --git a/app/models/follow.rb b/app/models/follow.rb index a6fb0d980..c64c1fde6 100644 --- a/app/models/follow.rb +++ b/app/models/follow.rb @@ -61,8 +61,8 @@ class Follow < ApplicationRecord def modify_chat_channel_status return unless followable_type == "User" && followable.following?(follower) - channel = follower.chat_channels. - find_by("slug LIKE ? OR slug like ?", "%/#{followable.username}%", "%#{followable.username}/%") + channel = follower.chat_channels + .find_by("slug LIKE ? OR slug like ?", "%/#{followable.username}%", "%#{followable.username}/%") channel&.update(status: "inactive") end end diff --git a/app/models/github_repo.rb b/app/models/github_repo.rb index f348c4b62..29bb82a78 100644 --- a/app/models/github_repo.rb +++ b/app/models/github_repo.rb @@ -15,10 +15,10 @@ class GithubRepo < ApplicationRecord # Update existing repository or create a new one with given params. # Repository is searched by either GitHub ID or URL. def self.upsert(user, **params) - repo = user.github_repos. - where(github_id_code: params[:github_id_code]). - or(where(url: params[:url])). - first + repo = user.github_repos + .where(github_id_code: params[:github_id_code]) + .or(where(url: params[:url])) + .first repo ||= new(params.merge(user_id: user.id)) repo.update(params) diff --git a/app/models/html_variant.rb b/app/models/html_variant.rb index de8e2b0a6..c471566bc 100644 --- a/app/models/html_variant.rb +++ b/app/models/html_variant.rb @@ -36,13 +36,13 @@ class HtmlVariant < ApplicationRecord private def find_top_for_test(tags_array, group) - where(group: group, approved: true, published: true, target_tag: tags_array). - order("success_rate DESC").limit(rand(1..20)).sample + where(group: group, approved: true, published: true, target_tag: tags_array) + .order("success_rate DESC").limit(rand(1..20)).sample end def find_random_for_test(tags_array, group) - where(group: group, approved: true, published: true, target_tag: tags_array). - order(Arel.sql("RANDOM()")).first + where(group: group, approved: true, published: true, target_tag: tags_array) + .order(Arel.sql("RANDOM()")).first end end diff --git a/app/models/message.rb b/app/models/message.rb index 09b2a15c5..3ceeee490 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -31,11 +31,11 @@ class Message < ApplicationRecord end def update_all_has_unopened_messages_statuses - chat_channel. - chat_channel_memberships. - where("last_opened_at < ?", 10.seconds.ago). - where.not(user_id: user_id). - update_all(has_unopened_messages: true) + chat_channel + .chat_channel_memberships + .where("last_opened_at < ?", 10.seconds.ago) + .where.not(user_id: user_id) + .update_all(has_unopened_messages: true) end def evaluate_markdown @@ -174,14 +174,14 @@ class Message < ApplicationRecord # rubocop:enable Rails/OutputSafety def cl_path(img_src) - ActionController::Base.helpers. - cl_image_path(img_src, - type: "fetch", - width: 725, - crop: "limit", - flags: "progressive", - fetch_format: "auto", - sign_url: true) + ActionController::Base.helpers + .cl_image_path(img_src, + type: "fetch", + width: 725, + crop: "limit", + flags: "progressive", + fetch_format: "auto", + sign_url: true) end def determine_user_validity @@ -223,8 +223,8 @@ class Message < ApplicationRecord recipient = direct_receiver return if !chat_channel.direct? || recipient.updated_at > 1.hour.ago || - recipient.chat_channel_memberships.order("last_opened_at DESC"). - first.last_opened_at > 15.hours.ago || + recipient.chat_channel_memberships.order("last_opened_at DESC") + .first.last_opened_at > 15.hours.ago || chat_channel.last_message_at > 30.minutes.ago || recipient.email_connect_messages == false diff --git a/app/models/podcast.rb b/app/models/podcast.rb index 9b8e6b3d9..d6ba40457 100644 --- a/app/models/podcast.rb +++ b/app/models/podcast.rb @@ -29,9 +29,9 @@ class Podcast < ApplicationRecord alias_attribute :name, :title def existing_episode(item) - episode = PodcastEpisode.where(media_url: item.enclosure_url). - or(PodcastEpisode.where(title: item.title)). - or(PodcastEpisode.where(guid: item.guid.to_s)).presence + episode = PodcastEpisode.where(media_url: item.enclosure_url) + .or(PodcastEpisode.where(title: item.title)) + .or(PodcastEpisode.where(guid: item.guid.to_s)).presence # if unique_website_url? is set to true (the default value), we try to find an episode by website_url as well # if unique_website_url? is set to false it usually means that website_url is the same for different episodes episode ||= PodcastEpisode.where(website_url: item.link).presence if item.link.present? && unique_website_url? diff --git a/app/models/podcast_episode.rb b/app/models/podcast_episode.rb index f44580ba4..d94e52225 100644 --- a/app/models/podcast_episode.rb +++ b/app/models/podcast_episode.rb @@ -102,9 +102,9 @@ class PodcastEpisode < ApplicationRecord def process_html_and_prefix_all_images return if body.blank? - self.processed_html = body. - gsub("\r\n

 

\r\n", "").gsub("\r\n

 

\r\n", ""). - gsub("\r\n

 

\r\n", "").gsub("\r\n

 

\r\n", "") + self.processed_html = body + .gsub("\r\n

 

\r\n", "").gsub("\r\n

 

\r\n", "") + .gsub("\r\n

 

\r\n", "").gsub("\r\n

 

\r\n", "") self.processed_html = "

#{processed_html}

" unless processed_html.include?("

") @@ -116,15 +116,15 @@ class PodcastEpisode < ApplicationRecord quality = "auto" quality = 66 if img_src.include?(".gif") - cloudinary_img_src = ActionController::Base.helpers. - cl_image_path(img_src, - type: "fetch", - width: 725, - crop: "limit", - quality: quality, - flags: "progressive", - fetch_format: "auto", - sign_url: true) + cloudinary_img_src = ActionController::Base.helpers + .cl_image_path(img_src, + type: "fetch", + width: 725, + crop: "limit", + quality: quality, + flags: "progressive", + fetch_format: "auto", + sign_url: true) self.processed_html = processed_html.gsub(img_src, cloudinary_img_src) end end diff --git a/app/models/sponsorship.rb b/app/models/sponsorship.rb index 35cbb3f35..30075cd47 100644 --- a/app/models/sponsorship.rb +++ b/app/models/sponsorship.rb @@ -34,15 +34,15 @@ class Sponsorship < ApplicationRecord private def validate_tag_uniqueness - return unless self.class.where(sponsorable: sponsorable, level: :tag). - where("expires_at > ? AND id != ?", Time.current, id.to_i).exists? + return unless self.class.where(sponsorable: sponsorable, level: :tag) + .where("expires_at > ? AND id != ?", Time.current, id.to_i).exists? errors.add(:level, "The tag is already sponsored") end def validate_level_uniqueness - return unless self.class.where(organization: organization). - where("level IN (?) AND expires_at > ? AND id != ?", METAL_LEVELS, Time.current, id.to_i).exists? + return unless self.class.where(organization: organization) + .where("level IN (?) AND expires_at > ? AND id != ?", METAL_LEVELS, Time.current, id.to_i).exists? errors.add(:level, "You can have only one sponsorship of #{METAL_LEVELS.join(', ')}") end diff --git a/app/models/tag.rb b/app/models/tag.rb index 433790fc1..4c1d2a728 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -97,12 +97,12 @@ class Tag < ActsAsTaggableOn::Tag end def calculate_hotness_score - self.hotness_score = Article.tagged_with(name). - where("articles.featured_number > ?", 7.days.ago.to_i). - map do |article| + self.hotness_score = Article.tagged_with(name) + .where("articles.featured_number > ?", 7.days.ago.to_i) + .map do |article| (article.comments_count * 14) + article.score + rand(6) + ((taggings_count + 1) / 2) - end. - sum + end + .sum end def bust_cache diff --git a/app/models/user.rb b/app/models/user.rb index 23ac206fd..63a5d1390 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -216,9 +216,9 @@ class User < ApplicationRecord end def followed_articles - Article.tagged_with(cached_followed_tag_names, any: true). - union(Article.where(user_id: cached_following_users_ids)). - where(language: preferred_languages_array, published: true) + Article.tagged_with(cached_followed_tag_names, any: true) + .union(Article.where(user_id: cached_following_users_ids)) + .where(language: preferred_languages_array, published: true) end def cached_following_users_ids diff --git a/app/queries/internal/moderators_query.rb b/app/queries/internal/moderators_query.rb index 2b2d68eb9..67ee41cd6 100644 --- a/app/queries/internal/moderators_query.rb +++ b/app/queries/internal/moderators_query.rb @@ -14,8 +14,8 @@ module Internal role_id_for(:trusted), ).order("users.comments_count DESC") else - relation.joins(:roles). - where(users_roles: { role_id: role_id_for(state) }) + relation.joins(:roles) + .where(users_roles: { role_id: role_id_for(state) }) end relation = search_relation(relation, search) if search.presence diff --git a/app/serializers/search/listing_serializer.rb b/app/serializers/search/listing_serializer.rb index 2866da1f3..c8f3805c5 100644 --- a/app/serializers/search/listing_serializer.rb +++ b/app/serializers/search/listing_serializer.rb @@ -18,9 +18,9 @@ module Search attribute :tags, &:tag_list attribute :author do |cl| - ListingAuthorSerializer.new(cl.author). - serializable_hash. - dig(:data, :attributes) + ListingAuthorSerializer.new(cl.author) + .serializable_hash + .dig(:data, :attributes) end end end diff --git a/app/services/analytics_service.rb b/app/services/analytics_service.rb index 07dd0245e..8076015ed 100644 --- a/app/services/analytics_service.rb +++ b/app/services/analytics_service.rb @@ -80,13 +80,13 @@ class AnalyticsService end # prepare relations for metrics - @comment_data = Comment. - where(commentable_id: article_ids, commentable_type: "Article"). - where("score > 0") - @follow_data = Follow. - where(followable_type: user_or_org.class.name, followable_id: user_or_org.id) - @reaction_data = Reaction.public_category. - where(reactable_id: article_ids, reactable_type: "Article") + @comment_data = Comment + .where(commentable_id: article_ids, commentable_type: "Article") + .where("score > 0") + @follow_data = Follow + .where(followable_type: user_or_org.class.name, followable_id: user_or_org.id) + @reaction_data = Reaction.public_category + .where(reactable_id: article_ids, reactable_type: "Article") @page_view_data = PageView.where(article_id: article_ids) # filter data by date if needed diff --git a/app/services/article_api_index_service.rb b/app/services/article_api_index_service.rb index a5ec7428b..38a8b0a57 100644 --- a/app/services/article_api_index_service.rb +++ b/app/services/article_api_index_service.rb @@ -40,17 +40,17 @@ class ArticleApiIndexService end if (user = User.find_by(username: username)) - user.articles.published. - includes(:organization). - order("published_at DESC"). - page(page). - per(per_page || num) + user.articles.published + .includes(:organization) + .order("published_at DESC") + .page(page) + .per(per_page || num) elsif (organization = Organization.find_by(slug: username)) - organization.articles.published. - includes(:user). - order("published_at DESC"). - page(page). - per(per_page || num) + organization.articles.published + .includes(:user) + .order("published_at DESC") + .page(page) + .per(per_page || num) else Article.none end @@ -62,8 +62,8 @@ class ArticleApiIndexService articles = if Tag.find_by(name: tag)&.requires_approval articles.where(approved: true).order("featured_number DESC") elsif top.present? - articles.where("published_at > ?", top.to_i.days.ago). - order("public_reactions_count DESC") + articles.where("published_at > ?", top.to_i.days.ago) + .order("public_reactions_count DESC") else articles.order("hotness_score DESC") end @@ -72,10 +72,10 @@ class ArticleApiIndexService end def top_articles - Article.published.includes(:user, :organization). - where("published_at > ?", top.to_i.days.ago). - order("public_reactions_count DESC"). - page(page).per(per_page || DEFAULT_PER_PAGE) + Article.published.includes(:user, :organization) + .where("published_at > ?", top.to_i.days.ago) + .order("public_reactions_count DESC") + .page(page).per(per_page || DEFAULT_PER_PAGE) end def state_articles(state) @@ -98,20 +98,20 @@ class ArticleApiIndexService end def collection_articles(collection_id) - Article.published. - where(collection_id: collection_id). - includes(:user, :organization). - order("published_at"). - page(page). - per(per_page || DEFAULT_PER_PAGE) + Article.published + .where(collection_id: collection_id) + .includes(:user, :organization) + .order("published_at") + .page(page) + .per(per_page || DEFAULT_PER_PAGE) end def base_articles - Article.published. - where(featured: true). - includes(:user, :organization). - order("hotness_score DESC"). - page(page). - per(per_page || DEFAULT_PER_PAGE) + Article.published + .where(featured: true) + .includes(:user, :organization) + .order("hotness_score DESC") + .page(page) + .per(per_page || DEFAULT_PER_PAGE) end end diff --git a/app/services/articles/feed.rb b/app/services/articles/feed.rb index 03d39ad86..ea552b474 100644 --- a/app/services/articles/feed.rb +++ b/app/services/articles/feed.rb @@ -27,23 +27,23 @@ module Articles end def published_articles_by_tag - articles = Article.published.limited_column_select. - includes(top_comments: :user). - page(@page).per(@number_of_articles) + articles = Article.published.limited_column_select + .includes(top_comments: :user) + .page(@page).per(@number_of_articles) articles = articles.cached_tagged_with(@tag) if @tag.present? # More efficient than tagged_with articles end # Timeframe values from Timeframer::DATETIMES def top_articles_by_timeframe(timeframe:) - published_articles_by_tag.where("published_at > ?", Timeframer.new(timeframe).datetime). - order("score DESC").page(@page).per(@number_of_articles) + published_articles_by_tag.where("published_at > ?", Timeframer.new(timeframe).datetime) + .order("score DESC").page(@page).per(@number_of_articles) end def latest_feed - published_articles_by_tag.order("published_at DESC"). - where("featured_number > ? AND score > ?", 1_449_999_999, -20). - page(@page).per(@number_of_articles) + published_articles_by_tag.order("published_at DESC") + .where("featured_number > ? AND score > ?", 1_449_999_999, -20) + .page(@page).per(@number_of_articles) end def default_home_feed_and_featured_story(user_signed_in: false, ranking: true) @@ -236,9 +236,9 @@ module Articles end def globally_hot_articles(user_signed_in) - hot_stories = published_articles_by_tag. - where("score > ? OR featured = ?", 7, true). - order("hotness_score DESC") + hot_stories = published_articles_by_tag + .where("score > ? OR featured = ?", 7, true) + .order("hotness_score DESC") featured_story = hot_stories.where.not(main_image: nil).first if user_signed_in hot_story_count = hot_stories.count @@ -246,9 +246,9 @@ module Articles i < hot_story_count end.sample # random offset, weighted more towards zero hot_stories = hot_stories.offset(offset) - new_stories = Article.published. - where("score > ?", -15). - limited_column_select.includes(top_comments: :user).order("published_at DESC").limit(rand(15..80)) + new_stories = Article.published + .where("score > ?", -15) + .limited_column_select.includes(top_comments: :user).order("published_at DESC").limit(rand(15..80)) hot_stories = hot_stories.to_a + new_stories.to_a end [featured_story, hot_stories.to_a] diff --git a/app/services/exporter/comments.rb b/app/services/exporter/comments.rb index 3219ca3a0..9839509e5 100644 --- a/app/services/exporter/comments.rb +++ b/app/services/exporter/comments.rb @@ -38,8 +38,8 @@ module Exporter attributes_to_select = %i[id commentable_id commentable_type] + allowed_attributes comments.includes(:commentable).select(attributes_to_select).find_each do |comment| # merge final json with the path of the commentable - comments_to_jsonify << comment.as_json(only: allowed_attributes). - merge(commentable_path: comment.commentable&.path) + comments_to_jsonify << comment.as_json(only: allowed_attributes) + .merge(commentable_path: comment.commentable&.path) end comments_to_jsonify.to_json diff --git a/app/services/mentions/create_all.rb b/app/services/mentions/create_all.rb index cfc1bc998..820f8479f 100644 --- a/app/services/mentions/create_all.rb +++ b/app/services/mentions/create_all.rb @@ -21,8 +21,8 @@ module Mentions def users_mentioned_in_text_excluding_author mentioned_usernames = extract_usernames_from_mentions_in_text - collect_existing_users(mentioned_usernames). - yield_self do |existing_mentioned_users| + collect_existing_users(mentioned_usernames) + .yield_self do |existing_mentioned_users| reject_notifiable_author(existing_mentioned_users) end end diff --git a/app/services/notifications/moderation.rb b/app/services/notifications/moderation.rb index bab8ad3fe..aab4a4d6d 100644 --- a/app/services/notifications/moderation.rb +++ b/app/services/notifications/moderation.rb @@ -4,9 +4,9 @@ module Notifications SUPPORTED = [Comment].freeze def self.available_moderators - User.with_role(:trusted). - where("last_moderation_notification < ?", MODERATORS_AVAILABILITY_DELAY.ago). - where(mod_roundrobin_notifications: true) + User.with_role(:trusted) + .where("last_moderation_notification < ?", MODERATORS_AVAILABILITY_DELAY.ago) + .where(mod_roundrobin_notifications: true) end end end diff --git a/app/services/notifications/new_comment/send.rb b/app/services/notifications/new_comment/send.rb index 43dabbd86..256b1b70c 100644 --- a/app/services/notifications/new_comment/send.rb +++ b/app/services/notifications/new_comment/send.rb @@ -54,9 +54,9 @@ module Notifications attr_reader :comment def user_ids_for(config_name) - NotificationSubscription. - where(notifiable_id: comment.commentable_id, notifiable_type: "Article", config: config_name). - pluck(:user_id) + NotificationSubscription + .where(notifiable_id: comment.commentable_id, notifiable_type: "Article", config: config_name) + .pluck(:user_id) end def comment_user_ids diff --git a/app/services/notifications/new_follower/send.rb b/app/services/notifications/new_follower/send.rb index 81a9d0a39..3135b05a0 100644 --- a/app/services/notifications/new_follower/send.rb +++ b/app/services/notifications/new_follower/send.rb @@ -24,8 +24,8 @@ module Notifications end def call - recent_follows = Follow.where(followable_type: followable_type, followable_id: followable_id). - where("created_at > ?", 24.hours.ago).order("created_at DESC") + recent_follows = Follow.where(followable_type: followable_type, followable_id: followable_id) + .where("created_at > ?", 24.hours.ago).order("created_at DESC") notification_params = { action: "Follow" } if followable_type == "User" diff --git a/app/services/notifications/reactions/send.rb b/app/services/notifications/reactions/send.rb index 1587e92f6..34c8efc6a 100644 --- a/app/services/notifications/reactions/send.rb +++ b/app/services/notifications/reactions/send.rb @@ -23,10 +23,10 @@ module Notifications return unless receiver.is_a?(User) || receiver.is_a?(Organization) reaction_siblings = Reaction.public_category.where(reactable_id: reaction.reactable_id, - reactable_type: reaction.reactable_type). - where.not(reactions: { user_id: reaction.reactable_user_id }). - preload(:reactable).includes(:user).where.not(users: { id: nil }). - order("reactions.created_at DESC") + reactable_type: reaction.reactable_type) + .where.not(reactions: { user_id: reaction.reactable_user_id }) + .preload(:reactable).includes(:user).where.not(users: { id: nil }) + .order("reactions.created_at DESC") aggregated_reaction_siblings = reaction_siblings.map do |reaction| { category: reaction.category, created_at: reaction.created_at, user: user_data(reaction.user) } diff --git a/app/services/rss_reader/assembler.rb b/app/services/rss_reader/assembler.rb index 5afc3082b..568e68dc8 100644 --- a/app/services/rss_reader/assembler.rb +++ b/app/services/rss_reader/assembler.rb @@ -41,10 +41,10 @@ class RssReader cleaned_content = HtmlCleaner.new.clean_html(get_content) cleaned_content = thorough_parsing(cleaned_content, @feed.url) - content = ReverseMarkdown. - convert(cleaned_content, github_flavored: true). - gsub("```\n\n```", ""). - gsub(/ |\u00A0/, " ") + content = ReverseMarkdown + .convert(cleaned_content, github_flavored: true) + .gsub("```\n\n```", "") + .gsub(/ |\u00A0/, " ") content.gsub!(/{%\syoutube\s(.{11,18})\s%}/) do |tag| tag.gsub("\\_", "_") diff --git a/app/services/suggester/users/recent.rb b/app/services/suggester/users/recent.rb index 7e726e16d..11f5a11b4 100644 --- a/app/services/suggester/users/recent.rb +++ b/app/services/suggester/users/recent.rb @@ -8,11 +8,11 @@ module Suggester def suggest if user.decorate.cached_followed_tag_names.any? - (recent_producers(3) - [user]). - sample(50).uniq + (recent_producers(3) - [user]) + .sample(50).uniq else - (recent_commenters(4, 30) + recent_top_producers - [user]). - uniq.sample(50) + (recent_commenters(4, 30) + recent_top_producers - [user]) + .uniq.sample(50) end end @@ -21,13 +21,13 @@ module Suggester attr_reader :user, :attributes_to_select def tagged_article_user_ids(num_weeks = 1) - Article.published. - tagged_with(user.decorate.cached_followed_tag_names, any: true). - where("score > ? AND published_at > ?", article_reaction_count, num_weeks.weeks.ago). - pluck(:user_id). - each_with_object(Hash.new(0)) { |value, counts| counts[value] += 1 }. - sort_by { |_key, value| value }. - map { |arr| arr[0] } + Article.published + .tagged_with(user.decorate.cached_followed_tag_names, any: true) + .where("score > ? AND published_at > ?", article_reaction_count, num_weeks.weeks.ago) + .pluck(:user_id) + .each_with_object(Hash.new(0)) { |value, counts| counts[value] += 1 } + .sort_by { |_key, value| value } + .map { |arr| arr[0] } end def recent_producers(num_weeks = 1) diff --git a/app/services/suggester/users/sidebar.rb b/app/services/suggester/users/sidebar.rb index c6c278967..687bf9d6b 100644 --- a/app/services/suggester/users/sidebar.rb +++ b/app/services/suggester/users/sidebar.rb @@ -23,12 +23,12 @@ module Suggester end def active_authors_for_given_tags - @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.following_by_type("User")). - pluck(:user_id) + @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.following_by_type("User")) + .pluck(:user_id) end def reputable_user_ids diff --git a/app/workers/follows/create_chat_channel_worker.rb b/app/workers/follows/create_chat_channel_worker.rb index 4623cf37f..84479d942 100644 --- a/app/workers/follows/create_chat_channel_worker.rb +++ b/app/workers/follows/create_chat_channel_worker.rb @@ -4,9 +4,9 @@ module Follows sidekiq_options queue: :medium_priority, retry: 10 def perform(follow_id) - follow = Follow. - includes(:follower, :followable). - find_by(id: follow_id, follower_type: "User", followable_type: "User") + follow = Follow + .includes(:follower, :followable) + .find_by(id: follow_id, follower_type: "User", followable_type: "User") return unless follow&.followable&.following?(follow.follower) ChatChannel.create_with_users(users: [follow.followable, follow.follower]) diff --git a/app/workers/follows/send_email_notification_worker.rb b/app/workers/follows/send_email_notification_worker.rb index 2765b309f..14fb73794 100644 --- a/app/workers/follows/send_email_notification_worker.rb +++ b/app/workers/follows/send_email_notification_worker.rb @@ -7,9 +7,9 @@ module Follows follow = Follow.find_by(id: follow_id, followable_type: "User") return unless follow&.followable.present? && follow.followable.receives_follower_email_notifications? - return if EmailMessage.where(user_id: follow.followable_id). - where("sent_at > ?", rand(15..35).hours.ago). - where("subject LIKE ?", "%#{NotifyMailer::SUBJECTS[:new_follower_email]}").exists? + return if EmailMessage.where(user_id: follow.followable_id) + .where("sent_at > ?", rand(15..35).hours.ago) + .where("subject LIKE ?", "%#{NotifyMailer::SUBJECTS[:new_follower_email]}").exists? mailer.constantize.with(follow: follow).new_follower_email.deliver_now end diff --git a/app/workers/metrics/record_daily_notifications_worker.rb b/app/workers/metrics/record_daily_notifications_worker.rb index 7eb1f7be8..9dfcc3120 100644 --- a/app/workers/metrics/record_daily_notifications_worker.rb +++ b/app/workers/metrics/record_daily_notifications_worker.rb @@ -19,9 +19,9 @@ module Metrics def perform # Welcome Notification click events created in the past day, logged by title. EVENT_TITLES.each do |title| - event = Ahoy::Event.where(name: "Clicked Welcome Notification"). - where("time > ?", 1.day.ago). - where("properties->>'title' = ?", title) + event = Ahoy::Event.where(name: "Clicked Welcome Notification") + .where("time > ?", 1.day.ago) + .where("properties->>'title' = ?", title) DatadogStatsClient.count( "ahoy_events", diff --git a/app/workers/metrics/record_daily_usage_worker.rb b/app/workers/metrics/record_daily_usage_worker.rb index 5cd0a22ab..497666eee 100644 --- a/app/workers/metrics/record_daily_usage_worker.rb +++ b/app/workers/metrics/record_daily_usage_worker.rb @@ -13,9 +13,9 @@ module Metrics ) # Articles published in the past 24 hours with at least 15 "score" (positive/negative reactions) - articles_min_15_comment_score_past_24h = Article.published. - where("comment_score >= ? AND published_at > ?", 15, 1.day.ago). - size + articles_min_15_comment_score_past_24h = Article.published + .where("comment_score >= ? AND published_at > ?", 15, 1.day.ago) + .size DatadogStatsClient.count( "articles.min_15_comment_score_past_24h", articles_min_15_comment_score_past_24h, @@ -57,10 +57,10 @@ module Metrics def get_days_active_past_week_counts ids_by_day = [] 7.times do |i| - id = PageView. - where("created_at > ? AND created_at < ?", (i + 1).days.ago, i.days.ago). - where.not(user_id: nil). - pluck(:user_id).uniq + id = PageView + .where("created_at > ? AND created_at < ?", (i + 1).days.ago, i.days.ago) + .where.not(user_id: nil) + .pluck(:user_id).uniq ids_by_day << id end flat_id_list = ids_by_day.flatten.uniq diff --git a/app/workers/search/bulk_index_worker.rb b/app/workers/search/bulk_index_worker.rb index f2c7d6adc..9d81ba0f1 100644 --- a/app/workers/search/bulk_index_worker.rb +++ b/app/workers/search/bulk_index_worker.rb @@ -5,10 +5,10 @@ module Search sidekiq_options queue: :high_priority, lock: :until_executing def perform(object_class, ids) - data_hashes = object_class.constantize. - eager_load_serialized_data. - where(id: ids). - find_each.map(&:serialized_search_hash) + data_hashes = object_class.constantize + .eager_load_serialized_data + .where(id: ids) + .find_each.map(&:serialized_search_hash) search_class = object_class.constantize::SEARCH_CLASS diff --git a/app/workers/users/record_field_test_event_worker.rb b/app/workers/users/record_field_test_event_worker.rb index 565cf753f..f8bf6eca5 100644 --- a/app/workers/users/record_field_test_event_worker.rb +++ b/app/workers/users/record_field_test_event_worker.rb @@ -21,8 +21,8 @@ module Users private def determine_weekly_pageview_goal(user, experiment) - past_week_page_view_counts = user.page_views.where("created_at > ?", 7.days.ago). - group("DATE(created_at)").count.values + past_week_page_view_counts = user.page_views.where("created_at > ?", 7.days.ago) + .group("DATE(created_at)").count.values past_week_page_view_counts.delete(0) return unless past_week_page_view_counts.size > 3 @@ -31,8 +31,8 @@ module Users # Almost repeat of above method, but rule of threes dictates this is fine duplication for now. def determine_daily_pageview_goal(user, experiment) - past_day_page_view_counts = user.page_views.where("created_at > ?", 24.hours.ago). - group("DATE_PART('hour', created_at)").count.values + past_day_page_view_counts = user.page_views.where("created_at > ?", 24.hours.ago) + .group("DATE_PART('hour', created_at)").count.values past_day_page_view_counts.delete(0) return unless past_day_page_view_counts.size > 3 diff --git a/config/sitemap.rb b/config/sitemap.rb index 84e13e62d..f5fd5a545 100644 --- a/config/sitemap.rb +++ b/config/sitemap.rb @@ -15,8 +15,8 @@ end SitemapGenerator::Sitemap.default_host = "#{ApplicationConfig['APP_PROTOCOL']}#{ApplicationConfig['APP_DOMAIN']}" SitemapGenerator::Sitemap.create do - Article.published.where("score > ? OR featured = ?", 12, true). - limit(38_000).find_each do |article| + Article.published.where("score > ? OR featured = ?", 12, true) + .limit(38_000).find_each do |article| add article.path, lastmod: article.last_comment_at, changefreq: "daily" end diff --git a/spec/decorators/article_decorator_spec.rb b/spec/decorators/article_decorator_spec.rb index 0b4f74c71..442c3a58c 100644 --- a/spec/decorators/article_decorator_spec.rb +++ b/spec/decorators/article_decorator_spec.rb @@ -179,8 +179,8 @@ RSpec.describe ArticleDecorator, type: :decorator do body_markdown = "---\ntitle: Title\npublished: false\ndescription:\ntags: heytag\n---\n\nHey this is the article" search_optimized_description_replacement = "Hey this is the expected result" expect(create_article(body_markdown: body_markdown, - search_optimized_description_replacement: search_optimized_description_replacement). - description_and_tags).to eq(search_optimized_description_replacement) + search_optimized_description_replacement: search_optimized_description_replacement) + .description_and_tags).to eq(search_optimized_description_replacement) end end end diff --git a/spec/decorators/listing_decorator_spec.rb b/spec/decorators/listing_decorator_spec.rb index 96b40e717..6c9e30dfc 100644 --- a/spec/decorators/listing_decorator_spec.rb +++ b/spec/decorators/listing_decorator_spec.rb @@ -14,8 +14,8 @@ RSpec.describe ListingDecorator, type: :decorator do end it "returns the category's social preview descripton if available" do - expect(decorated_listing.social_preview_category). - to eq(category.social_preview_description) + expect(decorated_listing.social_preview_category) + .to eq(category.social_preview_description) end end @@ -23,20 +23,20 @@ RSpec.describe ListingDecorator, type: :decorator do it "returns the default color if social preview color is blank" do allow(category).to receive(:social_preview_color).and_return(nil) - expect(decorated_listing.social_preview_color). - to eq(ListingDecorator::DEFAULT_COLOR) + expect(decorated_listing.social_preview_color) + .to eq(ListingDecorator::DEFAULT_COLOR) end it "returns the category's social preview color if available" do - expect(decorated_listing.social_preview_color). - to eq(category.social_preview_color) + expect(decorated_listing.social_preview_color) + .to eq(category.social_preview_color) end it "can modify the brightness" do color = category.social_preview_color - expect(decorated_listing.social_preview_color(brightness: 0.8)). - to eq(HexComparer.new([color]).brightness(0.8)) + expect(decorated_listing.social_preview_color(brightness: 0.8)) + .to eq(HexComparer.new([color]).brightness(0.8)) end end end diff --git a/spec/helpers/articles_helper_spec.rb b/spec/helpers/articles_helper_spec.rb index a8d88e384..28c2082ba 100644 --- a/spec/helpers/articles_helper_spec.rb +++ b/spec/helpers/articles_helper_spec.rb @@ -56,8 +56,8 @@ describe ArticlesHelper do describe "#utc_iso_timestamp" do it "correctly formats the date when present" do - expect(helper.utc_iso_timestamp(Time.current)). - to match(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z/) + expect(helper.utc_iso_timestamp(Time.current)) + .to match(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z/) end it "returns nil if there is no timestamp" do diff --git a/spec/initializers/application_config_spec.rb b/spec/initializers/application_config_spec.rb index ad0ac8f3f..6a7829d5f 100644 --- a/spec/initializers/application_config_spec.rb +++ b/spec/initializers/application_config_spec.rb @@ -31,8 +31,8 @@ describe ApplicationConfig do def setup_app_domain(app_domain) # No #and_return for #have_received. # rubocop:disable RSpec/MessageSpies - expect(ApplicationConfig).to receive(:[]).with("APP_DOMAIN"). - and_return(app_domain) + expect(ApplicationConfig).to receive(:[]).with("APP_DOMAIN") + .and_return(app_domain) # rubocop:enable RSpec/MessageSpies end end diff --git a/spec/labor/mailchimp_bot_spec.rb b/spec/labor/mailchimp_bot_spec.rb index 1a769c7c8..8f8d32c92 100644 --- a/spec/labor/mailchimp_bot_spec.rb +++ b/spec/labor/mailchimp_bot_spec.rb @@ -72,24 +72,24 @@ RSpec.describe MailchimpBot, type: :labor do it "unsubscribes properly" do user.update(email_newsletter: false) described_class.new(user).upsert_to_newsletter - expect(my_gibbon_client).to have_received(:upsert). - with(hash_including(body: hash_including(status: "unsubscribed"))) + expect(my_gibbon_client).to have_received(:upsert) + .with(hash_including(body: hash_including(status: "unsubscribed"))) end it "subscribes properly" do user.update(email_newsletter: false) user.update(email_newsletter: true) described_class.new(user).upsert_to_newsletter - expect(my_gibbon_client).to have_received(:upsert). - with(hash_including(body: hash_including(status: "subscribed"))) + expect(my_gibbon_client).to have_received(:upsert) + .with(hash_including(body: hash_including(status: "subscribed"))) end it "updates email properly" do user.update(email: Faker::Internet.email) user.confirm described_class.new(user).upsert_to_newsletter - expect(my_gibbon_client).to have_received(:upsert). - with(hash_including(body: hash_including(email_address: user.email))) + expect(my_gibbon_client).to have_received(:upsert) + .with(hash_including(body: hash_including(email_address: user.email))) end it "tries to resubscribe the user if the user has previously been subscribed" do @@ -115,12 +115,12 @@ RSpec.describe MailchimpBot, type: :labor do user.update(email_community_mod_newsletter: true) user.add_role :trusted described_class.new(user).manage_community_moderator_list - expect(my_gibbon_client).to have_received(:upsert). - with(hash_including( - body: hash_including( - status: "subscribed", - ), - )) + expect(my_gibbon_client).to have_received(:upsert) + .with(hash_including( + body: hash_including( + status: "subscribed", + ), + )) end end @@ -133,12 +133,12 @@ RSpec.describe MailchimpBot, type: :labor do user.update(email_tag_mod_newsletter: true) user.add_role(:tag_moderator, tag) described_class.new(user).manage_tag_moderator_list - expect(my_gibbon_client).to have_received(:upsert). - with(hash_including( - body: hash_including( - status: "subscribed", - ), - )) + expect(my_gibbon_client).to have_received(:upsert) + .with(hash_including( + body: hash_including( + status: "subscribed", + ), + )) end end @@ -148,8 +148,8 @@ RSpec.describe MailchimpBot, type: :labor do it "unsubscribes the user from the weekly newsletter" do described_class.new(user).unsubscribe_all_newsletters - expect(my_gibbon_client).to have_received(:update). - with(hash_including(body: hash_including(status: "unsubscribed"))) + expect(my_gibbon_client).to have_received(:update) + .with(hash_including(body: hash_including(status: "unsubscribed"))) end end end diff --git a/spec/labor/markdown_fixer_spec.rb b/spec/labor/markdown_fixer_spec.rb index 2256d6a0f..624fec8e8 100644 --- a/spec/labor/markdown_fixer_spec.rb +++ b/spec/labor/markdown_fixer_spec.rb @@ -62,23 +62,23 @@ RSpec.describe MarkdownFixer, type: :labor do it "does not escape a description that came pre-wrapped in single quotes" do legacy_description = "'#{sample_text}'" - result = described_class. - add_quotes_to_description(front_matter(description: legacy_description)) + result = described_class + .add_quotes_to_description(front_matter(description: legacy_description)) expect(result).to eq(front_matter(description: legacy_description)) end it "does not escape a description that came pre-wrapped in double quotes" do legacy_description = "\"#{sample_text}\"" - result = described_class. - add_quotes_to_description(front_matter(description: legacy_description)) + result = described_class + .add_quotes_to_description(front_matter(description: legacy_description)) expect(result).to eq(front_matter(description: legacy_description)) end it "handles a complex description" do legacy_description = %(Book review: "#{sample_text}", part 1 I'm #testing) expected_description = "\"Book review: \\\"#{sample_text}\\\", part 1 I'm #testing\"" - result = described_class. - add_quotes_to_description(front_matter(description: legacy_description)) + result = described_class + .add_quotes_to_description(front_matter(description: legacy_description)) expect(result).to eq(front_matter(description: expected_description)) end @@ -100,16 +100,16 @@ RSpec.describe MarkdownFixer, type: :labor do describe "::fix_all" do it "escapes title and description" do - result = described_class. - fix_all(front_matter(title: sample_text, description: sample_text)) + result = described_class + .fix_all(front_matter(title: sample_text, description: sample_text)) expected_result = front_matter(title: %("#{sample_text}"), description: %("#{sample_text}")) expect(result).to eq(expected_result) end context "when description is empty" do it "escapes title and description" do - result = described_class. - fix_all("---\ntitle: #{sample_text}\ndescription:\ntags: \n---\n") + result = described_class + .fix_all("---\ntitle: #{sample_text}\ndescription:\ntags: \n---\n") expected_result = "---\ntitle: \"#{sample_text}\"\ndescription: \"\"\ntags: \n---\n" expect(result).to eq(expected_result) end @@ -118,8 +118,8 @@ RSpec.describe MarkdownFixer, type: :labor do describe "::fix_for_preview" do it "escapes title and description" do - result = described_class. - fix_for_preview(front_matter(title: sample_text, description: sample_text)) + result = described_class + .fix_for_preview(front_matter(title: sample_text, description: sample_text)) expected_result = front_matter(title: %("#{sample_text}"), description: %("#{sample_text}")) expect(result).to eq(expected_result) end diff --git a/spec/labor/markdown_parser_spec.rb b/spec/labor/markdown_parser_spec.rb index cc9492e88..568e02f90 100644 --- a/spec/labor/markdown_parser_spec.rb +++ b/spec/labor/markdown_parser_spec.rb @@ -259,8 +259,8 @@ RSpec.describe MarkdownParser, type: :labor do end it "wraps the image with Cloudinary" do - expect(generate_and_parse_markdown(markdown_with_img)). - to include("https://res.cloudinary.com") + expect(generate_and_parse_markdown(markdown_with_img)) + .to include("https://res.cloudinary.com") end end diff --git a/spec/lib/html_css_to_image_spec.rb b/spec/lib/html_css_to_image_spec.rb index d13a83a01..87b1e14fb 100644 --- a/spec/lib/html_css_to_image_spec.rb +++ b/spec/lib/html_css_to_image_spec.rb @@ -3,19 +3,19 @@ require "rails_helper" RSpec.describe HtmlCssToImage, type: :lib do describe ".url" do it "returns the url to the created image" do - stub_request(:post, /hcti.io/). - to_return(status: 200, - body: '{ "url": "https://hcti.io/v1/image/6c52de9d-4d37-4008-80f8-67155589e1a1" }', - headers: { "Content-Type" => "application/json" }) + stub_request(:post, /hcti.io/) + .to_return(status: 200, + body: '{ "url": "https://hcti.io/v1/image/6c52de9d-4d37-4008-80f8-67155589e1a1" }', + headers: { "Content-Type" => "application/json" }) expect(described_class.url(html: "test")).to eq("https://hcti.io/v1/image/6c52de9d-4d37-4008-80f8-67155589e1a1") end it "returns fallback image if the request fails" do - stub_request(:post, /hcti.io/). - to_return(status: 429, - body: '{ "error": "Plan limit exceeded" }', - headers: { "Content-Type" => "application/json" }) + stub_request(:post, /hcti.io/) + .to_return(status: 429, + body: '{ "error": "Plan limit exceeded" }', + headers: { "Content-Type" => "application/json" }) expect(described_class.url(html: "test")).to eq described_class::FALLBACK_IMAGE end @@ -28,10 +28,10 @@ RSpec.describe HtmlCssToImage, type: :lib do end it "caches the image url when successful" do - stub_request(:post, /hcti.io/). - to_return(status: 200, - body: '{ "url": "https://hcti.io/v1/image/6c52de9d-4d37-4008-80f8-67155589e1a1" }', - headers: { "Content-Type" => "application/json" }) + stub_request(:post, /hcti.io/) + .to_return(status: 200, + body: '{ "url": "https://hcti.io/v1/image/6c52de9d-4d37-4008-80f8-67155589e1a1" }', + headers: { "Content-Type" => "application/json" }) expected_url = "https://hcti.io/v1/image/6c52de9d-4d37-4008-80f8-67155589e1a1" expect(described_class.fetch_url(html: "test")).to eq(expected_url) @@ -40,22 +40,22 @@ RSpec.describe HtmlCssToImage, type: :lib do it "cache has a long expiration" do # Images are expensive to generate, make sure we don't expire them too quickly. - stub_request(:post, /hcti.io/). - to_return(status: 200, - body: '{ "url": "https://hcti.io/v1/image/6c52de9d-4d37-4008-80f8-67155589e1a1" }', - headers: { "Content-Type" => "application/json" }) + stub_request(:post, /hcti.io/) + .to_return(status: 200, + body: '{ "url": "https://hcti.io/v1/image/6c52de9d-4d37-4008-80f8-67155589e1a1" }', + headers: { "Content-Type" => "application/json" }) expected_url = "https://hcti.io/v1/image/6c52de9d-4d37-4008-80f8-67155589e1a1" expect(described_class.fetch_url(html: "test")).to eq(expected_url) - expect(Rails.cache).to have_received(:write). - with(anything, anything, expires_in: HtmlCssToImage::CACHE_EXPIRATION).once + expect(Rails.cache).to have_received(:write) + .with(anything, anything, expires_in: HtmlCssToImage::CACHE_EXPIRATION).once end it "does not cache errors" do - stub_request(:post, /hcti.io/). - to_return(status: 429, - body: '{ "error": "Plan limit exceeded" }', - headers: { "Content-Type" => "application/json" }) + stub_request(:post, /hcti.io/) + .to_return(status: 429, + body: '{ "error": "Plan limit exceeded" }', + headers: { "Content-Type" => "application/json" }) expect(described_class.fetch_url(html: "test")).to eq described_class::FALLBACK_IMAGE expect(Rails.cache).not_to have_received(:write) diff --git a/spec/liquid_tags/link_tag_spec.rb b/spec/liquid_tags/link_tag_spec.rb index 4dc3bff43..d100f26c1 100644 --- a/spec/liquid_tags/link_tag_spec.rb +++ b/spec/liquid_tags/link_tag_spec.rb @@ -69,8 +69,8 @@ RSpec.describe LinkTag, type: :liquid_tag do end it "does not raise an error when invalid" do - expect { generate_new_liquid("fake_username/fake_article_slug") }. - not_to raise_error("Invalid link URL or link URL does not exist") + expect { generate_new_liquid("fake_username/fake_article_slug") } + .not_to raise_error("Invalid link URL or link URL does not exist") end it "renders a proper link tag" do diff --git a/spec/liquid_tags/listing_tag_spec.rb b/spec/liquid_tags/listing_tag_spec.rb index 65c470503..9fa6482b4 100644 --- a/spec/liquid_tags/listing_tag_spec.rb +++ b/spec/liquid_tags/listing_tag_spec.rb @@ -98,8 +98,8 @@ RSpec.describe ListingTag, type: :liquid_tag do end it "raises an error when invalid" do - expect { generate_new_liquid("/listings/fakecategory/fakeslug") }. - to raise_error("Invalid URL or slug. Listing not found.") + expect { generate_new_liquid("/listings/fakecategory/fakeslug") } + .to raise_error("Invalid URL or slug. Listing not found.") end it "displays expired message when listing is expired" do diff --git a/spec/models/chat_channel_membership_spec.rb b/spec/models/chat_channel_membership_spec.rb index 0422b132a..204a30d51 100644 --- a/spec/models/chat_channel_membership_spec.rb +++ b/spec/models/chat_channel_membership_spec.rb @@ -15,8 +15,8 @@ RSpec.describe ChatChannelMembership, type: :model do # rubocop:disable RSpec/NamedSubject it { - expect(subject).to validate_inclusion_of(:status). - in_array(%w[active inactive pending rejected left_channel removed_from_channel joining_request]) + expect(subject).to validate_inclusion_of(:status) + .in_array(%w[active inactive pending rejected left_channel removed_from_channel joining_request]) } # rubocop:enable RSpec/NamedSubject diff --git a/spec/models/feedback_message_spec.rb b/spec/models/feedback_message_spec.rb index 9c13d8d5f..f128f63bb 100644 --- a/spec/models/feedback_message_spec.rb +++ b/spec/models/feedback_message_spec.rb @@ -9,13 +9,13 @@ RSpec.describe FeedbackMessage, type: :model do it { is_expected.to validate_length_of(:message).is_at_most(2500) } it do - expect(feedback_message).to validate_inclusion_of(:category). - in_array(["spam", "other", "rude or vulgar", "harassment", "bug"]) + expect(feedback_message).to validate_inclusion_of(:category) + .in_array(["spam", "other", "rude or vulgar", "harassment", "bug"]) end it do - expect(feedback_message).to validate_inclusion_of(:status). - in_array(%w[Open Invalid Resolved]) + expect(feedback_message).to validate_inclusion_of(:status) + .in_array(%w[Open Invalid Resolved]) end describe "validations for an abuse report" do diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 70baf135c..8e367d0d1 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -57,79 +57,79 @@ RSpec.describe User, type: :model do # rubocop:disable RSpec/NamedSubject it do - expect(subject).to have_many(:access_grants). - class_name("Doorkeeper::AccessGrant"). - with_foreign_key("resource_owner_id"). - dependent(:delete_all) + expect(subject).to have_many(:access_grants) + .class_name("Doorkeeper::AccessGrant") + .with_foreign_key("resource_owner_id") + .dependent(:delete_all) end it do - expect(subject).to have_many(:access_tokens). - class_name("Doorkeeper::AccessToken"). - with_foreign_key("resource_owner_id"). - dependent(:delete_all) + expect(subject).to have_many(:access_tokens) + .class_name("Doorkeeper::AccessToken") + .with_foreign_key("resource_owner_id") + .dependent(:delete_all) end it do - expect(subject).to have_many(:affected_feedback_messages). - class_name("FeedbackMessage"). - with_foreign_key("affected_id"). - dependent(:nullify) + expect(subject).to have_many(:affected_feedback_messages) + .class_name("FeedbackMessage") + .with_foreign_key("affected_id") + .dependent(:nullify) end it do - expect(subject).to have_many(:authored_notes). - class_name("Note"). - with_foreign_key("author_id"). - dependent(:delete_all) + expect(subject).to have_many(:authored_notes) + .class_name("Note") + .with_foreign_key("author_id") + .dependent(:delete_all) end it do - expect(subject).to have_many(:backup_data). - class_name("BackupData"). - with_foreign_key("instance_user_id"). - dependent(:delete_all) + expect(subject).to have_many(:backup_data) + .class_name("BackupData") + .with_foreign_key("instance_user_id") + .dependent(:delete_all) end it do - expect(subject).to have_many(:blocked_blocks). - class_name("UserBlock"). - with_foreign_key("blocked_id"). - dependent(:delete_all) + expect(subject).to have_many(:blocked_blocks) + .class_name("UserBlock") + .with_foreign_key("blocked_id") + .dependent(:delete_all) end it do - expect(subject).to have_many(:blocker_blocks). - class_name("UserBlock"). - with_foreign_key("blocker_id"). - dependent(:delete_all) + expect(subject).to have_many(:blocker_blocks) + .class_name("UserBlock") + .with_foreign_key("blocker_id") + .dependent(:delete_all) end it do - expect(subject).to have_many(:created_podcasts). - class_name("Podcast"). - with_foreign_key(:creator_id). - dependent(:nullify) + expect(subject).to have_many(:created_podcasts) + .class_name("Podcast") + .with_foreign_key(:creator_id) + .dependent(:nullify) end it do - expect(subject).to have_many(:offender_feedback_messages). - class_name("FeedbackMessage"). - with_foreign_key(:offender_id). - dependent(:nullify) + expect(subject).to have_many(:offender_feedback_messages) + .class_name("FeedbackMessage") + .with_foreign_key(:offender_id) + .dependent(:nullify) end it do - expect(subject).to have_many(:reporter_feedback_messages). - class_name("FeedbackMessage"). - with_foreign_key(:reporter_id). - dependent(:nullify) + expect(subject).to have_many(:reporter_feedback_messages) + .class_name("FeedbackMessage") + .with_foreign_key(:reporter_id) + .dependent(:nullify) end it do - expect(subject).to have_many(:webhook_endpoints). - class_name("Webhook::Endpoint"). - dependent(:delete_all) + expect(subject).to have_many(:webhook_endpoints) + .class_name("Webhook::Endpoint") + .dependent(:delete_all) end # rubocop:enable RSpec/NamedSubject diff --git a/spec/models/user_subscription_spec.rb b/spec/models/user_subscription_spec.rb index c6a57ec14..5ec7581c6 100644 --- a/spec/models/user_subscription_spec.rb +++ b/spec/models/user_subscription_spec.rb @@ -16,8 +16,8 @@ RSpec.describe UserSubscription, type: :model do # rubocop:disable RSpec/NamedSubject it { - expect(subject).to validate_uniqueness_of(:subscriber_id). - scoped_to(%i[subscriber_email user_subscription_sourceable_type user_subscription_sourceable_id]) + expect(subject).to validate_uniqueness_of(:subscriber_id) + .scoped_to(%i[subscriber_email user_subscription_sourceable_type user_subscription_sourceable_id]) } # rubocop:enable RSpec/NamedSubject diff --git a/spec/policies/comment_policy_spec.rb b/spec/policies/comment_policy_spec.rb index 2c5cb6653..032c0bdec 100644 --- a/spec/policies/comment_policy_spec.rb +++ b/spec/policies/comment_policy_spec.rb @@ -53,8 +53,8 @@ RSpec.describe CommentPolicy, type: :policy do it { is_expected.to permit_actions(%i[create moderator_create]) } it do - expect(comment_policy).to permit_mass_assignment_of(valid_attributes_for_moderator_create). - for_action(:moderator_create) + expect(comment_policy).to permit_mass_assignment_of(valid_attributes_for_moderator_create) + .for_action(:moderator_create) end end @@ -64,8 +64,8 @@ RSpec.describe CommentPolicy, type: :policy do it { is_expected.to permit_actions(%i[create moderator_create]) } it do - expect(comment_policy).to permit_mass_assignment_of(valid_attributes_for_moderator_create). - for_action(:moderator_create) + expect(comment_policy).to permit_mass_assignment_of(valid_attributes_for_moderator_create) + .for_action(:moderator_create) end end end @@ -111,8 +111,8 @@ RSpec.describe CommentPolicy, type: :policy do it do expect(comment_policy).to permit_mass_assignment_of(valid_attributes_for_update).for_action(:update) - expect(comment_policy).to permit_mass_assignment_of(valid_attributes_for_moderator_create). - for_action(:moderator_create) + expect(comment_policy).to permit_mass_assignment_of(valid_attributes_for_moderator_create) + .for_action(:moderator_create) end end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index dd25b9bb9..5c66a612b 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -140,27 +140,27 @@ RSpec.configure do |config| stub_request(:any, /emojipedia-us.s3.dualstack.us-west-1.amazonaws.com/).to_rack("stubbed-emoji") - stub_request(:post, /api.fastly.com/). - to_return(status: 200, body: "".to_json, headers: {}) + stub_request(:post, /api.fastly.com/) + .to_return(status: 200, body: "".to_json, headers: {}) - stub_request(:post, /api.bufferapp.com/). - to_return(status: 200, body: { fake_text: "so fake" }.to_json, headers: {}) + stub_request(:post, /api.bufferapp.com/) + .to_return(status: 200, body: { fake_text: "so fake" }.to_json, headers: {}) # for twitter image cdn - stub_request(:get, /twimg.com/). - to_return(status: 200, body: "", headers: {}) + stub_request(:get, /twimg.com/) + .to_return(status: 200, body: "", headers: {}) - stub_request(:any, /api.mailchimp.com/). - to_return(status: 200, body: "", headers: {}) + stub_request(:any, /api.mailchimp.com/) + .to_return(status: 200, body: "", headers: {}) - stub_request(:any, /dummyimage.com/). - to_return(status: 200, body: "", headers: {}) + stub_request(:any, /dummyimage.com/) + .to_return(status: 200, body: "", headers: {}) - stub_request(:post, "http://www.google-analytics.com/collect"). - to_return(status: 200, body: "", headers: {}) + stub_request(:post, "http://www.google-analytics.com/collect") + .to_return(status: 200, body: "", headers: {}) - stub_request(:any, /robohash.org/). - with(headers: + stub_request(:any, /robohash.org/) + .with(headers: { "Accept" => "*/*", "Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3", diff --git a/spec/requests/api/v0/articles_spec.rb b/spec/requests/api/v0/articles_spec.rb index e76b10f27..8b9e7b22d 100644 --- a/spec/requests/api/v0/articles_spec.rb +++ b/spec/requests/api/v0/articles_spec.rb @@ -518,8 +518,8 @@ RSpec.describe "Api::V0::Articles", type: :request do end it "fails with a failing secure compare" do - allow(ActiveSupport::SecurityUtils). - to receive(:secure_compare).and_return(false) + allow(ActiveSupport::SecurityUtils) + .to receive(:secure_compare).and_return(false) post api_articles_path, headers: { "api-key" => api_secret.secret, "content-type" => "application/json" } expect(response).to have_http_status(:unauthorized) end @@ -830,8 +830,8 @@ RSpec.describe "Api::V0::Articles", type: :request do end it "fails with a failing secure compare" do - allow(ActiveSupport::SecurityUtils). - to receive(:secure_compare).and_return(false) + allow(ActiveSupport::SecurityUtils) + .to receive(:secure_compare).and_return(false) put path, headers: { "api-key" => api_secret.secret, "content-type" => "application/json" } expect(response).to have_http_status(:unauthorized) end diff --git a/spec/requests/api/v0/listings_spec.rb b/spec/requests/api/v0/listings_spec.rb index d29913b56..14376a3f0 100644 --- a/spec/requests/api/v0/listings_spec.rb +++ b/spec/requests/api/v0/listings_spec.rb @@ -294,8 +294,8 @@ RSpec.describe "Api::V0::Listings", type: :request do it "fails if category is invalid" do post_listing(title: "Title", body_markdown: "body", category: "unknown") expect(response).to have_http_status(:unprocessable_entity) - expect(response.parsed_body.dig("errors", "listing_category").first). - to match(/must exist/) + expect(response.parsed_body.dig("errors", "listing_category").first) + .to match(/must exist/) end it "does not subtract credits or create a listing if the listing is not valid" do @@ -358,8 +358,8 @@ RSpec.describe "Api::V0::Listings", type: :request do it "cannot create a draft due to internal error" do allow(Organization).to receive(:find_by) post_listing(draft_params.except(:category)) - expect(response.parsed_body.dig("errors", "listing_category").first). - to match(/must exist/) + expect(response.parsed_body.dig("errors", "listing_category").first) + .to match(/must exist/) expect(response).to have_http_status(:unprocessable_entity) end @@ -367,16 +367,16 @@ RSpec.describe "Api::V0::Listings", type: :request do allow(Credits::Buyer).to receive(:call).and_raise(ActiveRecord::Rollback) expect do post_listing(draft_params) - end.to change(Listing, :count).by(1). - and change(user.credits.spent, :size).by(0) + end.to change(Listing, :count).by(1) + .and change(user.credits.spent, :size).by(0) end it "does not create a listing or subtract credits if the purchase does not go through" do allow(Credits::Buyer).to receive(:call).and_raise(ActiveRecord::Rollback) expect do post_listing(listing_params) - end.to change(Listing, :count).by(0). - and change(user.credits.spent, :size).by(0) + end.to change(Listing, :count).by(0) + .and change(user.credits.spent, :size).by(0) end it "creates a listing belonging to the user" do @@ -610,8 +610,8 @@ RSpec.describe "Api::V0::Listings", type: :request do max_id = ListingCategory.maximum(:id) put_listing(listing.id, title: "New title", listing_category_id: max_id + 1) expect(response).to have_http_status(:unprocessable_entity) - expect(response.parsed_body.dig("errors", "listing_category").first). - to match(/must exist/) + expect(response.parsed_body.dig("errors", "listing_category").first) + .to match(/must exist/) end it "updates the title of his listing" do diff --git a/spec/requests/api_secrets_create_spec.rb b/spec/requests/api_secrets_create_spec.rb index 6a5cf8664..c46ba80a5 100644 --- a/spec/requests/api_secrets_create_spec.rb +++ b/spec/requests/api_secrets_create_spec.rb @@ -10,8 +10,8 @@ RSpec.describe "ApiSecretsCreate", type: :request do let(:valid_params) { { description: "My Test 3rd Party App" } } it "creates an ApiSecret for the user" do - expect { post "/users/api_secrets", params: { api_secret: valid_params } }. - to change { user.api_secrets.count }.by 1 + expect { post "/users/api_secrets", params: { api_secret: valid_params } } + .to change { user.api_secrets.count }.by 1 end it "sets the description" do @@ -30,8 +30,8 @@ RSpec.describe "ApiSecretsCreate", type: :request do let(:invalid_params) { { description: nil } } # Force model validation error it "does not create the ApiSecret" do - expect { post "/users/api_secrets", params: { api_secret: invalid_params } }. - not_to(change { user.api_secrets.count }) + expect { post "/users/api_secrets", params: { api_secret: invalid_params } } + .not_to(change { user.api_secrets.count }) end it "flashes an error message" do diff --git a/spec/requests/chat_channels_spec.rb b/spec/requests/chat_channels_spec.rb index 78dc39734..82dc0ef44 100644 --- a/spec/requests/chat_channels_spec.rb +++ b/spec/requests/chat_channels_spec.rb @@ -312,13 +312,13 @@ RSpec.describe "ChatChannels", type: :request do end it "does not block when channel is open" do - expect { post "/chat_channels/block_chat", params: { chat_id: chat_channel.id } }. - to raise_error(Pundit::NotAuthorizedError) + expect { post "/chat_channels/block_chat", params: { chat_id: chat_channel.id } } + .to raise_error(Pundit::NotAuthorizedError) end it "does not block when user does not have permissions" do - expect { post "/chat_channels/block_chat", params: { chat_id: direct_channel.id } }. - to raise_error(Pundit::NotAuthorizedError) + expect { post "/chat_channels/block_chat", params: { chat_id: direct_channel.id } } + .to raise_error(Pundit::NotAuthorizedError) end end diff --git a/spec/requests/comments_create_spec.rb b/spec/requests/comments_create_spec.rb index 6cb3d9cc9..544956d91 100644 --- a/spec/requests/comments_create_spec.rb +++ b/spec/requests/comments_create_spec.rb @@ -35,9 +35,9 @@ RSpec.describe "CommentsCreate", type: :request do it "returns 429 Too Many Requests when a user reaches their rate limit" do allow(RateLimitChecker).to receive(:new).and_return(rate_limit_checker) - allow(rate_limit_checker).to receive(:limit_by_action). - with(:comment_creation). - and_return(true) + allow(rate_limit_checker).to receive(:limit_by_action) + .with(:comment_creation) + .and_return(true) post comments_path, params: comment_params @@ -144,8 +144,8 @@ RSpec.describe "CommentsCreate", type: :request do end def reply_and_mention_comment_author_as_moderator(comment) - allow(SiteConfig).to receive(:mascot_user_id). - and_return(moderator_replier.id) + allow(SiteConfig).to receive(:mascot_user_id) + .and_return(moderator_replier.id) sign_in moderator_replier post moderator_create_comments_path, params: comment_params( diff --git a/spec/requests/email_subscriptions_spec.rb b/spec/requests/email_subscriptions_spec.rb index 0085c58d4..da6056e1f 100644 --- a/spec/requests/email_subscriptions_spec.rb +++ b/spec/requests/email_subscriptions_spec.rb @@ -28,8 +28,8 @@ RSpec.describe "EmailSubscriptions", type: :request do end it "handles error properly" do - expect { get email_subscriptions_unsubscribe_url }. - to raise_error(ActiveRecord::RecordNotFound) + expect { get email_subscriptions_unsubscribe_url } + .to raise_error(ActiveRecord::RecordNotFound) end it "won't work if it's past expiration date" do diff --git a/spec/requests/follows_create_spec.rb b/spec/requests/follows_create_spec.rb index 3eecab5d2..903b4c77c 100644 --- a/spec/requests/follows_create_spec.rb +++ b/spec/requests/follows_create_spec.rb @@ -20,13 +20,13 @@ RSpec.describe "Follows #create", type: :request do before do rate_limit_checker = RateLimitChecker.new(user) - allow(rate_limit_checker). - to receive(:user_today_follow_count). - and_return(SiteConfig.rate_limit_follow_count_daily + 1) + allow(rate_limit_checker) + .to receive(:user_today_follow_count) + .and_return(SiteConfig.rate_limit_follow_count_daily + 1) - allow(RateLimitChecker). - to receive(:new). - and_return(rate_limit_checker) + allow(RateLimitChecker) + .to receive(:new) + .and_return(rate_limit_checker) end it "returns an error for too many follows in a day" do diff --git a/spec/requests/internal/privileged_reactions_spec.rb b/spec/requests/internal/privileged_reactions_spec.rb index 38f86ab19..5070e6314 100644 --- a/spec/requests/internal/privileged_reactions_spec.rb +++ b/spec/requests/internal/privileged_reactions_spec.rb @@ -45,10 +45,10 @@ RSpec.describe "/internal/privileged_reactions", type: :request do describe "GETS /internal/privileged_reactions" do it "renders to appropriate page" do get "/internal/privileged_reactions" - expect(response.body).to include(CGI.escapeHTML(moderator.username)). - and include(CGI.escapeHTML(user_reaction.reactable.username)). - and include(CGI.escapeHTML(comment_reaction.reactable.user.username)). - and include(CGI.escapeHTML(article_reaction.reactable.title)) + expect(response.body).to include(CGI.escapeHTML(moderator.username)) + .and include(CGI.escapeHTML(user_reaction.reactable.username)) + .and include(CGI.escapeHTML(comment_reaction.reactable.user.username)) + .and include(CGI.escapeHTML(article_reaction.reactable.title)) end end end diff --git a/spec/requests/listings_spec.rb b/spec/requests/listings_spec.rb index de70bbff6..56f6251dc 100644 --- a/spec/requests/listings_spec.rb +++ b/spec/requests/listings_spec.rb @@ -169,8 +169,8 @@ RSpec.describe "/listings", type: :request do it "does not subtract credits or create a listing if the listing is not valid" do expect do post "/listings", params: invalid_params - end.to change(Listing, :count).by(0). - and change(user.credits.spent, :size).by(0) + end.to change(Listing, :count).by(0) + .and change(user.credits.spent, :size).by(0) end end @@ -248,16 +248,16 @@ RSpec.describe "/listings", type: :request do allow(Credits::Buyer).to receive(:call).and_raise(ActiveRecord::Rollback) expect do post "/listings", params: draft_params - end.to change(Listing, :count).by(1). - and change(user.credits.spent, :size).by(0) + end.to change(Listing, :count).by(1) + .and change(user.credits.spent, :size).by(0) end it "does not create a listing or subtract credits if the purchase does not go through" do allow(Credits::Buyer).to receive(:call).and_raise(ActiveRecord::Rollback) expect do post "/listings", params: listing_params - end.to change(Listing, :count).by(0). - and change(user.credits.spent, :size).by(0) + end.to change(Listing, :count).by(0) + .and change(user.credits.spent, :size).by(0) end end diff --git a/spec/requests/page_views_spec.rb b/spec/requests/page_views_spec.rb index 957f57e34..943197ea7 100644 --- a/spec/requests/page_views_spec.rb +++ b/spec/requests/page_views_spec.rb @@ -48,8 +48,8 @@ RSpec.describe "PageViews", type: :request do article_id: article.id, referrer: "test" } - expect(Users::RecordFieldTestEventWorker).to have_received(:perform_async). - with(user.id, :user_home_feed, "user_views_article_four_days_in_week") + expect(Users::RecordFieldTestEventWorker).to have_received(:perform_async) + .with(user.id, :user_home_feed, "user_views_article_four_days_in_week") end end diff --git a/spec/requests/social_previews_spec.rb b/spec/requests/social_previews_spec.rb index 3fc304ab5..330d3e745 100644 --- a/spec/requests/social_previews_spec.rb +++ b/spec/requests/social_previews_spec.rb @@ -9,10 +9,10 @@ RSpec.describe "SocialPreviews", type: :request do let(:image_url) { "https://hcti.io/v1/image/6c52de9d-4d37-4008-80f8-67155589e1a1" } before do - stub_request(:post, /hcti.io/). - to_return(status: 200, - body: "{ \"url\": \"#{image_url}\" }", - headers: { "Content-Type" => "application/json" }) + stub_request(:post, /hcti.io/) + .to_return(status: 200, + body: "{ \"url\": \"#{image_url}\" }", + headers: { "Content-Type" => "application/json" }) end describe "GET /social_previews/article/:id" do diff --git a/spec/requests/twitch_stream_updates_spec.rb b/spec/requests/twitch_stream_updates_spec.rb index 861b4ebe1..d19a64a9a 100644 --- a/spec/requests/twitch_stream_updates_spec.rb +++ b/spec/requests/twitch_stream_updates_spec.rb @@ -77,9 +77,9 @@ RSpec.describe "TwitchStramUpdates", type: :request do post "/users/#{user.id}/twitch_stream_updates", params: twitch_webhook_params, headers: { "Content-Type" => "application/json", "X-Hub-Signature" => twitch_webhook_secret_sha } - end. - to change { user.reload.currently_streaming? }.from(false).to(true). - and change { user.reload.currently_streaming_on_twitch? }.from(false).to(true) + end + .to change { user.reload.currently_streaming? }.from(false).to(true) + .and change { user.reload.currently_streaming_on_twitch? }.from(false).to(true) end end @@ -91,9 +91,9 @@ RSpec.describe "TwitchStramUpdates", type: :request do post "/users/#{user.id}/twitch_stream_updates", params: twitch_webhook_params, headers: { "Content-Type" => "application/json", "X-Hub-Signature" => twitch_webhook_secret_sha } - end. - to not_change { user.reload.currently_streaming? }.from(false). - and not_change { user.reload.currently_streaming_on_twitch? }.from(false) + end + .to not_change { user.reload.currently_streaming? }.from(false) + .and not_change { user.reload.currently_streaming_on_twitch? }.from(false) end end @@ -112,9 +112,9 @@ RSpec.describe "TwitchStramUpdates", type: :request do post "/users/#{user.id}/twitch_stream_updates", params: twitch_webhook_params, headers: { "Content-Type" => "application/json", "X-Hub-Signature" => twitch_webhook_secret_sha } - end. - to change { user.reload.currently_streaming? }.from(true).to(false). - and change { user.reload.currently_streaming_on_twitch? }.from(true).to(false) + end + .to change { user.reload.currently_streaming? }.from(true).to(false) + .and change { user.reload.currently_streaming_on_twitch? }.from(true).to(false) end end end diff --git a/spec/requests/user/user_organization_spec.rb b/spec/requests/user/user_organization_spec.rb index 3c1be9313..134e9861b 100644 --- a/spec/requests/user/user_organization_spec.rb +++ b/spec/requests/user/user_organization_spec.rb @@ -133,8 +133,8 @@ RSpec.describe "UserOrganization", type: :request do it "raises not_authorized if user is not org_admin" do org_member_org_id = org_member.organizations.first.id sign_in org_member - expect { post "/users/add_org_admin", params: { user_id: user2.id, organization_id: org_member_org_id } }. - to raise_error Pundit::NotAuthorizedError + expect { post "/users/add_org_admin", params: { user_id: user2.id, organization_id: org_member_org_id } } + .to raise_error Pundit::NotAuthorizedError end end @@ -161,8 +161,8 @@ RSpec.describe "UserOrganization", type: :request do it "remove_org_admin raises if user not org_admin" do org_admin.organization_memberships.update_all(type_of_user: "member") - expect { post "/users/remove_org_admin", params: { user_id: second_org_admin.id, organization_id: org_id } }. - to raise_error Pundit::NotAuthorizedError + expect { post "/users/remove_org_admin", params: { user_id: second_org_admin.id, organization_id: org_id } } + .to raise_error Pundit::NotAuthorizedError end end end diff --git a/spec/requests/user/user_settings_spec.rb b/spec/requests/user/user_settings_spec.rb index 20d8ac092..aed2789a3 100644 --- a/spec/requests/user/user_settings_spec.rb +++ b/spec/requests/user/user_settings_spec.rb @@ -22,8 +22,8 @@ RSpec.describe "UserSettings", type: :request do end it "handles unknown settings tab properly" do - expect { get "/settings/does-not-exist" }. - to raise_error(ActiveRecord::RecordNotFound) + expect { get "/settings/does-not-exist" } + .to raise_error(ActiveRecord::RecordNotFound) end it "displays content on ux tab properly" do diff --git a/spec/services/bulk_sql_delete_spec.rb b/spec/services/bulk_sql_delete_spec.rb index 9a380e400..f8acf75aa 100644 --- a/spec/services/bulk_sql_delete_spec.rb +++ b/spec/services/bulk_sql_delete_spec.rb @@ -29,8 +29,8 @@ describe BulkSqlDelete, type: :service do it "logs errors that occur" do allow(logger).to receive(:error) # rubocop:disable RSpec/AnyInstance - allow_any_instance_of(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter). - to(receive(:exec_delete)).and_raise("broken") + allow_any_instance_of(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) + .to(receive(:exec_delete)).and_raise("broken") # rubocop:enable RSpec/AnyInstance expect { described_class.delete_in_batches(sql) }.to raise_error("broken") diff --git a/spec/services/payments/customer_spec.rb b/spec/services/payments/customer_spec.rb index 4b9acc24f..82ab63e04 100644 --- a/spec/services/payments/customer_spec.rb +++ b/spec/services/payments/customer_spec.rb @@ -55,8 +55,8 @@ RSpec.describe Payments::Customer, type: :service do end it "raises Payments::PaymentsError for any other known error" do - allow(Stripe::Customer).to receive(:create).with(email: "foobar"). - and_raise(Stripe::StripeError) + allow(Stripe::Customer).to receive(:create).with(email: "foobar") + .and_raise(Stripe::StripeError) expect { described_class.create(email: "foobar") }.to raise_error(Payments::PaymentsError) end end diff --git a/spec/services/rate_limit_checker_spec.rb b/spec/services/rate_limit_checker_spec.rb index c6d00ef71..8bcaa7efd 100644 --- a/spec/services/rate_limit_checker_spec.rb +++ b/spec/services/rate_limit_checker_spec.rb @@ -67,25 +67,25 @@ RSpec.describe RateLimitChecker, type: :service do end it "returns true if a user has followed more than accounts today" do - allow(rate_limit_checker). - to receive(:user_today_follow_count). - and_return(SiteConfig.rate_limit_follow_count_daily + 1) + allow(rate_limit_checker) + .to receive(:user_today_follow_count) + .and_return(SiteConfig.rate_limit_follow_count_daily + 1) expect(rate_limit_checker.limit_by_action("follow_account")).to be(true) end it "returns false if a user's following_users_count is less than " do - allow(user). - to receive(:following_users_count). - and_return(SiteConfig.rate_limit_follow_count_daily - 1) + allow(user) + .to receive(:following_users_count) + .and_return(SiteConfig.rate_limit_follow_count_daily - 1) expect(rate_limit_checker.limit_by_action("follow_account")).to be(false) end it "returns false if a user has followed less than accounts today" do - allow(rate_limit_checker). - to receive(:user_today_follow_count). - and_return(SiteConfig.rate_limit_follow_count_daily) + allow(rate_limit_checker) + .to receive(:user_today_follow_count) + .and_return(SiteConfig.rate_limit_follow_count_daily) expect(rate_limit_checker.limit_by_action("follow_account")).to be(false) end @@ -95,9 +95,9 @@ RSpec.describe RateLimitChecker, type: :service do end it "logs a rate limit hit to datadog" do - allow(Rails.cache). - to receive(:read).with("#{user.id}_organization_creation", raw: true). - and_return(SiteConfig.rate_limit_organization_creation + 1) + allow(Rails.cache) + .to receive(:read).with("#{user.id}_organization_creation", raw: true) + .and_return(SiteConfig.rate_limit_organization_creation + 1) allow(DatadogStatsClient).to receive(:increment) described_class.new(user).limit_by_action("organization_creation") diff --git a/spec/services/slack/announcer_spec.rb b/spec/services/slack/announcer_spec.rb index 56c12049e..7bd36b597 100644 --- a/spec/services/slack/announcer_spec.rb +++ b/spec/services/slack/announcer_spec.rb @@ -27,8 +27,8 @@ RSpec.describe Slack::Announcer, type: :service do described_class.call(params) - expect(SlackClient).to have_received(:ping). - with(message, params.reject { |k| k == :message }). - once + expect(SlackClient).to have_received(:ping) + .with(message, params.reject { |k| k == :message }) + .once end end diff --git a/spec/services/streams/twitch_access_token/get_spec.rb b/spec/services/streams/twitch_access_token/get_spec.rb index 1c475c606..e6ac3ab61 100644 --- a/spec/services/streams/twitch_access_token/get_spec.rb +++ b/spec/services/streams/twitch_access_token/get_spec.rb @@ -10,10 +10,10 @@ RSpec.describe Streams::TwitchAccessToken::Get, type: :service do } end let!(:twitch_token_stubbed_route) do - stub_request(:post, "https://id.twitch.tv/oauth2/token"). - with(body: expected_twitch_token_body). - and_return(body: { access_token: "FAKE_BRAND_NEW_TWITCH_TOKEN", - expires_in: 5_184_000 }.to_json, headers: { "Content-Type" => "application/json" }) + stub_request(:post, "https://id.twitch.tv/oauth2/token") + .with(body: expected_twitch_token_body) + .and_return(body: { access_token: "FAKE_BRAND_NEW_TWITCH_TOKEN", + expires_in: 5_184_000 }.to_json, headers: { "Content-Type" => "application/json" }) end before do diff --git a/spec/services/streams/twitch_webhook/register_spec.rb b/spec/services/streams/twitch_webhook/register_spec.rb index 3a4aa9069..828fcb785 100644 --- a/spec/services/streams/twitch_webhook/register_spec.rb +++ b/spec/services/streams/twitch_webhook/register_spec.rb @@ -21,16 +21,16 @@ RSpec.describe Streams::TwitchWebhook::Register, type: :service do let(:expected_twitch_user_params) { { login: "test-username" } } let!(:twitch_webhook_registration_stubbed_route) do - stub_request(:post, "https://api.twitch.tv/helix/webhooks/hub"). - with(body: URI.encode_www_form(expected_twitch_webhook_params), headers: expected_headers). - and_return(status: 204) + stub_request(:post, "https://api.twitch.tv/helix/webhooks/hub") + .with(body: URI.encode_www_form(expected_twitch_webhook_params), headers: expected_headers) + .and_return(status: 204) end context "when twitch returns data" do let!(:twitch_user_stubbed_route) do - stub_request(:get, "https://api.twitch.tv/helix/users"). - with(query: expected_twitch_user_params, headers: expected_headers). - and_return(body: { data: [{ id: 654_321 }] }.to_json, headers: { "Content-Type" => "application/json" }) + stub_request(:get, "https://api.twitch.tv/helix/users") + .with(query: expected_twitch_user_params, headers: expected_headers) + .and_return(body: { data: [{ id: 654_321 }] }.to_json, headers: { "Content-Type" => "application/json" }) end it "registers for webhooks" do @@ -43,9 +43,9 @@ RSpec.describe Streams::TwitchWebhook::Register, type: :service do context "when twitch return no data" do let!(:twitch_user_stubbed_route) do - stub_request(:get, "https://api.twitch.tv/helix/users"). - with(query: expected_twitch_user_params, headers: expected_headers). - and_return(body: {}.to_json, headers: { "Content-Type" => "application/json" }) + stub_request(:get, "https://api.twitch.tv/helix/users") + .with(query: expected_twitch_user_params, headers: expected_headers) + .and_return(body: {}.to_json, headers: { "Content-Type" => "application/json" }) end it "doesn't fail when twitch doesn't return data" do @@ -61,9 +61,9 @@ RSpec.describe Streams::TwitchWebhook::Register, type: :service do context "when twitch returns empty data" do let!(:twitch_user_stubbed_route) do - stub_request(:get, "https://api.twitch.tv/helix/users"). - with(query: expected_twitch_user_params, headers: expected_headers). - and_return(body: { "data" => [] }.to_json, headers: { "Content-Type" => "application/json" }) + stub_request(:get, "https://api.twitch.tv/helix/users") + .with(query: expected_twitch_user_params, headers: expected_headers) + .and_return(body: { "data" => [] }.to_json, headers: { "Content-Type" => "application/json" }) end it "doesn't fail" do diff --git a/spec/services/user_blocks/channel_handler_spec.rb b/spec/services/user_blocks/channel_handler_spec.rb index 9b1781107..cb899d2ac 100644 --- a/spec/services/user_blocks/channel_handler_spec.rb +++ b/spec/services/user_blocks/channel_handler_spec.rb @@ -25,8 +25,8 @@ RSpec.describe UserBlocks::ChannelHandler, type: :service do end it "removes the related chat channel memberships" do - expect { described_class.new(UserBlock.first).block_chat_channel }. - to change(ChatChannelMembership.where(status: "active"), :count).to 0 + expect { described_class.new(UserBlock.first).block_chat_channel } + .to change(ChatChannelMembership.where(status: "active"), :count).to 0 end end @@ -38,8 +38,8 @@ RSpec.describe UserBlocks::ChannelHandler, type: :service do it "updates the related chat channel memberships" do ChatChannelMembership.update_all(status: "left-channel") - expect { described_class.new(UserBlock.first).unblock_chat_channel }. - to change(ChatChannelMembership.where(status: "left-channel"), :count).to 0 + expect { described_class.new(UserBlock.first).unblock_chat_channel } + .to change(ChatChannelMembership.where(status: "left-channel"), :count).to 0 end end end diff --git a/spec/system/internal/admin_awards_badges_spec.rb b/spec/system/internal/admin_awards_badges_spec.rb index 7b38e1b09..4a4641d44 100644 --- a/spec/system/internal/admin_awards_badges_spec.rb +++ b/spec/system/internal/admin_awards_badges_spec.rb @@ -36,8 +36,8 @@ RSpec.describe "Admin awards badges", type: :system do end it "awards badges" do - expect { award_two_badges }.to change { user.badges.count }.by(1). - and change { user2.badges.count }.by(1) + expect { award_two_badges }.to change { user.badges.count }.by(1) + .and change { user2.badges.count }.by(1) expect(page).to have_content("BadgeRewarder task ran!") visit "/#{user.username}/" diff --git a/spec/system/search/display_comments_search_spec.rb b/spec/system/search/display_comments_search_spec.rb index 1242e0da8..b15c5d343 100644 --- a/spec/system/search/display_comments_search_spec.rb +++ b/spec/system/search/display_comments_search_spec.rb @@ -9,7 +9,7 @@ RSpec.describe "Display articles search spec", type: :system, js: true, elastics url_encoded_query = CGI.escape(query) visit "/search?q=#{url_encoded_query}&filters=class_name:Comment" - expect(page.find(".crayons-story__snippet")["innerHTML"]). - to eq("…<marquee='alert(document.cookie)'>XSS…") + expect(page.find(".crayons-story__snippet")["innerHTML"]) + .to eq("…<marquee='alert(document.cookie)'>XSS…") end end diff --git a/spec/system/user/user_edits_integrations_spec.rb b/spec/system/user/user_edits_integrations_spec.rb index f896407b7..044dd55c1 100644 --- a/spec/system/user/user_edits_integrations_spec.rb +++ b/spec/system/user/user_edits_integrations_spec.rb @@ -15,8 +15,8 @@ RSpec.describe "User edits their integrations", type: :system, js: true do before do sign_in user - stub_request(:get, "https://api.github.com/user/repos?per_page=100"). - to_return(status: 200, body: github_response_body.to_json, headers: { "Content-Type" => "application/json" }) + stub_request(:get, "https://api.github.com/user/repos?per_page=100") + .to_return(status: 200, body: github_response_body.to_json, headers: { "Content-Type" => "application/json" }) end describe "via visiting /settings" do diff --git a/spec/workers/metrics/record_daily_notifications_worker_spec.rb b/spec/workers/metrics/record_daily_notifications_worker_spec.rb index 7230da9c7..4d5579662 100644 --- a/spec/workers/metrics/record_daily_notifications_worker_spec.rb +++ b/spec/workers/metrics/record_daily_notifications_worker_spec.rb @@ -18,9 +18,9 @@ RSpec.describe Metrics::RecordDailyNotificationsWorker, type: :worker do expect(DatadogStatsClient).to have_received(:count).exactly(event_title_count).times expect( DatadogStatsClient, - ).to have_received(:count). - with("ahoy_events", 1, { tags: ["title:welcome_notification_welcome_thread"] }). - at_least(1) + ).to have_received(:count) + .with("ahoy_events", 1, { tags: ["title:welcome_notification_welcome_thread"] }) + .at_least(1) end end end diff --git a/spec/workers/webhook/dispatch_event_worker_spec.rb b/spec/workers/webhook/dispatch_event_worker_spec.rb index d6b656bbd..d76f8e3d5 100644 --- a/spec/workers/webhook/dispatch_event_worker_spec.rb +++ b/spec/workers/webhook/dispatch_event_worker_spec.rb @@ -15,10 +15,10 @@ RSpec.describe Webhook::DispatchEventWorker, type: :worker do it "posts an event" do allow(client).to receive(:post) worker.perform(url, json) - expect(client).to have_received(:post).once. - with(Addressable::URI.parse(url), headers: { "Content-Type" => "application/json" }, - body: json, - timeout: 10) + expect(client).to have_received(:post).once + .with(Addressable::URI.parse(url), headers: { "Content-Type" => "application/json" }, + body: json, + timeout: 10) end it "doesn't fail" do