diff options
author | Claire <claire.github-309c@sitedethib.com> | 2022-11-06 18:49:46 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-06 18:49:46 +0100 |
commit | 54101563bbadbfafd9291a867d7fbea6df3a8b7b (patch) | |
tree | fcf9a125f6ebc3ad4182fa0edcbd7101b33aebb0 /spec | |
parent | 2f8fb49d1314db931385089bc9004a48700161ad (diff) | |
parent | 21d6bc16893a9dd24c5ef54cf2f554846c8eca5b (diff) |
Merge pull request #1892 from ClearlyClaire/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/admin/action_logs_controller_spec.rb | 13 | ||||
-rw-r--r-- | spec/fabricators/assets/utah_teapot.png | bin | 248232 -> 195600 bytes | |||
-rw-r--r-- | spec/fixtures/files/emojo.png | bin | 29814 -> 29283 bytes | |||
-rw-r--r-- | spec/lib/status_cache_hydrator_spec.rb | 123 | ||||
-rw-r--r-- | spec/models/media_attachment_spec.rb | 6 | ||||
-rw-r--r-- | spec/services/account_search_service_spec.rb | 1 | ||||
-rw-r--r-- | spec/services/process_mentions_service_spec.rb | 100 |
7 files changed, 203 insertions, 40 deletions
diff --git a/spec/controllers/admin/action_logs_controller_spec.rb b/spec/controllers/admin/action_logs_controller_spec.rb index c1957258f..7cd8cdf46 100644 --- a/spec/controllers/admin/action_logs_controller_spec.rb +++ b/spec/controllers/admin/action_logs_controller_spec.rb @@ -3,6 +3,19 @@ require 'rails_helper' describe Admin::ActionLogsController, type: :controller do + render_views + + # Action logs typically cause issues when their targets are not in the database + let!(:account) { Fabricate(:account) } + + let!(:orphaned_logs) do + %w( + Account User UserRole Report DomainBlock DomainAllow + EmailDomainBlock UnavailableDomain Status AccountWarning + Announcement IpBlock Instance CustomEmoji CanonicalEmailBlock Appeal + ).map { |type| Admin::ActionLog.new(account: account, action: 'destroy', target_type: type, target_id: 1312).save! } + end + describe 'GET #index' do it 'returns 200' do sign_in Fabricate(:user, role: UserRole.find_by(name: 'Admin')) diff --git a/spec/fabricators/assets/utah_teapot.png b/spec/fabricators/assets/utah_teapot.png index 6708361e5..ccf202de4 100644 --- a/spec/fabricators/assets/utah_teapot.png +++ b/spec/fabricators/assets/utah_teapot.png Binary files differdiff --git a/spec/fixtures/files/emojo.png b/spec/fixtures/files/emojo.png index cb5993499..6ef0a5fbc 100644 --- a/spec/fixtures/files/emojo.png +++ b/spec/fixtures/files/emojo.png Binary files differdiff --git a/spec/lib/status_cache_hydrator_spec.rb b/spec/lib/status_cache_hydrator_spec.rb new file mode 100644 index 000000000..c9d8d0fe1 --- /dev/null +++ b/spec/lib/status_cache_hydrator_spec.rb @@ -0,0 +1,123 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe StatusCacheHydrator do + let(:status) { Fabricate(:status) } + let(:account) { Fabricate(:account) } + + describe '#hydrate' do + let(:compare_to_hash) { InlineRenderer.render(status, account, :status) } + + shared_examples 'shared behavior' do + context 'when handling a new status' do + let(:poll) { Fabricate(:poll) } + let(:status) { Fabricate(:status, poll: poll) } + + it 'renders the same attributes as a full render' do + expect(subject).to eql(compare_to_hash) + end + end + + context 'when handling a new status with own poll' do + let(:poll) { Fabricate(:poll, account: account) } + let(:status) { Fabricate(:status, poll: poll, account: account) } + + it 'renders the same attributes as a full render' do + expect(subject).to eql(compare_to_hash) + end + end + + context 'when handling a reblog' do + let(:reblog) { Fabricate(:status) } + let(:status) { Fabricate(:status, reblog: reblog) } + + context 'that has been favourited' do + before do + FavouriteService.new.call(account, reblog) + end + + it 'renders the same attributes as a full render' do + expect(subject).to eql(compare_to_hash) + end + end + + context 'that has been reblogged' do + before do + ReblogService.new.call(account, reblog) + end + + it 'renders the same attributes as a full render' do + expect(subject).to eql(compare_to_hash) + end + end + + context 'that has been pinned' do + let(:reblog) { Fabricate(:status, account: account) } + + before do + StatusPin.create!(account: account, status: reblog) + end + + it 'renders the same attributes as a full render' do + expect(subject).to eql(compare_to_hash) + end + end + + context 'that has been followed tags' do + let(:followed_tag) { Fabricate(:tag) } + + before do + reblog.tags << Fabricate(:tag) + reblog.tags << followed_tag + TagFollow.create!(tag: followed_tag, account: account, rate_limit: false) + end + + it 'renders the same attributes as a full render' do + expect(subject).to eql(compare_to_hash) + end + end + + context 'that has a poll authored by the user' do + let(:poll) { Fabricate(:poll, account: account) } + let(:reblog) { Fabricate(:status, poll: poll, account: account) } + + it 'renders the same attributes as a full render' do + expect(subject).to eql(compare_to_hash) + end + end + + context 'that has been voted in' do + let(:poll) { Fabricate(:poll, options: %w(Yellow Blue)) } + let(:reblog) { Fabricate(:status, poll: poll) } + + before do + VoteService.new.call(account, poll, [0]) + end + + it 'renders the same attributes as a full render' do + expect(subject).to eql(compare_to_hash) + end + end + end + end + + context 'when cache is warm' do + subject do + Rails.cache.write("fan-out/#{status.id}", InlineRenderer.render(status, nil, :status)) + described_class.new(status).hydrate(account.id) + end + + it_behaves_like 'shared behavior' + end + + context 'when cache is cold' do + subject do + Rails.cache.delete("fan-out/#{status.id}") + described_class.new(status).hydrate(account.id) + end + + it_behaves_like 'shared behavior' + end + end +end diff --git a/spec/models/media_attachment_spec.rb b/spec/models/media_attachment_spec.rb index cbd9a09c5..29fd313ae 100644 --- a/spec/models/media_attachment_spec.rb +++ b/spec/models/media_attachment_spec.rb @@ -157,9 +157,9 @@ RSpec.describe MediaAttachment, type: :model do expect(media.file.meta["original"]["width"]).to eq 600 expect(media.file.meta["original"]["height"]).to eq 400 expect(media.file.meta["original"]["aspect"]).to eq 1.5 - expect(media.file.meta["small"]["width"]).to eq 490 - expect(media.file.meta["small"]["height"]).to eq 327 - expect(media.file.meta["small"]["aspect"]).to eq 490.0 / 327 + expect(media.file.meta["small"]["width"]).to eq 588 + expect(media.file.meta["small"]["height"]).to eq 392 + expect(media.file.meta["small"]["aspect"]).to eq 1.5 end it 'gives the file a random name' do diff --git a/spec/services/account_search_service_spec.rb b/spec/services/account_search_service_spec.rb index 5b7182586..81cbc175e 100644 --- a/spec/services/account_search_service_spec.rb +++ b/spec/services/account_search_service_spec.rb @@ -45,7 +45,6 @@ describe AccountSearchService, type: :service do results = subject.call('e@example.com', nil, limit: 2) - expect(results.size).to eq 2 expect(results).to eq([exact, remote]).or eq([exact, remote_too]) end end diff --git a/spec/services/process_mentions_service_spec.rb b/spec/services/process_mentions_service_spec.rb index 89b265e9a..5b9d17a4c 100644 --- a/spec/services/process_mentions_service_spec.rb +++ b/spec/services/process_mentions_service_spec.rb @@ -1,43 +1,85 @@ require 'rails_helper' RSpec.describe ProcessMentionsService, type: :service do - let(:account) { Fabricate(:account, username: 'alice') } - let(:visibility) { :public } - let(:status) { Fabricate(:status, account: account, text: "Hello @#{remote_user.acct}", visibility: visibility) } + let(:account) { Fabricate(:account, username: 'alice') } subject { ProcessMentionsService.new } - context 'ActivityPub' do - context do - let!(:remote_user) { Fabricate(:account, username: 'remote_user', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox') } + context 'when mentions contain blocked accounts' do + let(:non_blocked_account) { Fabricate(:account) } + let(:individually_blocked_account) { Fabricate(:account) } + let(:domain_blocked_account) { Fabricate(:account, domain: 'evil.com') } + let(:status) { Fabricate(:status, account: account, text: "Hello @#{non_blocked_account.acct} @#{individually_blocked_account.acct} @#{domain_blocked_account.acct}", visibility: :public) } - before do - subject.call(status) - end + before do + account.block!(individually_blocked_account) + account.domain_blocks.create!(domain: domain_blocked_account.domain) - it 'creates a mention' do - expect(remote_user.mentions.where(status: status).count).to eq 1 - end + subject.call(status) + end + + it 'creates a mention to the non-blocked account' do + expect(non_blocked_account.mentions.where(status: status).count).to eq 1 end - context 'with an IDN domain' do - let!(:remote_user) { Fabricate(:account, username: 'sneak', protocol: :activitypub, domain: 'xn--hresiar-mxa.ch', inbox_url: 'http://example.com/inbox') } - let!(:status) { Fabricate(:status, account: account, text: "Hello @sneak@hæresiar.ch") } + it 'does not create a mention to the individually blocked account' do + expect(individually_blocked_account.mentions.where(status: status).count).to eq 0 + end - before do - subject.call(status) + it 'does not create a mention to the domain-blocked account' do + expect(domain_blocked_account.mentions.where(status: status).count).to eq 0 + end + end + + context 'resolving a mention to a remote account' do + let(:status) { Fabricate(:status, account: account, text: "Hello @#{remote_user.acct}", visibility: :public) } + + context 'ActivityPub' do + context do + let!(:remote_user) { Fabricate(:account, username: 'remote_user', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox') } + + before do + subject.call(status) + end + + it 'creates a mention' do + expect(remote_user.mentions.where(status: status).count).to eq 1 + end end - it 'creates a mention' do - expect(remote_user.mentions.where(status: status).count).to eq 1 + context 'with an IDN domain' do + let!(:remote_user) { Fabricate(:account, username: 'sneak', protocol: :activitypub, domain: 'xn--hresiar-mxa.ch', inbox_url: 'http://example.com/inbox') } + let!(:status) { Fabricate(:status, account: account, text: "Hello @sneak@hæresiar.ch") } + + before do + subject.call(status) + end + + it 'creates a mention' do + expect(remote_user.mentions.where(status: status).count).to eq 1 + end + end + + context 'with an IDN TLD' do + let!(:remote_user) { Fabricate(:account, username: 'foo', protocol: :activitypub, domain: 'xn--y9a3aq.xn--y9a3aq', inbox_url: 'http://example.com/inbox') } + let!(:status) { Fabricate(:status, account: account, text: "Hello @foo@հայ.հայ") } + + before do + subject.call(status) + end + + it 'creates a mention' do + expect(remote_user.mentions.where(status: status).count).to eq 1 + end end end - context 'with an IDN TLD' do - let!(:remote_user) { Fabricate(:account, username: 'foo', protocol: :activitypub, domain: 'xn--y9a3aq.xn--y9a3aq', inbox_url: 'http://example.com/inbox') } - let!(:status) { Fabricate(:status, account: account, text: "Hello @foo@հայ.հայ") } + context 'Temporarily-unreachable ActivityPub user' do + let!(:remote_user) { Fabricate(:account, username: 'remote_user', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox', last_webfingered_at: nil) } before do + stub_request(:get, "https://example.com/.well-known/host-meta").to_return(status: 404) + stub_request(:get, "https://example.com/.well-known/webfinger?resource=acct:remote_user@example.com").to_return(status: 500) subject.call(status) end @@ -46,18 +88,4 @@ RSpec.describe ProcessMentionsService, type: :service do end end end - - context 'Temporarily-unreachable ActivityPub user' do - let!(:remote_user) { Fabricate(:account, username: 'remote_user', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox', last_webfingered_at: nil) } - - before do - stub_request(:get, "https://example.com/.well-known/host-meta").to_return(status: 404) - stub_request(:get, "https://example.com/.well-known/webfinger?resource=acct:remote_user@example.com").to_return(status: 500) - subject.call(status) - end - - it 'creates a mention' do - expect(remote_user.mentions.where(status: status).count).to eq 1 - end - end end |