From 00d94f3ffabda89a2f955212e763cdba3f1f54c6 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 12 Mar 2024 13:10:37 -0400 Subject: [PATCH 01/11] Use vanilla JS to get Rails CSRF values (#29403) --- app/javascript/mastodon/utils/log_out.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/javascript/mastodon/utils/log_out.ts b/app/javascript/mastodon/utils/log_out.ts index 3a4cc8ecb1..b08a61a6a2 100644 --- a/app/javascript/mastodon/utils/log_out.ts +++ b/app/javascript/mastodon/utils/log_out.ts @@ -1,5 +1,3 @@ -import Rails from '@rails/ujs'; - export const logOut = () => { const form = document.createElement('form'); @@ -9,13 +7,18 @@ export const logOut = () => { methodInput.setAttribute('type', 'hidden'); form.appendChild(methodInput); - const csrfToken = Rails.csrfToken(); - const csrfParam = Rails.csrfParam(); + const csrfToken = document.querySelector( + 'meta[name=csrf-token]', + ); + + const csrfParam = document.querySelector( + 'meta[name=csrf-param]', + ); if (csrfParam && csrfToken) { const csrfInput = document.createElement('input'); - csrfInput.setAttribute('name', csrfParam); - csrfInput.setAttribute('value', csrfToken); + csrfInput.setAttribute('name', csrfParam.content); + csrfInput.setAttribute('value', csrfToken.content); csrfInput.setAttribute('type', 'hidden'); form.appendChild(csrfInput); } From 96013cd576ec51a41a7fe06a28225a3e43ca8496 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 13 Mar 2024 04:22:32 -0400 Subject: [PATCH 02/11] Reduce `RSpec/ExampleLength` in CSP request spec (#29104) --- spec/requests/content_security_policy_spec.rb | 49 ++++++++++++------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/spec/requests/content_security_policy_spec.rb b/spec/requests/content_security_policy_spec.rb index d4cc40bce5..d4447dca4b 100644 --- a/spec/requests/content_security_policy_spec.rb +++ b/spec/requests/content_security_policy_spec.rb @@ -3,25 +3,38 @@ require 'rails_helper' describe 'Content-Security-Policy' do - it 'sets the expected CSP headers' do - allow(SecureRandom).to receive(:base64).with(16).and_return('ZbA+JmE7+bK8F5qvADZHuQ==') + before { allow(SecureRandom).to receive(:base64).with(16).and_return('ZbA+JmE7+bK8F5qvADZHuQ==') } + it 'sets the expected CSP headers' do get '/' - expect(response.headers['Content-Security-Policy'].split(';').map(&:strip)).to contain_exactly( - "base-uri 'none'", - "default-src 'none'", - "frame-ancestors 'none'", - "font-src 'self' https://cb6e6126.ngrok.io", - "img-src 'self' data: blob: https://cb6e6126.ngrok.io", - "style-src 'self' https://cb6e6126.ngrok.io 'nonce-ZbA+JmE7+bK8F5qvADZHuQ=='", - "media-src 'self' data: https://cb6e6126.ngrok.io", - "frame-src 'self' https:", - "manifest-src 'self' https://cb6e6126.ngrok.io", - "form-action 'self'", - "child-src 'self' blob: https://cb6e6126.ngrok.io", - "worker-src 'self' blob: https://cb6e6126.ngrok.io", - "connect-src 'self' data: blob: https://cb6e6126.ngrok.io ws://cb6e6126.ngrok.io:4000", - "script-src 'self' https://cb6e6126.ngrok.io 'wasm-unsafe-eval'" - ) + + expect(response_csp_headers) + .to match_array(expected_csp_headers) + end + + def response_csp_headers + response + .headers['Content-Security-Policy'] + .split(';') + .map(&:strip) + end + + def expected_csp_headers + <<~CSP.split("\n").map(&:strip) + base-uri 'none' + child-src 'self' blob: https://cb6e6126.ngrok.io + connect-src 'self' data: blob: https://cb6e6126.ngrok.io ws://cb6e6126.ngrok.io:4000 + default-src 'none' + font-src 'self' https://cb6e6126.ngrok.io + form-action 'self' + frame-ancestors 'none' + frame-src 'self' https: + img-src 'self' data: blob: https://cb6e6126.ngrok.io + manifest-src 'self' https://cb6e6126.ngrok.io + media-src 'self' data: https://cb6e6126.ngrok.io + script-src 'self' https://cb6e6126.ngrok.io 'wasm-unsafe-eval' + style-src 'self' https://cb6e6126.ngrok.io 'nonce-ZbA+JmE7+bK8F5qvADZHuQ==' + worker-src 'self' blob: https://cb6e6126.ngrok.io + CSP end end From 19f0590795500c2a93baa317b79b53efaca2ec88 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 13 Mar 2024 04:33:03 -0400 Subject: [PATCH 03/11] Add basic coverage for `TagSearchService` class (#29319) --- spec/services/tag_search_service_spec.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 spec/services/tag_search_service_spec.rb diff --git a/spec/services/tag_search_service_spec.rb b/spec/services/tag_search_service_spec.rb new file mode 100644 index 0000000000..de42e54071 --- /dev/null +++ b/spec/services/tag_search_service_spec.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe TagSearchService do + describe '#call' do + let!(:one) { Fabricate(:tag, name: 'one') } + + before { Fabricate(:tag, name: 'two') } + + it 'runs a search for tags' do + results = subject.call('#one', limit: 5) + + expect(results) + .to have_attributes( + size: 1, + first: eq(one) + ) + end + end +end From 3eaac3af73eac44accf4abefb273486e90c4c9dd Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 13 Mar 2024 04:38:57 -0400 Subject: [PATCH 04/11] Use `before_all` block to setup `requests/cache_spec` data (#29437) --- spec/rails_helper.rb | 1 + spec/requests/cache_spec.rb | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 3e84d68738..89fc25bcbd 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -21,6 +21,7 @@ require 'paperclip/matchers' require 'capybara/rspec' require 'chewy/rspec' require 'email_spec/rspec' +require 'test_prof/recipes/rspec/before_all' Dir[Rails.root.join('spec', 'support', '**', '*.rb')].each { |f| require f } diff --git a/spec/requests/cache_spec.rb b/spec/requests/cache_spec.rb index c56eec16c5..91e5b022e3 100644 --- a/spec/requests/cache_spec.rb +++ b/spec/requests/cache_spec.rb @@ -39,7 +39,7 @@ module TestEndpoints /api/v1/accounts/lookup?acct=alice /api/v1/statuses/110224538612341312 /api/v1/statuses/110224538612341312/context - /api/v1/polls/12345 + /api/v1/polls/123456789 /api/v1/trends/statuses /api/v1/directory ).freeze @@ -166,14 +166,18 @@ describe 'Caching behavior' do ActionController::Base.allow_forgery_protection = old end - let(:alice) { Fabricate(:account, username: 'alice') } - let(:user) { Fabricate(:user, role: UserRole.find_by(name: 'Moderator')) } + let(:alice) { Account.find_by(username: 'alice') } + let(:user) { User.find_by(email: 'user@host.example') } + let(:token) { Doorkeeper::AccessToken.find_by(resource_owner_id: user.id) } - before do - status = Fabricate(:status, account: alice, id: '110224538612341312') - Fabricate(:status, account: alice, id: '110224538643211312', visibility: :private) + before_all do + alice = Fabricate(:account, username: 'alice') + user = Fabricate(:user, email: 'user@host.example', role: UserRole.find_by(name: 'Moderator')) + status = Fabricate(:status, account: alice, id: 110_224_538_612_341_312) + Fabricate(:status, account: alice, id: 110_224_538_643_211_312, visibility: :private) Fabricate(:invite, code: 'abcdef') - Fabricate(:poll, status: status, account: alice, id: '12345') + Fabricate(:poll, status: status, account: alice, id: 123_456_789) + Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read') user.account.follow!(alice) end @@ -321,8 +325,6 @@ describe 'Caching behavior' do end context 'with an auth token' do - let!(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read') } - TestEndpoints::ALWAYS_CACHED.each do |endpoint| describe endpoint do before do @@ -585,8 +587,6 @@ describe 'Caching behavior' do end context 'with an auth token' do - let!(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read') } - TestEndpoints::ALWAYS_CACHED.each do |endpoint| describe endpoint do before do From 469028b6d3788c1b1e535d6d0b1f9f6e91e26c33 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 13 Mar 2024 04:39:26 -0400 Subject: [PATCH 05/11] Remove unneeded `type: :service` from spec/services files (#29304) --- spec/services/account_search_service_spec.rb | 2 +- spec/services/account_statuses_cleanup_service_spec.rb | 2 +- .../activitypub/fetch_featured_collection_service_spec.rb | 2 +- .../activitypub/fetch_featured_tags_collection_service_spec.rb | 2 +- spec/services/activitypub/fetch_remote_account_service_spec.rb | 2 +- spec/services/activitypub/fetch_remote_actor_service_spec.rb | 2 +- spec/services/activitypub/fetch_remote_key_service_spec.rb | 2 +- spec/services/activitypub/fetch_remote_status_service_spec.rb | 2 +- spec/services/activitypub/fetch_replies_service_spec.rb | 2 +- spec/services/activitypub/process_account_service_spec.rb | 2 +- spec/services/activitypub/process_collection_service_spec.rb | 2 +- spec/services/activitypub/process_status_update_service_spec.rb | 2 +- spec/services/activitypub/synchronize_followers_service_spec.rb | 2 +- spec/services/after_block_domain_from_account_service_spec.rb | 2 +- spec/services/after_block_service_spec.rb | 2 +- spec/services/app_sign_up_service_spec.rb | 2 +- spec/services/authorize_follow_service_spec.rb | 2 +- spec/services/backup_service_spec.rb | 2 +- spec/services/batched_remove_status_service_spec.rb | 2 +- spec/services/block_domain_service_spec.rb | 2 +- spec/services/block_service_spec.rb | 2 +- spec/services/bootstrap_timeline_service_spec.rb | 2 +- spec/services/clear_domain_media_service_spec.rb | 2 +- spec/services/delete_account_service_spec.rb | 2 +- spec/services/fan_out_on_write_service_spec.rb | 2 +- spec/services/favourite_service_spec.rb | 2 +- spec/services/fetch_link_card_service_spec.rb | 2 +- spec/services/fetch_oembed_service_spec.rb | 2 +- spec/services/fetch_remote_status_service_spec.rb | 2 +- spec/services/fetch_resource_service_spec.rb | 2 +- spec/services/follow_service_spec.rb | 2 +- spec/services/import_service_spec.rb | 2 +- spec/services/mute_service_spec.rb | 2 +- spec/services/notify_service_spec.rb | 2 +- spec/services/post_status_service_spec.rb | 2 +- spec/services/precompute_feed_service_spec.rb | 2 +- spec/services/process_mentions_service_spec.rb | 2 +- spec/services/purge_domain_service_spec.rb | 2 +- spec/services/reblog_service_spec.rb | 2 +- spec/services/reject_follow_service_spec.rb | 2 +- spec/services/remove_from_followers_service_spec.rb | 2 +- spec/services/remove_status_service_spec.rb | 2 +- spec/services/report_service_spec.rb | 2 +- spec/services/resolve_account_service_spec.rb | 2 +- spec/services/resolve_url_service_spec.rb | 2 +- spec/services/search_service_spec.rb | 2 +- spec/services/software_update_check_service_spec.rb | 2 +- spec/services/suspend_account_service_spec.rb | 2 +- spec/services/translate_status_service_spec.rb | 2 +- spec/services/unallow_domain_service_spec.rb | 2 +- spec/services/unblock_domain_service_spec.rb | 2 +- spec/services/unblock_service_spec.rb | 2 +- spec/services/unfollow_service_spec.rb | 2 +- spec/services/unsuspend_account_service_spec.rb | 2 +- spec/services/update_account_service_spec.rb | 2 +- spec/services/update_status_service_spec.rb | 2 +- spec/services/verify_link_service_spec.rb | 2 +- 57 files changed, 57 insertions(+), 57 deletions(-) diff --git a/spec/services/account_search_service_spec.rb b/spec/services/account_search_service_spec.rb index 4f89cd220c..5ec0885903 100644 --- a/spec/services/account_search_service_spec.rb +++ b/spec/services/account_search_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -describe AccountSearchService, type: :service do +describe AccountSearchService do describe '#call' do context 'with a query to ignore' do it 'returns empty array for missing query' do diff --git a/spec/services/account_statuses_cleanup_service_spec.rb b/spec/services/account_statuses_cleanup_service_spec.rb index 0ac113f105..403c4632d7 100644 --- a/spec/services/account_statuses_cleanup_service_spec.rb +++ b/spec/services/account_statuses_cleanup_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -describe AccountStatusesCleanupService, type: :service do +describe AccountStatusesCleanupService do let(:account) { Fabricate(:account, username: 'alice', domain: nil) } let(:account_policy) { Fabricate(:account_statuses_cleanup_policy, account: account) } let!(:unrelated_status) { Fabricate(:status, created_at: 3.years.ago) } diff --git a/spec/services/activitypub/fetch_featured_collection_service_spec.rb b/spec/services/activitypub/fetch_featured_collection_service_spec.rb index dab204406b..7ea87922ac 100644 --- a/spec/services/activitypub/fetch_featured_collection_service_spec.rb +++ b/spec/services/activitypub/fetch_featured_collection_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe ActivityPub::FetchFeaturedCollectionService, type: :service do +RSpec.describe ActivityPub::FetchFeaturedCollectionService do subject { described_class.new } let(:actor) { Fabricate(:account, domain: 'example.com', uri: 'https://example.com/account', featured_collection_url: 'https://example.com/account/pinned') } diff --git a/spec/services/activitypub/fetch_featured_tags_collection_service_spec.rb b/spec/services/activitypub/fetch_featured_tags_collection_service_spec.rb index 638278a10e..59367b1e32 100644 --- a/spec/services/activitypub/fetch_featured_tags_collection_service_spec.rb +++ b/spec/services/activitypub/fetch_featured_tags_collection_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe ActivityPub::FetchFeaturedTagsCollectionService, type: :service do +RSpec.describe ActivityPub::FetchFeaturedTagsCollectionService do subject { described_class.new } let(:collection_url) { 'https://example.com/account/tags' } diff --git a/spec/services/activitypub/fetch_remote_account_service_spec.rb b/spec/services/activitypub/fetch_remote_account_service_spec.rb index 799a70d091..789a705c41 100644 --- a/spec/services/activitypub/fetch_remote_account_service_spec.rb +++ b/spec/services/activitypub/fetch_remote_account_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe ActivityPub::FetchRemoteAccountService, type: :service do +RSpec.describe ActivityPub::FetchRemoteAccountService do 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 4ce42ea560..025051e9fa 100644 --- a/spec/services/activitypub/fetch_remote_actor_service_spec.rb +++ b/spec/services/activitypub/fetch_remote_actor_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe ActivityPub::FetchRemoteActorService, type: :service do +RSpec.describe ActivityPub::FetchRemoteActorService do 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 478778cc9f..b6fcf3f479 100644 --- a/spec/services/activitypub/fetch_remote_key_service_spec.rb +++ b/spec/services/activitypub/fetch_remote_key_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe ActivityPub::FetchRemoteKeyService, type: :service do +RSpec.describe ActivityPub::FetchRemoteKeyService do subject { described_class.new } let(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/alice' }] } } diff --git a/spec/services/activitypub/fetch_remote_status_service_spec.rb b/spec/services/activitypub/fetch_remote_status_service_spec.rb index 0fb32d20b1..a86f141fe0 100644 --- a/spec/services/activitypub/fetch_remote_status_service_spec.rb +++ b/spec/services/activitypub/fetch_remote_status_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe ActivityPub::FetchRemoteStatusService, type: :service do +RSpec.describe ActivityPub::FetchRemoteStatusService do include ActionView::Helpers::TextHelper subject { described_class.new } diff --git a/spec/services/activitypub/fetch_replies_service_spec.rb b/spec/services/activitypub/fetch_replies_service_spec.rb index 8e1f606e26..e7d8d3528a 100644 --- a/spec/services/activitypub/fetch_replies_service_spec.rb +++ b/spec/services/activitypub/fetch_replies_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe ActivityPub::FetchRepliesService, type: :service do +RSpec.describe ActivityPub::FetchRepliesService do subject { described_class.new } let(:actor) { Fabricate(:account, domain: 'example.com', uri: 'http://example.com/account') } diff --git a/spec/services/activitypub/process_account_service_spec.rb b/spec/services/activitypub/process_account_service_spec.rb index b13869f357..8b80dafe45 100644 --- a/spec/services/activitypub/process_account_service_spec.rb +++ b/spec/services/activitypub/process_account_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe ActivityPub::ProcessAccountService, type: :service do +RSpec.describe ActivityPub::ProcessAccountService do subject { described_class.new } context 'with property values, an avatar, and a profile header' do diff --git a/spec/services/activitypub/process_collection_service_spec.rb b/spec/services/activitypub/process_collection_service_spec.rb index 63502c546e..74df0f9106 100644 --- a/spec/services/activitypub/process_collection_service_spec.rb +++ b/spec/services/activitypub/process_collection_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe ActivityPub::ProcessCollectionService, type: :service do +RSpec.describe ActivityPub::ProcessCollectionService do subject { described_class.new } let(:actor) { Fabricate(:account, domain: 'example.com', uri: 'http://example.com/account') } diff --git a/spec/services/activitypub/process_status_update_service_spec.rb b/spec/services/activitypub/process_status_update_service_spec.rb index 67f2f27276..e451d15dc0 100644 --- a/spec/services/activitypub/process_status_update_service_spec.rb +++ b/spec/services/activitypub/process_status_update_service_spec.rb @@ -6,7 +6,7 @@ def poll_option_json(name, votes) { type: 'Note', name: name, replies: { type: 'Collection', totalItems: votes } } end -RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do +RSpec.describe ActivityPub::ProcessStatusUpdateService do subject { described_class.new } let!(:status) { Fabricate(:status, text: 'Hello world', account: Fabricate(:account, domain: 'example.com')) } diff --git a/spec/services/activitypub/synchronize_followers_service_spec.rb b/spec/services/activitypub/synchronize_followers_service_spec.rb index f62376ab95..648f9a3321 100644 --- a/spec/services/activitypub/synchronize_followers_service_spec.rb +++ b/spec/services/activitypub/synchronize_followers_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe ActivityPub::SynchronizeFollowersService, type: :service do +RSpec.describe ActivityPub::SynchronizeFollowersService do subject { described_class.new } let(:actor) { Fabricate(:account, domain: 'example.com', uri: 'http://example.com/account', inbox_url: 'http://example.com/inbox') } 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 05af125997..2fce424b1a 100644 --- a/spec/services/after_block_domain_from_account_service_spec.rb +++ b/spec/services/after_block_domain_from_account_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe AfterBlockDomainFromAccountService, type: :service do +RSpec.describe AfterBlockDomainFromAccountService do subject { described_class.new } let!(:wolf) { Fabricate(:account, username: 'wolf', domain: 'evil.org', inbox_url: 'https://evil.org/inbox', protocol: :activitypub) } diff --git a/spec/services/after_block_service_spec.rb b/spec/services/after_block_service_spec.rb index d81bba1d8d..82825dad98 100644 --- a/spec/services/after_block_service_spec.rb +++ b/spec/services/after_block_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe AfterBlockService, type: :service do +RSpec.describe AfterBlockService do subject { described_class.new.call(account, target_account) } let(:account) { Fabricate(:account) } diff --git a/spec/services/app_sign_up_service_spec.rb b/spec/services/app_sign_up_service_spec.rb index b37b6da1f0..ec7b7516f9 100644 --- a/spec/services/app_sign_up_service_spec.rb +++ b/spec/services/app_sign_up_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe AppSignUpService, type: :service do +RSpec.describe AppSignUpService do subject { described_class.new } let(:app) { Fabricate(:application, scopes: 'read write') } diff --git a/spec/services/authorize_follow_service_spec.rb b/spec/services/authorize_follow_service_spec.rb index 602250ee96..be2a864185 100644 --- a/spec/services/authorize_follow_service_spec.rb +++ b/spec/services/authorize_follow_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe AuthorizeFollowService, type: :service do +RSpec.describe AuthorizeFollowService do subject { described_class.new } let(:sender) { Fabricate(:account, username: 'alice') } diff --git a/spec/services/backup_service_spec.rb b/spec/services/backup_service_spec.rb index 806ba18323..b4cb60083b 100644 --- a/spec/services/backup_service_spec.rb +++ b/spec/services/backup_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe BackupService, type: :service do +RSpec.describe BackupService do subject(:service_call) { described_class.new.call(backup) } let!(:user) { Fabricate(:user) } diff --git a/spec/services/batched_remove_status_service_spec.rb b/spec/services/batched_remove_status_service_spec.rb index 1c59d5ed06..e501b9ba84 100644 --- a/spec/services/batched_remove_status_service_spec.rb +++ b/spec/services/batched_remove_status_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe BatchedRemoveStatusService, :sidekiq_inline, type: :service do +RSpec.describe BatchedRemoveStatusService, :sidekiq_inline do subject { described_class.new } let!(:alice) { Fabricate(:account) } diff --git a/spec/services/block_domain_service_spec.rb b/spec/services/block_domain_service_spec.rb index 7ad00fff68..0f278293a8 100644 --- a/spec/services/block_domain_service_spec.rb +++ b/spec/services/block_domain_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe BlockDomainService, type: :service do +RSpec.describe BlockDomainService do subject { described_class.new } let!(:bad_account) { Fabricate(:account, username: 'badguy666', domain: 'evil.org') } diff --git a/spec/services/block_service_spec.rb b/spec/services/block_service_spec.rb index 9e4ff8e598..e72e528259 100644 --- a/spec/services/block_service_spec.rb +++ b/spec/services/block_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe BlockService, type: :service do +RSpec.describe BlockService do 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 721a0337fd..c99813bceb 100644 --- a/spec/services/bootstrap_timeline_service_spec.rb +++ b/spec/services/bootstrap_timeline_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe BootstrapTimelineService, type: :service do +RSpec.describe BootstrapTimelineService do subject { described_class.new } context 'when the new user has registered from an invite' do diff --git a/spec/services/clear_domain_media_service_spec.rb b/spec/services/clear_domain_media_service_spec.rb index 9766e62de8..f1e5097a99 100644 --- a/spec/services/clear_domain_media_service_spec.rb +++ b/spec/services/clear_domain_media_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe ClearDomainMediaService, type: :service do +RSpec.describe ClearDomainMediaService do subject { described_class.new } let!(:bad_account) { Fabricate(:account, username: 'badguy666', domain: 'evil.org') } diff --git a/spec/services/delete_account_service_spec.rb b/spec/services/delete_account_service_spec.rb index 1965b7daab..de93862435 100644 --- a/spec/services/delete_account_service_spec.rb +++ b/spec/services/delete_account_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe DeleteAccountService, type: :service do +RSpec.describe DeleteAccountService do shared_examples 'common behavior' do subject { described_class.new.call(account) } diff --git a/spec/services/fan_out_on_write_service_spec.rb b/spec/services/fan_out_on_write_service_spec.rb index 77237dffbd..b51d802a5b 100644 --- a/spec/services/fan_out_on_write_service_spec.rb +++ b/spec/services/fan_out_on_write_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe FanOutOnWriteService, type: :service do +RSpec.describe FanOutOnWriteService do subject { described_class.new } let(:last_active_at) { Time.now.utc } diff --git a/spec/services/favourite_service_spec.rb b/spec/services/favourite_service_spec.rb index 3143e7b669..d0f1ff17c1 100644 --- a/spec/services/favourite_service_spec.rb +++ b/spec/services/favourite_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe FavouriteService, type: :service do +RSpec.describe FavouriteService do subject { described_class.new } let(:sender) { Fabricate(:account, username: 'alice') } diff --git a/spec/services/fetch_link_card_service_spec.rb b/spec/services/fetch_link_card_service_spec.rb index d8ca310b28..63ebc3b978 100644 --- a/spec/services/fetch_link_card_service_spec.rb +++ b/spec/services/fetch_link_card_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe FetchLinkCardService, type: :service do +RSpec.describe FetchLinkCardService do subject { described_class.new } let(:html) { 'Hello world' } diff --git a/spec/services/fetch_oembed_service_spec.rb b/spec/services/fetch_oembed_service_spec.rb index 777cbae3fb..c9f84048b6 100644 --- a/spec/services/fetch_oembed_service_spec.rb +++ b/spec/services/fetch_oembed_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -describe FetchOEmbedService, type: :service do +describe FetchOEmbedService do subject { described_class.new } before do diff --git a/spec/services/fetch_remote_status_service_spec.rb b/spec/services/fetch_remote_status_service_spec.rb index 798740c9b3..a9c61e7b4e 100644 --- a/spec/services/fetch_remote_status_service_spec.rb +++ b/spec/services/fetch_remote_status_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe FetchRemoteStatusService, type: :service do +RSpec.describe FetchRemoteStatusService do let(:account) { Fabricate(:account, domain: 'example.org', uri: 'https://example.org/foo') } let(:prefetched_body) { nil } diff --git a/spec/services/fetch_resource_service_spec.rb b/spec/services/fetch_resource_service_spec.rb index 78037a06ce..ee4810571b 100644 --- a/spec/services/fetch_resource_service_spec.rb +++ b/spec/services/fetch_resource_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe FetchResourceService, type: :service do +RSpec.describe FetchResourceService do describe '#call' do subject { described_class.new.call(url) } diff --git a/spec/services/follow_service_spec.rb b/spec/services/follow_service_spec.rb index cf4de34c89..bea2412a3d 100644 --- a/spec/services/follow_service_spec.rb +++ b/spec/services/follow_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe FollowService, type: :service do +RSpec.describe FollowService do 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 7d005c8a11..90877d9997 100644 --- a/spec/services/import_service_spec.rb +++ b/spec/services/import_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe ImportService, :sidekiq_inline, type: :service do +RSpec.describe ImportService, :sidekiq_inline do include RoutingHelper let!(:account) { Fabricate(:account, locked: false) } diff --git a/spec/services/mute_service_spec.rb b/spec/services/mute_service_spec.rb index a2ca2ffe13..681afc0b16 100644 --- a/spec/services/mute_service_spec.rb +++ b/spec/services/mute_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe MuteService, type: :service do +RSpec.describe MuteService do subject { described_class.new.call(account, target_account) } let(:account) { Fabricate(:account) } diff --git a/spec/services/notify_service_spec.rb b/spec/services/notify_service_spec.rb index 57ff326c73..514f634d7f 100644 --- a/spec/services/notify_service_spec.rb +++ b/spec/services/notify_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe NotifyService, type: :service do +RSpec.describe NotifyService do subject { described_class.new.call(recipient, type, activity) } let(:user) { Fabricate(:user) } diff --git a/spec/services/post_status_service_spec.rb b/spec/services/post_status_service_spec.rb index acbebc5056..ee68092a36 100644 --- a/spec/services/post_status_service_spec.rb +++ b/spec/services/post_status_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe PostStatusService, type: :service do +RSpec.describe PostStatusService do subject { described_class.new } it 'creates a new status' do diff --git a/spec/services/precompute_feed_service_spec.rb b/spec/services/precompute_feed_service_spec.rb index 663babae8a..9b2c6c280f 100644 --- a/spec/services/precompute_feed_service_spec.rb +++ b/spec/services/precompute_feed_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe PrecomputeFeedService, type: :service do +RSpec.describe PrecomputeFeedService do subject { described_class.new } describe 'call' do diff --git a/spec/services/process_mentions_service_spec.rb b/spec/services/process_mentions_service_spec.rb index 0db73c41fa..2c202d3e57 100644 --- a/spec/services/process_mentions_service_spec.rb +++ b/spec/services/process_mentions_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe ProcessMentionsService, type: :service do +RSpec.describe ProcessMentionsService do 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 6d8af14deb..a5c49160db 100644 --- a/spec/services/purge_domain_service_spec.rb +++ b/spec/services/purge_domain_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe PurgeDomainService, type: :service do +RSpec.describe PurgeDomainService do subject { described_class.new } let(:domain) { 'obsolete.org' } diff --git a/spec/services/reblog_service_spec.rb b/spec/services/reblog_service_spec.rb index e5d0a2d6ce..f807536a2e 100644 --- a/spec/services/reblog_service_spec.rb +++ b/spec/services/reblog_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe ReblogService, type: :service do +RSpec.describe ReblogService do let(:alice) { Fabricate(:account, username: 'alice') } context 'when creates a reblog with appropriate visibility' do diff --git a/spec/services/reject_follow_service_spec.rb b/spec/services/reject_follow_service_spec.rb index 48316a6c4d..98aaf70478 100644 --- a/spec/services/reject_follow_service_spec.rb +++ b/spec/services/reject_follow_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe RejectFollowService, type: :service do +RSpec.describe RejectFollowService do 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 21da38a97b..d6420f7674 100644 --- a/spec/services/remove_from_followers_service_spec.rb +++ b/spec/services/remove_from_followers_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe RemoveFromFollowersService, type: :service do +RSpec.describe RemoveFromFollowersService do 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 109acfb09a..b385cfa55b 100644 --- a/spec/services/remove_status_service_spec.rb +++ b/spec/services/remove_status_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe RemoveStatusService, :sidekiq_inline, type: :service do +RSpec.describe RemoveStatusService, :sidekiq_inline do subject { described_class.new } let!(:alice) { Fabricate(:account) } diff --git a/spec/services/report_service_spec.rb b/spec/services/report_service_spec.rb index 2caeb189d9..141dc8c3be 100644 --- a/spec/services/report_service_spec.rb +++ b/spec/services/report_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe ReportService, type: :service do +RSpec.describe ReportService do subject { described_class.new } let(:source_account) { Fabricate(:account) } diff --git a/spec/services/resolve_account_service_spec.rb b/spec/services/resolve_account_service_spec.rb index b82e5b3865..316266c8f8 100644 --- a/spec/services/resolve_account_service_spec.rb +++ b/spec/services/resolve_account_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe ResolveAccountService, type: :service do +RSpec.describe ResolveAccountService do subject { described_class.new } before do diff --git a/spec/services/resolve_url_service_spec.rb b/spec/services/resolve_url_service_spec.rb index 5270cc10dd..3d59a55f10 100644 --- a/spec/services/resolve_url_service_spec.rb +++ b/spec/services/resolve_url_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -describe ResolveURLService, type: :service do +describe ResolveURLService do subject { described_class.new } describe '#call' do diff --git a/spec/services/search_service_spec.rb b/spec/services/search_service_spec.rb index 39adf43876..394ee7c3a6 100644 --- a/spec/services/search_service_spec.rb +++ b/spec/services/search_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -describe SearchService, type: :service do +describe SearchService do subject { described_class.new } describe '#call' do diff --git a/spec/services/software_update_check_service_spec.rb b/spec/services/software_update_check_service_spec.rb index c8821348ac..a1eb9d86e9 100644 --- a/spec/services/software_update_check_service_spec.rb +++ b/spec/services/software_update_check_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe SoftwareUpdateCheckService, type: :service do +RSpec.describe SoftwareUpdateCheckService do subject { described_class.new } shared_examples 'when the feature is enabled' do diff --git a/spec/services/suspend_account_service_spec.rb b/spec/services/suspend_account_service_spec.rb index 4a5f8a0b6b..d62f7ef0d6 100644 --- a/spec/services/suspend_account_service_spec.rb +++ b/spec/services/suspend_account_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe SuspendAccountService, :sidekiq_inline, type: :service do +RSpec.describe SuspendAccountService, :sidekiq_inline do shared_examples 'common behavior' do subject { described_class.new.call(account) } diff --git a/spec/services/translate_status_service_spec.rb b/spec/services/translate_status_service_spec.rb index 5f6418f5d6..0779fbbe6c 100644 --- a/spec/services/translate_status_service_spec.rb +++ b/spec/services/translate_status_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe TranslateStatusService, type: :service do +RSpec.describe TranslateStatusService do subject(:service) { described_class.new } let(:status) { Fabricate(:status, text: text, spoiler_text: spoiler_text, language: 'en', preloadable_poll: poll, media_attachments: media_attachments) } diff --git a/spec/services/unallow_domain_service_spec.rb b/spec/services/unallow_domain_service_spec.rb index 383977d352..caec3d596f 100644 --- a/spec/services/unallow_domain_service_spec.rb +++ b/spec/services/unallow_domain_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe UnallowDomainService, type: :service do +RSpec.describe UnallowDomainService do subject { described_class.new } let(:bad_domain) { 'evil.org' } diff --git a/spec/services/unblock_domain_service_spec.rb b/spec/services/unblock_domain_service_spec.rb index 3d6d82ff68..289ddfc218 100644 --- a/spec/services/unblock_domain_service_spec.rb +++ b/spec/services/unblock_domain_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -describe UnblockDomainService, type: :service do +describe UnblockDomainService do subject { described_class.new } describe 'call' do diff --git a/spec/services/unblock_service_spec.rb b/spec/services/unblock_service_spec.rb index 9813c5e7fa..4c9fcb9aee 100644 --- a/spec/services/unblock_service_spec.rb +++ b/spec/services/unblock_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe UnblockService, type: :service do +RSpec.describe UnblockService do 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 18a25a676d..bba17a8d27 100644 --- a/spec/services/unfollow_service_spec.rb +++ b/spec/services/unfollow_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe UnfollowService, type: :service do +RSpec.describe UnfollowService do subject { described_class.new } let(:sender) { Fabricate(:account, username: 'alice') } diff --git a/spec/services/unsuspend_account_service_spec.rb b/spec/services/unsuspend_account_service_spec.rb index c848767cd1..79a4441d3e 100644 --- a/spec/services/unsuspend_account_service_spec.rb +++ b/spec/services/unsuspend_account_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe UnsuspendAccountService, type: :service do +RSpec.describe UnsuspendAccountService do shared_context 'with common context' do subject { described_class.new.call(account) } diff --git a/spec/services/update_account_service_spec.rb b/spec/services/update_account_service_spec.rb index 9f4e36862d..5204f1f34d 100644 --- a/spec/services/update_account_service_spec.rb +++ b/spec/services/update_account_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe UpdateAccountService, type: :service do +RSpec.describe UpdateAccountService do subject { described_class.new } describe 'switching form locked to unlocked accounts', :sidekiq_inline do diff --git a/spec/services/update_status_service_spec.rb b/spec/services/update_status_service_spec.rb index 55651c305d..930f673e10 100644 --- a/spec/services/update_status_service_spec.rb +++ b/spec/services/update_status_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe UpdateStatusService, type: :service do +RSpec.describe UpdateStatusService do subject { described_class.new } context 'when nothing changes' do diff --git a/spec/services/verify_link_service_spec.rb b/spec/services/verify_link_service_spec.rb index 2895072420..0ce8c9a904 100644 --- a/spec/services/verify_link_service_spec.rb +++ b/spec/services/verify_link_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe VerifyLinkService, type: :service do +RSpec.describe VerifyLinkService do subject { described_class.new } context 'when given a local account' do From 8349b45d6038c4d029b6371ea1caa40c48a8ea3b Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 13 Mar 2024 04:46:11 -0400 Subject: [PATCH 06/11] Accept extra args that we wont verify in `ap/activity/add_spec` (#29005) --- spec/lib/activitypub/activity/add_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/lib/activitypub/activity/add_spec.rb b/spec/lib/activitypub/activity/add_spec.rb index ec6df01716..c0abd9f393 100644 --- a/spec/lib/activitypub/activity/add_spec.rb +++ b/spec/lib/activitypub/activity/add_spec.rb @@ -50,7 +50,7 @@ RSpec.describe ActivityPub::Activity::Add do end it 'fetches the status and pins it' do - allow(service_stub).to receive(:call) do |uri, id: true, on_behalf_of: nil, request_id: nil| # rubocop:disable Lint/UnusedBlockArgument + allow(service_stub).to receive(:call) do |uri, id: true, on_behalf_of: nil, **| expect(uri).to eq 'https://example.com/unknown' expect(id).to be true expect(on_behalf_of&.following?(sender)).to be true @@ -64,7 +64,7 @@ RSpec.describe ActivityPub::Activity::Add do context 'when there is no local follower' do it 'tries to fetch the status' do - allow(service_stub).to receive(:call) do |uri, id: true, on_behalf_of: nil, request_id: nil| # rubocop:disable Lint/UnusedBlockArgument + allow(service_stub).to receive(:call) do |uri, id: true, on_behalf_of: nil, **| expect(uri).to eq 'https://example.com/unknown' expect(id).to be true expect(on_behalf_of).to be_nil From 71eecbfa1fa5a8c2a06d232260ac9d3a4bd77ddb Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 13 Mar 2024 04:47:09 -0400 Subject: [PATCH 07/11] Move `api/v2/filters/*` to request spec (#28956) --- .../api/v2/filters/keywords_spec.rb} | 31 ++++++++----------- .../api/v2/filters/statuses_spec.rb} | 25 ++++++--------- 2 files changed, 23 insertions(+), 33 deletions(-) rename spec/{controllers/api/v2/filters/keywords_controller_spec.rb => requests/api/v2/filters/keywords_spec.rb} (79%) rename spec/{controllers/api/v2/filters/statuses_controller_spec.rb => requests/api/v2/filters/statuses_spec.rb} (81%) diff --git a/spec/controllers/api/v2/filters/keywords_controller_spec.rb b/spec/requests/api/v2/filters/keywords_spec.rb similarity index 79% rename from spec/controllers/api/v2/filters/keywords_controller_spec.rb rename to spec/requests/api/v2/filters/keywords_spec.rb index 9f25237bcf..55fb2afd95 100644 --- a/spec/controllers/api/v2/filters/keywords_controller_spec.rb +++ b/spec/requests/api/v2/filters/keywords_spec.rb @@ -2,25 +2,20 @@ require 'rails_helper' -RSpec.describe Api::V2::Filters::KeywordsController do - render_views - +RSpec.describe 'API V2 Filters Keywords' do let(:user) { Fabricate(:user) } let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) } let(:filter) { Fabricate(:custom_filter, account: user.account) } let(:other_user) { Fabricate(:user) } let(:other_filter) { Fabricate(:custom_filter, account: other_user.account) } + let(:headers) { { 'Authorization' => "Bearer #{token.token}" } } - before do - allow(controller).to receive(:doorkeeper_token) { token } - end - - describe 'GET #index' do + describe 'GET /api/v2/filters/:filter_id/keywords' do let(:scopes) { 'read:filters' } let!(:keyword) { Fabricate(:custom_filter_keyword, custom_filter: filter) } it 'returns http success' do - get :index, params: { filter_id: filter.id } + get "/api/v2/filters/#{filter.id}/keywords", headers: headers expect(response).to have_http_status(200) expect(body_as_json) .to contain_exactly( @@ -30,18 +25,18 @@ RSpec.describe Api::V2::Filters::KeywordsController do context "when trying to access another's user filters" do it 'returns http not found' do - get :index, params: { filter_id: other_filter.id } + get "/api/v2/filters/#{other_filter.id}/keywords", headers: headers expect(response).to have_http_status(404) end end end - describe 'POST #create' do + describe 'POST /api/v2/filters/:filter_id/keywords' do let(:scopes) { 'write:filters' } let(:filter_id) { filter.id } before do - post :create, params: { filter_id: filter_id, keyword: 'magic', whole_word: false } + post "/api/v2/filters/#{filter_id}/keywords", headers: headers, params: { keyword: 'magic', whole_word: false } end it 'creates a filter', :aggregate_failures do @@ -65,12 +60,12 @@ RSpec.describe Api::V2::Filters::KeywordsController do end end - describe 'GET #show' do + describe 'GET /api/v2/filters/keywords/:id' do let(:scopes) { 'read:filters' } let(:keyword) { Fabricate(:custom_filter_keyword, keyword: 'foo', whole_word: false, custom_filter: filter) } before do - get :show, params: { id: keyword.id } + get "/api/v2/filters/keywords/#{keyword.id}", headers: headers end it 'responds with the keyword', :aggregate_failures do @@ -90,12 +85,12 @@ RSpec.describe Api::V2::Filters::KeywordsController do end end - describe 'PUT #update' do + describe 'PUT /api/v2/filters/keywords/:id' do let(:scopes) { 'write:filters' } let(:keyword) { Fabricate(:custom_filter_keyword, custom_filter: filter) } before do - get :update, params: { id: keyword.id, keyword: 'updated' } + put "/api/v2/filters/keywords/#{keyword.id}", headers: headers, params: { keyword: 'updated' } end it 'updates the keyword', :aggregate_failures do @@ -113,12 +108,12 @@ RSpec.describe Api::V2::Filters::KeywordsController do end end - describe 'DELETE #destroy' do + describe 'DELETE /api/v2/filters/keywords/:id' do let(:scopes) { 'write:filters' } let(:keyword) { Fabricate(:custom_filter_keyword, custom_filter: filter) } before do - delete :destroy, params: { id: keyword.id } + delete "/api/v2/filters/keywords/#{keyword.id}", headers: headers end it 'destroys the keyword', :aggregate_failures do diff --git a/spec/controllers/api/v2/filters/statuses_controller_spec.rb b/spec/requests/api/v2/filters/statuses_spec.rb similarity index 81% rename from spec/controllers/api/v2/filters/statuses_controller_spec.rb rename to spec/requests/api/v2/filters/statuses_spec.rb index d9df803971..26d2fb00e1 100644 --- a/spec/controllers/api/v2/filters/statuses_controller_spec.rb +++ b/spec/requests/api/v2/filters/statuses_spec.rb @@ -2,25 +2,20 @@ require 'rails_helper' -RSpec.describe Api::V2::Filters::StatusesController do - render_views - +RSpec.describe 'API V2 Filters Statuses' do let(:user) { Fabricate(:user) } let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) } let(:filter) { Fabricate(:custom_filter, account: user.account) } let(:other_user) { Fabricate(:user) } let(:other_filter) { Fabricate(:custom_filter, account: other_user.account) } + let(:headers) { { 'Authorization' => "Bearer #{token.token}" } } - before do - allow(controller).to receive(:doorkeeper_token) { token } - end - - describe 'GET #index' do + describe 'GET /api/v2/filters/:filter_id/statuses' do let(:scopes) { 'read:filters' } let!(:status_filter) { Fabricate(:custom_filter_status, custom_filter: filter) } it 'returns http success' do - get :index, params: { filter_id: filter.id } + get "/api/v2/filters/#{filter.id}/statuses", headers: headers expect(response).to have_http_status(200) expect(body_as_json) .to contain_exactly( @@ -30,7 +25,7 @@ RSpec.describe Api::V2::Filters::StatusesController do context "when trying to access another's user filters" do it 'returns http not found' do - get :index, params: { filter_id: other_filter.id } + get "/api/v2/filters/#{other_filter.id}/statuses", headers: headers expect(response).to have_http_status(404) end end @@ -42,7 +37,7 @@ RSpec.describe Api::V2::Filters::StatusesController do let!(:status) { Fabricate(:status) } before do - post :create, params: { filter_id: filter_id, status_id: status.id } + post "/api/v2/filters/#{filter_id}/statuses", headers: headers, params: { status_id: status.id } end it 'creates a filter', :aggregate_failures do @@ -65,12 +60,12 @@ RSpec.describe Api::V2::Filters::StatusesController do end end - describe 'GET #show' do + describe 'GET /api/v2/filters/statuses/:id' do let(:scopes) { 'read:filters' } let!(:status_filter) { Fabricate(:custom_filter_status, custom_filter: filter) } before do - get :show, params: { id: status_filter.id } + get "/api/v2/filters/statuses/#{status_filter.id}", headers: headers end it 'responds with the filter', :aggregate_failures do @@ -89,12 +84,12 @@ RSpec.describe Api::V2::Filters::StatusesController do end end - describe 'DELETE #destroy' do + describe 'DELETE /api/v2/filters/statuses/:id' do let(:scopes) { 'write:filters' } let(:status_filter) { Fabricate(:custom_filter_status, custom_filter: filter) } before do - delete :destroy, params: { id: status_filter.id } + delete "/api/v2/filters/statuses/#{status_filter.id}", headers: headers end it 'destroys the filter', :aggregate_failures do From 01b624c4a0d17ec24f6acf56298fe9e5e8a6dd49 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 13 Mar 2024 04:50:21 -0400 Subject: [PATCH 08/11] Use `normalizes` on `CustomFilter#context` value (#27602) --- app/models/custom_filter.rb | 6 +----- spec/models/custom_filter_spec.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/models/custom_filter.rb b/app/models/custom_filter.rb index 5e2d152e34..7c148e877f 100644 --- a/app/models/custom_filter.rb +++ b/app/models/custom_filter.rb @@ -41,7 +41,7 @@ class CustomFilter < ApplicationRecord validates :title, :context, presence: true validate :context_must_be_valid - before_validation :clean_up_contexts + normalizes :context, with: ->(context) { context.map(&:strip).filter_map(&:presence) } before_save :prepare_cache_invalidation! before_destroy :prepare_cache_invalidation! @@ -114,10 +114,6 @@ class CustomFilter < ApplicationRecord private - def clean_up_contexts - self.context = Array(context).map(&:strip).filter_map(&:presence) - end - def context_must_be_valid errors.add(:context, I18n.t('filters.errors.invalid_context')) if invalid_context_value? end diff --git a/spec/models/custom_filter_spec.rb b/spec/models/custom_filter_spec.rb index 9404936337..8ac9dbb896 100644 --- a/spec/models/custom_filter_spec.rb +++ b/spec/models/custom_filter_spec.rb @@ -32,4 +32,12 @@ RSpec.describe CustomFilter do expect(record).to model_have_error_on_field(:context) end end + + describe 'Normalizations' do + it 'cleans up context values' do + record = described_class.new(context: ['home', 'notifications', 'public ', '']) + + expect(record.context).to eq(%w(home notifications public)) + end + end end From 9754967d5fd37cf35b362d4429d320c1e5f94428 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 13 Mar 2024 04:51:44 -0400 Subject: [PATCH 09/11] Move `pagination_max_id` and `pagination_since_id` into api/base controller (#28844) --- app/controllers/api/base_controller.rb | 8 ++++++++ app/controllers/api/v1/accounts/statuses_controller.rb | 8 ++------ app/controllers/api/v1/admin/accounts_controller.rb | 8 ++------ .../api/v1/admin/canonical_email_blocks_controller.rb | 8 ++------ app/controllers/api/v1/admin/domain_allows_controller.rb | 8 ++------ app/controllers/api/v1/admin/domain_blocks_controller.rb | 8 ++------ .../api/v1/admin/email_domain_blocks_controller.rb | 8 ++------ app/controllers/api/v1/admin/ip_blocks_controller.rb | 8 ++------ app/controllers/api/v1/admin/reports_controller.rb | 8 ++------ app/controllers/api/v1/admin/tags_controller.rb | 8 ++------ .../trends/links/preview_card_providers_controller.rb | 8 ++------ app/controllers/api/v1/blocks_controller.rb | 8 ++------ app/controllers/api/v1/bookmarks_controller.rb | 8 ++------ .../api/v1/crypto/encrypted_messages_controller.rb | 8 ++------ app/controllers/api/v1/domain_blocks_controller.rb | 8 ++------ app/controllers/api/v1/endorsements_controller.rb | 8 ++------ app/controllers/api/v1/favourites_controller.rb | 8 ++------ app/controllers/api/v1/followed_tags_controller.rb | 8 ++------ app/controllers/api/v1/lists/accounts_controller.rb | 8 ++------ app/controllers/api/v1/mutes_controller.rb | 8 ++------ app/controllers/api/v1/notifications_controller.rb | 8 ++------ app/controllers/api/v1/scheduled_statuses_controller.rb | 8 ++------ app/controllers/api/v1/timelines/base_controller.rb | 8 ++------ 23 files changed, 52 insertions(+), 132 deletions(-) diff --git a/app/controllers/api/base_controller.rb b/app/controllers/api/base_controller.rb index 98fa1897ef..8bf9da2cfd 100644 --- a/app/controllers/api/base_controller.rb +++ b/app/controllers/api/base_controller.rb @@ -73,6 +73,14 @@ class Api::BaseController < ApplicationController protected + def pagination_max_id + pagination_collection.last.id + end + + def pagination_since_id + pagination_collection.first.id + end + def set_pagination_headers(next_path = nil, prev_path = nil) links = [] links << [next_path, [%w(rel next)]] if next_path diff --git a/app/controllers/api/v1/accounts/statuses_controller.rb b/app/controllers/api/v1/accounts/statuses_controller.rb index 6a994ff541..56d4e69091 100644 --- a/app/controllers/api/v1/accounts/statuses_controller.rb +++ b/app/controllers/api/v1/accounts/statuses_controller.rb @@ -51,11 +51,7 @@ class Api::V1::Accounts::StatusesController < Api::BaseController @statuses.size == limit_param(DEFAULT_STATUSES_LIMIT) end - def pagination_max_id - @statuses.last.id - end - - def pagination_since_id - @statuses.first.id + def pagination_collection + @statuses end end diff --git a/app/controllers/api/v1/admin/accounts_controller.rb b/app/controllers/api/v1/admin/accounts_controller.rb index ff9cae6398..06cebffcb6 100644 --- a/app/controllers/api/v1/admin/accounts_controller.rb +++ b/app/controllers/api/v1/admin/accounts_controller.rb @@ -137,12 +137,8 @@ class Api::V1::Admin::AccountsController < Api::BaseController api_v1_admin_accounts_url(pagination_params(min_id: pagination_since_id)) unless @accounts.empty? end - def pagination_max_id - @accounts.last.id - end - - def pagination_since_id - @accounts.first.id + def pagination_collection + @accounts end def records_continue? diff --git a/app/controllers/api/v1/admin/canonical_email_blocks_controller.rb b/app/controllers/api/v1/admin/canonical_email_blocks_controller.rb index 7b192b979f..f81e480bd7 100644 --- a/app/controllers/api/v1/admin/canonical_email_blocks_controller.rb +++ b/app/controllers/api/v1/admin/canonical_email_blocks_controller.rb @@ -77,12 +77,8 @@ class Api::V1::Admin::CanonicalEmailBlocksController < Api::BaseController api_v1_admin_canonical_email_blocks_url(pagination_params(min_id: pagination_since_id)) unless @canonical_email_blocks.empty? end - def pagination_max_id - @canonical_email_blocks.last.id - end - - def pagination_since_id - @canonical_email_blocks.first.id + def pagination_collection + @canonical_email_blocks end def records_continue? diff --git a/app/controllers/api/v1/admin/domain_allows_controller.rb b/app/controllers/api/v1/admin/domain_allows_controller.rb index dd54d67106..1841292843 100644 --- a/app/controllers/api/v1/admin/domain_allows_controller.rb +++ b/app/controllers/api/v1/admin/domain_allows_controller.rb @@ -73,12 +73,8 @@ class Api::V1::Admin::DomainAllowsController < Api::BaseController api_v1_admin_domain_allows_url(pagination_params(min_id: pagination_since_id)) unless @domain_allows.empty? end - def pagination_max_id - @domain_allows.last.id - end - - def pagination_since_id - @domain_allows.first.id + def pagination_collection + @domain_allows end def records_continue? diff --git a/app/controllers/api/v1/admin/domain_blocks_controller.rb b/app/controllers/api/v1/admin/domain_blocks_controller.rb index 2538c7c7c2..8cd90b7c52 100644 --- a/app/controllers/api/v1/admin/domain_blocks_controller.rb +++ b/app/controllers/api/v1/admin/domain_blocks_controller.rb @@ -84,12 +84,8 @@ class Api::V1::Admin::DomainBlocksController < Api::BaseController api_v1_admin_domain_blocks_url(pagination_params(min_id: pagination_since_id)) unless @domain_blocks.empty? end - def pagination_max_id - @domain_blocks.last.id - end - - def pagination_since_id - @domain_blocks.first.id + def pagination_collection + @domain_blocks end def records_continue? diff --git a/app/controllers/api/v1/admin/email_domain_blocks_controller.rb b/app/controllers/api/v1/admin/email_domain_blocks_controller.rb index df54b9f0a4..34489e19b4 100644 --- a/app/controllers/api/v1/admin/email_domain_blocks_controller.rb +++ b/app/controllers/api/v1/admin/email_domain_blocks_controller.rb @@ -70,12 +70,8 @@ class Api::V1::Admin::EmailDomainBlocksController < Api::BaseController api_v1_admin_email_domain_blocks_url(pagination_params(min_id: pagination_since_id)) unless @email_domain_blocks.empty? end - def pagination_max_id - @email_domain_blocks.last.id - end - - def pagination_since_id - @email_domain_blocks.first.id + def pagination_collection + @email_domain_blocks end def records_continue? diff --git a/app/controllers/api/v1/admin/ip_blocks_controller.rb b/app/controllers/api/v1/admin/ip_blocks_controller.rb index 61c1912344..0f666476c5 100644 --- a/app/controllers/api/v1/admin/ip_blocks_controller.rb +++ b/app/controllers/api/v1/admin/ip_blocks_controller.rb @@ -75,12 +75,8 @@ class Api::V1::Admin::IpBlocksController < Api::BaseController api_v1_admin_ip_blocks_url(pagination_params(min_id: pagination_since_id)) unless @ip_blocks.empty? end - def pagination_max_id - @ip_blocks.last.id - end - - def pagination_since_id - @ip_blocks.first.id + def pagination_collection + @ip_blocks end def records_continue? diff --git a/app/controllers/api/v1/admin/reports_controller.rb b/app/controllers/api/v1/admin/reports_controller.rb index 7129a5f6ca..f0598aa81e 100644 --- a/app/controllers/api/v1/admin/reports_controller.rb +++ b/app/controllers/api/v1/admin/reports_controller.rb @@ -101,12 +101,8 @@ class Api::V1::Admin::ReportsController < Api::BaseController api_v1_admin_reports_url(pagination_params(min_id: pagination_since_id)) unless @reports.empty? end - def pagination_max_id - @reports.last.id - end - - def pagination_since_id - @reports.first.id + def pagination_collection + @reports end def records_continue? diff --git a/app/controllers/api/v1/admin/tags_controller.rb b/app/controllers/api/v1/admin/tags_controller.rb index 6a7c9f5bf3..989e7e610a 100644 --- a/app/controllers/api/v1/admin/tags_controller.rb +++ b/app/controllers/api/v1/admin/tags_controller.rb @@ -56,12 +56,8 @@ class Api::V1::Admin::TagsController < Api::BaseController api_v1_admin_tags_url(pagination_params(min_id: pagination_since_id)) unless @tags.empty? end - def pagination_max_id - @tags.last.id - end - - def pagination_since_id - @tags.first.id + def pagination_collection + @tags end def records_continue? diff --git a/app/controllers/api/v1/admin/trends/links/preview_card_providers_controller.rb b/app/controllers/api/v1/admin/trends/links/preview_card_providers_controller.rb index 5d9fcc82c0..7ab7e6bd04 100644 --- a/app/controllers/api/v1/admin/trends/links/preview_card_providers_controller.rb +++ b/app/controllers/api/v1/admin/trends/links/preview_card_providers_controller.rb @@ -54,12 +54,8 @@ class Api::V1::Admin::Trends::Links::PreviewCardProvidersController < Api::BaseC api_v1_admin_trends_links_preview_card_providers_url(pagination_params(min_id: pagination_since_id)) unless @providers.empty? end - def pagination_max_id - @providers.last.id - end - - def pagination_since_id - @providers.first.id + def pagination_collection + @providers end def records_continue? diff --git a/app/controllers/api/v1/blocks_controller.rb b/app/controllers/api/v1/blocks_controller.rb index 0934622f88..7826a3c681 100644 --- a/app/controllers/api/v1/blocks_controller.rb +++ b/app/controllers/api/v1/blocks_controller.rb @@ -40,12 +40,8 @@ class Api::V1::BlocksController < Api::BaseController api_v1_blocks_url pagination_params(since_id: pagination_since_id) unless paginated_blocks.empty? end - def pagination_max_id - paginated_blocks.last.id - end - - def pagination_since_id - paginated_blocks.first.id + def pagination_collection + paginated_blocks end def records_continue? diff --git a/app/controllers/api/v1/bookmarks_controller.rb b/app/controllers/api/v1/bookmarks_controller.rb index 498eb16f44..08d3cf8344 100644 --- a/app/controllers/api/v1/bookmarks_controller.rb +++ b/app/controllers/api/v1/bookmarks_controller.rb @@ -43,12 +43,8 @@ class Api::V1::BookmarksController < Api::BaseController api_v1_bookmarks_url pagination_params(min_id: pagination_since_id) unless results.empty? end - def pagination_max_id - results.last.id - end - - def pagination_since_id - results.first.id + def pagination_collection + results end def records_continue? diff --git a/app/controllers/api/v1/crypto/encrypted_messages_controller.rb b/app/controllers/api/v1/crypto/encrypted_messages_controller.rb index 68cf4384f7..c70ae46d18 100644 --- a/app/controllers/api/v1/crypto/encrypted_messages_controller.rb +++ b/app/controllers/api/v1/crypto/encrypted_messages_controller.rb @@ -41,12 +41,8 @@ class Api::V1::Crypto::EncryptedMessagesController < Api::BaseController api_v1_crypto_encrypted_messages_url pagination_params(min_id: pagination_since_id) unless @encrypted_messages.empty? end - def pagination_max_id - @encrypted_messages.last.id - end - - def pagination_since_id - @encrypted_messages.first.id + def pagination_collection + @encrypted_messages end def records_continue? diff --git a/app/controllers/api/v1/domain_blocks_controller.rb b/app/controllers/api/v1/domain_blocks_controller.rb index 34def3c44a..5774c4d1c7 100644 --- a/app/controllers/api/v1/domain_blocks_controller.rb +++ b/app/controllers/api/v1/domain_blocks_controller.rb @@ -50,12 +50,8 @@ class Api::V1::DomainBlocksController < Api::BaseController api_v1_domain_blocks_url pagination_params(since_id: pagination_since_id) unless @blocks.empty? end - def pagination_max_id - @blocks.last.id - end - - def pagination_since_id - @blocks.first.id + def pagination_collection + @blocks end def records_continue? diff --git a/app/controllers/api/v1/endorsements_controller.rb b/app/controllers/api/v1/endorsements_controller.rb index 2216a9860d..449a9ac245 100644 --- a/app/controllers/api/v1/endorsements_controller.rb +++ b/app/controllers/api/v1/endorsements_controller.rb @@ -44,12 +44,8 @@ class Api::V1::EndorsementsController < Api::BaseController api_v1_endorsements_url pagination_params(since_id: pagination_since_id) unless @accounts.empty? end - def pagination_max_id - @accounts.last.id - end - - def pagination_since_id - @accounts.first.id + def pagination_collection + @accounts end def records_continue? diff --git a/app/controllers/api/v1/favourites_controller.rb b/app/controllers/api/v1/favourites_controller.rb index faf1bda96a..85e46b1166 100644 --- a/app/controllers/api/v1/favourites_controller.rb +++ b/app/controllers/api/v1/favourites_controller.rb @@ -43,12 +43,8 @@ class Api::V1::FavouritesController < Api::BaseController api_v1_favourites_url pagination_params(min_id: pagination_since_id) unless results.empty? end - def pagination_max_id - results.last.id - end - - def pagination_since_id - results.first.id + def pagination_collection + results end def records_continue? diff --git a/app/controllers/api/v1/followed_tags_controller.rb b/app/controllers/api/v1/followed_tags_controller.rb index eae2bdc010..0ea4a95ef5 100644 --- a/app/controllers/api/v1/followed_tags_controller.rb +++ b/app/controllers/api/v1/followed_tags_controller.rb @@ -34,12 +34,8 @@ class Api::V1::FollowedTagsController < Api::BaseController api_v1_followed_tags_url pagination_params(since_id: pagination_since_id) unless @results.empty? end - def pagination_max_id - @results.last.id - end - - def pagination_since_id - @results.first.id + def pagination_collection + @results end def records_continue? diff --git a/app/controllers/api/v1/lists/accounts_controller.rb b/app/controllers/api/v1/lists/accounts_controller.rb index 0604ad60fc..5ae74bf04d 100644 --- a/app/controllers/api/v1/lists/accounts_controller.rb +++ b/app/controllers/api/v1/lists/accounts_controller.rb @@ -71,12 +71,8 @@ class Api::V1::Lists::AccountsController < Api::BaseController api_v1_list_accounts_url pagination_params(since_id: pagination_since_id) unless @accounts.empty? end - def pagination_max_id - @accounts.last.id - end - - def pagination_since_id - @accounts.first.id + def pagination_collection + @accounts end def records_continue? diff --git a/app/controllers/api/v1/mutes_controller.rb b/app/controllers/api/v1/mutes_controller.rb index 2fb685ac39..9542d96110 100644 --- a/app/controllers/api/v1/mutes_controller.rb +++ b/app/controllers/api/v1/mutes_controller.rb @@ -40,12 +40,8 @@ class Api::V1::MutesController < Api::BaseController api_v1_mutes_url pagination_params(since_id: pagination_since_id) unless paginated_mutes.empty? end - def pagination_max_id - paginated_mutes.last.id - end - - def pagination_since_id - paginated_mutes.first.id + def pagination_collection + paginated_mutes end def records_continue? diff --git a/app/controllers/api/v1/notifications_controller.rb b/app/controllers/api/v1/notifications_controller.rb index 52280ef607..777740751f 100644 --- a/app/controllers/api/v1/notifications_controller.rb +++ b/app/controllers/api/v1/notifications_controller.rb @@ -70,12 +70,8 @@ class Api::V1::NotificationsController < Api::BaseController api_v1_notifications_url pagination_params(min_id: pagination_since_id) unless @notifications.empty? end - def pagination_max_id - @notifications.last.id - end - - def pagination_since_id - @notifications.first.id + def pagination_collection + @notifications end def browserable_params diff --git a/app/controllers/api/v1/scheduled_statuses_controller.rb b/app/controllers/api/v1/scheduled_statuses_controller.rb index 2220b6d22e..f6c0703833 100644 --- a/app/controllers/api/v1/scheduled_statuses_controller.rb +++ b/app/controllers/api/v1/scheduled_statuses_controller.rb @@ -63,11 +63,7 @@ class Api::V1::ScheduledStatusesController < Api::BaseController @statuses.size == limit_param(DEFAULT_STATUSES_LIMIT) end - def pagination_max_id - @statuses.last.id - end - - def pagination_since_id - @statuses.first.id + def pagination_collection + @statuses end end diff --git a/app/controllers/api/v1/timelines/base_controller.rb b/app/controllers/api/v1/timelines/base_controller.rb index 173e173cc9..7735cf1dc0 100644 --- a/app/controllers/api/v1/timelines/base_controller.rb +++ b/app/controllers/api/v1/timelines/base_controller.rb @@ -9,12 +9,8 @@ class Api::V1::Timelines::BaseController < Api::BaseController set_pagination_headers(next_path, prev_path) end - def pagination_max_id - @statuses.last.id - end - - def pagination_since_id - @statuses.first.id + def pagination_collection + @statuses end def next_path_params From 7e6eb64f1e89179f49ebdaddab7f96ac3f53ad05 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 13 Mar 2024 04:56:37 -0400 Subject: [PATCH 10/11] Use full snowflake range in `admin/metrics` classes (#29416) --- .../admin/metrics/dimension/instance_languages_dimension.rb | 4 ++-- app/lib/admin/metrics/dimension/servers_dimension.rb | 4 ++-- app/lib/admin/metrics/dimension/tag_languages_dimension.rb | 4 ++-- app/lib/admin/metrics/dimension/tag_servers_dimension.rb | 4 ++-- app/lib/admin/metrics/measure/instance_statuses_measure.rb | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/lib/admin/metrics/dimension/instance_languages_dimension.rb b/app/lib/admin/metrics/dimension/instance_languages_dimension.rb index b478213808..661e6d93b7 100644 --- a/app/lib/admin/metrics/dimension/instance_languages_dimension.rb +++ b/app/lib/admin/metrics/dimension/instance_languages_dimension.rb @@ -37,11 +37,11 @@ class Admin::Metrics::Dimension::InstanceLanguagesDimension < Admin::Metrics::Di end def earliest_status_id - Mastodon::Snowflake.id_at(@start_at, with_random: false) + Mastodon::Snowflake.id_at(@start_at.beginning_of_day, with_random: false) end def latest_status_id - Mastodon::Snowflake.id_at(@end_at, with_random: false) + Mastodon::Snowflake.id_at(@end_at.end_of_day, with_random: false) end def params diff --git a/app/lib/admin/metrics/dimension/servers_dimension.rb b/app/lib/admin/metrics/dimension/servers_dimension.rb index 42aba8e213..2c8406d52f 100644 --- a/app/lib/admin/metrics/dimension/servers_dimension.rb +++ b/app/lib/admin/metrics/dimension/servers_dimension.rb @@ -30,10 +30,10 @@ class Admin::Metrics::Dimension::ServersDimension < Admin::Metrics::Dimension::B end def earliest_status_id - Mastodon::Snowflake.id_at(@start_at) + Mastodon::Snowflake.id_at(@start_at.beginning_of_day, with_random: false) end def latest_status_id - Mastodon::Snowflake.id_at(@end_at) + Mastodon::Snowflake.id_at(@end_at.end_of_day, with_random: false) end end diff --git a/app/lib/admin/metrics/dimension/tag_languages_dimension.rb b/app/lib/admin/metrics/dimension/tag_languages_dimension.rb index cd077ff863..6e283d2c65 100644 --- a/app/lib/admin/metrics/dimension/tag_languages_dimension.rb +++ b/app/lib/admin/metrics/dimension/tag_languages_dimension.rb @@ -40,11 +40,11 @@ class Admin::Metrics::Dimension::TagLanguagesDimension < Admin::Metrics::Dimensi end def earliest_status_id - Mastodon::Snowflake.id_at(@start_at, with_random: false) + Mastodon::Snowflake.id_at(@start_at.beginning_of_day, with_random: false) end def latest_status_id - Mastodon::Snowflake.id_at(@end_at, with_random: false) + Mastodon::Snowflake.id_at(@end_at.end_of_day, with_random: false) end def params diff --git a/app/lib/admin/metrics/dimension/tag_servers_dimension.rb b/app/lib/admin/metrics/dimension/tag_servers_dimension.rb index fc5e49a966..db820e965c 100644 --- a/app/lib/admin/metrics/dimension/tag_servers_dimension.rb +++ b/app/lib/admin/metrics/dimension/tag_servers_dimension.rb @@ -40,11 +40,11 @@ class Admin::Metrics::Dimension::TagServersDimension < Admin::Metrics::Dimension end def earliest_status_id - Mastodon::Snowflake.id_at(@start_at, with_random: false) + Mastodon::Snowflake.id_at(@start_at.beginning_of_day, with_random: false) end def latest_status_id - Mastodon::Snowflake.id_at(@end_at, with_random: false) + Mastodon::Snowflake.id_at(@end_at.end_of_day, with_random: false) end def params diff --git a/app/lib/admin/metrics/measure/instance_statuses_measure.rb b/app/lib/admin/metrics/measure/instance_statuses_measure.rb index 8c71c66145..b918a30a57 100644 --- a/app/lib/admin/metrics/measure/instance_statuses_measure.rb +++ b/app/lib/admin/metrics/measure/instance_statuses_measure.rb @@ -51,11 +51,11 @@ class Admin::Metrics::Measure::InstanceStatusesMeasure < Admin::Metrics::Measure end def earliest_status_id - Mastodon::Snowflake.id_at(@start_at, with_random: false) + Mastodon::Snowflake.id_at(@start_at.beginning_of_day, with_random: false) end def latest_status_id - Mastodon::Snowflake.id_at(@end_at, with_random: false) + Mastodon::Snowflake.id_at(@end_at.end_of_day, with_random: false) end def time_period From 2c0441acd7f943a9873b650cf75d33c73d545acf Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 13 Mar 2024 05:19:54 -0400 Subject: [PATCH 11/11] Use rails built-in `tag` methods in `TextFormatter.shortened_link` (#28976) --- app/lib/text_formatter.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/lib/text_formatter.rb b/app/lib/text_formatter.rb index 581ee835b3..2b3febc219 100644 --- a/app/lib/text_formatter.rb +++ b/app/lib/text_formatter.rb @@ -50,6 +50,7 @@ class TextFormatter class << self include ERB::Util + include ActionView::Helpers::TagHelper def shortened_link(url, rel_me: false) url = Addressable::URI.parse(url).to_s @@ -60,9 +61,11 @@ class TextFormatter suffix = url[prefix.length + 30..] cutoff = url[prefix.length..].length > 30 - <<~HTML.squish.html_safe # rubocop:disable Rails/OutputSafety - #{h(display_url)} - HTML + tag.a href: url, target: '_blank', rel: rel.join(' '), translate: 'no' do + tag.span(prefix, class: 'invisible') + + tag.span(display_url, class: (cutoff ? 'ellipsis' : '')) + + tag.span(suffix, class: 'invisible') + end rescue Addressable::URI::InvalidURIError, IDN::Idna::IdnaError h(url) end