From e428670e614b59048431c79e849d18315da98d72 Mon Sep 17 00:00:00 2001 From: Claire Date: Mon, 5 Jun 2023 17:35:05 +0200 Subject: [PATCH 01/24] Fix CSP headers when S3_ALIAS_HOST includes a path component (#25273) --- config/initializers/content_security_policy.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/initializers/content_security_policy.rb b/config/initializers/content_security_policy.rb index f4f917799..a05b67440 100644 --- a/config/initializers/content_security_policy.rb +++ b/config/initializers/content_security_policy.rb @@ -3,7 +3,7 @@ # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy def host_to_url(str) - "http#{Rails.configuration.x.use_https ? 's' : ''}://#{str}" if str.present? + "http#{Rails.configuration.x.use_https ? 's' : ''}://#{str}".split('/').first if str.present? end base_host = Rails.configuration.x.web_domain From af135bddd0a17be9a1345216db7986b593d51151 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Mon, 5 Jun 2023 14:46:04 -0400 Subject: [PATCH 02/24] Update `Admin::Metrics::Measure` classes for Rails 7 (#25236) --- .../measure/instance_accounts_measure.rb | 24 ++++++--------- .../measure/instance_followers_measure.rb | 24 ++++++--------- .../measure/instance_follows_measure.rb | 24 ++++++--------- .../instance_media_attachments_measure.rb | 23 +++++--------- .../measure/instance_reports_measure.rb | 24 ++++++--------- .../measure/instance_statuses_measure.rb | 30 ++++++++++--------- .../metrics/measure/new_users_measure.rb | 16 +++++----- .../metrics/measure/opened_reports_measure.rb | 16 +++++----- app/lib/admin/metrics/measure/query_helper.rb | 25 ++++++++++++++++ .../measure/resolved_reports_measure.rb | 16 +++++----- .../metrics/measure/tag_servers_measure.rb | 24 ++++++++++----- .../measure/active_users_measure_spec.rb | 17 +++++++++++ .../measure/instance_accounts_measure_spec.rb | 6 ++++ .../instance_followers_measure_spec.rb | 6 ++++ .../measure/instance_follows_measure_spec.rb | 6 ++++ ...instance_media_attachments_measure_spec.rb | 6 ++++ .../measure/instance_reports_measure_spec.rb | 6 ++++ .../measure/instance_statuses_measure_spec.rb | 6 ++++ .../measure/interactions_measure_spec.rb | 17 +++++++++++ .../metrics/measure/new_users_measure_spec.rb | 17 +++++++++++ .../measure/opened_reports_measure_spec.rb | 17 +++++++++++ .../measure/resolved_reports_measure_spec.rb | 17 +++++++++++ .../measure/tag_accounts_measure_spec.rb | 19 ++++++++++++ .../measure/tag_servers_measure_spec.rb | 19 ++++++++++++ .../metrics/measure/tag_uses_measure_spec.rb | 19 ++++++++++++ 25 files changed, 307 insertions(+), 117 deletions(-) create mode 100644 app/lib/admin/metrics/measure/query_helper.rb create mode 100644 spec/lib/admin/metrics/measure/active_users_measure_spec.rb create mode 100644 spec/lib/admin/metrics/measure/interactions_measure_spec.rb create mode 100644 spec/lib/admin/metrics/measure/new_users_measure_spec.rb create mode 100644 spec/lib/admin/metrics/measure/opened_reports_measure_spec.rb create mode 100644 spec/lib/admin/metrics/measure/resolved_reports_measure_spec.rb create mode 100644 spec/lib/admin/metrics/measure/tag_accounts_measure_spec.rb create mode 100644 spec/lib/admin/metrics/measure/tag_servers_measure_spec.rb create mode 100644 spec/lib/admin/metrics/measure/tag_uses_measure_spec.rb diff --git a/app/lib/admin/metrics/measure/instance_accounts_measure.rb b/app/lib/admin/metrics/measure/instance_accounts_measure.rb index 14a61de88..3d081fdd9 100644 --- a/app/lib/admin/metrics/measure/instance_accounts_measure.rb +++ b/app/lib/admin/metrics/measure/instance_accounts_measure.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class Admin::Metrics::Measure::InstanceAccountsMeasure < Admin::Metrics::Measure::BaseMeasure + include Admin::Metrics::Measure::QueryHelper + def self.with_params? true end @@ -25,33 +27,25 @@ class Admin::Metrics::Measure::InstanceAccountsMeasure < Admin::Metrics::Measure nil end - def perform_data_query - account_matching_sql = begin - if params[:include_subdomains] - "accounts.domain IN (SELECT domain FROM instances WHERE reverse('.' || domain) LIKE reverse('.' || $3::text))" - else - 'accounts.domain = $3::text' - end - end + def sql_array + [sql_query_string, { start_at: @start_at, end_at: @end_at, domain: params[:domain] }] + end - sql = <<-SQL.squish + def sql_query_string + <<~SQL.squish SELECT axis.*, ( WITH new_accounts AS ( SELECT accounts.id FROM accounts WHERE date_trunc('day', accounts.created_at)::date = axis.period - AND #{account_matching_sql} + AND #{account_domain_sql(params[:include_subdomains])} ) SELECT count(*) FROM new_accounts ) AS value FROM ( - SELECT generate_series(date_trunc('day', $1::timestamp)::date, date_trunc('day', $2::timestamp)::date, interval '1 day') AS period + SELECT generate_series(date_trunc('day', :start_at::timestamp)::date, date_trunc('day', :end_at::timestamp)::date, interval '1 day') AS period ) AS axis SQL - - rows = ActiveRecord::Base.connection.select_all(sql, nil, [[nil, @start_at], [nil, @end_at], [nil, params[:domain]]]) - - rows.map { |row| { date: row['period'], value: row['value'].to_s } } end def time_period diff --git a/app/lib/admin/metrics/measure/instance_followers_measure.rb b/app/lib/admin/metrics/measure/instance_followers_measure.rb index dc0f5492c..378c6754d 100644 --- a/app/lib/admin/metrics/measure/instance_followers_measure.rb +++ b/app/lib/admin/metrics/measure/instance_followers_measure.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class Admin::Metrics::Measure::InstanceFollowersMeasure < Admin::Metrics::Measure::BaseMeasure + include Admin::Metrics::Measure::QueryHelper + def self.with_params? true end @@ -25,34 +27,26 @@ class Admin::Metrics::Measure::InstanceFollowersMeasure < Admin::Metrics::Measur nil end - def perform_data_query - account_matching_sql = begin - if params[:include_subdomains] - "accounts.domain IN (SELECT domain FROM instances WHERE reverse('.' || domain) LIKE reverse('.' || $3::text))" - else - 'accounts.domain = $3::text' - end - end + def sql_array + [sql_query_string, { start_at: @start_at, end_at: @end_at, domain: params[:domain] }] + end - sql = <<-SQL.squish + def sql_query_string + <<~SQL.squish SELECT axis.*, ( WITH new_followers AS ( SELECT follows.id FROM follows INNER JOIN accounts ON follows.account_id = accounts.id WHERE date_trunc('day', follows.created_at)::date = axis.period - AND #{account_matching_sql} + AND #{account_domain_sql(params[:include_subdomains])} ) SELECT count(*) FROM new_followers ) AS value FROM ( - SELECT generate_series(date_trunc('day', $1::timestamp)::date, date_trunc('day', $2::timestamp)::date, interval '1 day') AS period + SELECT generate_series(date_trunc('day', :start_at::timestamp)::date, date_trunc('day', :end_at::timestamp)::date, interval '1 day') AS period ) AS axis SQL - - rows = ActiveRecord::Base.connection.select_all(sql, nil, [[nil, @start_at], [nil, @end_at], [nil, params[:domain]]]) - - rows.map { |row| { date: row['period'], value: row['value'].to_s } } end def time_period diff --git a/app/lib/admin/metrics/measure/instance_follows_measure.rb b/app/lib/admin/metrics/measure/instance_follows_measure.rb index f2088ffb3..e213348fb 100644 --- a/app/lib/admin/metrics/measure/instance_follows_measure.rb +++ b/app/lib/admin/metrics/measure/instance_follows_measure.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class Admin::Metrics::Measure::InstanceFollowsMeasure < Admin::Metrics::Measure::BaseMeasure + include Admin::Metrics::Measure::QueryHelper + def self.with_params? true end @@ -25,34 +27,26 @@ class Admin::Metrics::Measure::InstanceFollowsMeasure < Admin::Metrics::Measure: nil end - def perform_data_query - account_matching_sql = begin - if params[:include_subdomains] - "accounts.domain IN (SELECT domain FROM instances WHERE reverse('.' || domain) LIKE reverse('.' || $3::text))" - else - 'accounts.domain = $3::text' - end - end + def sql_array + [sql_query_string, { start_at: @start_at, end_at: @end_at, domain: params[:domain] }] + end - sql = <<-SQL.squish + def sql_query_string + <<~SQL.squish SELECT axis.*, ( WITH new_follows AS ( SELECT follows.id FROM follows INNER JOIN accounts ON follows.target_account_id = accounts.id WHERE date_trunc('day', follows.created_at)::date = axis.period - AND #{account_matching_sql} + AND #{account_domain_sql(params[:include_subdomains])} ) SELECT count(*) FROM new_follows ) AS value FROM ( - SELECT generate_series(date_trunc('day', $1::timestamp)::date, date_trunc('day', $2::timestamp)::date, interval '1 day') AS period + SELECT generate_series(date_trunc('day', :start_at::timestamp)::date, date_trunc('day', :end_at::timestamp)::date, interval '1 day') AS period ) AS axis SQL - - rows = ActiveRecord::Base.connection.select_all(sql, nil, [[nil, @start_at], [nil, @end_at], [nil, params[:domain]]]) - - rows.map { |row| { date: row['period'], value: row['value'].to_s } } end def time_period diff --git a/app/lib/admin/metrics/measure/instance_media_attachments_measure.rb b/app/lib/admin/metrics/measure/instance_media_attachments_measure.rb index 779883e03..2d4b5f56b 100644 --- a/app/lib/admin/metrics/measure/instance_media_attachments_measure.rb +++ b/app/lib/admin/metrics/measure/instance_media_attachments_measure.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true class Admin::Metrics::Measure::InstanceMediaAttachmentsMeasure < Admin::Metrics::Measure::BaseMeasure + include Admin::Metrics::Measure::QueryHelper include ActionView::Helpers::NumberHelper def self.with_params? @@ -35,34 +36,26 @@ class Admin::Metrics::Measure::InstanceMediaAttachmentsMeasure < Admin::Metrics: nil end - def perform_data_query - account_matching_sql = begin - if params[:include_subdomains] - "accounts.domain IN (SELECT domain FROM instances WHERE reverse('.' || domain) LIKE reverse('.' || $3::text))" - else - 'accounts.domain = $3::text' - end - end + def sql_array + [sql_query_string, { start_at: @start_at, end_at: @end_at, domain: params[:domain] }] + end - sql = <<-SQL.squish + def sql_query_string + <<~SQL.squish SELECT axis.*, ( WITH new_media_attachments AS ( SELECT COALESCE(media_attachments.file_file_size, 0) + COALESCE(media_attachments.thumbnail_file_size, 0) AS size FROM media_attachments INNER JOIN accounts ON accounts.id = media_attachments.account_id WHERE date_trunc('day', media_attachments.created_at)::date = axis.period - AND #{account_matching_sql} + AND #{account_domain_sql(params[:include_subdomains])} ) SELECT SUM(size) FROM new_media_attachments ) AS value FROM ( - SELECT generate_series(date_trunc('day', $1::timestamp)::date, date_trunc('day', $2::timestamp)::date, interval '1 day') AS period + SELECT generate_series(date_trunc('day', :start_at::timestamp)::date, date_trunc('day', :end_at::timestamp)::date, interval '1 day') AS period ) AS axis SQL - - rows = ActiveRecord::Base.connection.select_all(sql, nil, [[nil, @start_at], [nil, @end_at], [nil, params[:domain]]]) - - rows.map { |row| { date: row['period'], value: row['value'].to_s } } end def time_period diff --git a/app/lib/admin/metrics/measure/instance_reports_measure.rb b/app/lib/admin/metrics/measure/instance_reports_measure.rb index c1f7189bf..9da3d53e3 100644 --- a/app/lib/admin/metrics/measure/instance_reports_measure.rb +++ b/app/lib/admin/metrics/measure/instance_reports_measure.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class Admin::Metrics::Measure::InstanceReportsMeasure < Admin::Metrics::Measure::BaseMeasure + include Admin::Metrics::Measure::QueryHelper + def self.with_params? true end @@ -25,34 +27,26 @@ class Admin::Metrics::Measure::InstanceReportsMeasure < Admin::Metrics::Measure: nil end - def perform_data_query - account_matching_sql = begin - if params[:include_subdomains] - "accounts.domain IN (SELECT domain FROM instances WHERE reverse('.' || domain) LIKE reverse('.' || $3::text))" - else - 'accounts.domain = $3::text' - end - end + def sql_array + [sql_query_string, { start_at: @start_at, end_at: @end_at, domain: params[:domain] }] + end - sql = <<-SQL.squish + def sql_query_string + <<~SQL.squish SELECT axis.*, ( WITH new_reports AS ( SELECT reports.id FROM reports INNER JOIN accounts ON accounts.id = reports.target_account_id WHERE date_trunc('day', reports.created_at)::date = axis.period - AND #{account_matching_sql} + AND #{account_domain_sql(params[:include_subdomains])} ) SELECT count(*) FROM new_reports ) AS value FROM ( - SELECT generate_series(date_trunc('day', $1::timestamp)::date, date_trunc('day', $2::timestamp)::date, interval '1 day') AS period + SELECT generate_series(date_trunc('day', :start_at::timestamp)::date, date_trunc('day', :end_at::timestamp)::date, interval '1 day') AS period ) AS axis SQL - - rows = ActiveRecord::Base.connection.select_all(sql, nil, [[nil, @start_at], [nil, @end_at], [nil, params[:domain]]]) - - rows.map { |row| { date: row['period'], value: row['value'].to_s } } end def time_period diff --git a/app/lib/admin/metrics/measure/instance_statuses_measure.rb b/app/lib/admin/metrics/measure/instance_statuses_measure.rb index 1b38b40c5..8c71c6614 100644 --- a/app/lib/admin/metrics/measure/instance_statuses_measure.rb +++ b/app/lib/admin/metrics/measure/instance_statuses_measure.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class Admin::Metrics::Measure::InstanceStatusesMeasure < Admin::Metrics::Measure::BaseMeasure + include Admin::Metrics::Measure::QueryHelper + def self.with_params? true end @@ -25,35 +27,35 @@ class Admin::Metrics::Measure::InstanceStatusesMeasure < Admin::Metrics::Measure nil end - def perform_data_query - account_matching_sql = begin - if params[:include_subdomains] - "accounts.domain IN (SELECT domain FROM instances WHERE reverse('.' || domain) LIKE reverse('.' || $5::text))" - else - 'accounts.domain = $5::text' - end - end + def sql_array + [sql_query_string, { start_at: @start_at, end_at: @end_at, domain: params[:domain], earliest_status_id: earliest_status_id, latest_status_id: latest_status_id }] + end - sql = <<-SQL.squish + def sql_query_string + <<~SQL.squish SELECT axis.*, ( WITH new_statuses AS ( SELECT statuses.id FROM statuses INNER JOIN accounts ON accounts.id = statuses.account_id - WHERE statuses.id BETWEEN $3 AND $4 - AND #{account_matching_sql} + WHERE statuses.id BETWEEN :earliest_status_id AND :latest_status_id + AND #{account_domain_sql(params[:include_subdomains])} AND date_trunc('day', statuses.created_at)::date = axis.period ) SELECT count(*) FROM new_statuses ) AS value FROM ( - SELECT generate_series(date_trunc('day', $1::timestamp)::date, date_trunc('day', $2::timestamp)::date, interval '1 day') AS period + SELECT generate_series(date_trunc('day', :start_at::timestamp)::date, date_trunc('day', :end_at::timestamp)::date, interval '1 day') AS period ) AS axis SQL + end - rows = ActiveRecord::Base.connection.select_all(sql, nil, [[nil, @start_at], [nil, @end_at], [nil, Mastodon::Snowflake.id_at(@start_at, with_random: false)], [nil, Mastodon::Snowflake.id_at(@end_at, with_random: false)], [nil, params[:domain]]]) + def earliest_status_id + Mastodon::Snowflake.id_at(@start_at, with_random: false) + end - rows.map { |row| { date: row['period'], value: row['value'].to_s } } + def latest_status_id + Mastodon::Snowflake.id_at(@end_at, with_random: false) end def time_period diff --git a/app/lib/admin/metrics/measure/new_users_measure.rb b/app/lib/admin/metrics/measure/new_users_measure.rb index 71191f1a2..6837c14c8 100644 --- a/app/lib/admin/metrics/measure/new_users_measure.rb +++ b/app/lib/admin/metrics/measure/new_users_measure.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class Admin::Metrics::Measure::NewUsersMeasure < Admin::Metrics::Measure::BaseMeasure + include Admin::Metrics::Measure::QueryHelper + def key 'new_users' end @@ -15,8 +17,12 @@ class Admin::Metrics::Measure::NewUsersMeasure < Admin::Metrics::Measure::BaseMe User.where(created_at: previous_time_period).count end - def perform_data_query - sql = <<-SQL.squish + def sql_array + [sql_query_string, { start_at: @start_at, end_at: @end_at }] + end + + def sql_query_string + <<~SQL.squish SELECT axis.*, ( WITH new_users AS ( SELECT users.id @@ -26,12 +32,8 @@ class Admin::Metrics::Measure::NewUsersMeasure < Admin::Metrics::Measure::BaseMe SELECT count(*) FROM new_users ) AS value FROM ( - SELECT generate_series(date_trunc('day', $1::timestamp)::date, date_trunc('day', $2::timestamp)::date, interval '1 day') AS period + SELECT generate_series(date_trunc('day', :start_at::timestamp)::date, date_trunc('day', :end_at::timestamp)::date, interval '1 day') AS period ) AS axis SQL - - rows = ActiveRecord::Base.connection.select_all(sql, nil, [[nil, @start_at], [nil, @end_at]]) - - rows.map { |row| { date: row['period'], value: row['value'].to_s } } end end diff --git a/app/lib/admin/metrics/measure/opened_reports_measure.rb b/app/lib/admin/metrics/measure/opened_reports_measure.rb index 4b80a0c8c..c395c4634 100644 --- a/app/lib/admin/metrics/measure/opened_reports_measure.rb +++ b/app/lib/admin/metrics/measure/opened_reports_measure.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class Admin::Metrics::Measure::OpenedReportsMeasure < Admin::Metrics::Measure::BaseMeasure + include Admin::Metrics::Measure::QueryHelper + def key 'opened_reports' end @@ -15,8 +17,12 @@ class Admin::Metrics::Measure::OpenedReportsMeasure < Admin::Metrics::Measure::B Report.where(created_at: previous_time_period).count end - def perform_data_query - sql = <<-SQL.squish + def sql_array + [sql_query_string, { start_at: @start_at, end_at: @end_at }] + end + + def sql_query_string + <<~SQL.squish SELECT axis.*, ( WITH new_reports AS ( SELECT reports.id @@ -26,12 +32,8 @@ class Admin::Metrics::Measure::OpenedReportsMeasure < Admin::Metrics::Measure::B SELECT count(*) FROM new_reports ) AS value FROM ( - SELECT generate_series(date_trunc('day', $1::timestamp)::date, date_trunc('day', $2::timestamp)::date, interval '1 day') AS period + SELECT generate_series(date_trunc('day', :start_at::timestamp)::date, date_trunc('day', :end_at::timestamp)::date, interval '1 day') AS period ) AS axis SQL - - rows = ActiveRecord::Base.connection.select_all(sql, nil, [[nil, @start_at], [nil, @end_at]]) - - rows.map { |row| { date: row['period'], value: row['value'].to_s } } end end diff --git a/app/lib/admin/metrics/measure/query_helper.rb b/app/lib/admin/metrics/measure/query_helper.rb new file mode 100644 index 000000000..969065f73 --- /dev/null +++ b/app/lib/admin/metrics/measure/query_helper.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +module Admin::Metrics::Measure::QueryHelper + protected + + def perform_data_query + measurement_data_rows.map { |row| { date: row['period'], value: row['value'].to_s } } + end + + def measurement_data_rows + ActiveRecord::Base.connection.select_all(sanitized_sql_string) + end + + def sanitized_sql_string + ActiveRecord::Base.sanitize_sql_array(sql_array) + end + + def account_domain_sql(include_subdomains) + if include_subdomains + "accounts.domain IN (SELECT domain FROM instances WHERE reverse('.' || domain) LIKE reverse('.' || :domain::text))" + else + 'accounts.domain = :domain::text' + end + end +end diff --git a/app/lib/admin/metrics/measure/resolved_reports_measure.rb b/app/lib/admin/metrics/measure/resolved_reports_measure.rb index 4ab746c8f..780db75a1 100644 --- a/app/lib/admin/metrics/measure/resolved_reports_measure.rb +++ b/app/lib/admin/metrics/measure/resolved_reports_measure.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class Admin::Metrics::Measure::ResolvedReportsMeasure < Admin::Metrics::Measure::BaseMeasure + include Admin::Metrics::Measure::QueryHelper + def key 'resolved_reports' end @@ -15,8 +17,12 @@ class Admin::Metrics::Measure::ResolvedReportsMeasure < Admin::Metrics::Measure: Report.resolved.where(action_taken_at: previous_time_period).count end - def perform_data_query - sql = <<-SQL.squish + def sql_array + [sql_query_string, { start_at: @start_at, end_at: @end_at }] + end + + def sql_query_string + <<~SQL.squish SELECT axis.*, ( WITH resolved_reports AS ( SELECT reports.id @@ -26,12 +32,8 @@ class Admin::Metrics::Measure::ResolvedReportsMeasure < Admin::Metrics::Measure: SELECT count(*) FROM resolved_reports ) AS value FROM ( - SELECT generate_series(date_trunc('day', $1::timestamp)::date, date_trunc('day', $2::timestamp)::date, interval '1 day') AS period + SELECT generate_series(date_trunc('day', :start_at::timestamp)::date, date_trunc('day', :end_at::timestamp)::date, interval '1 day') AS period ) AS axis SQL - - rows = ActiveRecord::Base.connection.select_all(sql, nil, [[nil, @start_at], [nil, @end_at]]) - - rows.map { |row| { date: row['period'], value: row['value'].to_s } } end end diff --git a/app/lib/admin/metrics/measure/tag_servers_measure.rb b/app/lib/admin/metrics/measure/tag_servers_measure.rb index 11f229602..e6378b802 100644 --- a/app/lib/admin/metrics/measure/tag_servers_measure.rb +++ b/app/lib/admin/metrics/measure/tag_servers_measure.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class Admin::Metrics::Measure::TagServersMeasure < Admin::Metrics::Measure::BaseMeasure + include Admin::Metrics::Measure::QueryHelper + def self.with_params? true end @@ -19,25 +21,33 @@ class Admin::Metrics::Measure::TagServersMeasure < Admin::Metrics::Measure::Base tag.statuses.where('statuses.id BETWEEN ? AND ?', Mastodon::Snowflake.id_at(@start_at - length_of_period, with_random: false), Mastodon::Snowflake.id_at(@end_at - length_of_period, with_random: false)).joins(:account).count('distinct accounts.domain') end - def perform_data_query - sql = <<-SQL.squish + def sql_array + [sql_query_string, { start_at: @start_at, end_at: @end_at, tag_id: tag.id, earliest_status_id: earliest_status_id, latest_status_id: latest_status_id }] + end + + def sql_query_string + <<~SQL.squish SELECT axis.*, ( SELECT count(distinct accounts.domain) AS value FROM statuses INNER JOIN statuses_tags ON statuses.id = statuses_tags.status_id INNER JOIN accounts ON statuses.account_id = accounts.id - WHERE statuses_tags.tag_id = $1 - AND statuses.id BETWEEN $2 AND $3 + WHERE statuses_tags.tag_id = :tag_id + AND statuses.id BETWEEN :earliest_status_id AND :latest_status_id AND date_trunc('day', statuses.created_at)::date = axis.day ) FROM ( - SELECT generate_series(date_trunc('day', $4::timestamp)::date, date_trunc('day', $5::timestamp)::date, ('1 day')::interval) AS day + SELECT generate_series(date_trunc('day', :start_at::timestamp)::date, date_trunc('day', :end_at::timestamp)::date, ('1 day')::interval) AS day ) as axis SQL + end - rows = ActiveRecord::Base.connection.select_all(sql, nil, [[nil, params[:id].to_i], [nil, Mastodon::Snowflake.id_at(@start_at, with_random: false)], [nil, Mastodon::Snowflake.id_at(@end_at, with_random: false)], [nil, @start_at], [nil, @end_at]]) + def earliest_status_id + Mastodon::Snowflake.id_at(@start_at, with_random: false) + end - rows.map { |row| { date: row['day'], value: row['value'].to_s } } + def latest_status_id + Mastodon::Snowflake.id_at(@end_at, with_random: false) end def tag diff --git a/spec/lib/admin/metrics/measure/active_users_measure_spec.rb b/spec/lib/admin/metrics/measure/active_users_measure_spec.rb new file mode 100644 index 000000000..55164ed88 --- /dev/null +++ b/spec/lib/admin/metrics/measure/active_users_measure_spec.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe Admin::Metrics::Measure::ActiveUsersMeasure do + subject(:measure) { described_class.new(start_at, end_at, params) } + + let(:start_at) { 2.days.ago } + let(:end_at) { Time.now.utc } + let(:params) { ActionController::Parameters.new } + + describe '#data' do + it 'runs data query without error' do + expect { measure.data }.to_not raise_error + end + end +end diff --git a/spec/lib/admin/metrics/measure/instance_accounts_measure_spec.rb b/spec/lib/admin/metrics/measure/instance_accounts_measure_spec.rb index 29a157491..8e414963f 100644 --- a/spec/lib/admin/metrics/measure/instance_accounts_measure_spec.rb +++ b/spec/lib/admin/metrics/measure/instance_accounts_measure_spec.rb @@ -37,4 +37,10 @@ describe Admin::Metrics::Measure::InstanceAccountsMeasure do end end end + + describe '#data' do + it 'runs data query without error' do + expect { measure.data }.to_not raise_error + end + end end diff --git a/spec/lib/admin/metrics/measure/instance_followers_measure_spec.rb b/spec/lib/admin/metrics/measure/instance_followers_measure_spec.rb index ebf789c1b..c627e6ced 100644 --- a/spec/lib/admin/metrics/measure/instance_followers_measure_spec.rb +++ b/spec/lib/admin/metrics/measure/instance_followers_measure_spec.rb @@ -39,4 +39,10 @@ describe Admin::Metrics::Measure::InstanceFollowersMeasure do end end end + + describe '#data' do + it 'runs data query without error' do + expect { measure.data }.to_not raise_error + end + end end diff --git a/spec/lib/admin/metrics/measure/instance_follows_measure_spec.rb b/spec/lib/admin/metrics/measure/instance_follows_measure_spec.rb index 335e3c732..42f33dfc3 100644 --- a/spec/lib/admin/metrics/measure/instance_follows_measure_spec.rb +++ b/spec/lib/admin/metrics/measure/instance_follows_measure_spec.rb @@ -39,4 +39,10 @@ describe Admin::Metrics::Measure::InstanceFollowsMeasure do end end end + + describe '#data' do + it 'runs data query without error' do + expect { measure.data }.to_not raise_error + end + end end diff --git a/spec/lib/admin/metrics/measure/instance_media_attachments_measure_spec.rb b/spec/lib/admin/metrics/measure/instance_media_attachments_measure_spec.rb index 711a2aff0..c103307f9 100644 --- a/spec/lib/admin/metrics/measure/instance_media_attachments_measure_spec.rb +++ b/spec/lib/admin/metrics/measure/instance_media_attachments_measure_spec.rb @@ -40,4 +40,10 @@ describe Admin::Metrics::Measure::InstanceMediaAttachmentsMeasure do end end end + + describe '#data' do + it 'runs data query without error' do + expect { measure.data }.to_not raise_error + end + end end diff --git a/spec/lib/admin/metrics/measure/instance_reports_measure_spec.rb b/spec/lib/admin/metrics/measure/instance_reports_measure_spec.rb index f0ffd39cf..62fcf84ac 100644 --- a/spec/lib/admin/metrics/measure/instance_reports_measure_spec.rb +++ b/spec/lib/admin/metrics/measure/instance_reports_measure_spec.rb @@ -36,4 +36,10 @@ describe Admin::Metrics::Measure::InstanceReportsMeasure do end end end + + describe '#data' do + it 'runs data query without error' do + expect { measure.data }.to_not raise_error + end + end end diff --git a/spec/lib/admin/metrics/measure/instance_statuses_measure_spec.rb b/spec/lib/admin/metrics/measure/instance_statuses_measure_spec.rb index c1425ecdb..df4cfe207 100644 --- a/spec/lib/admin/metrics/measure/instance_statuses_measure_spec.rb +++ b/spec/lib/admin/metrics/measure/instance_statuses_measure_spec.rb @@ -36,4 +36,10 @@ describe Admin::Metrics::Measure::InstanceStatusesMeasure do end end end + + describe '#data' do + it 'runs data query without error' do + expect { measure.data }.to_not raise_error + end + end end diff --git a/spec/lib/admin/metrics/measure/interactions_measure_spec.rb b/spec/lib/admin/metrics/measure/interactions_measure_spec.rb new file mode 100644 index 000000000..e98c83059 --- /dev/null +++ b/spec/lib/admin/metrics/measure/interactions_measure_spec.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe Admin::Metrics::Measure::InteractionsMeasure do + subject(:measure) { described_class.new(start_at, end_at, params) } + + let(:start_at) { 2.days.ago } + let(:end_at) { Time.now.utc } + let(:params) { ActionController::Parameters.new } + + describe '#data' do + it 'runs data query without error' do + expect { measure.data }.to_not raise_error + end + end +end diff --git a/spec/lib/admin/metrics/measure/new_users_measure_spec.rb b/spec/lib/admin/metrics/measure/new_users_measure_spec.rb new file mode 100644 index 000000000..fe82f8219 --- /dev/null +++ b/spec/lib/admin/metrics/measure/new_users_measure_spec.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe Admin::Metrics::Measure::NewUsersMeasure do + subject(:measure) { described_class.new(start_at, end_at, params) } + + let(:start_at) { 2.days.ago } + let(:end_at) { Time.now.utc } + let(:params) { ActionController::Parameters.new } + + describe '#data' do + it 'runs data query without error' do + expect { measure.data }.to_not raise_error + end + end +end diff --git a/spec/lib/admin/metrics/measure/opened_reports_measure_spec.rb b/spec/lib/admin/metrics/measure/opened_reports_measure_spec.rb new file mode 100644 index 000000000..deed64ae8 --- /dev/null +++ b/spec/lib/admin/metrics/measure/opened_reports_measure_spec.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe Admin::Metrics::Measure::OpenedReportsMeasure do + subject(:measure) { described_class.new(start_at, end_at, params) } + + let(:start_at) { 2.days.ago } + let(:end_at) { Time.now.utc } + let(:params) { ActionController::Parameters.new } + + describe '#data' do + it 'runs data query without error' do + expect { measure.data }.to_not raise_error + end + end +end diff --git a/spec/lib/admin/metrics/measure/resolved_reports_measure_spec.rb b/spec/lib/admin/metrics/measure/resolved_reports_measure_spec.rb new file mode 100644 index 000000000..cb98df2dc --- /dev/null +++ b/spec/lib/admin/metrics/measure/resolved_reports_measure_spec.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe Admin::Metrics::Measure::ResolvedReportsMeasure do + subject(:measure) { described_class.new(start_at, end_at, params) } + + let(:start_at) { 2.days.ago } + let(:end_at) { Time.now.utc } + let(:params) { ActionController::Parameters.new } + + describe '#data' do + it 'runs data query without error' do + expect { measure.data }.to_not raise_error + end + end +end diff --git a/spec/lib/admin/metrics/measure/tag_accounts_measure_spec.rb b/spec/lib/admin/metrics/measure/tag_accounts_measure_spec.rb new file mode 100644 index 000000000..938b67afa --- /dev/null +++ b/spec/lib/admin/metrics/measure/tag_accounts_measure_spec.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe Admin::Metrics::Measure::TagAccountsMeasure do + subject(:measure) { described_class.new(start_at, end_at, params) } + + let!(:tag) { Fabricate(:tag) } + + let(:start_at) { 2.days.ago } + let(:end_at) { Time.now.utc } + let(:params) { ActionController::Parameters.new(id: tag.id) } + + describe '#data' do + it 'runs data query without error' do + expect { measure.data }.to_not raise_error + end + end +end diff --git a/spec/lib/admin/metrics/measure/tag_servers_measure_spec.rb b/spec/lib/admin/metrics/measure/tag_servers_measure_spec.rb new file mode 100644 index 000000000..e09a2b04e --- /dev/null +++ b/spec/lib/admin/metrics/measure/tag_servers_measure_spec.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe Admin::Metrics::Measure::TagServersMeasure do + subject(:measure) { described_class.new(start_at, end_at, params) } + + let!(:tag) { Fabricate(:tag) } + + let(:start_at) { 2.days.ago } + let(:end_at) { Time.now.utc } + let(:params) { ActionController::Parameters.new(id: tag.id) } + + describe '#data' do + it 'runs data query without error' do + expect { measure.data }.to_not raise_error + end + end +end diff --git a/spec/lib/admin/metrics/measure/tag_uses_measure_spec.rb b/spec/lib/admin/metrics/measure/tag_uses_measure_spec.rb new file mode 100644 index 000000000..869e93744 --- /dev/null +++ b/spec/lib/admin/metrics/measure/tag_uses_measure_spec.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe Admin::Metrics::Measure::TagUsesMeasure do + subject(:measure) { described_class.new(start_at, end_at, params) } + + let!(:tag) { Fabricate(:tag) } + + let(:start_at) { 2.days.ago } + let(:end_at) { Time.now.utc } + let(:params) { ActionController::Parameters.new(id: tag.id) } + + describe '#data' do + it 'runs data query without error' do + expect { measure.data }.to_not raise_error + end + end +end From 0ddc89528213859bf4caeefd475a93ed973ab0e0 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Tue, 6 Jun 2023 04:14:28 +0200 Subject: [PATCH 03/24] Change follow button in account row to be more obvious in web UI (#24956) --- .../mastodon/components/account.jsx | 41 ++++++++++--------- app/javascript/mastodon/locales/en.json | 8 ++-- .../styles/mastodon/components.scss | 6 ++- 3 files changed, 30 insertions(+), 25 deletions(-) diff --git a/app/javascript/mastodon/components/account.jsx b/app/javascript/mastodon/components/account.jsx index ea863f5d1..0f3b85388 100644 --- a/app/javascript/mastodon/components/account.jsx +++ b/app/javascript/mastodon/components/account.jsx @@ -16,6 +16,7 @@ import { VerifiedBadge } from 'mastodon/components/verified_badge'; import { me } from '../initial_state'; import { Avatar } from './avatar'; +import Button from './button'; import { DisplayName } from './display_name'; import { IconButton } from './icon_button'; import { RelativeTimestamp } from './relative_timestamp'; @@ -23,13 +24,13 @@ import { RelativeTimestamp } from './relative_timestamp'; const messages = defineMessages({ follow: { id: 'account.follow', defaultMessage: 'Follow' }, unfollow: { id: 'account.unfollow', defaultMessage: 'Unfollow' }, - requested: { id: 'account.requested', defaultMessage: 'Awaiting approval. Click to cancel follow request' }, - unblock: { id: 'account.unblock', defaultMessage: 'Unblock @{name}' }, - unmute: { id: 'account.unmute', defaultMessage: 'Unmute @{name}' }, - mute_notifications: { id: 'account.mute_notifications', defaultMessage: 'Mute notifications from @{name}' }, - unmute_notifications: { id: 'account.unmute_notifications', defaultMessage: 'Unmute notifications from @{name}' }, - mute: { id: 'account.mute', defaultMessage: 'Mute @{name}' }, - block: { id: 'account.block', defaultMessage: 'Block @{name}' }, + cancel_follow_request: { id: 'account.cancel_follow_request', defaultMessage: 'Withdraw follow request' }, + unblock: { id: 'account.unblock_short', defaultMessage: 'Unblock' }, + unmute: { id: 'account.unmute_short', defaultMessage: 'Unmute' }, + mute_notifications: { id: 'account.mute_notifications_short', defaultMessage: 'Mute notifications' }, + unmute_notifications: { id: 'account.unmute_notifications_short', defaultMessage: 'Unmute notifications' }, + mute: { id: 'account.mute_short', defaultMessage: 'Mute' }, + block: { id: 'account.block_short', defaultMessage: 'Block' }, }); class Account extends ImmutablePureComponent { @@ -96,39 +97,39 @@ class Account extends ImmutablePureComponent { let buttons; - if (actionIcon) { - if (onActionClick) { - buttons = ; - } - } else if (account.get('id') !== me && account.get('relationship', null) !== null) { + if (actionIcon && onActionClick) { + buttons = ; + } else if (!actionIcon && account.get('id') !== me && account.get('relationship', null) !== null) { const following = account.getIn(['relationship', 'following']); const requested = account.getIn(['relationship', 'requested']); const blocking = account.getIn(['relationship', 'blocking']); const muting = account.getIn(['relationship', 'muting']); if (requested) { - buttons = ; + buttons = - ); - } - -} diff --git a/app/javascript/mastodon/components/load_more.tsx b/app/javascript/mastodon/components/load_more.tsx new file mode 100644 index 000000000..8b5746ad3 --- /dev/null +++ b/app/javascript/mastodon/components/load_more.tsx @@ -0,0 +1,24 @@ +import { FormattedMessage } from 'react-intl'; + +interface Props { + onClick: (event: React.MouseEvent) => void; + disabled?: boolean; + visible?: boolean; +} +export const LoadMore: React.FC = ({ + onClick, + disabled, + visible = true, +}) => { + return ( + + ); +}; diff --git a/app/javascript/mastodon/components/scrollable_list.jsx b/app/javascript/mastodon/components/scrollable_list.jsx index 9a0c4c8a7..53a84ecb5 100644 --- a/app/javascript/mastodon/components/scrollable_list.jsx +++ b/app/javascript/mastodon/components/scrollable_list.jsx @@ -15,7 +15,7 @@ import IntersectionObserverArticleContainer from '../containers/intersection_obs import { attachFullscreenListener, detachFullscreenListener, isFullscreen } from '../features/ui/util/fullscreen'; import IntersectionObserverWrapper from '../features/ui/util/intersection_observer_wrapper'; -import LoadMore from './load_more'; +import { LoadMore } from './load_more'; import LoadPending from './load_pending'; import LoadingIndicator from './loading_indicator'; diff --git a/app/javascript/mastodon/features/account_gallery/index.jsx b/app/javascript/mastodon/features/account_gallery/index.jsx index 27de4740c..653a25866 100644 --- a/app/javascript/mastodon/features/account_gallery/index.jsx +++ b/app/javascript/mastodon/features/account_gallery/index.jsx @@ -9,7 +9,7 @@ import { connect } from 'react-redux'; import { lookupAccount, fetchAccount } from 'mastodon/actions/accounts'; import { openModal } from 'mastodon/actions/modal'; import ColumnBackButton from 'mastodon/components/column_back_button'; -import LoadMore from 'mastodon/components/load_more'; +import { LoadMore } from 'mastodon/components/load_more'; import LoadingIndicator from 'mastodon/components/loading_indicator'; import ScrollContainer from 'mastodon/containers/scroll_container'; import BundleColumnError from 'mastodon/features/ui/components/bundle_column_error'; diff --git a/app/javascript/mastodon/features/compose/components/search_results.jsx b/app/javascript/mastodon/features/compose/components/search_results.jsx index b329cae79..b11ac478a 100644 --- a/app/javascript/mastodon/features/compose/components/search_results.jsx +++ b/app/javascript/mastodon/features/compose/components/search_results.jsx @@ -6,7 +6,7 @@ import ImmutablePropTypes from 'react-immutable-proptypes'; import ImmutablePureComponent from 'react-immutable-pure-component'; import { Icon } from 'mastodon/components/icon'; -import LoadMore from 'mastodon/components/load_more'; +import { LoadMore } from 'mastodon/components/load_more'; import { ImmutableHashtag as Hashtag } from '../../../components/hashtag'; import AccountContainer from '../../../containers/account_container'; diff --git a/app/javascript/mastodon/features/directory/index.jsx b/app/javascript/mastodon/features/directory/index.jsx index d4854f186..635b6f411 100644 --- a/app/javascript/mastodon/features/directory/index.jsx +++ b/app/javascript/mastodon/features/directory/index.jsx @@ -13,7 +13,7 @@ import { addColumn, removeColumn, moveColumn, changeColumnParams } from 'mastodo import { fetchDirectory, expandDirectory } from 'mastodon/actions/directory'; import Column from 'mastodon/components/column'; import ColumnHeader from 'mastodon/components/column_header'; -import LoadMore from 'mastodon/components/load_more'; +import { LoadMore } from 'mastodon/components/load_more'; import LoadingIndicator from 'mastodon/components/loading_indicator'; import { RadioButton } from 'mastodon/components/radio_button'; import ScrollContainer from 'mastodon/containers/scroll_container'; diff --git a/app/javascript/mastodon/features/explore/results.jsx b/app/javascript/mastodon/features/explore/results.jsx index 6b053a9dc..dc1f72022 100644 --- a/app/javascript/mastodon/features/explore/results.jsx +++ b/app/javascript/mastodon/features/explore/results.jsx @@ -11,7 +11,7 @@ import { connect } from 'react-redux'; import { expandSearch } from 'mastodon/actions/search'; import { ImmutableHashtag as Hashtag } from 'mastodon/components/hashtag'; -import LoadMore from 'mastodon/components/load_more'; +import { LoadMore } from 'mastodon/components/load_more'; import LoadingIndicator from 'mastodon/components/loading_indicator'; import Account from 'mastodon/containers/account_container'; import Status from 'mastodon/containers/status_container'; From b22bfae4f93d635dc9416d45ad11b29d9f5104e5 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 6 Jun 2023 07:34:04 -0400 Subject: [PATCH 09/24] Add coverage for `DomainBlock#public_domain` method (#25283) --- spec/models/domain_block_spec.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/spec/models/domain_block_spec.rb b/spec/models/domain_block_spec.rb index f10f47027..e123c03d6 100644 --- a/spec/models/domain_block_spec.rb +++ b/spec/models/domain_block_spec.rb @@ -91,4 +91,22 @@ RSpec.describe DomainBlock do expect(newer.stricter_than?(older)).to be false end end + + describe '#public_domain' do + context 'with a domain block that is obfuscated' do + let(:domain_block) { Fabricate(:domain_block, domain: 'hostname.example.com', obfuscate: true) } + + it 'garbles the domain' do + expect(domain_block.public_domain).to eq 'hostna**.******e.com' + end + end + + context 'with a domain block that is not obfuscated' do + let(:domain_block) { Fabricate(:domain_block, domain: 'example.com', obfuscate: false) } + + it 'returns the domain value' do + expect(domain_block.public_domain).to eq 'example.com' + end + end + end end From eb6f8181e12ad0d7c47ae7c71ca6b737c844e35c Mon Sep 17 00:00:00 2001 From: Daniel M Brasil Date: Tue, 6 Jun 2023 08:37:09 -0300 Subject: [PATCH 10/24] Add test coverage for `Mastodon::CLI::Accounts#reset_relationships` (#25194) --- spec/lib/mastodon/cli/accounts_spec.rb | 113 +++++++++++++++++++++++++ 1 file changed, 113 insertions(+) diff --git a/spec/lib/mastodon/cli/accounts_spec.rb b/spec/lib/mastodon/cli/accounts_spec.rb index cf1d612f3..a263d673d 100644 --- a/spec/lib/mastodon/cli/accounts_spec.rb +++ b/spec/lib/mastodon/cli/accounts_spec.rb @@ -1248,4 +1248,117 @@ describe Mastodon::CLI::Accounts do end end end + + describe '#reset_relationships' do + let(:target_account) { Fabricate(:account) } + let(:arguments) { [target_account.username] } + + context 'when no option is given' do + it 'exits with an error message indicating that at least one option is required' do + expect { cli.invoke(:reset_relationships, arguments) }.to output( + a_string_including('Please specify either --follows or --followers, or both') + ).to_stdout + .and raise_error(SystemExit) + end + end + + context 'when the given username is not found' do + let(:arguments) { ['non_existent_username'] } + + it 'exits with an error message indicating that there is no such account' do + expect { cli.invoke(:reset_relationships, arguments, follows: true) }.to output( + a_string_including('No such account') + ).to_stdout + .and raise_error(SystemExit) + end + end + + context 'when the given username is found' do + let(:total_relationships) { 10 } + let!(:accounts) { Fabricate.times(total_relationships, :account) } + + context 'with --follows option' do + let(:options) { { follows: true } } + + before do + accounts.each { |account| target_account.follow!(account) } + end + + it 'resets all "following" relationships from the target account' do + cli.invoke(:reset_relationships, arguments, options) + + expect(target_account.reload.following).to be_empty + end + + it 'calls BootstrapTimelineWorker once to rebuild the timeline' do + allow(BootstrapTimelineWorker).to receive(:perform_async) + + cli.invoke(:reset_relationships, arguments, options) + + expect(BootstrapTimelineWorker).to have_received(:perform_async).with(target_account.id).once + end + + it 'displays a successful message' do + expect { cli.invoke(:reset_relationships, arguments, options) }.to output( + a_string_including("Processed #{total_relationships} relationships") + ).to_stdout + end + end + + context 'with --followers option' do + let(:options) { { followers: true } } + + before do + accounts.each { |account| account.follow!(target_account) } + end + + it 'resets all "followers" relationships from the target account' do + cli.invoke(:reset_relationships, arguments, options) + + expect(target_account.reload.followers).to be_empty + end + + it 'displays a successful message' do + expect { cli.invoke(:reset_relationships, arguments, options) }.to output( + a_string_including("Processed #{total_relationships} relationships") + ).to_stdout + end + end + + context 'with --follows and --followers options' do + let(:options) { { followers: true, follows: true } } + + before do + accounts.first(6).each { |account| account.follow!(target_account) } + accounts.last(4).each { |account| target_account.follow!(account) } + end + + it 'resets all "followers" relationships from the target account' do + cli.invoke(:reset_relationships, arguments, options) + + expect(target_account.reload.followers).to be_empty + end + + it 'resets all "following" relationships from the target account' do + cli.invoke(:reset_relationships, arguments, options) + + expect(target_account.reload.following).to be_empty + end + + it 'calls BootstrapTimelineWorker once to rebuild the timeline' do + allow(BootstrapTimelineWorker).to receive(:perform_async) + + cli.invoke(:reset_relationships, arguments, options) + + expect(BootstrapTimelineWorker).to have_received(:perform_async).with(target_account.id).once + end + + it 'displays a successful message' do + expect { cli.invoke(:reset_relationships, arguments, options) }.to output( + a_string_including("Processed #{total_relationships} relationships") + ).to_stdout + end + end + end + end end From 1e243e2df7ff9dfaf753e86e8f93760a96ffda18 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 6 Jun 2023 07:57:00 -0400 Subject: [PATCH 11/24] Misc spec coverage for `Admin::` area controllers (#25282) --- .../admin/account_actions_controller_spec.rb | 12 ++ .../admin/accounts_controller_spec.rb | 124 ++++++++++++++++++ .../admin/announcements_controller_spec.rb | 26 ++++ .../admin/relays_controller_spec.rb | 41 ++++++ .../admin/statuses_controller_spec.rb | 10 ++ .../admin/warning_presets_controller_spec.rb | 64 +++++++++ 6 files changed, 277 insertions(+) diff --git a/spec/controllers/admin/account_actions_controller_spec.rb b/spec/controllers/admin/account_actions_controller_spec.rb index 4eae51c7b..b8dae7993 100644 --- a/spec/controllers/admin/account_actions_controller_spec.rb +++ b/spec/controllers/admin/account_actions_controller_spec.rb @@ -20,4 +20,16 @@ describe Admin::AccountActionsController do expect(response).to have_http_status(:success) end end + + describe 'POST #create' do + let(:account) { Fabricate(:account) } + + it 'records the account action' do + expect do + post :create, params: { account_id: account.id, admin_account_action: { type: 'silence' } } + end.to change { account.strikes.count }.by(1) + + expect(response).to redirect_to(admin_account_path(account.id)) + end + end end diff --git a/spec/controllers/admin/accounts_controller_spec.rb b/spec/controllers/admin/accounts_controller_spec.rb index 7d001c4cb..782e460a4 100644 --- a/spec/controllers/admin/accounts_controller_spec.rb +++ b/spec/controllers/admin/accounts_controller_spec.rb @@ -309,4 +309,128 @@ RSpec.describe Admin::AccountsController do end end end + + describe 'POST #unsensitive' do + subject { post :unsensitive, params: { id: account.id } } + + let(:current_user) { Fabricate(:user, role: role) } + let(:account) { Fabricate(:account, sensitized_at: 1.year.ago) } + + context 'when user is admin' do + let(:role) { UserRole.find_by(name: 'Admin') } + + it 'marks accounts not sensitized' do + subject + + expect(account.reload).to_not be_sensitized + expect(response).to redirect_to admin_account_path(account.id) + end + end + + context 'when user is not admin' do + let(:role) { UserRole.everyone } + + it 'fails to change account' do + subject + + expect(response).to have_http_status 403 + end + end + end + + describe 'POST #unsilence' do + subject { post :unsilence, params: { id: account.id } } + + let(:current_user) { Fabricate(:user, role: role) } + let(:account) { Fabricate(:account, silenced_at: 1.year.ago) } + + context 'when user is admin' do + let(:role) { UserRole.find_by(name: 'Admin') } + + it 'marks accounts not silenced' do + subject + + expect(account.reload).to_not be_silenced + expect(response).to redirect_to admin_account_path(account.id) + end + end + + context 'when user is not admin' do + let(:role) { UserRole.everyone } + + it 'fails to change account' do + subject + + expect(response).to have_http_status 403 + end + end + end + + describe 'POST #unsuspend' do + subject { post :unsuspend, params: { id: account.id } } + + let(:current_user) { Fabricate(:user, role: role) } + let(:account) { Fabricate(:account) } + + before do + account.suspend! + end + + context 'when user is admin' do + let(:role) { UserRole.find_by(name: 'Admin') } + + it 'marks accounts not suspended' do + subject + + expect(account.reload).to_not be_suspended + expect(response).to redirect_to admin_account_path(account.id) + end + end + + context 'when user is not admin' do + let(:role) { UserRole.everyone } + + it 'fails to change account' do + subject + + expect(response).to have_http_status 403 + end + end + end + + describe 'POST #destroy' do + subject { post :destroy, params: { id: account.id } } + + let(:current_user) { Fabricate(:user, role: role) } + let(:account) { Fabricate(:account) } + + before do + account.suspend! + end + + context 'when user is admin' do + let(:role) { UserRole.find_by(name: 'Admin') } + + before do + allow(Admin::AccountDeletionWorker).to receive(:perform_async).with(account.id) + end + + it 'destroys the account' do + subject + + expect(Admin::AccountDeletionWorker).to have_received(:perform_async).with(account.id) + expect(response).to redirect_to admin_account_path(account.id) + end + end + + context 'when user is not admin' do + let(:role) { UserRole.everyone } + + it 'fails to change account' do + subject + + expect(response).to have_http_status 403 + end + end + end end diff --git a/spec/controllers/admin/announcements_controller_spec.rb b/spec/controllers/admin/announcements_controller_spec.rb index a8905160f..c2d3135d9 100644 --- a/spec/controllers/admin/announcements_controller_spec.rb +++ b/spec/controllers/admin/announcements_controller_spec.rb @@ -73,4 +73,30 @@ describe Admin::AnnouncementsController do expect(flash.notice).to match(I18n.t('admin.announcements.destroyed_msg')) end end + + describe 'POST #publish' do + subject { post :publish, params: { id: announcement.id } } + + let(:announcement) { Fabricate(:announcement, published_at: nil) } + + it 'marks announcement published' do + subject + + expect(announcement.reload).to be_published + expect(response).to redirect_to admin_announcements_path + end + end + + describe 'POST #unpublish' do + subject { post :unpublish, params: { id: announcement.id } } + + let(:announcement) { Fabricate(:announcement, published_at: 4.days.ago) } + + it 'marks announcement as not published' do + subject + + expect(announcement.reload).to_not be_published + expect(response).to redirect_to admin_announcements_path + end + end end diff --git a/spec/controllers/admin/relays_controller_spec.rb b/spec/controllers/admin/relays_controller_spec.rb index 261f302c0..ca351c39b 100644 --- a/spec/controllers/admin/relays_controller_spec.rb +++ b/spec/controllers/admin/relays_controller_spec.rb @@ -56,4 +56,45 @@ describe Admin::RelaysController do end end end + + describe 'DELETE #destroy' do + let(:relay) { Fabricate(:relay) } + + it 'deletes an existing relay' do + delete :destroy, params: { id: relay.id } + + expect { relay.reload }.to raise_error(ActiveRecord::RecordNotFound) + expect(response).to redirect_to(admin_relays_path) + end + end + + describe 'POST #enable' do + let(:relay) { Fabricate(:relay, state: :idle) } + + before do + stub_request(:post, /example.com/).to_return(status: 200) + end + + it 'updates a relay from idle to pending' do + post :enable, params: { id: relay.id } + + expect(relay.reload).to be_pending + expect(response).to redirect_to(admin_relays_path) + end + end + + describe 'POST #disable' do + let(:relay) { Fabricate(:relay, state: :pending) } + + before do + stub_request(:post, /example.com/).to_return(status: 200) + end + + it 'updates a relay from pending to idle' do + post :disable, params: { id: relay.id } + + expect(relay.reload).to be_idle + expect(response).to redirect_to(admin_relays_path) + end + end end diff --git a/spec/controllers/admin/statuses_controller_spec.rb b/spec/controllers/admin/statuses_controller_spec.rb index 872aed999..fc27f7147 100644 --- a/spec/controllers/admin/statuses_controller_spec.rb +++ b/spec/controllers/admin/statuses_controller_spec.rb @@ -41,6 +41,16 @@ describe Admin::StatusesController do end end + describe 'GET #show' do + before do + get :show, params: { account_id: account.id, id: status.id } + end + + it 'returns http success' do + expect(response).to have_http_status(200) + end + end + describe 'POST #batch' do before do post :batch, params: { :account_id => account.id, action => '', :admin_status_batch_action => { status_ids: status_ids } } diff --git a/spec/controllers/admin/warning_presets_controller_spec.rb b/spec/controllers/admin/warning_presets_controller_spec.rb index 6b48fc28b..b32a58e99 100644 --- a/spec/controllers/admin/warning_presets_controller_spec.rb +++ b/spec/controllers/admin/warning_presets_controller_spec.rb @@ -18,4 +18,68 @@ describe Admin::WarningPresetsController do expect(response).to have_http_status(:success) end end + + describe 'GET #edit' do + let(:account_warning_preset) { Fabricate(:account_warning_preset) } + + it 'returns http success and renders edit' do + get :edit, params: { id: account_warning_preset.id } + + expect(response).to have_http_status(:success) + expect(response).to render_template(:edit) + end + end + + describe 'POST #create' do + context 'with valid data' do + it 'creates a new account_warning_preset and redirects' do + expect do + post :create, params: { account_warning_preset: { text: 'The account_warning_preset text.' } } + end.to change(AccountWarningPreset, :count).by(1) + + expect(response).to redirect_to(admin_warning_presets_path) + end + end + + context 'with invalid data' do + it 'does creates a new account_warning_preset and renders index' do + expect do + post :create, params: { account_warning_preset: { text: '' } } + end.to_not change(AccountWarningPreset, :count) + + expect(response).to render_template(:index) + end + end + end + + describe 'PUT #update' do + let(:account_warning_preset) { Fabricate(:account_warning_preset, text: 'Original text') } + + context 'with valid data' do + it 'updates the account_warning_preset and redirects' do + put :update, params: { id: account_warning_preset.id, account_warning_preset: { text: 'Updated text.' } } + + expect(response).to redirect_to(admin_warning_presets_path) + end + end + + context 'with invalid data' do + it 'does not update the account_warning_preset and renders index' do + put :update, params: { id: account_warning_preset.id, account_warning_preset: { text: '' } } + + expect(response).to render_template(:edit) + end + end + end + + describe 'DELETE #destroy' do + let!(:account_warning_preset) { Fabricate(:account_warning_preset) } + + it 'destroys the account_warning_preset and redirects' do + delete :destroy, params: { id: account_warning_preset.id } + + expect { account_warning_preset.reload }.to raise_error(ActiveRecord::RecordNotFound) + expect(response).to redirect_to(admin_warning_presets_path) + end + end end From c42591356da45c52f215ea00cf5c0ecd753afe06 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 6 Jun 2023 07:58:33 -0400 Subject: [PATCH 12/24] Fix `RSpec/DescribedClass` cop (#25104) --- .rubocop_todo.yml | 73 --------- spec/controllers/.rubocop.yml | 6 + spec/lib/entity_cache_spec.rb | 2 +- spec/lib/extractor_spec.rb | 20 +-- spec/lib/feed_manager_spec.rb | 140 +++++++++--------- spec/lib/ostatus/tag_manager_spec.rb | 16 +- spec/lib/request_spec.rb | 2 +- spec/lib/tag_manager_spec.rb | 22 +-- spec/lib/webfinger_resource_spec.rb | 28 ++-- spec/mailers/notification_mailer_spec.rb | 10 +- spec/mailers/user_mailer_spec.rb | 20 +-- spec/models/account_conversation_spec.rb | 16 +- spec/models/account_domain_block_spec.rb | 4 +- spec/models/account_migration_spec.rb | 2 +- spec/models/account_spec.rb | 90 +++++------ spec/models/block_spec.rb | 4 +- spec/models/domain_block_spec.rb | 36 ++--- spec/models/email_domain_block_spec.rb | 6 +- spec/models/export_spec.rb | 14 +- spec/models/favourite_spec.rb | 8 +- spec/models/follow_spec.rb | 8 +- spec/models/identity_spec.rb | 2 +- spec/models/import_spec.rb | 6 +- spec/models/media_attachment_spec.rb | 20 +-- spec/models/notification_spec.rb | 8 +- spec/models/relationship_filter_spec.rb | 2 +- spec/models/report_filter_spec.rb | 6 +- spec/models/session_activation_spec.rb | 2 +- spec/models/setting_spec.rb | 2 +- spec/models/site_upload_spec.rb | 2 +- spec/models/status_pin_spec.rb | 18 +-- spec/models/status_spec.rb | 54 +++---- spec/models/user_spec.rb | 32 ++-- .../account_moderation_note_policy_spec.rb | 4 +- .../account_relationships_presenter_spec.rb | 2 +- .../status_relationships_presenter_spec.rb | 2 +- .../activitypub/note_serializer_spec.rb | 2 +- .../update_poll_serializer_spec.rb | 2 +- .../rest/account_serializer_spec.rb | 2 +- .../fetch_remote_account_service_spec.rb | 2 +- .../fetch_remote_actor_service_spec.rb | 2 +- .../fetch_remote_key_service_spec.rb | 2 +- ..._block_domain_from_account_service_spec.rb | 2 +- .../services/authorize_follow_service_spec.rb | 2 +- .../batched_remove_status_service_spec.rb | 2 +- spec/services/block_domain_service_spec.rb | 2 +- spec/services/block_service_spec.rb | 2 +- .../bootstrap_timeline_service_spec.rb | 2 +- .../clear_domain_media_service_spec.rb | 2 +- spec/services/favourite_service_spec.rb | 2 +- spec/services/follow_service_spec.rb | 2 +- spec/services/import_service_spec.rb | 12 +- spec/services/post_status_service_spec.rb | 2 +- spec/services/precompute_feed_service_spec.rb | 2 +- .../services/process_mentions_service_spec.rb | 2 +- spec/services/purge_domain_service_spec.rb | 2 +- spec/services/reblog_service_spec.rb | 4 +- spec/services/reject_follow_service_spec.rb | 2 +- .../remove_from_followers_service_spec.rb | 2 +- spec/services/remove_status_service_spec.rb | 2 +- spec/services/unallow_domain_service_spec.rb | 2 +- spec/services/unblock_service_spec.rb | 2 +- spec/services/unfollow_service_spec.rb | 2 +- spec/services/unmute_service_spec.rb | 2 +- spec/services/update_account_service_spec.rb | 2 +- spec/validators/note_length_validator_spec.rb | 2 +- 66 files changed, 347 insertions(+), 414 deletions(-) create mode 100644 spec/controllers/.rubocop.yml diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index c8b287f90..1a16472bd 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -237,79 +237,6 @@ RSpec/AnyInstance: - 'spec/workers/activitypub/delivery_worker_spec.rb' - 'spec/workers/web/push_notification_worker_spec.rb' -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: SkipBlocks, EnforcedStyle. -# SupportedStyles: described_class, explicit -RSpec/DescribedClass: - Exclude: - - 'spec/controllers/concerns/cache_concern_spec.rb' - - 'spec/controllers/concerns/challengable_concern_spec.rb' - - 'spec/lib/entity_cache_spec.rb' - - 'spec/lib/extractor_spec.rb' - - 'spec/lib/feed_manager_spec.rb' - - 'spec/lib/hash_object_spec.rb' - - 'spec/lib/ostatus/tag_manager_spec.rb' - - 'spec/lib/request_spec.rb' - - 'spec/lib/tag_manager_spec.rb' - - 'spec/lib/webfinger_resource_spec.rb' - - 'spec/mailers/notification_mailer_spec.rb' - - 'spec/mailers/user_mailer_spec.rb' - - 'spec/models/account_conversation_spec.rb' - - 'spec/models/account_domain_block_spec.rb' - - 'spec/models/account_migration_spec.rb' - - 'spec/models/account_spec.rb' - - 'spec/models/block_spec.rb' - - 'spec/models/domain_block_spec.rb' - - 'spec/models/email_domain_block_spec.rb' - - 'spec/models/export_spec.rb' - - 'spec/models/favourite_spec.rb' - - 'spec/models/follow_spec.rb' - - 'spec/models/identity_spec.rb' - - 'spec/models/import_spec.rb' - - 'spec/models/media_attachment_spec.rb' - - 'spec/models/notification_spec.rb' - - 'spec/models/relationship_filter_spec.rb' - - 'spec/models/report_filter_spec.rb' - - 'spec/models/session_activation_spec.rb' - - 'spec/models/setting_spec.rb' - - 'spec/models/site_upload_spec.rb' - - 'spec/models/status_pin_spec.rb' - - 'spec/models/status_spec.rb' - - 'spec/models/user_spec.rb' - - 'spec/policies/account_moderation_note_policy_spec.rb' - - 'spec/presenters/account_relationships_presenter_spec.rb' - - 'spec/presenters/status_relationships_presenter_spec.rb' - - 'spec/serializers/activitypub/note_serializer_spec.rb' - - 'spec/serializers/activitypub/update_poll_serializer_spec.rb' - - 'spec/serializers/rest/account_serializer_spec.rb' - - 'spec/services/activitypub/fetch_remote_account_service_spec.rb' - - 'spec/services/activitypub/fetch_remote_actor_service_spec.rb' - - 'spec/services/activitypub/fetch_remote_key_service_spec.rb' - - 'spec/services/after_block_domain_from_account_service_spec.rb' - - 'spec/services/authorize_follow_service_spec.rb' - - 'spec/services/batched_remove_status_service_spec.rb' - - 'spec/services/block_domain_service_spec.rb' - - 'spec/services/block_service_spec.rb' - - 'spec/services/bootstrap_timeline_service_spec.rb' - - 'spec/services/clear_domain_media_service_spec.rb' - - 'spec/services/favourite_service_spec.rb' - - 'spec/services/follow_service_spec.rb' - - 'spec/services/import_service_spec.rb' - - 'spec/services/post_status_service_spec.rb' - - 'spec/services/precompute_feed_service_spec.rb' - - 'spec/services/process_mentions_service_spec.rb' - - 'spec/services/purge_domain_service_spec.rb' - - 'spec/services/reblog_service_spec.rb' - - 'spec/services/reject_follow_service_spec.rb' - - 'spec/services/remove_from_followers_service_spec.rb' - - 'spec/services/remove_status_service_spec.rb' - - 'spec/services/unallow_domain_service_spec.rb' - - 'spec/services/unblock_service_spec.rb' - - 'spec/services/unfollow_service_spec.rb' - - 'spec/services/unmute_service_spec.rb' - - 'spec/services/update_account_service_spec.rb' - - 'spec/validators/note_length_validator_spec.rb' - # This cop supports unsafe autocorrection (--autocorrect-all). RSpec/EmptyExampleGroup: Exclude: diff --git a/spec/controllers/.rubocop.yml b/spec/controllers/.rubocop.yml new file mode 100644 index 000000000..525479be8 --- /dev/null +++ b/spec/controllers/.rubocop.yml @@ -0,0 +1,6 @@ +inherit_from: ../../.rubocop.yml + +# Anonymous controllers in specs cannot access described_class +# https://github.com/rubocop/rubocop-rspec/blob/master/lib/rubocop/cop/rspec/described_class.rb#L36-L39 +RSpec/DescribedClass: + SkipBlocks: true diff --git a/spec/lib/entity_cache_spec.rb b/spec/lib/entity_cache_spec.rb index 6d9afa474..5818de711 100644 --- a/spec/lib/entity_cache_spec.rb +++ b/spec/lib/entity_cache_spec.rb @@ -7,7 +7,7 @@ RSpec.describe EntityCache do let(:remote_account) { Fabricate(:account, domain: 'remote.test', username: 'bob', url: 'https://remote.test/') } describe '#emoji' do - subject { EntityCache.instance.emoji(shortcodes, domain) } + subject { described_class.instance.emoji(shortcodes, domain) } context 'when called with an empty list of shortcodes' do let(:shortcodes) { [] } diff --git a/spec/lib/extractor_spec.rb b/spec/lib/extractor_spec.rb index 560617ed7..b6c910171 100644 --- a/spec/lib/extractor_spec.rb +++ b/spec/lib/extractor_spec.rb @@ -6,19 +6,19 @@ describe Extractor do describe 'extract_mentions_or_lists_with_indices' do it 'returns an empty array if the given string does not have at signs' do text = 'a string without at signs' - extracted = Extractor.extract_mentions_or_lists_with_indices(text) + extracted = described_class.extract_mentions_or_lists_with_indices(text) expect(extracted).to eq [] end it 'does not extract mentions which ends with particular characters' do text = '@screen_name@' - extracted = Extractor.extract_mentions_or_lists_with_indices(text) + extracted = described_class.extract_mentions_or_lists_with_indices(text) expect(extracted).to eq [] end it 'returns mentions as an array' do text = '@screen_name' - extracted = Extractor.extract_mentions_or_lists_with_indices(text) + extracted = described_class.extract_mentions_or_lists_with_indices(text) expect(extracted).to eq [ { screen_name: 'screen_name', indices: [0, 12] }, ] @@ -26,7 +26,7 @@ describe Extractor do it 'yields mentions if a block is given' do text = '@screen_name' - Extractor.extract_mentions_or_lists_with_indices(text) do |screen_name, start_position, end_position| + described_class.extract_mentions_or_lists_with_indices(text) do |screen_name, start_position, end_position| expect(screen_name).to eq 'screen_name' expect(start_position).to eq 0 expect(end_position).to eq 12 @@ -37,31 +37,31 @@ describe Extractor do describe 'extract_hashtags_with_indices' do it 'returns an empty array if it does not have #' do text = 'a string without hash sign' - extracted = Extractor.extract_hashtags_with_indices(text) + extracted = described_class.extract_hashtags_with_indices(text) expect(extracted).to eq [] end it 'does not exclude normal hash text before ://' do text = '#hashtag://' - extracted = Extractor.extract_hashtags_with_indices(text) + extracted = described_class.extract_hashtags_with_indices(text) expect(extracted).to eq [{ hashtag: 'hashtag', indices: [0, 8] }] end it 'excludes http://' do text = '#hashtaghttp://' - extracted = Extractor.extract_hashtags_with_indices(text) + extracted = described_class.extract_hashtags_with_indices(text) expect(extracted).to eq [{ hashtag: 'hashtag', indices: [0, 8] }] end it 'excludes https://' do text = '#hashtaghttps://' - extracted = Extractor.extract_hashtags_with_indices(text) + extracted = described_class.extract_hashtags_with_indices(text) expect(extracted).to eq [{ hashtag: 'hashtag', indices: [0, 8] }] end it 'yields hashtags if a block is given' do text = '#hashtag' - Extractor.extract_hashtags_with_indices(text) do |hashtag, start_position, end_position| + described_class.extract_hashtags_with_indices(text) do |hashtag, start_position, end_position| expect(hashtag).to eq 'hashtag' expect(start_position).to eq 0 expect(end_position).to eq 8 @@ -72,7 +72,7 @@ describe Extractor do describe 'extract_cashtags_with_indices' do it 'returns []' do text = '$cashtag' - extracted = Extractor.extract_cashtags_with_indices(text) + extracted = described_class.extract_cashtags_with_indices(text) expect(extracted).to eq [] end end diff --git a/spec/lib/feed_manager_spec.rb b/spec/lib/feed_manager_spec.rb index 31b53fd87..5bfe11f6a 100644 --- a/spec/lib/feed_manager_spec.rb +++ b/spec/lib/feed_manager_spec.rb @@ -15,7 +15,7 @@ RSpec.describe FeedManager do end describe '#key' do - subject { FeedManager.instance.key(:home, 1) } + subject { described_class.instance.key(:home, 1) } it 'returns a string' do expect(subject).to be_a String @@ -32,26 +32,26 @@ RSpec.describe FeedManager do it 'returns false for followee\'s status' do status = Fabricate(:status, text: 'Hello world', account: alice) bob.follow!(alice) - expect(FeedManager.instance.filter?(:home, status, bob)).to be false + expect(described_class.instance.filter?(:home, status, bob)).to be false end it 'returns false for reblog by followee' do status = Fabricate(:status, text: 'Hello world', account: jeff) reblog = Fabricate(:status, reblog: status, account: alice) bob.follow!(alice) - expect(FeedManager.instance.filter?(:home, reblog, bob)).to be false + expect(described_class.instance.filter?(:home, reblog, bob)).to be false end it 'returns true for post from account who blocked me' do status = Fabricate(:status, text: 'Hello, World', account: alice) alice.block!(bob) - expect(FeedManager.instance.filter?(:home, status, bob)).to be true + expect(described_class.instance.filter?(:home, status, bob)).to be true end it 'returns true for post from blocked account' do status = Fabricate(:status, text: 'Hello, World', account: alice) bob.block!(alice) - expect(FeedManager.instance.filter?(:home, status, bob)).to be true + expect(described_class.instance.filter?(:home, status, bob)).to be true end it 'returns true for reblog by followee of blocked account' do @@ -59,7 +59,7 @@ RSpec.describe FeedManager do reblog = Fabricate(:status, reblog: status, account: alice) bob.follow!(alice) bob.block!(jeff) - expect(FeedManager.instance.filter?(:home, reblog, bob)).to be true + expect(described_class.instance.filter?(:home, reblog, bob)).to be true end it 'returns true for reblog by followee of muted account' do @@ -67,7 +67,7 @@ RSpec.describe FeedManager do reblog = Fabricate(:status, reblog: status, account: alice) bob.follow!(alice) bob.mute!(jeff) - expect(FeedManager.instance.filter?(:home, reblog, bob)).to be true + expect(described_class.instance.filter?(:home, reblog, bob)).to be true end it 'returns true for reblog by followee of someone who is blocking recipient' do @@ -75,14 +75,14 @@ RSpec.describe FeedManager do reblog = Fabricate(:status, reblog: status, account: alice) bob.follow!(alice) jeff.block!(bob) - expect(FeedManager.instance.filter?(:home, reblog, bob)).to be true + expect(described_class.instance.filter?(:home, reblog, bob)).to be true end it 'returns true for reblog from account with reblogs disabled' do status = Fabricate(:status, text: 'Hello world', account: jeff) reblog = Fabricate(:status, reblog: status, account: alice) bob.follow!(alice, reblogs: false) - expect(FeedManager.instance.filter?(:home, reblog, bob)).to be true + expect(described_class.instance.filter?(:home, reblog, bob)).to be true end it 'returns false for reply by followee to another followee' do @@ -90,49 +90,49 @@ RSpec.describe FeedManager do reply = Fabricate(:status, text: 'Nay', thread: status, account: alice) bob.follow!(alice) bob.follow!(jeff) - expect(FeedManager.instance.filter?(:home, reply, bob)).to be false + expect(described_class.instance.filter?(:home, reply, bob)).to be false end it 'returns false for reply by followee to recipient' do status = Fabricate(:status, text: 'Hello world', account: bob) reply = Fabricate(:status, text: 'Nay', thread: status, account: alice) bob.follow!(alice) - expect(FeedManager.instance.filter?(:home, reply, bob)).to be false + expect(described_class.instance.filter?(:home, reply, bob)).to be false end it 'returns false for reply by followee to self' do status = Fabricate(:status, text: 'Hello world', account: alice) reply = Fabricate(:status, text: 'Nay', thread: status, account: alice) bob.follow!(alice) - expect(FeedManager.instance.filter?(:home, reply, bob)).to be false + expect(described_class.instance.filter?(:home, reply, bob)).to be false end it 'returns true for reply by followee to non-followed account' do status = Fabricate(:status, text: 'Hello world', account: jeff) reply = Fabricate(:status, text: 'Nay', thread: status, account: alice) bob.follow!(alice) - expect(FeedManager.instance.filter?(:home, reply, bob)).to be true + expect(described_class.instance.filter?(:home, reply, bob)).to be true end it 'returns true for the second reply by followee to a non-federated status' do reply = Fabricate(:status, text: 'Reply 1', reply: true, account: alice) second_reply = Fabricate(:status, text: 'Reply 2', thread: reply, account: alice) bob.follow!(alice) - expect(FeedManager.instance.filter?(:home, second_reply, bob)).to be true + expect(described_class.instance.filter?(:home, second_reply, bob)).to be true end it 'returns false for status by followee mentioning another account' do bob.follow!(alice) jeff.follow!(alice) status = PostStatusService.new.call(alice, text: 'Hey @jeff') - expect(FeedManager.instance.filter?(:home, status, bob)).to be false + expect(described_class.instance.filter?(:home, status, bob)).to be false end it 'returns true for status by followee mentioning blocked account' do bob.block!(jeff) bob.follow!(alice) status = PostStatusService.new.call(alice, text: 'Hey @jeff') - expect(FeedManager.instance.filter?(:home, status, bob)).to be true + expect(described_class.instance.filter?(:home, status, bob)).to be true end it 'returns true for reblog of a personally blocked domain' do @@ -140,19 +140,19 @@ RSpec.describe FeedManager do alice.follow!(jeff) status = Fabricate(:status, text: 'Hello world', account: bob) reblog = Fabricate(:status, reblog: status, account: jeff) - expect(FeedManager.instance.filter?(:home, reblog, alice)).to be true + expect(described_class.instance.filter?(:home, reblog, alice)).to be true end it 'returns true for German post when follow is set to English only' do alice.follow!(bob, languages: %w(en)) status = Fabricate(:status, text: 'Hallo Welt', account: bob, language: 'de') - expect(FeedManager.instance.filter?(:home, status, alice)).to be true + expect(described_class.instance.filter?(:home, status, alice)).to be true end it 'returns false for German post when follow is set to German' do alice.follow!(bob, languages: %w(de)) status = Fabricate(:status, text: 'Hallo Welt', account: bob, language: 'de') - expect(FeedManager.instance.filter?(:home, status, alice)).to be false + expect(described_class.instance.filter?(:home, status, alice)).to be false end it 'returns true for post from followee on exclusive list' do @@ -196,27 +196,27 @@ RSpec.describe FeedManager do it 'returns true for status that mentions blocked account' do bob.block!(jeff) status = PostStatusService.new.call(alice, text: 'Hey @jeff') - expect(FeedManager.instance.filter?(:mentions, status, bob)).to be true + expect(described_class.instance.filter?(:mentions, status, bob)).to be true end it 'returns true for status that replies to a blocked account' do status = Fabricate(:status, text: 'Hello world', account: jeff) reply = Fabricate(:status, text: 'Nay', thread: status, account: alice) bob.block!(jeff) - expect(FeedManager.instance.filter?(:mentions, reply, bob)).to be true + expect(described_class.instance.filter?(:mentions, reply, bob)).to be true end it 'returns true for status by silenced account who recipient is not following' do status = Fabricate(:status, text: 'Hello world', account: alice) alice.silence! - expect(FeedManager.instance.filter?(:mentions, status, bob)).to be true + expect(described_class.instance.filter?(:mentions, status, bob)).to be true end it 'returns false for status by followed silenced account' do status = Fabricate(:status, text: 'Hello world', account: alice) alice.silence! bob.follow!(alice) - expect(FeedManager.instance.filter?(:mentions, status, bob)).to be false + expect(described_class.instance.filter?(:mentions, status, bob)).to be false end end end @@ -228,7 +228,7 @@ RSpec.describe FeedManager do members = Array.new(FeedManager::MAX_ITEMS) { |count| [count, count] } redis.zadd("feed:home:#{account.id}", members) - FeedManager.instance.push_to_home(account, status) + described_class.instance.push_to_home(account, status) expect(redis.zcard("feed:home:#{account.id}")).to eq FeedManager::MAX_ITEMS end @@ -239,7 +239,7 @@ RSpec.describe FeedManager do reblogged = Fabricate(:status) reblog = Fabricate(:status, reblog: reblogged) - expect(FeedManager.instance.push_to_home(account, reblog)).to be true + expect(described_class.instance.push_to_home(account, reblog)).to be true end it 'does not save a new reblog of a recent status' do @@ -247,9 +247,9 @@ RSpec.describe FeedManager do reblogged = Fabricate(:status) reblog = Fabricate(:status, reblog: reblogged) - FeedManager.instance.push_to_home(account, reblogged) + described_class.instance.push_to_home(account, reblogged) - expect(FeedManager.instance.push_to_home(account, reblog)).to be false + expect(described_class.instance.push_to_home(account, reblog)).to be false end it 'saves a new reblog of an old status' do @@ -257,14 +257,14 @@ RSpec.describe FeedManager do reblogged = Fabricate(:status) reblog = Fabricate(:status, reblog: reblogged) - FeedManager.instance.push_to_home(account, reblogged) + described_class.instance.push_to_home(account, reblogged) # Fill the feed with intervening statuses FeedManager::REBLOG_FALLOFF.times do - FeedManager.instance.push_to_home(account, Fabricate(:status)) + described_class.instance.push_to_home(account, Fabricate(:status)) end - expect(FeedManager.instance.push_to_home(account, reblog)).to be true + expect(described_class.instance.push_to_home(account, reblog)).to be true end it 'does not save a new reblog of a recently-reblogged status' do @@ -273,10 +273,10 @@ RSpec.describe FeedManager do reblogs = Array.new(2) { Fabricate(:status, reblog: reblogged) } # The first reblog will be accepted - FeedManager.instance.push_to_home(account, reblogs.first) + described_class.instance.push_to_home(account, reblogs.first) # The second reblog should be ignored - expect(FeedManager.instance.push_to_home(account, reblogs.last)).to be false + expect(described_class.instance.push_to_home(account, reblogs.last)).to be false end it 'saves a new reblog of a recently-reblogged status when previous reblog has been deleted' do @@ -285,15 +285,15 @@ RSpec.describe FeedManager do old_reblog = Fabricate(:status, reblog: reblogged) # The first reblog should be accepted - expect(FeedManager.instance.push_to_home(account, old_reblog)).to be true + expect(described_class.instance.push_to_home(account, old_reblog)).to be true # The first reblog should be successfully removed - expect(FeedManager.instance.unpush_from_home(account, old_reblog)).to be true + expect(described_class.instance.unpush_from_home(account, old_reblog)).to be true reblog = Fabricate(:status, reblog: reblogged) # The second reblog should be accepted - expect(FeedManager.instance.push_to_home(account, reblog)).to be true + expect(described_class.instance.push_to_home(account, reblog)).to be true end it 'does not save a new reblog of a multiply-reblogged-then-unreblogged status' do @@ -302,14 +302,14 @@ RSpec.describe FeedManager do reblogs = Array.new(3) { Fabricate(:status, reblog: reblogged) } # Accept the reblogs - FeedManager.instance.push_to_home(account, reblogs[0]) - FeedManager.instance.push_to_home(account, reblogs[1]) + described_class.instance.push_to_home(account, reblogs[0]) + described_class.instance.push_to_home(account, reblogs[1]) # Unreblog the first one - FeedManager.instance.unpush_from_home(account, reblogs[0]) + described_class.instance.unpush_from_home(account, reblogs[0]) # The last reblog should still be ignored - expect(FeedManager.instance.push_to_home(account, reblogs.last)).to be false + expect(described_class.instance.push_to_home(account, reblogs.last)).to be false end it 'saves a new reblog of a long-ago-reblogged status' do @@ -318,15 +318,15 @@ RSpec.describe FeedManager do reblogs = Array.new(2) { Fabricate(:status, reblog: reblogged) } # The first reblog will be accepted - FeedManager.instance.push_to_home(account, reblogs.first) + described_class.instance.push_to_home(account, reblogs.first) # Fill the feed with intervening statuses FeedManager::REBLOG_FALLOFF.times do - FeedManager.instance.push_to_home(account, Fabricate(:status)) + described_class.instance.push_to_home(account, Fabricate(:status)) end # The second reblog should also be accepted - expect(FeedManager.instance.push_to_home(account, reblogs.last)).to be true + expect(described_class.instance.push_to_home(account, reblogs.last)).to be true end end @@ -334,9 +334,9 @@ RSpec.describe FeedManager do account = Fabricate(:account) reblog = Fabricate(:status) status = Fabricate(:status, reblog: reblog) - FeedManager.instance.push_to_home(account, status) + described_class.instance.push_to_home(account, status) - expect(FeedManager.instance.push_to_home(account, reblog)).to be false + expect(described_class.instance.push_to_home(account, reblog)).to be false end end @@ -359,9 +359,9 @@ RSpec.describe FeedManager do it "does not push when the given status's reblog is already inserted" do reblog = Fabricate(:status) status = Fabricate(:status, reblog: reblog) - FeedManager.instance.push_to_list(list, status) + described_class.instance.push_to_list(list, status) - expect(FeedManager.instance.push_to_list(list, reblog)).to be false + expect(described_class.instance.push_to_list(list, reblog)).to be false end context 'when replies policy is set to no replies' do @@ -371,19 +371,19 @@ RSpec.describe FeedManager do it 'pushes statuses that are not replies' do status = Fabricate(:status, text: 'Hello world', account: bob) - expect(FeedManager.instance.push_to_list(list, status)).to be true + expect(described_class.instance.push_to_list(list, status)).to be true end it 'pushes statuses that are replies to list owner' do status = Fabricate(:status, text: 'Hello world', account: owner) reply = Fabricate(:status, text: 'Nay', thread: status, account: bob) - expect(FeedManager.instance.push_to_list(list, reply)).to be true + expect(described_class.instance.push_to_list(list, reply)).to be true end it 'does not push replies to another member of the list' do status = Fabricate(:status, text: 'Hello world', account: alice) reply = Fabricate(:status, text: 'Nay', thread: status, account: bob) - expect(FeedManager.instance.push_to_list(list, reply)).to be false + expect(described_class.instance.push_to_list(list, reply)).to be false end end @@ -394,25 +394,25 @@ RSpec.describe FeedManager do it 'pushes statuses that are not replies' do status = Fabricate(:status, text: 'Hello world', account: bob) - expect(FeedManager.instance.push_to_list(list, status)).to be true + expect(described_class.instance.push_to_list(list, status)).to be true end it 'pushes statuses that are replies to list owner' do status = Fabricate(:status, text: 'Hello world', account: owner) reply = Fabricate(:status, text: 'Nay', thread: status, account: bob) - expect(FeedManager.instance.push_to_list(list, reply)).to be true + expect(described_class.instance.push_to_list(list, reply)).to be true end it 'pushes replies to another member of the list' do status = Fabricate(:status, text: 'Hello world', account: alice) reply = Fabricate(:status, text: 'Nay', thread: status, account: bob) - expect(FeedManager.instance.push_to_list(list, reply)).to be true + expect(described_class.instance.push_to_list(list, reply)).to be true end it 'does not push replies to someone not a member of the list' do status = Fabricate(:status, text: 'Hello world', account: eve) reply = Fabricate(:status, text: 'Nay', thread: status, account: bob) - expect(FeedManager.instance.push_to_list(list, reply)).to be false + expect(described_class.instance.push_to_list(list, reply)).to be false end end @@ -423,25 +423,25 @@ RSpec.describe FeedManager do it 'pushes statuses that are not replies' do status = Fabricate(:status, text: 'Hello world', account: bob) - expect(FeedManager.instance.push_to_list(list, status)).to be true + expect(described_class.instance.push_to_list(list, status)).to be true end it 'pushes statuses that are replies to list owner' do status = Fabricate(:status, text: 'Hello world', account: owner) reply = Fabricate(:status, text: 'Nay', thread: status, account: bob) - expect(FeedManager.instance.push_to_list(list, reply)).to be true + expect(described_class.instance.push_to_list(list, reply)).to be true end it 'pushes replies to another member of the list' do status = Fabricate(:status, text: 'Hello world', account: alice) reply = Fabricate(:status, text: 'Nay', thread: status, account: bob) - expect(FeedManager.instance.push_to_list(list, reply)).to be true + expect(described_class.instance.push_to_list(list, reply)).to be true end it 'pushes replies to someone not a member of the list' do status = Fabricate(:status, text: 'Hello world', account: eve) reply = Fabricate(:status, text: 'Nay', thread: status, account: bob) - expect(FeedManager.instance.push_to_list(list, reply)).to be true + expect(described_class.instance.push_to_list(list, reply)).to be true end end end @@ -451,9 +451,9 @@ RSpec.describe FeedManager do account = Fabricate(:account, id: 0) reblog = Fabricate(:status) status = Fabricate(:status, reblog: reblog) - FeedManager.instance.push_to_home(account, status) + described_class.instance.push_to_home(account, status) - FeedManager.instance.merge_into_home(account, reblog.account) + described_class.instance.merge_into_home(account, reblog.account) expect(redis.zscore('feed:home:0', reblog.id)).to be_nil end @@ -466,14 +466,14 @@ RSpec.describe FeedManager do reblogged = Fabricate(:status) status = Fabricate(:status, reblog: reblogged) - FeedManager.instance.push_to_home(receiver, reblogged) - FeedManager::REBLOG_FALLOFF.times { FeedManager.instance.push_to_home(receiver, Fabricate(:status)) } - FeedManager.instance.push_to_home(receiver, status) + described_class.instance.push_to_home(receiver, reblogged) + FeedManager::REBLOG_FALLOFF.times { described_class.instance.push_to_home(receiver, Fabricate(:status)) } + described_class.instance.push_to_home(receiver, status) # The reblogging status should show up under normal conditions. expect(redis.zrange("feed:home:#{receiver.id}", 0, -1)).to include(status.id.to_s) - FeedManager.instance.unpush_from_home(receiver, status) + described_class.instance.unpush_from_home(receiver, status) # Restore original status expect(redis.zrange("feed:home:#{receiver.id}", 0, -1)).to_not include(status.id.to_s) @@ -484,12 +484,12 @@ RSpec.describe FeedManager do reblogged = Fabricate(:status) status = Fabricate(:status, reblog: reblogged) - FeedManager.instance.push_to_home(receiver, status) + described_class.instance.push_to_home(receiver, status) # The reblogging status should show up under normal conditions. expect(redis.zrange("feed:home:#{receiver.id}", 0, -1)).to eq [status.id.to_s] - FeedManager.instance.unpush_from_home(receiver, status) + described_class.instance.unpush_from_home(receiver, status) expect(redis.zrange("feed:home:#{receiver.id}", 0, -1)).to be_empty end @@ -499,14 +499,14 @@ RSpec.describe FeedManager do reblogs = Array.new(3) { Fabricate(:status, reblog: reblogged) } reblogs.each do |reblog| - FeedManager.instance.push_to_home(receiver, reblog) + described_class.instance.push_to_home(receiver, reblog) end # The reblogging status should show up under normal conditions. expect(redis.zrange("feed:home:#{receiver.id}", 0, -1)).to eq [reblogs.first.id.to_s] reblogs[0...-1].each do |reblog| - FeedManager.instance.unpush_from_home(receiver, reblog) + described_class.instance.unpush_from_home(receiver, reblog) end expect(redis.zrange("feed:home:#{receiver.id}", 0, -1)).to eq [reblogs.last.id.to_s] @@ -515,10 +515,10 @@ RSpec.describe FeedManager do it 'sends push updates' do status = Fabricate(:status) - FeedManager.instance.push_to_home(receiver, status) + described_class.instance.push_to_home(receiver, status) allow(redis).to receive_messages(publish: nil) - FeedManager.instance.unpush_from_home(receiver, status) + described_class.instance.unpush_from_home(receiver, status) deletion = Oj.dump(event: :delete, payload: status.id.to_s) expect(redis).to have_received(:publish).with("timeline:#{receiver.id}", deletion) @@ -544,7 +544,7 @@ RSpec.describe FeedManager do end it 'correctly cleans the home timeline' do - FeedManager.instance.clear_from_home(account, target_account) + described_class.instance.clear_from_home(account, target_account) expect(redis.zrange("feed:home:#{account.id}", 0, -1)).to eq [status_1.id.to_s, status_7.id.to_s] end diff --git a/spec/lib/ostatus/tag_manager_spec.rb b/spec/lib/ostatus/tag_manager_spec.rb index fb9740ce3..0e20f26c7 100644 --- a/spec/lib/ostatus/tag_manager_spec.rb +++ b/spec/lib/ostatus/tag_manager_spec.rb @@ -5,40 +5,40 @@ require 'rails_helper' describe OStatus::TagManager do describe '#unique_tag' do it 'returns a unique tag' do - expect(OStatus::TagManager.instance.unique_tag(Time.utc(2000), 12, 'Status')).to eq 'tag:cb6e6126.ngrok.io,2000-01-01:objectId=12:objectType=Status' + expect(described_class.instance.unique_tag(Time.utc(2000), 12, 'Status')).to eq 'tag:cb6e6126.ngrok.io,2000-01-01:objectId=12:objectType=Status' end end describe '#unique_tag_to_local_id' do it 'returns the ID part' do - expect(OStatus::TagManager.instance.unique_tag_to_local_id('tag:cb6e6126.ngrok.io,2000-01-01:objectId=12:objectType=Status', 'Status')).to eql '12' + expect(described_class.instance.unique_tag_to_local_id('tag:cb6e6126.ngrok.io,2000-01-01:objectId=12:objectType=Status', 'Status')).to eql '12' end it 'returns nil if it is not local id' do - expect(OStatus::TagManager.instance.unique_tag_to_local_id('tag:remote,2000-01-01:objectId=12:objectType=Status', 'Status')).to be_nil + expect(described_class.instance.unique_tag_to_local_id('tag:remote,2000-01-01:objectId=12:objectType=Status', 'Status')).to be_nil end it 'returns nil if it is not expected type' do - expect(OStatus::TagManager.instance.unique_tag_to_local_id('tag:cb6e6126.ngrok.io,2000-01-01:objectId=12:objectType=Block', 'Status')).to be_nil + expect(described_class.instance.unique_tag_to_local_id('tag:cb6e6126.ngrok.io,2000-01-01:objectId=12:objectType=Block', 'Status')).to be_nil end it 'returns nil if it does not have object ID' do - expect(OStatus::TagManager.instance.unique_tag_to_local_id('tag:cb6e6126.ngrok.io,2000-01-01:objectType=Status', 'Status')).to be_nil + expect(described_class.instance.unique_tag_to_local_id('tag:cb6e6126.ngrok.io,2000-01-01:objectType=Status', 'Status')).to be_nil end end describe '#local_id?' do it 'returns true for a local ID' do - expect(OStatus::TagManager.instance.local_id?('tag:cb6e6126.ngrok.io;objectId=12:objectType=Status')).to be true + expect(described_class.instance.local_id?('tag:cb6e6126.ngrok.io;objectId=12:objectType=Status')).to be true end it 'returns false for a foreign ID' do - expect(OStatus::TagManager.instance.local_id?('tag:foreign.tld;objectId=12:objectType=Status')).to be false + expect(described_class.instance.local_id?('tag:foreign.tld;objectId=12:objectType=Status')).to be false end end describe '#uri_for' do - subject { OStatus::TagManager.instance.uri_for(target) } + subject { described_class.instance.uri_for(target) } context 'with comment object' do let(:target) { Fabricate(:status, created_at: '2000-01-01T00:00:00Z', reply: true) } diff --git a/spec/lib/request_spec.rb b/spec/lib/request_spec.rb index 25fe9ed37..e88631e47 100644 --- a/spec/lib/request_spec.rb +++ b/spec/lib/request_spec.rb @@ -4,7 +4,7 @@ require 'rails_helper' require 'securerandom' describe Request do - subject { Request.new(:get, 'http://example.com') } + subject { described_class.new(:get, 'http://example.com') } describe '#headers' do it 'returns user agent' do diff --git a/spec/lib/tag_manager_spec.rb b/spec/lib/tag_manager_spec.rb index 8de290541..38203a55f 100644 --- a/spec/lib/tag_manager_spec.rb +++ b/spec/lib/tag_manager_spec.rb @@ -16,15 +16,15 @@ RSpec.describe TagManager do end it 'returns true for nil' do - expect(TagManager.instance.local_domain?(nil)).to be true + expect(described_class.instance.local_domain?(nil)).to be true end it 'returns true if the slash-stripped string equals to local domain' do - expect(TagManager.instance.local_domain?('DoMaIn.Example.com/')).to be true + expect(described_class.instance.local_domain?('DoMaIn.Example.com/')).to be true end it 'returns false for irrelevant string' do - expect(TagManager.instance.local_domain?('DoMaIn.Example.com!')).to be false + expect(described_class.instance.local_domain?('DoMaIn.Example.com!')).to be false end end @@ -41,25 +41,25 @@ RSpec.describe TagManager do end it 'returns true for nil' do - expect(TagManager.instance.web_domain?(nil)).to be true + expect(described_class.instance.web_domain?(nil)).to be true end it 'returns true if the slash-stripped string equals to web domain' do - expect(TagManager.instance.web_domain?('DoMaIn.Example.com/')).to be true + expect(described_class.instance.web_domain?('DoMaIn.Example.com/')).to be true end it 'returns false for string with irrelevant characters' do - expect(TagManager.instance.web_domain?('DoMaIn.Example.com!')).to be false + expect(described_class.instance.web_domain?('DoMaIn.Example.com!')).to be false end end describe '#normalize_domain' do it 'returns nil if the given parameter is nil' do - expect(TagManager.instance.normalize_domain(nil)).to be_nil + expect(described_class.instance.normalize_domain(nil)).to be_nil end it 'returns normalized domain' do - expect(TagManager.instance.normalize_domain('DoMaIn.Example.com/')).to eq 'domain.example.com' + expect(described_class.instance.normalize_domain('DoMaIn.Example.com/')).to eq 'domain.example.com' end end @@ -72,17 +72,17 @@ RSpec.describe TagManager do it 'returns true if the normalized string with port is local URL' do Rails.configuration.x.web_domain = 'domain.example.com:42' - expect(TagManager.instance.local_url?('https://DoMaIn.Example.com:42/')).to be true + expect(described_class.instance.local_url?('https://DoMaIn.Example.com:42/')).to be true end it 'returns true if the normalized string without port is local URL' do Rails.configuration.x.web_domain = 'domain.example.com' - expect(TagManager.instance.local_url?('https://DoMaIn.Example.com/')).to be true + expect(described_class.instance.local_url?('https://DoMaIn.Example.com/')).to be true end it 'returns false for string with irrelevant characters' do Rails.configuration.x.web_domain = 'domain.example.com' - expect(TagManager.instance.local_url?('https://domain.example.net/')).to be false + expect(described_class.instance.local_url?('https://domain.example.net/')).to be false end end end diff --git a/spec/lib/webfinger_resource_spec.rb b/spec/lib/webfinger_resource_spec.rb index 8ec6dd205..2cad04fcc 100644 --- a/spec/lib/webfinger_resource_spec.rb +++ b/spec/lib/webfinger_resource_spec.rb @@ -17,7 +17,7 @@ describe WebfingerResource do resource = 'https://example.com/users/alice/other' expect do - WebfingerResource.new(resource).username + described_class.new(resource).username end.to raise_error(ActiveRecord::RecordNotFound) end @@ -32,7 +32,7 @@ describe WebfingerResource do expect(Rails.application.routes).to receive(:recognize_path).with(resource).and_return(recognized).at_least(:once) expect do - WebfingerResource.new(resource).username + described_class.new(resource).username end.to raise_error(ActiveRecord::RecordNotFound) end @@ -40,28 +40,28 @@ describe WebfingerResource do resource = 'website for http://example.com/users/alice/other' expect do - WebfingerResource.new(resource).username + described_class.new(resource).username end.to raise_error(WebfingerResource::InvalidRequest) end it 'finds the username in a valid https route' do resource = 'https://example.com/users/alice' - result = WebfingerResource.new(resource).username + result = described_class.new(resource).username expect(result).to eq 'alice' end it 'finds the username in a mixed case http route' do resource = 'HTTp://exAMPLe.com/users/alice' - result = WebfingerResource.new(resource).username + result = described_class.new(resource).username expect(result).to eq 'alice' end it 'finds the username in a valid http route' do resource = 'http://example.com/users/alice' - result = WebfingerResource.new(resource).username + result = described_class.new(resource).username expect(result).to eq 'alice' end end @@ -71,7 +71,7 @@ describe WebfingerResource do resource = 'user@remote-host.com' expect do - WebfingerResource.new(resource).username + described_class.new(resource).username end.to raise_error(ActiveRecord::RecordNotFound) end @@ -79,7 +79,7 @@ describe WebfingerResource do Rails.configuration.x.local_domain = 'example.com' resource = 'alice@example.com' - result = WebfingerResource.new(resource).username + result = described_class.new(resource).username expect(result).to eq 'alice' end @@ -87,7 +87,7 @@ describe WebfingerResource do Rails.configuration.x.web_domain = 'example.com' resource = 'alice@example.com' - result = WebfingerResource.new(resource).username + result = described_class.new(resource).username expect(result).to eq 'alice' end end @@ -97,7 +97,7 @@ describe WebfingerResource do resource = 'acct:user@remote-host.com' expect do - WebfingerResource.new(resource).username + described_class.new(resource).username end.to raise_error(ActiveRecord::RecordNotFound) end @@ -105,7 +105,7 @@ describe WebfingerResource do resource = 'acct:user@remote-host@remote-hostess.remote.local@remote' expect do - WebfingerResource.new(resource).username + described_class.new(resource).username end.to raise_error(ActiveRecord::RecordNotFound) end @@ -113,7 +113,7 @@ describe WebfingerResource do Rails.configuration.x.local_domain = 'example.com' resource = 'acct:alice@example.com' - result = WebfingerResource.new(resource).username + result = described_class.new(resource).username expect(result).to eq 'alice' end @@ -121,7 +121,7 @@ describe WebfingerResource do Rails.configuration.x.web_domain = 'example.com' resource = 'acct:alice@example.com' - result = WebfingerResource.new(resource).username + result = described_class.new(resource).username expect(result).to eq 'alice' end end @@ -131,7 +131,7 @@ describe WebfingerResource do resource = 'df/:dfkj' expect do - WebfingerResource.new(resource).username + described_class.new(resource).username end.to raise_error(WebfingerResource::InvalidRequest) end end diff --git a/spec/mailers/notification_mailer_spec.rb b/spec/mailers/notification_mailer_spec.rb index 73c751def..bf364b625 100644 --- a/spec/mailers/notification_mailer_spec.rb +++ b/spec/mailers/notification_mailer_spec.rb @@ -23,7 +23,7 @@ RSpec.describe NotificationMailer do describe 'mention' do let(:mention) { Mention.create!(account: receiver.account, status: foreign_status) } - let(:mail) { NotificationMailer.mention(receiver.account, Notification.create!(account: receiver.account, activity: mention)) } + let(:mail) { described_class.mention(receiver.account, Notification.create!(account: receiver.account, activity: mention)) } include_examples 'localized subject', 'notification_mailer.mention.subject', name: 'bob' @@ -40,7 +40,7 @@ RSpec.describe NotificationMailer do describe 'follow' do let(:follow) { sender.follow!(receiver.account) } - let(:mail) { NotificationMailer.follow(receiver.account, Notification.create!(account: receiver.account, activity: follow)) } + let(:mail) { described_class.follow(receiver.account, Notification.create!(account: receiver.account, activity: follow)) } include_examples 'localized subject', 'notification_mailer.follow.subject', name: 'bob' @@ -56,7 +56,7 @@ RSpec.describe NotificationMailer do describe 'favourite' do let(:favourite) { Favourite.create!(account: sender, status: own_status) } - let(:mail) { NotificationMailer.favourite(own_status.account, Notification.create!(account: receiver.account, activity: favourite)) } + let(:mail) { described_class.favourite(own_status.account, Notification.create!(account: receiver.account, activity: favourite)) } include_examples 'localized subject', 'notification_mailer.favourite.subject', name: 'bob' @@ -73,7 +73,7 @@ RSpec.describe NotificationMailer do describe 'reblog' do let(:reblog) { Status.create!(account: sender, reblog: own_status) } - let(:mail) { NotificationMailer.reblog(own_status.account, Notification.create!(account: receiver.account, activity: reblog)) } + let(:mail) { described_class.reblog(own_status.account, Notification.create!(account: receiver.account, activity: reblog)) } include_examples 'localized subject', 'notification_mailer.reblog.subject', name: 'bob' @@ -90,7 +90,7 @@ RSpec.describe NotificationMailer do describe 'follow_request' do let(:follow_request) { Fabricate(:follow_request, account: sender, target_account: receiver.account) } - let(:mail) { NotificationMailer.follow_request(receiver.account, Notification.create!(account: receiver.account, activity: follow_request)) } + let(:mail) { described_class.follow_request(receiver.account, Notification.create!(account: receiver.account, activity: follow_request)) } include_examples 'localized subject', 'notification_mailer.follow_request.subject', name: 'bob' diff --git a/spec/mailers/user_mailer_spec.rb b/spec/mailers/user_mailer_spec.rb index a4f6c145a..702aa1c35 100644 --- a/spec/mailers/user_mailer_spec.rb +++ b/spec/mailers/user_mailer_spec.rb @@ -19,7 +19,7 @@ describe UserMailer do end describe 'confirmation_instructions' do - let(:mail) { UserMailer.confirmation_instructions(receiver, 'spec') } + let(:mail) { described_class.confirmation_instructions(receiver, 'spec') } it 'renders confirmation instructions' do receiver.update!(locale: nil) @@ -34,7 +34,7 @@ describe UserMailer do end describe 'reconfirmation_instructions' do - let(:mail) { UserMailer.confirmation_instructions(receiver, 'spec') } + let(:mail) { described_class.confirmation_instructions(receiver, 'spec') } it 'renders reconfirmation instructions' do receiver.update!(email: 'new-email@example.com', locale: nil) @@ -48,7 +48,7 @@ describe UserMailer do end describe 'reset_password_instructions' do - let(:mail) { UserMailer.reset_password_instructions(receiver, 'spec') } + let(:mail) { described_class.reset_password_instructions(receiver, 'spec') } it 'renders reset password instructions' do receiver.update!(locale: nil) @@ -61,7 +61,7 @@ describe UserMailer do end describe 'password_change' do - let(:mail) { UserMailer.password_change(receiver) } + let(:mail) { described_class.password_change(receiver) } it 'renders password change notification' do receiver.update!(locale: nil) @@ -73,7 +73,7 @@ describe UserMailer do end describe 'email_changed' do - let(:mail) { UserMailer.email_changed(receiver) } + let(:mail) { described_class.email_changed(receiver) } it 'renders email change notification' do receiver.update!(locale: nil) @@ -86,7 +86,7 @@ describe UserMailer do describe 'warning' do let(:strike) { Fabricate(:account_warning, target_account: receiver.account, text: 'dont worry its just the testsuite', action: 'suspend') } - let(:mail) { UserMailer.warning(receiver, strike) } + let(:mail) { described_class.warning(receiver, strike) } it 'renders warning notification' do receiver.update!(locale: nil) @@ -97,7 +97,7 @@ describe UserMailer do describe 'webauthn_credential_deleted' do let(:credential) { Fabricate(:webauthn_credential, user_id: receiver.id) } - let(:mail) { UserMailer.webauthn_credential_deleted(receiver, credential) } + let(:mail) { described_class.webauthn_credential_deleted(receiver, credential) } it 'renders webauthn credential deleted notification' do receiver.update!(locale: nil) @@ -112,7 +112,7 @@ describe UserMailer do let(:ip) { '192.168.0.1' } let(:agent) { 'NCSA_Mosaic/2.0 (Windows 3.1)' } let(:timestamp) { Time.now.utc } - let(:mail) { UserMailer.suspicious_sign_in(receiver, ip, agent, timestamp) } + let(:mail) { described_class.suspicious_sign_in(receiver, ip, agent, timestamp) } it 'renders suspicious sign in notification' do receiver.update!(locale: nil) @@ -125,7 +125,7 @@ describe UserMailer do describe 'appeal_approved' do let(:appeal) { Fabricate(:appeal, account: receiver.account, approved_at: Time.now.utc) } - let(:mail) { UserMailer.appeal_approved(receiver, appeal) } + let(:mail) { described_class.appeal_approved(receiver, appeal) } it 'renders appeal_approved notification' do expect(mail.subject).to eq I18n.t('user_mailer.appeal_approved.subject', date: I18n.l(appeal.created_at)) @@ -135,7 +135,7 @@ describe UserMailer do describe 'appeal_rejected' do let(:appeal) { Fabricate(:appeal, account: receiver.account, rejected_at: Time.now.utc) } - let(:mail) { UserMailer.appeal_rejected(receiver, appeal) } + let(:mail) { described_class.appeal_rejected(receiver, appeal) } it 'renders appeal_rejected notification' do expect(mail.subject).to eq I18n.t('user_mailer.appeal_rejected.subject', date: I18n.l(appeal.created_at)) diff --git a/spec/models/account_conversation_spec.rb b/spec/models/account_conversation_spec.rb index a16aa500c..4e8727ca3 100644 --- a/spec/models/account_conversation_spec.rb +++ b/spec/models/account_conversation_spec.rb @@ -12,7 +12,7 @@ RSpec.describe AccountConversation do status = Fabricate(:status, account: alice, visibility: :direct) status.mentions.create(account: bob) - conversation = AccountConversation.add_status(alice, status) + conversation = described_class.add_status(alice, status) expect(conversation.participant_accounts).to include(bob) expect(conversation.last_status).to eq status @@ -21,12 +21,12 @@ RSpec.describe AccountConversation do it 'appends to old record when there is a match' do last_status = Fabricate(:status, account: alice, visibility: :direct) - conversation = AccountConversation.create!(account: alice, conversation: last_status.conversation, participant_account_ids: [bob.id], status_ids: [last_status.id]) + conversation = described_class.create!(account: alice, conversation: last_status.conversation, participant_account_ids: [bob.id], status_ids: [last_status.id]) status = Fabricate(:status, account: bob, visibility: :direct, thread: last_status) status.mentions.create(account: alice) - new_conversation = AccountConversation.add_status(alice, status) + new_conversation = described_class.add_status(alice, status) expect(new_conversation.id).to eq conversation.id expect(new_conversation.participant_accounts).to include(bob) @@ -36,13 +36,13 @@ RSpec.describe AccountConversation do it 'creates new record when new participants are added' do last_status = Fabricate(:status, account: alice, visibility: :direct) - conversation = AccountConversation.create!(account: alice, conversation: last_status.conversation, participant_account_ids: [bob.id], status_ids: [last_status.id]) + conversation = described_class.create!(account: alice, conversation: last_status.conversation, participant_account_ids: [bob.id], status_ids: [last_status.id]) status = Fabricate(:status, account: bob, visibility: :direct, thread: last_status) status.mentions.create(account: alice) status.mentions.create(account: mark) - new_conversation = AccountConversation.add_status(alice, status) + new_conversation = described_class.add_status(alice, status) expect(new_conversation.id).to_not eq conversation.id expect(new_conversation.participant_accounts).to include(bob, mark) @@ -55,7 +55,7 @@ RSpec.describe AccountConversation do it 'updates last status to a previous value' do last_status = Fabricate(:status, account: alice, visibility: :direct) status = Fabricate(:status, account: alice, visibility: :direct) - conversation = AccountConversation.create!(account: alice, conversation: last_status.conversation, participant_account_ids: [bob.id], status_ids: [status.id, last_status.id]) + conversation = described_class.create!(account: alice, conversation: last_status.conversation, participant_account_ids: [bob.id], status_ids: [status.id, last_status.id]) last_status.mentions.create(account: bob) last_status.destroy! conversation.reload @@ -65,10 +65,10 @@ RSpec.describe AccountConversation do it 'removes the record if no other statuses are referenced' do last_status = Fabricate(:status, account: alice, visibility: :direct) - conversation = AccountConversation.create!(account: alice, conversation: last_status.conversation, participant_account_ids: [bob.id], status_ids: [last_status.id]) + conversation = described_class.create!(account: alice, conversation: last_status.conversation, participant_account_ids: [bob.id], status_ids: [last_status.id]) last_status.mentions.create(account: bob) last_status.destroy! - expect(AccountConversation.where(id: conversation.id).count).to eq 0 + expect(described_class.where(id: conversation.id).count).to eq 0 end end end diff --git a/spec/models/account_domain_block_spec.rb b/spec/models/account_domain_block_spec.rb index f3246d04c..10bd57936 100644 --- a/spec/models/account_domain_block_spec.rb +++ b/spec/models/account_domain_block_spec.rb @@ -7,14 +7,14 @@ RSpec.describe AccountDomainBlock do account = Fabricate(:account) Rails.cache.write("exclude_domains_for:#{account.id}", 'a.domain.already.blocked') - AccountDomainBlock.create!(account: account, domain: 'a.domain.blocked.later') + described_class.create!(account: account, domain: 'a.domain.blocked.later') expect(Rails.cache.exist?("exclude_domains_for:#{account.id}")).to be false end it 'removes blocking cache after destruction' do account = Fabricate(:account) - block = AccountDomainBlock.create!(account: account, domain: 'domain') + block = described_class.create!(account: account, domain: 'domain') Rails.cache.write("exclude_domains_for:#{account.id}", 'domain') block.destroy! diff --git a/spec/models/account_migration_spec.rb b/spec/models/account_migration_spec.rb index 519b9a97a..d76edddd5 100644 --- a/spec/models/account_migration_spec.rb +++ b/spec/models/account_migration_spec.rb @@ -7,7 +7,7 @@ RSpec.describe AccountMigration do let(:source_account) { Fabricate(:account) } let(:target_acct) { target_account.acct } - let(:subject) { AccountMigration.new(account: source_account, acct: target_acct) } + let(:subject) { described_class.new(account: source_account, acct: target_acct) } context 'with valid properties' do let(:target_account) { Fabricate(:account, username: 'target', domain: 'remote.org') } diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb index 6e9c608ab..d966bffa9 100644 --- a/spec/models/account_spec.rb +++ b/spec/models/account_spec.rb @@ -362,7 +362,7 @@ RSpec.describe Account do suspended: true ) - results = Account.search_for('username') + results = described_class.search_for('username') expect(results).to eq [] end @@ -375,7 +375,7 @@ RSpec.describe Account do match.user.update(approved: false) - results = Account.search_for('username') + results = described_class.search_for('username') expect(results).to eq [] end @@ -388,7 +388,7 @@ RSpec.describe Account do match.user.update(confirmed_at: nil) - results = Account.search_for('username') + results = described_class.search_for('username') expect(results).to eq [] end @@ -400,7 +400,7 @@ RSpec.describe Account do domain: 'example.com' ) - results = Account.search_for('A?l\i:c e') + results = described_class.search_for('A?l\i:c e') expect(results).to eq [match] end @@ -412,7 +412,7 @@ RSpec.describe Account do domain: 'example.com' ) - results = Account.search_for('display') + results = described_class.search_for('display') expect(results).to eq [match] end @@ -424,7 +424,7 @@ RSpec.describe Account do domain: 'example.com' ) - results = Account.search_for('username') + results = described_class.search_for('username') expect(results).to eq [match] end @@ -436,19 +436,19 @@ RSpec.describe Account do domain: 'example.com' ) - results = Account.search_for('example') + results = described_class.search_for('example') expect(results).to eq [match] end it 'limits by 10 by default' do 11.times.each { Fabricate(:account, display_name: 'Display Name') } - results = Account.search_for('display') + results = described_class.search_for('display') expect(results.size).to eq 10 end it 'accepts arbitrary limits' do 2.times.each { Fabricate(:account, display_name: 'Display Name') } - results = Account.search_for('display', limit: 1) + results = described_class.search_for('display', limit: 1) expect(results.size).to eq 1 end @@ -458,7 +458,7 @@ RSpec.describe Account do { display_name: 'Display Name', username: 'username', domain: 'example.com' }, ].map(&method(:Fabricate).curry(2).call(:account)) - results = Account.search_for('username') + results = described_class.search_for('username') expect(results).to eq matches end end @@ -476,7 +476,7 @@ RSpec.describe Account do ) account.follow!(match) - results = Account.advanced_search_for('A?l\i:c e', account, limit: 10, following: true) + results = described_class.advanced_search_for('A?l\i:c e', account, limit: 10, following: true) expect(results).to eq [match] end @@ -488,7 +488,7 @@ RSpec.describe Account do domain: 'example.com' ) - results = Account.advanced_search_for('A?l\i:c e', account, limit: 10, following: true) + results = described_class.advanced_search_for('A?l\i:c e', account, limit: 10, following: true) expect(results).to eq [] end @@ -501,7 +501,7 @@ RSpec.describe Account do suspended: true ) - results = Account.advanced_search_for('username', account, limit: 10, following: true) + results = described_class.advanced_search_for('username', account, limit: 10, following: true) expect(results).to eq [] end @@ -514,7 +514,7 @@ RSpec.describe Account do match.user.update(approved: false) - results = Account.advanced_search_for('username', account, limit: 10, following: true) + results = described_class.advanced_search_for('username', account, limit: 10, following: true) expect(results).to eq [] end @@ -527,7 +527,7 @@ RSpec.describe Account do match.user.update(confirmed_at: nil) - results = Account.advanced_search_for('username', account, limit: 10, following: true) + results = described_class.advanced_search_for('username', account, limit: 10, following: true) expect(results).to eq [] end end @@ -541,7 +541,7 @@ RSpec.describe Account do suspended: true ) - results = Account.advanced_search_for('username', account) + results = described_class.advanced_search_for('username', account) expect(results).to eq [] end @@ -554,7 +554,7 @@ RSpec.describe Account do match.user.update(approved: false) - results = Account.advanced_search_for('username', account) + results = described_class.advanced_search_for('username', account) expect(results).to eq [] end @@ -567,7 +567,7 @@ RSpec.describe Account do match.user.update(confirmed_at: nil) - results = Account.advanced_search_for('username', account) + results = described_class.advanced_search_for('username', account) expect(results).to eq [] end @@ -579,19 +579,19 @@ RSpec.describe Account do domain: 'example.com' ) - results = Account.advanced_search_for('A?l\i:c e', account) + results = described_class.advanced_search_for('A?l\i:c e', account) expect(results).to eq [match] end it 'limits by 10 by default' do 11.times { Fabricate(:account, display_name: 'Display Name') } - results = Account.advanced_search_for('display', account) + results = described_class.advanced_search_for('display', account) expect(results.size).to eq 10 end it 'accepts arbitrary limits' do 2.times { Fabricate(:account, display_name: 'Display Name') } - results = Account.advanced_search_for('display', account, limit: 1) + results = described_class.advanced_search_for('display', account, limit: 1) expect(results.size).to eq 1 end @@ -600,7 +600,7 @@ RSpec.describe Account do followed_match = Fabricate(:account, username: 'Matcher') Fabricate(:follow, account: account, target_account: followed_match) - results = Account.advanced_search_for('match', account) + results = described_class.advanced_search_for('match', account) expect(results).to eq [followed_match, match] expect(results.first.rank).to be > results.last.rank end @@ -639,31 +639,31 @@ RSpec.describe Account do describe '.following_map' do it 'returns an hash' do - expect(Account.following_map([], 1)).to be_a Hash + expect(described_class.following_map([], 1)).to be_a Hash end end describe '.followed_by_map' do it 'returns an hash' do - expect(Account.followed_by_map([], 1)).to be_a Hash + expect(described_class.followed_by_map([], 1)).to be_a Hash end end describe '.blocking_map' do it 'returns an hash' do - expect(Account.blocking_map([], 1)).to be_a Hash + expect(described_class.blocking_map([], 1)).to be_a Hash end end describe '.requested_map' do it 'returns an hash' do - expect(Account.requested_map([], 1)).to be_a Hash + expect(described_class.requested_map([], 1)).to be_a Hash end end describe '.requested_by_map' do it 'returns an hash' do - expect(Account.requested_by_map([], 1)).to be_a Hash + expect(described_class.requested_by_map([], 1)).to be_a Hash end end @@ -834,7 +834,7 @@ RSpec.describe Account do { username: 'b', domain: 'b' }, ].map(&method(:Fabricate).curry(2).call(:account)) - expect(Account.where('id > 0').alphabetic).to eq matches + expect(described_class.where('id > 0').alphabetic).to eq matches end end @@ -843,7 +843,7 @@ RSpec.describe Account do match = Fabricate(:account, display_name: 'pattern and suffix') Fabricate(:account, display_name: 'prefix and pattern') - expect(Account.matches_display_name('pattern')).to eq [match] + expect(described_class.matches_display_name('pattern')).to eq [match] end end @@ -852,24 +852,24 @@ RSpec.describe Account do match = Fabricate(:account, username: 'pattern_and_suffix') Fabricate(:account, username: 'prefix_and_pattern') - expect(Account.matches_username('pattern')).to eq [match] + expect(described_class.matches_username('pattern')).to eq [match] end end describe 'by_domain_and_subdomains' do it 'returns exact domain matches' do account = Fabricate(:account, domain: 'example.com') - expect(Account.by_domain_and_subdomains('example.com')).to eq [account] + expect(described_class.by_domain_and_subdomains('example.com')).to eq [account] end it 'returns subdomains' do account = Fabricate(:account, domain: 'foo.example.com') - expect(Account.by_domain_and_subdomains('example.com')).to eq [account] + expect(described_class.by_domain_and_subdomains('example.com')).to eq [account] end it 'does not return partially matching domains' do account = Fabricate(:account, domain: 'grexample.com') - expect(Account.by_domain_and_subdomains('example.com')).to_not eq [account] + expect(described_class.by_domain_and_subdomains('example.com')).to_not eq [account] end end @@ -877,7 +877,7 @@ RSpec.describe Account do it 'returns an array of accounts who have a domain' do account_1 = Fabricate(:account, domain: nil) account_2 = Fabricate(:account, domain: 'example.com') - expect(Account.remote).to contain_exactly(account_2) + expect(described_class.remote).to contain_exactly(account_2) end end @@ -885,7 +885,7 @@ RSpec.describe Account do it 'returns an array of accounts who do not have a domain' do account_1 = Fabricate(:account, domain: nil) account_2 = Fabricate(:account, domain: 'example.com') - expect(Account.where('id > 0').local).to contain_exactly(account_1) + expect(described_class.where('id > 0').local).to contain_exactly(account_1) end end @@ -896,14 +896,14 @@ RSpec.describe Account do matches[index] = Fabricate(:account, domain: matches[index]) end - expect(Account.where('id > 0').partitioned).to match_array(matches) + expect(described_class.where('id > 0').partitioned).to match_array(matches) end end describe 'recent' do it 'returns a relation of accounts sorted by recent creation' do matches = Array.new(2) { Fabricate(:account) } - expect(Account.where('id > 0').recent).to match_array(matches) + expect(described_class.where('id > 0').recent).to match_array(matches) end end @@ -911,7 +911,7 @@ RSpec.describe Account do it 'returns an array of accounts who are silenced' do account_1 = Fabricate(:account, silenced: true) account_2 = Fabricate(:account, silenced: false) - expect(Account.silenced).to contain_exactly(account_1) + expect(described_class.silenced).to contain_exactly(account_1) end end @@ -919,7 +919,7 @@ RSpec.describe Account do it 'returns an array of accounts who are suspended' do account_1 = Fabricate(:account, suspended: true) account_2 = Fabricate(:account, suspended: false) - expect(Account.suspended).to contain_exactly(account_1) + expect(described_class.suspended).to contain_exactly(account_1) end end @@ -941,18 +941,18 @@ RSpec.describe Account do end it 'returns every usable non-suspended account' do - expect(Account.searchable).to contain_exactly(silenced_local, silenced_remote, local_account, remote_account) + expect(described_class.searchable).to contain_exactly(silenced_local, silenced_remote, local_account, remote_account) end it 'does not mess with previously-applied scopes' do - expect(Account.where.not(id: remote_account.id).searchable).to contain_exactly(silenced_local, silenced_remote, local_account) + expect(described_class.where.not(id: remote_account.id).searchable).to contain_exactly(silenced_local, silenced_remote, local_account) end end end context 'when is local' do it 'generates keys' do - account = Account.create!(domain: nil, username: Faker::Internet.user_name(separators: ['_'])) + account = described_class.create!(domain: nil, username: Faker::Internet.user_name(separators: ['_'])) expect(account.keypair).to be_private expect(account.keypair).to be_public end @@ -961,12 +961,12 @@ RSpec.describe Account do context 'when is remote' do it 'does not generate keys' do key = OpenSSL::PKey::RSA.new(1024).public_key - account = Account.create!(domain: 'remote', username: Faker::Internet.user_name(separators: ['_']), public_key: key.to_pem) + account = described_class.create!(domain: 'remote', username: Faker::Internet.user_name(separators: ['_']), public_key: key.to_pem) expect(account.keypair.params).to eq key.params end it 'normalizes domain' do - account = Account.create!(domain: 'にゃん', username: Faker::Internet.user_name(separators: ['_'])) + account = described_class.create!(domain: 'にゃん', username: Faker::Internet.user_name(separators: ['_'])) expect(account.domain).to eq 'xn--r9j5b5b' end end @@ -986,7 +986,7 @@ RSpec.describe Account do threads = Array.new(increment_by) do Thread.new do true while wait_for_start - Account.find(subject.id).increment_count!(:followers_count) + described_class.find(subject.id).increment_count!(:followers_count) end end diff --git a/spec/models/block_spec.rb b/spec/models/block_spec.rb index de3410fd5..8249503c5 100644 --- a/spec/models/block_spec.rb +++ b/spec/models/block_spec.rb @@ -23,7 +23,7 @@ RSpec.describe Block do Rails.cache.write("exclude_account_ids_for:#{account.id}", []) Rails.cache.write("exclude_account_ids_for:#{target_account.id}", []) - Block.create!(account: account, target_account: target_account) + described_class.create!(account: account, target_account: target_account) expect(Rails.cache.exist?("exclude_account_ids_for:#{account.id}")).to be false expect(Rails.cache.exist?("exclude_account_ids_for:#{target_account.id}")).to be false @@ -32,7 +32,7 @@ RSpec.describe Block do it 'removes blocking cache after destruction' do account = Fabricate(:account) target_account = Fabricate(:account) - block = Block.create!(account: account, target_account: target_account) + block = described_class.create!(account: account, target_account: target_account) Rails.cache.write("exclude_account_ids_for:#{account.id}", [target_account.id]) Rails.cache.write("exclude_account_ids_for:#{target_account.id}", [account.id]) diff --git a/spec/models/domain_block_spec.rb b/spec/models/domain_block_spec.rb index e123c03d6..67f53fa78 100644 --- a/spec/models/domain_block_spec.rb +++ b/spec/models/domain_block_spec.rb @@ -21,73 +21,73 @@ RSpec.describe DomainBlock do describe '.blocked?' do it 'returns true if the domain is suspended' do Fabricate(:domain_block, domain: 'example.com', severity: :suspend) - expect(DomainBlock.blocked?('example.com')).to be true + expect(described_class.blocked?('example.com')).to be true end it 'returns false even if the domain is silenced' do Fabricate(:domain_block, domain: 'example.com', severity: :silence) - expect(DomainBlock.blocked?('example.com')).to be false + expect(described_class.blocked?('example.com')).to be false end it 'returns false if the domain is not suspended nor silenced' do - expect(DomainBlock.blocked?('example.com')).to be false + expect(described_class.blocked?('example.com')).to be false end end describe '.rule_for' do it 'returns rule matching a blocked domain' do block = Fabricate(:domain_block, domain: 'example.com') - expect(DomainBlock.rule_for('example.com')).to eq block + expect(described_class.rule_for('example.com')).to eq block end it 'returns a rule matching a subdomain of a blocked domain' do block = Fabricate(:domain_block, domain: 'example.com') - expect(DomainBlock.rule_for('sub.example.com')).to eq block + expect(described_class.rule_for('sub.example.com')).to eq block end it 'returns a rule matching a blocked subdomain' do block = Fabricate(:domain_block, domain: 'sub.example.com') - expect(DomainBlock.rule_for('sub.example.com')).to eq block + expect(described_class.rule_for('sub.example.com')).to eq block end it 'returns a rule matching a blocked TLD' do block = Fabricate(:domain_block, domain: 'google') - expect(DomainBlock.rule_for('google')).to eq block + expect(described_class.rule_for('google')).to eq block end it 'returns a rule matching a subdomain of a blocked TLD' do block = Fabricate(:domain_block, domain: 'google') - expect(DomainBlock.rule_for('maps.google')).to eq block + expect(described_class.rule_for('maps.google')).to eq block end end describe '#stricter_than?' do it 'returns true if the new block has suspend severity while the old has lower severity' do - suspend = DomainBlock.new(domain: 'domain', severity: :suspend) - silence = DomainBlock.new(domain: 'domain', severity: :silence) - noop = DomainBlock.new(domain: 'domain', severity: :noop) + suspend = described_class.new(domain: 'domain', severity: :suspend) + silence = described_class.new(domain: 'domain', severity: :silence) + noop = described_class.new(domain: 'domain', severity: :noop) expect(suspend.stricter_than?(silence)).to be true expect(suspend.stricter_than?(noop)).to be true end it 'returns false if the new block has lower severity than the old one' do - suspend = DomainBlock.new(domain: 'domain', severity: :suspend) - silence = DomainBlock.new(domain: 'domain', severity: :silence) - noop = DomainBlock.new(domain: 'domain', severity: :noop) + suspend = described_class.new(domain: 'domain', severity: :suspend) + silence = described_class.new(domain: 'domain', severity: :silence) + noop = described_class.new(domain: 'domain', severity: :noop) expect(silence.stricter_than?(suspend)).to be false expect(noop.stricter_than?(suspend)).to be false expect(noop.stricter_than?(silence)).to be false end it 'returns false if the new block does is less strict regarding reports' do - older = DomainBlock.new(domain: 'domain', severity: :silence, reject_reports: true) - newer = DomainBlock.new(domain: 'domain', severity: :silence, reject_reports: false) + older = described_class.new(domain: 'domain', severity: :silence, reject_reports: true) + newer = described_class.new(domain: 'domain', severity: :silence, reject_reports: false) expect(newer.stricter_than?(older)).to be false end it 'returns false if the new block does is less strict regarding media' do - older = DomainBlock.new(domain: 'domain', severity: :silence, reject_media: true) - newer = DomainBlock.new(domain: 'domain', severity: :silence, reject_media: false) + older = described_class.new(domain: 'domain', severity: :silence, reject_media: true) + newer = described_class.new(domain: 'domain', severity: :silence, reject_media: false) expect(newer.stricter_than?(older)).to be false end end diff --git a/spec/models/email_domain_block_spec.rb b/spec/models/email_domain_block_spec.rb index a7232eb6b..9d9c74887 100644 --- a/spec/models/email_domain_block_spec.rb +++ b/spec/models/email_domain_block_spec.rb @@ -14,12 +14,12 @@ RSpec.describe EmailDomainBlock do it 'returns true if the domain is blocked' do Fabricate(:email_domain_block, domain: 'example.com') - expect(EmailDomainBlock.block?(input)).to be true + expect(described_class.block?(input)).to be true end it 'returns false if the domain is not blocked' do Fabricate(:email_domain_block, domain: 'other-example.com') - expect(EmailDomainBlock.block?(input)).to be false + expect(described_class.block?(input)).to be false end end @@ -38,7 +38,7 @@ RSpec.describe EmailDomainBlock do it 'returns true if the domain is blocked' do Fabricate(:email_domain_block, domain: 'mail.foo.com') - expect(EmailDomainBlock.block?(input)).to be true + expect(described_class.block?(input)).to be true end end end diff --git a/spec/models/export_spec.rb b/spec/models/export_spec.rb index a863678a3..75468898d 100644 --- a/spec/models/export_spec.rb +++ b/spec/models/export_spec.rb @@ -12,7 +12,7 @@ describe Export do it 'returns a csv of the blocked accounts' do target_accounts.each { |target_account| account.block!(target_account) } - export = Export.new(account).to_blocked_accounts_csv + export = described_class.new(account).to_blocked_accounts_csv results = export.strip.split expect(results.size).to eq 2 @@ -22,7 +22,7 @@ describe Export do it 'returns a csv of the muted accounts' do target_accounts.each { |target_account| account.mute!(target_account) } - export = Export.new(account).to_muted_accounts_csv + export = described_class.new(account).to_muted_accounts_csv results = export.strip.split("\n") expect(results.size).to eq 3 @@ -33,7 +33,7 @@ describe Export do it 'returns a csv of the following accounts' do target_accounts.each { |target_account| account.follow!(target_account) } - export = Export.new(account).to_following_accounts_csv + export = described_class.new(account).to_following_accounts_csv results = export.strip.split("\n") expect(results.size).to eq 3 @@ -45,24 +45,24 @@ describe Export do describe 'total_storage' do it 'returns the total size of the media attachments' do media_attachment = Fabricate(:media_attachment, account: account) - expect(Export.new(account).total_storage).to eq media_attachment.file_file_size || 0 + expect(described_class.new(account).total_storage).to eq media_attachment.file_file_size || 0 end end describe 'total_follows' do it 'returns the total number of the followed accounts' do target_accounts.each { |target_account| account.follow!(target_account) } - expect(Export.new(account.reload).total_follows).to eq 2 + expect(described_class.new(account.reload).total_follows).to eq 2 end it 'returns the total number of the blocked accounts' do target_accounts.each { |target_account| account.block!(target_account) } - expect(Export.new(account.reload).total_blocks).to eq 2 + expect(described_class.new(account.reload).total_blocks).to eq 2 end it 'returns the total number of the muted accounts' do target_accounts.each { |target_account| account.mute!(target_account) } - expect(Export.new(account.reload).total_mutes).to eq 2 + expect(described_class.new(account.reload).total_mutes).to eq 2 end end end diff --git a/spec/models/favourite_spec.rb b/spec/models/favourite_spec.rb index 9e69570a0..ef7fbdefc 100644 --- a/spec/models/favourite_spec.rb +++ b/spec/models/favourite_spec.rb @@ -10,12 +10,12 @@ RSpec.describe Favourite do let(:status) { Fabricate(:status, reblog: reblog) } it 'invalidates if the reblogged status is already a favourite' do - Favourite.create!(account: account, status: reblog) - expect(Favourite.new(account: account, status: status).valid?).to be false + described_class.create!(account: account, status: reblog) + expect(described_class.new(account: account, status: status).valid?).to be false end it 'replaces status with the reblogged one if it is a reblog' do - favourite = Favourite.create!(account: account, status: status) + favourite = described_class.create!(account: account, status: status) expect(favourite.status).to eq reblog end end @@ -24,7 +24,7 @@ RSpec.describe Favourite do let(:status) { Fabricate(:status, reblog: nil) } it 'saves with the specified status' do - favourite = Favourite.create!(account: account, status: status) + favourite = described_class.create!(account: account, status: status) expect(favourite.status).to eq status end end diff --git a/spec/models/follow_spec.rb b/spec/models/follow_spec.rb index 79c0048f9..c7743183c 100644 --- a/spec/models/follow_spec.rb +++ b/spec/models/follow_spec.rb @@ -7,7 +7,7 @@ RSpec.describe Follow do let(:bob) { Fabricate(:account, username: 'bob') } describe 'validations' do - subject { Follow.new(account: alice, target_account: bob, rate_limit: true) } + subject { described_class.new(account: alice, target_account: bob, rate_limit: true) } it 'is invalid without an account' do follow = Fabricate.build(:follow, account: nil) @@ -38,10 +38,10 @@ RSpec.describe Follow do describe 'recent' do it 'sorts so that more recent follows comes earlier' do - follow0 = Follow.create!(account: alice, target_account: bob) - follow1 = Follow.create!(account: bob, target_account: alice) + follow0 = described_class.create!(account: alice, target_account: bob) + follow1 = described_class.create!(account: bob, target_account: alice) - a = Follow.recent.to_a + a = described_class.recent.to_a expect(a.size).to eq 2 expect(a[0]).to eq follow1 diff --git a/spec/models/identity_spec.rb b/spec/models/identity_spec.rb index 59155781c..2fca1e1c1 100644 --- a/spec/models/identity_spec.rb +++ b/spec/models/identity_spec.rb @@ -12,7 +12,7 @@ RSpec.describe Identity do end it 'returns an instance of Identity' do - expect(described_class.find_for_oauth(auth)).to be_instance_of Identity + expect(described_class.find_for_oauth(auth)).to be_instance_of described_class end end end diff --git a/spec/models/import_spec.rb b/spec/models/import_spec.rb index 1dae40a73..3605f0b9b 100644 --- a/spec/models/import_spec.rb +++ b/spec/models/import_spec.rb @@ -9,17 +9,17 @@ RSpec.describe Import do describe 'validations' do it 'has a valid parameters' do - import = Import.create(account: account, type: type, data: data) + import = described_class.create(account: account, type: type, data: data) expect(import).to be_valid end it 'is invalid without an type' do - import = Import.create(account: account, data: data) + import = described_class.create(account: account, data: data) expect(import).to model_have_error_on_field(:type) end it 'is invalid without a data' do - import = Import.create(account: account, type: type) + import = described_class.create(account: account, type: type) expect(import).to model_have_error_on_field(:data) end end diff --git a/spec/models/media_attachment_spec.rb b/spec/models/media_attachment_spec.rb index becc74824..4d4bc748f 100644 --- a/spec/models/media_attachment_spec.rb +++ b/spec/models/media_attachment_spec.rb @@ -85,7 +85,7 @@ RSpec.describe MediaAttachment do end describe 'animated gif conversion' do - let(:media) { MediaAttachment.create(account: Fabricate(:account), file: attachment_fixture('avatar.gif')) } + let(:media) { described_class.create(account: Fabricate(:account), file: attachment_fixture('avatar.gif')) } it 'sets type to gifv' do expect(media.type).to eq 'gifv' @@ -109,7 +109,7 @@ RSpec.describe MediaAttachment do fixtures.each do |fixture| context fixture[:filename] do - let(:media) { MediaAttachment.create(account: Fabricate(:account), file: attachment_fixture(fixture[:filename])) } + let(:media) { described_class.create(account: Fabricate(:account), file: attachment_fixture(fixture[:filename])) } it 'sets type to image' do expect(media.type).to eq 'image' @@ -129,7 +129,7 @@ RSpec.describe MediaAttachment do end describe 'ogg with cover art' do - let(:media) { MediaAttachment.create(account: Fabricate(:account), file: attachment_fixture('boop.ogg')) } + let(:media) { described_class.create(account: Fabricate(:account), file: attachment_fixture('boop.ogg')) } it 'detects it as an audio file' do expect(media.type).to eq 'audio' @@ -153,7 +153,7 @@ RSpec.describe MediaAttachment do end describe 'jpeg' do - let(:media) { MediaAttachment.create(account: Fabricate(:account), file: attachment_fixture('attachment.jpg')) } + let(:media) { described_class.create(account: Fabricate(:account), file: attachment_fixture('attachment.jpg')) } it 'sets meta for different style' do expect(media.file.meta['original']['width']).to eq 600 @@ -171,7 +171,7 @@ RSpec.describe MediaAttachment do describe 'base64-encoded jpeg' do let(:base64_attachment) { "data:image/jpeg;base64,#{Base64.encode64(attachment_fixture('attachment.jpg').read)}" } - let(:media) { MediaAttachment.create(account: Fabricate(:account), file: base64_attachment) } + let(:media) { described_class.create(account: Fabricate(:account), file: base64_attachment) } it 'saves media attachment' do expect(media.persisted?).to be true @@ -184,7 +184,7 @@ RSpec.describe MediaAttachment do end it 'is invalid without file' do - media = MediaAttachment.new(account: Fabricate(:account)) + media = described_class.new(account: Fabricate(:account)) expect(media.valid?).to be false end @@ -192,26 +192,26 @@ RSpec.describe MediaAttachment do it 'rejects video files that are too large' do stub_const 'MediaAttachment::IMAGE_LIMIT', 100.megabytes stub_const 'MediaAttachment::VIDEO_LIMIT', 1.kilobyte - expect { MediaAttachment.create!(account: Fabricate(:account), file: attachment_fixture('attachment.webm')) }.to raise_error(ActiveRecord::RecordInvalid) + expect { described_class.create!(account: Fabricate(:account), file: attachment_fixture('attachment.webm')) }.to raise_error(ActiveRecord::RecordInvalid) end it 'accepts video files that are small enough' do stub_const 'MediaAttachment::IMAGE_LIMIT', 1.kilobyte stub_const 'MediaAttachment::VIDEO_LIMIT', 100.megabytes - media = MediaAttachment.create!(account: Fabricate(:account), file: attachment_fixture('attachment.webm')) + media = described_class.create!(account: Fabricate(:account), file: attachment_fixture('attachment.webm')) expect(media.valid?).to be true end it 'rejects image files that are too large' do stub_const 'MediaAttachment::IMAGE_LIMIT', 1.kilobyte stub_const 'MediaAttachment::VIDEO_LIMIT', 100.megabytes - expect { MediaAttachment.create!(account: Fabricate(:account), file: attachment_fixture('attachment.jpg')) }.to raise_error(ActiveRecord::RecordInvalid) + expect { described_class.create!(account: Fabricate(:account), file: attachment_fixture('attachment.jpg')) }.to raise_error(ActiveRecord::RecordInvalid) end it 'accepts image files that are small enough' do stub_const 'MediaAttachment::IMAGE_LIMIT', 100.megabytes stub_const 'MediaAttachment::VIDEO_LIMIT', 1.kilobyte - media = MediaAttachment.create!(account: Fabricate(:account), file: attachment_fixture('attachment.jpg')) + media = described_class.create!(account: Fabricate(:account), file: attachment_fixture('attachment.jpg')) expect(media.valid?).to be true end end diff --git a/spec/models/notification_spec.rb b/spec/models/notification_spec.rb index 795491546..0dd9264e0 100644 --- a/spec/models/notification_spec.rb +++ b/spec/models/notification_spec.rb @@ -38,22 +38,22 @@ RSpec.describe Notification do describe '#type' do it 'returns :reblog for a Status' do - notification = Notification.new(activity: Status.new) + notification = described_class.new(activity: Status.new) expect(notification.type).to eq :reblog end it 'returns :mention for a Mention' do - notification = Notification.new(activity: Mention.new) + notification = described_class.new(activity: Mention.new) expect(notification.type).to eq :mention end it 'returns :favourite for a Favourite' do - notification = Notification.new(activity: Favourite.new) + notification = described_class.new(activity: Favourite.new) expect(notification.type).to eq :favourite end it 'returns :follow for a Follow' do - notification = Notification.new(activity: Follow.new) + notification = described_class.new(activity: Follow.new) expect(notification.type).to eq :follow end end diff --git a/spec/models/relationship_filter_spec.rb b/spec/models/relationship_filter_spec.rb index 7c0f37a06..b3e855c12 100644 --- a/spec/models/relationship_filter_spec.rb +++ b/spec/models/relationship_filter_spec.rb @@ -8,7 +8,7 @@ describe RelationshipFilter do describe '#results' do context 'when default params are used' do let(:subject) do - RelationshipFilter.new(account, 'order' => 'active').results + described_class.new(account, 'order' => 'active').results end before do diff --git a/spec/models/report_filter_spec.rb b/spec/models/report_filter_spec.rb index 8269c4579..4b0852f08 100644 --- a/spec/models/report_filter_spec.rb +++ b/spec/models/report_filter_spec.rb @@ -5,7 +5,7 @@ require 'rails_helper' describe ReportFilter do describe 'with empty params' do it 'defaults to unresolved reports list' do - filter = ReportFilter.new({}) + filter = described_class.new({}) expect(filter.results).to eq Report.unresolved end @@ -13,7 +13,7 @@ describe ReportFilter do describe 'with invalid params' do it 'raises with key error' do - filter = ReportFilter.new(wrong: true) + filter = described_class.new(wrong: true) expect { filter.results }.to raise_error(/wrong/) end @@ -21,7 +21,7 @@ describe ReportFilter do describe 'with valid params' do it 'combines filters on Report' do - filter = ReportFilter.new(account_id: '123', resolved: true, target_account_id: '456') + filter = described_class.new(account_id: '123', resolved: true, target_account_id: '456') allow(Report).to receive(:where).and_return(Report.none) allow(Report).to receive(:resolved).and_return(Report.none) diff --git a/spec/models/session_activation_spec.rb b/spec/models/session_activation_spec.rb index 51c6aa5cb..052a06e5c 100644 --- a/spec/models/session_activation_spec.rb +++ b/spec/models/session_activation_spec.rb @@ -80,7 +80,7 @@ RSpec.describe SessionActivation do end it 'returns an instance of SessionActivation' do - expect(described_class.activate(**options)).to be_a SessionActivation + expect(described_class.activate(**options)).to be_a described_class end end diff --git a/spec/models/setting_spec.rb b/spec/models/setting_spec.rb index accce10f8..bba585cec 100644 --- a/spec/models/setting_spec.rb +++ b/spec/models/setting_spec.rb @@ -146,7 +146,7 @@ RSpec.describe Setting do it 'includes Setting with value of default_value' do setting = described_class.all_as_records[key] - expect(setting).to be_a Setting + expect(setting).to be_a described_class expect(setting).to have_attributes(var: key) expect(setting).to have_attributes(value: 'default_value') end diff --git a/spec/models/site_upload_spec.rb b/spec/models/site_upload_spec.rb index d4a929311..9689bce9e 100644 --- a/spec/models/site_upload_spec.rb +++ b/spec/models/site_upload_spec.rb @@ -4,7 +4,7 @@ require 'rails_helper' RSpec.describe SiteUpload do describe '#cache_key' do - let(:site_upload) { SiteUpload.new(var: 'var') } + let(:site_upload) { described_class.new(var: 'var') } it 'returns cache_key' do expect(site_upload.cache_key).to eq 'site_uploads/var' diff --git a/spec/models/status_pin_spec.rb b/spec/models/status_pin_spec.rb index 52ce0847c..660b2e92a 100644 --- a/spec/models/status_pin_spec.rb +++ b/spec/models/status_pin_spec.rb @@ -8,14 +8,14 @@ RSpec.describe StatusPin do account = Fabricate(:account) status = Fabricate(:status, account: account) - expect(StatusPin.new(account: account, status: status).save).to be true + expect(described_class.new(account: account, status: status).save).to be true end it 'does not allow pins of statuses by someone else' do account = Fabricate(:account) status = Fabricate(:status) - expect(StatusPin.new(account: account, status: status).save).to be false + expect(described_class.new(account: account, status: status).save).to be false end it 'does not allow pins of reblogs' do @@ -23,21 +23,21 @@ RSpec.describe StatusPin do status = Fabricate(:status, account: account) reblog = Fabricate(:status, reblog: status) - expect(StatusPin.new(account: account, status: reblog).save).to be false + expect(described_class.new(account: account, status: reblog).save).to be false end it 'does allow pins of direct statuses' do account = Fabricate(:account) status = Fabricate(:status, account: account, visibility: :private) - expect(StatusPin.new(account: account, status: status).save).to be true + expect(described_class.new(account: account, status: status).save).to be true end it 'does not allow pins of direct statuses' do account = Fabricate(:account) status = Fabricate(:status, account: account, visibility: :direct) - expect(StatusPin.new(account: account, status: status).save).to be false + expect(described_class.new(account: account, status: status).save).to be false end max_pins = 5 @@ -50,10 +50,10 @@ RSpec.describe StatusPin do end max_pins.times do |i| - expect(StatusPin.new(account: account, status: status[i]).save).to be true + expect(described_class.new(account: account, status: status[i]).save).to be true end - expect(StatusPin.new(account: account, status: status[max_pins]).save).to be false + expect(described_class.new(account: account, status: status[max_pins]).save).to be false end it 'allows pins above the max for remote accounts' do @@ -65,10 +65,10 @@ RSpec.describe StatusPin do end max_pins.times do |i| - expect(StatusPin.new(account: account, status: status[i]).save).to be true + expect(described_class.new(account: account, status: status[i]).save).to be true end - expect(StatusPin.new(account: account, status: status[max_pins]).save).to be true + expect(described_class.new(account: account, status: status[max_pins]).save).to be true end end end diff --git a/spec/models/status_spec.rb b/spec/models/status_spec.rb index 84ff82c78..3141c52c0 100644 --- a/spec/models/status_spec.rb +++ b/spec/models/status_spec.rb @@ -160,7 +160,7 @@ RSpec.describe Status do reblog = Fabricate(:status, account: bob, reblog: subject) expect(subject.reblogs_count).to eq 1 expect { subject.destroy }.to_not raise_error - expect(Status.find_by(id: reblog.id)).to be_nil + expect(described_class.find_by(id: reblog.id)).to be_nil end end @@ -206,7 +206,7 @@ RSpec.describe Status do end describe '.mutes_map' do - subject { Status.mutes_map([status.conversation.id], account) } + subject { described_class.mutes_map([status.conversation.id], account) } let(:status) { Fabricate(:status) } let(:account) { Fabricate(:account) } @@ -222,7 +222,7 @@ RSpec.describe Status do end describe '.favourites_map' do - subject { Status.favourites_map([status], account) } + subject { described_class.favourites_map([status], account) } let(:status) { Fabricate(:status) } let(:account) { Fabricate(:account) } @@ -238,7 +238,7 @@ RSpec.describe Status do end describe '.reblogs_map' do - subject { Status.reblogs_map([status], account) } + subject { described_class.reblogs_map([status], account) } let(:status) { Fabricate(:status) } let(:account) { Fabricate(:account) } @@ -265,17 +265,17 @@ RSpec.describe Status do context 'when given one tag' do it 'returns the expected statuses' do - expect(Status.tagged_with([tag1.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status1.id, status5.id) - expect(Status.tagged_with([tag2.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status2.id, status5.id) - expect(Status.tagged_with([tag3.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status3.id, status5.id) + expect(described_class.tagged_with([tag1.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status1.id, status5.id) + expect(described_class.tagged_with([tag2.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status2.id, status5.id) + expect(described_class.tagged_with([tag3.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status3.id, status5.id) end end context 'when given multiple tags' do it 'returns the expected statuses' do - expect(Status.tagged_with([tag1.id, tag2.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status1.id, status2.id, status5.id) - expect(Status.tagged_with([tag1.id, tag3.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status1.id, status3.id, status5.id) - expect(Status.tagged_with([tag2.id, tag3.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status2.id, status3.id, status5.id) + expect(described_class.tagged_with([tag1.id, tag2.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status1.id, status2.id, status5.id) + expect(described_class.tagged_with([tag1.id, tag3.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status1.id, status3.id, status5.id) + expect(described_class.tagged_with([tag2.id, tag3.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status2.id, status3.id, status5.id) end end end @@ -292,17 +292,17 @@ RSpec.describe Status do context 'when given one tag' do it 'returns the expected statuses' do - expect(Status.tagged_with_all([tag1.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status1.id, status5.id) - expect(Status.tagged_with_all([tag2.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status2.id, status5.id) - expect(Status.tagged_with_all([tag3.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status3.id) + expect(described_class.tagged_with_all([tag1.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status1.id, status5.id) + expect(described_class.tagged_with_all([tag2.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status2.id, status5.id) + expect(described_class.tagged_with_all([tag3.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status3.id) end end context 'when given multiple tags' do it 'returns the expected statuses' do - expect(Status.tagged_with_all([tag1.id, tag2.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status5.id) - expect(Status.tagged_with_all([tag1.id, tag3.id]).reorder(:id).pluck(:id).uniq).to eq [] - expect(Status.tagged_with_all([tag2.id, tag3.id]).reorder(:id).pluck(:id).uniq).to eq [] + expect(described_class.tagged_with_all([tag1.id, tag2.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status5.id) + expect(described_class.tagged_with_all([tag1.id, tag3.id]).reorder(:id).pluck(:id).uniq).to eq [] + expect(described_class.tagged_with_all([tag2.id, tag3.id]).reorder(:id).pluck(:id).uniq).to eq [] end end end @@ -319,17 +319,17 @@ RSpec.describe Status do context 'when given one tag' do it 'returns the expected statuses' do - expect(Status.tagged_with_none([tag1.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status2.id, status3.id, status4.id) - expect(Status.tagged_with_none([tag2.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status1.id, status3.id, status4.id) - expect(Status.tagged_with_none([tag3.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status1.id, status2.id, status4.id) + expect(described_class.tagged_with_none([tag1.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status2.id, status3.id, status4.id) + expect(described_class.tagged_with_none([tag2.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status1.id, status3.id, status4.id) + expect(described_class.tagged_with_none([tag3.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status1.id, status2.id, status4.id) end end context 'when given multiple tags' do it 'returns the expected statuses' do - expect(Status.tagged_with_none([tag1.id, tag2.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status3.id, status4.id) - expect(Status.tagged_with_none([tag1.id, tag3.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status2.id, status4.id) - expect(Status.tagged_with_none([tag2.id, tag3.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status1.id, status4.id) + expect(described_class.tagged_with_none([tag1.id, tag2.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status3.id, status4.id) + expect(described_class.tagged_with_none([tag1.id, tag3.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status2.id, status4.id) + expect(described_class.tagged_with_none([tag2.id, tag3.id]).reorder(:id).pluck(:id).uniq).to contain_exactly(status1.id, status4.id) end end end @@ -344,21 +344,21 @@ RSpec.describe Status do end it 'creates new conversation for stand-alone status' do - expect(Status.create(account: alice, text: 'First').conversation_id).to_not be_nil + expect(described_class.create(account: alice, text: 'First').conversation_id).to_not be_nil end it 'keeps conversation of parent node' do parent = Fabricate(:status, text: 'First') - expect(Status.create(account: alice, thread: parent, text: 'Response').conversation_id).to eq parent.conversation_id + expect(described_class.create(account: alice, thread: parent, text: 'Response').conversation_id).to eq parent.conversation_id end it 'sets `local` to true for status by local account' do - expect(Status.create(account: alice, text: 'foo').local).to be true + expect(described_class.create(account: alice, text: 'foo').local).to be true end it 'sets `local` to false for status by remote account' do alice.update(domain: 'example.com') - expect(Status.create(account: alice, text: 'foo').local).to be false + expect(described_class.create(account: alice, text: 'foo').local).to be false end end @@ -372,7 +372,7 @@ RSpec.describe Status do describe 'after_create' do it 'saves ActivityPub uri as uri for local status' do - status = Status.create(account: alice, text: 'foo') + status = described_class.create(account: alice, text: 'foo') status.reload expect(status.uri).to start_with('https://') end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index d3e0ac63a..554e7efb6 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -57,7 +57,7 @@ RSpec.describe User do it 'returns an array of recent users ordered by id' do user_1 = Fabricate(:user) user_2 = Fabricate(:user) - expect(User.recent).to eq [user_2, user_1] + expect(described_class.recent).to eq [user_2, user_1] end end @@ -65,7 +65,7 @@ RSpec.describe User do it 'returns an array of users who are confirmed' do user_1 = Fabricate(:user, confirmed_at: nil) user_2 = Fabricate(:user, confirmed_at: Time.zone.now) - expect(User.confirmed).to contain_exactly(user_2) + expect(described_class.confirmed).to contain_exactly(user_2) end end @@ -74,7 +74,7 @@ RSpec.describe User do specified = Fabricate(:user, current_sign_in_at: 15.days.ago) Fabricate(:user, current_sign_in_at: 6.days.ago) - expect(User.inactive).to contain_exactly(specified) + expect(described_class.inactive).to contain_exactly(specified) end end @@ -83,7 +83,7 @@ RSpec.describe User do specified = Fabricate(:user, email: 'specified@spec') Fabricate(:user, email: 'unspecified@spec') - expect(User.matches_email('specified')).to contain_exactly(specified) + expect(described_class.matches_email('specified')).to contain_exactly(specified) end end @@ -96,7 +96,7 @@ RSpec.describe User do Fabricate(:session_activation, user: user2, ip: '2160:8888::24', session_id: '3') Fabricate(:session_activation, user: user2, ip: '2160:8888::25', session_id: '4') - expect(User.matches_ip('2160:2160::/32')).to contain_exactly(user1) + expect(described_class.matches_ip('2160:2160::/32')).to contain_exactly(user1) end end end @@ -113,19 +113,19 @@ RSpec.describe User do end it 'allows a non-blacklisted user to be created' do - user = User.new(email: 'foo@example.com', account: account, password: password, agreement: true) + user = described_class.new(email: 'foo@example.com', account: account, password: password, agreement: true) expect(user).to be_valid end it 'does not allow a blacklisted user to be created' do - user = User.new(email: 'foo@mvrht.com', account: account, password: password, agreement: true) + user = described_class.new(email: 'foo@mvrht.com', account: account, password: password, agreement: true) expect(user).to_not be_valid end it 'does not allow a subdomain blacklisted user to be created' do - user = User.new(email: 'foo@mvrht.com.topdomain.tld', account: account, password: password, agreement: true) + user = described_class.new(email: 'foo@mvrht.com.topdomain.tld', account: account, password: password, agreement: true) expect(user).to_not be_valid end @@ -349,17 +349,17 @@ RSpec.describe User do end it 'does not allow a user to be created unless they are whitelisted' do - user = User.new(email: 'foo@example.com', account: account, password: password, agreement: true) + user = described_class.new(email: 'foo@example.com', account: account, password: password, agreement: true) expect(user).to_not be_valid end it 'allows a user to be created if they are whitelisted' do - user = User.new(email: 'foo@mastodon.space', account: account, password: password, agreement: true) + user = described_class.new(email: 'foo@mastodon.space', account: account, password: password, agreement: true) expect(user).to be_valid end it 'does not allow a user with a whitelisted top domain as subdomain in their email address to be created' do - user = User.new(email: 'foo@mastodon.space.userdomain.com', account: account, password: password, agreement: true) + user = described_class.new(email: 'foo@mastodon.space.userdomain.com', account: account, password: password, agreement: true) expect(user).to_not be_valid end @@ -373,7 +373,7 @@ RSpec.describe User do it 'does not allow a user to be created with a specific blacklisted subdomain even if the top domain is whitelisted' do Rails.configuration.x.email_domains_blacklist = 'blacklisted.mastodon.space' - user = User.new(email: 'foo@blacklisted.mastodon.space', account: account, password: password) + user = described_class.new(email: 'foo@blacklisted.mastodon.space', account: account, password: password) expect(user).to_not be_valid end end @@ -527,19 +527,19 @@ RSpec.describe User do end describe '.those_who_can' do - let!(:moderator_user) { Fabricate(:user, role: UserRole.find_by(name: 'Moderator')) } + before { Fabricate(:user, role: UserRole.find_by(name: 'Moderator')) } context 'when there are not any user roles' do before { UserRole.destroy_all } it 'returns an empty list' do - expect(User.those_who_can(:manage_blocks)).to eq([]) + expect(described_class.those_who_can(:manage_blocks)).to eq([]) end end context 'when there are not users with the needed role' do it 'returns an empty list' do - expect(User.those_who_can(:manage_blocks)).to eq([]) + expect(described_class.those_who_can(:manage_blocks)).to eq([]) end end @@ -547,7 +547,7 @@ RSpec.describe User do let!(:admin_user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) } it 'returns the users with the role' do - expect(User.those_who_can(:manage_blocks)).to eq([admin_user]) + expect(described_class.those_who_can(:manage_blocks)).to eq([admin_user]) end end end diff --git a/spec/policies/account_moderation_note_policy_spec.rb b/spec/policies/account_moderation_note_policy_spec.rb index 03d18250b..90abdfea7 100644 --- a/spec/policies/account_moderation_note_policy_spec.rb +++ b/spec/policies/account_moderation_note_policy_spec.rb @@ -11,13 +11,13 @@ RSpec.describe AccountModerationNotePolicy do permissions :create? do context 'when staff' do it 'grants to create' do - expect(subject).to permit(admin, AccountModerationNotePolicy) + expect(subject).to permit(admin, described_class) end end context 'when not staff' do it 'denies to create' do - expect(subject).to_not permit(john, AccountModerationNotePolicy) + expect(subject).to_not permit(john, described_class) end end end diff --git a/spec/presenters/account_relationships_presenter_spec.rb b/spec/presenters/account_relationships_presenter_spec.rb index d59060bd5..5c2ba54e0 100644 --- a/spec/presenters/account_relationships_presenter_spec.rb +++ b/spec/presenters/account_relationships_presenter_spec.rb @@ -14,7 +14,7 @@ RSpec.describe AccountRelationshipsPresenter do allow(Account).to receive(:domain_blocking_map).with(account_ids, current_account_id).and_return(default_map) end - let(:presenter) { AccountRelationshipsPresenter.new(account_ids, current_account_id, **options) } + let(:presenter) { described_class.new(account_ids, current_account_id, **options) } let(:current_account_id) { Fabricate(:account).id } let(:account_ids) { [Fabricate(:account).id] } let(:default_map) { { 1 => true } } diff --git a/spec/presenters/status_relationships_presenter_spec.rb b/spec/presenters/status_relationships_presenter_spec.rb index a62fa004a..7746c8cd7 100644 --- a/spec/presenters/status_relationships_presenter_spec.rb +++ b/spec/presenters/status_relationships_presenter_spec.rb @@ -12,7 +12,7 @@ RSpec.describe StatusRelationshipsPresenter do allow(Status).to receive(:pins_map).with(anything, current_account_id).and_return(default_map) end - let(:presenter) { StatusRelationshipsPresenter.new(statuses, current_account_id, **options) } + let(:presenter) { described_class.new(statuses, current_account_id, **options) } let(:current_account_id) { Fabricate(:account).id } let(:statuses) { [Fabricate(:status)] } let(:status_ids) { statuses.map(&:id) + statuses.filter_map(&:reblog_of_id) } diff --git a/spec/serializers/activitypub/note_serializer_spec.rb b/spec/serializers/activitypub/note_serializer_spec.rb index 7ea47baef..68f537891 100644 --- a/spec/serializers/activitypub/note_serializer_spec.rb +++ b/spec/serializers/activitypub/note_serializer_spec.rb @@ -15,7 +15,7 @@ describe ActivityPub::NoteSerializer do let!(:reply5) { Fabricate(:status, account: account, thread: parent, visibility: :direct) } before(:each) do - @serialization = ActiveModelSerializers::SerializableResource.new(parent, serializer: ActivityPub::NoteSerializer, adapter: ActivityPub::Adapter) + @serialization = ActiveModelSerializers::SerializableResource.new(parent, serializer: described_class, adapter: ActivityPub::Adapter) end it 'has a Note type' do diff --git a/spec/serializers/activitypub/update_poll_serializer_spec.rb b/spec/serializers/activitypub/update_poll_serializer_spec.rb index 4360808b5..14c24c70c 100644 --- a/spec/serializers/activitypub/update_poll_serializer_spec.rb +++ b/spec/serializers/activitypub/update_poll_serializer_spec.rb @@ -10,7 +10,7 @@ describe ActivityPub::UpdatePollSerializer do let!(:status) { Fabricate(:status, account: account, poll: poll) } before(:each) do - @serialization = ActiveModelSerializers::SerializableResource.new(status, serializer: ActivityPub::UpdatePollSerializer, adapter: ActivityPub::Adapter) + @serialization = ActiveModelSerializers::SerializableResource.new(status, serializer: described_class, adapter: ActivityPub::Adapter) end it 'has a Update type' do diff --git a/spec/serializers/rest/account_serializer_spec.rb b/spec/serializers/rest/account_serializer_spec.rb index 528639943..e399e88f3 100644 --- a/spec/serializers/rest/account_serializer_spec.rb +++ b/spec/serializers/rest/account_serializer_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' describe REST::AccountSerializer do - subject { JSON.parse(ActiveModelSerializers::SerializableResource.new(account, serializer: REST::AccountSerializer).to_json) } + subject { JSON.parse(ActiveModelSerializers::SerializableResource.new(account, serializer: described_class).to_json) } let(:role) { Fabricate(:user_role, name: 'Role', highlighted: true) } let(:user) { Fabricate(:user, role: role) } diff --git a/spec/services/activitypub/fetch_remote_account_service_spec.rb b/spec/services/activitypub/fetch_remote_account_service_spec.rb index 868bc2a58..ac7484d96 100644 --- a/spec/services/activitypub/fetch_remote_account_service_spec.rb +++ b/spec/services/activitypub/fetch_remote_account_service_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe ActivityPub::FetchRemoteAccountService, type: :service do - subject { ActivityPub::FetchRemoteAccountService.new } + subject { described_class.new } let!(:actor) do { diff --git a/spec/services/activitypub/fetch_remote_actor_service_spec.rb b/spec/services/activitypub/fetch_remote_actor_service_spec.rb index a72c6941e..93d31b69d 100644 --- a/spec/services/activitypub/fetch_remote_actor_service_spec.rb +++ b/spec/services/activitypub/fetch_remote_actor_service_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe ActivityPub::FetchRemoteActorService, type: :service do - subject { ActivityPub::FetchRemoteActorService.new } + subject { described_class.new } let!(:actor) do { diff --git a/spec/services/activitypub/fetch_remote_key_service_spec.rb b/spec/services/activitypub/fetch_remote_key_service_spec.rb index 0ec0c2736..cd8f29ddd 100644 --- a/spec/services/activitypub/fetch_remote_key_service_spec.rb +++ b/spec/services/activitypub/fetch_remote_key_service_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe ActivityPub::FetchRemoteKeyService, type: :service do - subject { ActivityPub::FetchRemoteKeyService.new } + subject { described_class.new } let(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/alice' }] } } diff --git a/spec/services/after_block_domain_from_account_service_spec.rb b/spec/services/after_block_domain_from_account_service_spec.rb index b75f92372..9bfaa3580 100644 --- a/spec/services/after_block_domain_from_account_service_spec.rb +++ b/spec/services/after_block_domain_from_account_service_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe AfterBlockDomainFromAccountService, type: :service do - subject { AfterBlockDomainFromAccountService.new } + subject { described_class.new } let!(:wolf) { Fabricate(:account, username: 'wolf', domain: 'evil.org', inbox_url: 'https://evil.org/inbox', protocol: :activitypub) } let!(:alice) { Fabricate(:account, username: 'alice') } diff --git a/spec/services/authorize_follow_service_spec.rb b/spec/services/authorize_follow_service_spec.rb index 63d9e2a0f..d07645ab6 100644 --- a/spec/services/authorize_follow_service_spec.rb +++ b/spec/services/authorize_follow_service_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe AuthorizeFollowService, type: :service do - subject { AuthorizeFollowService.new } + subject { described_class.new } let(:sender) { Fabricate(:account, username: 'alice') } diff --git a/spec/services/batched_remove_status_service_spec.rb b/spec/services/batched_remove_status_service_spec.rb index 9bedf3744..c0cd01315 100644 --- a/spec/services/batched_remove_status_service_spec.rb +++ b/spec/services/batched_remove_status_service_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe BatchedRemoveStatusService, type: :service do - subject { BatchedRemoveStatusService.new } + subject { described_class.new } let!(:alice) { Fabricate(:account) } let!(:bob) { Fabricate(:account, username: 'bob', domain: 'example.com') } diff --git a/spec/services/block_domain_service_spec.rb b/spec/services/block_domain_service_spec.rb index 0ab97b8ce..93722a15b 100644 --- a/spec/services/block_domain_service_spec.rb +++ b/spec/services/block_domain_service_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe BlockDomainService, type: :service do - subject { BlockDomainService.new } + subject { described_class.new } let!(:bad_account) { Fabricate(:account, username: 'badguy666', domain: 'evil.org') } let!(:bad_status1) { Fabricate(:status, account: bad_account, text: 'You suck') } diff --git a/spec/services/block_service_spec.rb b/spec/services/block_service_spec.rb index 75f07f5ad..5f7c2e8da 100644 --- a/spec/services/block_service_spec.rb +++ b/spec/services/block_service_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe BlockService, type: :service do - subject { BlockService.new } + subject { described_class.new } let(:sender) { Fabricate(:account, username: 'alice') } diff --git a/spec/services/bootstrap_timeline_service_spec.rb b/spec/services/bootstrap_timeline_service_spec.rb index 670ac652f..5a15ba741 100644 --- a/spec/services/bootstrap_timeline_service_spec.rb +++ b/spec/services/bootstrap_timeline_service_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe BootstrapTimelineService, type: :service do - subject { BootstrapTimelineService.new } + subject { described_class.new } context 'when the new user has registered from an invite' do let(:service) { double } diff --git a/spec/services/clear_domain_media_service_spec.rb b/spec/services/clear_domain_media_service_spec.rb index 987507579..2a00409a4 100644 --- a/spec/services/clear_domain_media_service_spec.rb +++ b/spec/services/clear_domain_media_service_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe ClearDomainMediaService, type: :service do - subject { ClearDomainMediaService.new } + subject { described_class.new } let!(:bad_account) { Fabricate(:account, username: 'badguy666', domain: 'evil.org') } let!(:bad_status1) { Fabricate(:status, account: bad_account, text: 'You suck') } diff --git a/spec/services/favourite_service_spec.rb b/spec/services/favourite_service_spec.rb index 613ae203e..782c235c4 100644 --- a/spec/services/favourite_service_spec.rb +++ b/spec/services/favourite_service_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe FavouriteService, type: :service do - subject { FavouriteService.new } + subject { described_class.new } let(:sender) { Fabricate(:account, username: 'alice') } diff --git a/spec/services/follow_service_spec.rb b/spec/services/follow_service_spec.rb index c9521e3c8..c2ad0d717 100644 --- a/spec/services/follow_service_spec.rb +++ b/spec/services/follow_service_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe FollowService, type: :service do - subject { FollowService.new } + subject { described_class.new } let(:sender) { Fabricate(:account, username: 'alice') } diff --git a/spec/services/import_service_spec.rb b/spec/services/import_service_spec.rb index 7f8e5855f..32ba4409c 100644 --- a/spec/services/import_service_spec.rb +++ b/spec/services/import_service_spec.rb @@ -14,7 +14,7 @@ RSpec.describe ImportService, type: :service do end context 'when importing old-style list of muted users' do - subject { ImportService.new } + subject { described_class.new } let(:csv) { attachment_fixture('mute-imports.txt') } @@ -52,7 +52,7 @@ RSpec.describe ImportService, type: :service do end context 'when importing new-style list of muted users' do - subject { ImportService.new } + subject { described_class.new } let(:csv) { attachment_fixture('new-mute-imports.txt') } @@ -93,7 +93,7 @@ RSpec.describe ImportService, type: :service do end context 'when importing old-style list of followed users' do - subject { ImportService.new } + subject { described_class.new } let(:csv) { attachment_fixture('mute-imports.txt') } @@ -135,7 +135,7 @@ RSpec.describe ImportService, type: :service do end context 'when importing new-style list of followed users' do - subject { ImportService.new } + subject { described_class.new } let(:csv) { attachment_fixture('new-following-imports.txt') } @@ -182,7 +182,7 @@ RSpec.describe ImportService, type: :service do # # https://github.com/mastodon/mastodon/issues/20571 context 'with a utf-8 encoded domains' do - subject { ImportService.new } + subject { described_class.new } let!(:nare) { Fabricate(:account, username: 'nare', domain: 'թութ.հայ', locked: false, protocol: :activitypub, inbox_url: 'https://թութ.հայ/inbox') } let(:csv) { attachment_fixture('utf8-followers.txt') } @@ -201,7 +201,7 @@ RSpec.describe ImportService, type: :service do end context 'when importing bookmarks' do - subject { ImportService.new } + subject { described_class.new } let(:csv) { attachment_fixture('bookmark-imports.txt') } let(:local_account) { Fabricate(:account, username: 'foo', domain: '') } diff --git a/spec/services/post_status_service_spec.rb b/spec/services/post_status_service_spec.rb index f57712271..76ef5391f 100644 --- a/spec/services/post_status_service_spec.rb +++ b/spec/services/post_status_service_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe PostStatusService, type: :service do - subject { PostStatusService.new } + subject { described_class.new } it 'creates a new status' do account = Fabricate(:account) diff --git a/spec/services/precompute_feed_service_spec.rb b/spec/services/precompute_feed_service_spec.rb index 18ba00244..54e0d94ee 100644 --- a/spec/services/precompute_feed_service_spec.rb +++ b/spec/services/precompute_feed_service_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe PrecomputeFeedService, type: :service do - subject { PrecomputeFeedService.new } + subject { described_class.new } describe 'call' do let(:account) { Fabricate(:account) } diff --git a/spec/services/process_mentions_service_spec.rb b/spec/services/process_mentions_service_spec.rb index 399800b2a..a28b6db40 100644 --- a/spec/services/process_mentions_service_spec.rb +++ b/spec/services/process_mentions_service_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe ProcessMentionsService, type: :service do - subject { ProcessMentionsService.new } + subject { described_class.new } let(:account) { Fabricate(:account, username: 'alice') } diff --git a/spec/services/purge_domain_service_spec.rb b/spec/services/purge_domain_service_spec.rb index 310affa5e..89ab4d8d9 100644 --- a/spec/services/purge_domain_service_spec.rb +++ b/spec/services/purge_domain_service_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe PurgeDomainService, type: :service do - subject { PurgeDomainService.new } + subject { described_class.new } let!(:old_account) { Fabricate(:account, domain: 'obsolete.org') } let!(:old_status1) { Fabricate(:status, account: old_account) } diff --git a/spec/services/reblog_service_spec.rb b/spec/services/reblog_service_spec.rb index 69500848d..7b85e37ed 100644 --- a/spec/services/reblog_service_spec.rb +++ b/spec/services/reblog_service_spec.rb @@ -6,7 +6,7 @@ RSpec.describe ReblogService, type: :service do let(:alice) { Fabricate(:account, username: 'alice') } context 'when creates a reblog with appropriate visibility' do - subject { ReblogService.new } + subject { described_class.new } let(:visibility) { :public } let(:reblog_visibility) { :public } @@ -62,7 +62,7 @@ RSpec.describe ReblogService, type: :service do end context 'with ActivityPub' do - subject { ReblogService.new } + subject { described_class.new } let(:bob) { Fabricate(:account, username: 'bob', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox') } let(:status) { Fabricate(:status, account: bob) } diff --git a/spec/services/reject_follow_service_spec.rb b/spec/services/reject_follow_service_spec.rb index be9363d84..d28104b2c 100644 --- a/spec/services/reject_follow_service_spec.rb +++ b/spec/services/reject_follow_service_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe RejectFollowService, type: :service do - subject { RejectFollowService.new } + subject { described_class.new } let(:sender) { Fabricate(:account, username: 'alice') } diff --git a/spec/services/remove_from_followers_service_spec.rb b/spec/services/remove_from_followers_service_spec.rb index 21cea2e4f..1b29cdcbe 100644 --- a/spec/services/remove_from_followers_service_spec.rb +++ b/spec/services/remove_from_followers_service_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe RemoveFromFollowersService, type: :service do - subject { RemoveFromFollowersService.new } + subject { described_class.new } let(:bob) { Fabricate(:account, username: 'bob') } diff --git a/spec/services/remove_status_service_spec.rb b/spec/services/remove_status_service_spec.rb index a836109a0..77b01d307 100644 --- a/spec/services/remove_status_service_spec.rb +++ b/spec/services/remove_status_service_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe RemoveStatusService, type: :service do - subject { RemoveStatusService.new } + subject { described_class.new } let!(:alice) { Fabricate(:account) } let!(:bob) { Fabricate(:account, username: 'bob', domain: 'example.com') } diff --git a/spec/services/unallow_domain_service_spec.rb b/spec/services/unallow_domain_service_spec.rb index fbc1d5959..4db718d07 100644 --- a/spec/services/unallow_domain_service_spec.rb +++ b/spec/services/unallow_domain_service_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe UnallowDomainService, type: :service do - subject { UnallowDomainService.new } + subject { described_class.new } let!(:bad_account) { Fabricate(:account, username: 'badguy666', domain: 'evil.org') } let!(:bad_status1) { Fabricate(:status, account: bad_account, text: 'You suck') } diff --git a/spec/services/unblock_service_spec.rb b/spec/services/unblock_service_spec.rb index 8098d7e6d..86632c393 100644 --- a/spec/services/unblock_service_spec.rb +++ b/spec/services/unblock_service_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe UnblockService, type: :service do - subject { UnblockService.new } + subject { described_class.new } let(:sender) { Fabricate(:account, username: 'alice') } diff --git a/spec/services/unfollow_service_spec.rb b/spec/services/unfollow_service_spec.rb index a12f01fa5..3e65e610b 100644 --- a/spec/services/unfollow_service_spec.rb +++ b/spec/services/unfollow_service_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe UnfollowService, type: :service do - subject { UnfollowService.new } + subject { described_class.new } let(:sender) { Fabricate(:account, username: 'alice') } diff --git a/spec/services/unmute_service_spec.rb b/spec/services/unmute_service_spec.rb index 2edb6cfc2..236f837e2 100644 --- a/spec/services/unmute_service_spec.rb +++ b/spec/services/unmute_service_spec.rb @@ -3,5 +3,5 @@ require 'rails_helper' RSpec.describe UnmuteService, type: :service do - subject { UnmuteService.new } + subject { described_class.new } end diff --git a/spec/services/update_account_service_spec.rb b/spec/services/update_account_service_spec.rb index a711a8ae7..6318cc95f 100644 --- a/spec/services/update_account_service_spec.rb +++ b/spec/services/update_account_service_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe UpdateAccountService, type: :service do - subject { UpdateAccountService.new } + subject { described_class.new } describe 'switching form locked to unlocked accounts' do let(:account) { Fabricate(:account, locked: true) } diff --git a/spec/validators/note_length_validator_spec.rb b/spec/validators/note_length_validator_spec.rb index 390ac8d90..e45d221d7 100644 --- a/spec/validators/note_length_validator_spec.rb +++ b/spec/validators/note_length_validator_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' describe NoteLengthValidator do - subject { NoteLengthValidator.new(attributes: { note: true }, maximum: 500) } + subject { described_class.new(attributes: { note: true }, maximum: 500) } describe '#validate' do it 'adds an error when text is over 500 characters' do From 9a653899e907ff7c1dcec3a6faf868075976974e Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 6 Jun 2023 14:16:41 +0200 Subject: [PATCH 13/24] Update dependency redis to v4.6.7 (#25300) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- yarn.lock | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/yarn.lock b/yarn.lock index 8839ed68d..76414138a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1880,10 +1880,10 @@ resolved "https://registry.yarnpkg.com/@redis/bloom/-/bloom-1.2.0.tgz#d3fd6d3c0af3ef92f26767b56414a370c7b63b71" integrity sha512-HG2DFjYKbpNmVXsa0keLHp/3leGJz1mjh09f2RLGGLQZzSHpkmZWuwJbAvo3QcRY8p80m5+ZdXZdYOSBLlp7Cg== -"@redis/client@1.5.6": - version "1.5.6" - resolved "https://registry.yarnpkg.com/@redis/client/-/client-1.5.6.tgz#869cc65718d7d5493ef655a71dc40f3bc64a1b28" - integrity sha512-dFD1S6je+A47Lj22jN/upVU2fj4huR7S9APd7/ziUXsIXDL+11GPYti4Suv5y8FuXaN+0ZG4JF+y1houEJ7ToA== +"@redis/client@1.5.8": + version "1.5.8" + resolved "https://registry.yarnpkg.com/@redis/client/-/client-1.5.8.tgz#a375ba7861825bd0d2dc512282b8bff7b98dbcb1" + integrity sha512-xzElwHIO6rBAqzPeVnCzgvrnBEcFL1P0w8P65VNLRkdVW8rOE58f52hdj0BDgmsdOm4f1EoXPZtH4Fh7M/qUpw== dependencies: cluster-key-slot "1.1.2" generic-pool "3.9.0" @@ -1899,10 +1899,10 @@ resolved "https://registry.yarnpkg.com/@redis/json/-/json-1.0.4.tgz#f372b5f93324e6ffb7f16aadcbcb4e5c3d39bda1" integrity sha512-LUZE2Gdrhg0Rx7AN+cZkb1e6HjoSKaeeW8rYnt89Tly13GBI5eP4CwDVr+MY8BAYfCg4/N15OUrtLoona9uSgw== -"@redis/search@1.1.2": - version "1.1.2" - resolved "https://registry.yarnpkg.com/@redis/search/-/search-1.1.2.tgz#6a8f66ba90812d39c2457420f859ce8fbd8f3838" - integrity sha512-/cMfstG/fOh/SsE+4/BQGeuH/JJloeWuH+qJzM8dbxuWvdWibWAOAHHCZTMPhV3xIlH4/cUEIA8OV5QnYpaVoA== +"@redis/search@1.1.3": + version "1.1.3" + resolved "https://registry.yarnpkg.com/@redis/search/-/search-1.1.3.tgz#b5a6837522ce9028267fe6f50762a8bcfd2e998b" + integrity sha512-4Dg1JjvCevdiCBTZqjhKkGoC5/BcB7k9j99kdMnaXFXg8x4eyOIVg9487CMv7/BUVkFLZCaIh8ead9mU15DNng== "@redis/time-series@1.0.4": version "1.0.4" @@ -10001,15 +10001,15 @@ redent@^3.0.0: strip-indent "^3.0.0" redis@^4.6.5: - version "4.6.5" - resolved "https://registry.yarnpkg.com/redis/-/redis-4.6.5.tgz#f32fbde44429e96f562bb0c9b1db0143ab8cfa4f" - integrity sha512-O0OWA36gDQbswOdUuAhRL6mTZpHFN525HlgZgDaVNgCJIAZR3ya06NTESb0R+TUZ+BFaDpz6NnnVvoMx9meUFg== + version "4.6.7" + resolved "https://registry.yarnpkg.com/redis/-/redis-4.6.7.tgz#c73123ad0b572776223f172ec78185adb72a6b57" + integrity sha512-KrkuNJNpCwRm5vFJh0tteMxW8SaUzkm5fBH7eL5hd/D0fAkzvapxbfGPP/r+4JAXdQuX7nebsBkBqA2RHB7Usw== dependencies: "@redis/bloom" "1.2.0" - "@redis/client" "1.5.6" + "@redis/client" "1.5.8" "@redis/graph" "1.1.0" "@redis/json" "1.0.4" - "@redis/search" "1.1.2" + "@redis/search" "1.1.3" "@redis/time-series" "1.0.4" redux-immutable@^4.0.0: From c66250abf17b4aad1abc1500c14bf9862c078226 Mon Sep 17 00:00:00 2001 From: Nick Schonning Date: Tue, 6 Jun 2023 08:50:51 -0400 Subject: [PATCH 14/24] Autofix Rubocop Regex Style rules (#23690) Co-authored-by: Claire --- .rubocop_todo.yml | 46 ---------------------- app/lib/link_details_extractor.rb | 14 +++---- app/lib/plain_text_formatter.rb | 2 +- app/lib/tag_manager.rb | 6 +-- app/lib/text_formatter.rb | 2 +- app/lib/webfinger_resource.rb | 2 +- app/models/account.rb | 6 +-- app/models/domain_allow.rb | 2 +- app/models/domain_block.rb | 2 +- app/models/site_upload.rb | 2 +- app/models/tag.rb | 2 +- app/services/backup_service.rb | 4 +- app/services/fetch_link_card_service.rb | 2 +- app/services/fetch_oembed_service.rb | 2 +- app/services/search_service.rb | 2 +- config/initializers/rack_attack.rb | 6 +-- config/initializers/twitter_regex.rb | 16 ++++---- config/routes.rb | 6 +-- lib/mastodon/premailer_webpack_strategy.rb | 2 +- lib/paperclip/color_extractor.rb | 2 +- lib/tasks/emojis.rake | 2 +- lib/tasks/mastodon.rake | 8 ++-- 22 files changed, 46 insertions(+), 92 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 1a16472bd..0d0fbfac9 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1412,52 +1412,6 @@ Style/RedundantFetchBlock: - 'config/initializers/paperclip.rb' - 'config/puma.rb' -# This cop supports safe autocorrection (--autocorrect). -Style/RedundantRegexpCharacterClass: - Exclude: - - 'app/lib/link_details_extractor.rb' - - 'app/lib/tag_manager.rb' - - 'app/models/domain_allow.rb' - - 'app/models/domain_block.rb' - - 'app/services/fetch_oembed_service.rb' - - 'config/initializers/rack_attack.rb' - - 'lib/tasks/emojis.rake' - - 'lib/tasks/mastodon.rake' - -# This cop supports safe autocorrection (--autocorrect). -Style/RedundantRegexpEscape: - Exclude: - - 'app/lib/webfinger_resource.rb' - - 'app/models/account.rb' - - 'app/models/tag.rb' - - 'app/services/fetch_link_card_service.rb' - - 'config/initializers/twitter_regex.rb' - - 'lib/paperclip/color_extractor.rb' - - 'lib/tasks/mastodon.rake' - -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, AllowInnerSlashes. -# SupportedStyles: slashes, percent_r, mixed -Style/RegexpLiteral: - Exclude: - - 'app/lib/link_details_extractor.rb' - - 'app/lib/plain_text_formatter.rb' - - 'app/lib/tag_manager.rb' - - 'app/lib/text_formatter.rb' - - 'app/models/account.rb' - - 'app/models/domain_allow.rb' - - 'app/models/domain_block.rb' - - 'app/models/site_upload.rb' - - 'app/models/tag.rb' - - 'app/services/backup_service.rb' - - 'app/services/fetch_oembed_service.rb' - - 'app/services/search_service.rb' - - 'config/initializers/rack_attack.rb' - - 'config/initializers/twitter_regex.rb' - - 'config/routes.rb' - - 'lib/mastodon/premailer_webpack_strategy.rb' - - 'lib/tasks/mastodon.rake' - # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods, MaxChainLength. # AllowedMethods: present?, blank?, presence, try, try! diff --git a/app/lib/link_details_extractor.rb b/app/lib/link_details_extractor.rb index dfed69285..f0aeec0b3 100644 --- a/app/lib/link_details_extractor.rb +++ b/app/lib/link_details_extractor.rb @@ -7,15 +7,15 @@ class LinkDetailsExtractor # Some publications wrap their JSON-LD data in their