Merge remote-tracking branch 'parent/main' into upstream-20231116
This commit is contained in:
commit
0704829a9b
80 changed files with 1483 additions and 1117 deletions
|
@ -20,8 +20,7 @@ RSpec.describe Admin::AccountsController do
|
|||
it 'filters with parameters' do
|
||||
account_filter = instance_double(AccountFilter, results: Account.all)
|
||||
allow(AccountFilter).to receive(:new).and_return(account_filter)
|
||||
|
||||
get :index, params: {
|
||||
params = {
|
||||
origin: 'local',
|
||||
by_domain: 'domain',
|
||||
status: 'active',
|
||||
|
@ -31,17 +30,9 @@ RSpec.describe Admin::AccountsController do
|
|||
ip: '0.0.0.42',
|
||||
}
|
||||
|
||||
expect(AccountFilter).to have_received(:new) do |params|
|
||||
h = params.to_h
|
||||
get :index, params: params
|
||||
|
||||
expect(h[:origin]).to eq 'local'
|
||||
expect(h[:by_domain]).to eq 'domain'
|
||||
expect(h[:status]).to eq 'active'
|
||||
expect(h[:username]).to eq 'username'
|
||||
expect(h[:display_name]).to eq 'display name'
|
||||
expect(h[:email]).to eq 'local-part@domain'
|
||||
expect(h[:ip]).to eq '0.0.0.42'
|
||||
end
|
||||
expect(AccountFilter).to have_received(:new).with(hash_including(params))
|
||||
end
|
||||
|
||||
it 'paginates accounts' do
|
||||
|
|
|
@ -2,14 +2,44 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Api::V1::Trends::LinksController do
|
||||
RSpec.describe Api::V1::Trends::LinksController do
|
||||
render_views
|
||||
|
||||
describe 'GET #index' do
|
||||
it 'returns http success' do
|
||||
get :index
|
||||
around do |example|
|
||||
previous = Setting.trends
|
||||
example.run
|
||||
Setting.trends = previous
|
||||
end
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
context 'when trends are disabled' do
|
||||
before { Setting.trends = false }
|
||||
|
||||
it 'returns http success' do
|
||||
get :index
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when trends are enabled' do
|
||||
before { Setting.trends = true }
|
||||
|
||||
it 'returns http success' do
|
||||
prepare_trends
|
||||
stub_const('Api::V1::Trends::LinksController::DEFAULT_LINKS_LIMIT', 2)
|
||||
get :index
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response.headers).to include('Link')
|
||||
end
|
||||
|
||||
def prepare_trends
|
||||
Fabricate.times(3, :preview_card, trendable: true, language: 'en').each do |link|
|
||||
2.times { |i| Trends.links.add(link, i) }
|
||||
end
|
||||
Trends::Links.new(threshold: 1).refresh
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,14 +2,44 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Api::V1::Trends::StatusesController do
|
||||
RSpec.describe Api::V1::Trends::StatusesController do
|
||||
render_views
|
||||
|
||||
describe 'GET #index' do
|
||||
it 'returns http success' do
|
||||
get :index
|
||||
around do |example|
|
||||
previous = Setting.trends
|
||||
example.run
|
||||
Setting.trends = previous
|
||||
end
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
context 'when trends are disabled' do
|
||||
before { Setting.trends = false }
|
||||
|
||||
it 'returns http success' do
|
||||
get :index
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when trends are enabled' do
|
||||
before { Setting.trends = true }
|
||||
|
||||
it 'returns http success' do
|
||||
prepare_trends
|
||||
stub_const('Api::BaseController::DEFAULT_STATUSES_LIMIT', 2)
|
||||
get :index
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response.headers).to include('Link')
|
||||
end
|
||||
|
||||
def prepare_trends
|
||||
Fabricate.times(3, :status, trendable: true, language: 'en').each do |status|
|
||||
2.times { |i| Trends.statuses.add(status, i) }
|
||||
end
|
||||
Trends::Statuses.new(threshold: 1, decay_threshold: -1).refresh
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,16 +6,41 @@ RSpec.describe Api::V1::Trends::TagsController do
|
|||
render_views
|
||||
|
||||
describe 'GET #index' do
|
||||
before do
|
||||
Fabricate.times(10, :tag).each do |tag|
|
||||
10.times { |i| Trends.tags.add(tag, i) }
|
||||
end
|
||||
|
||||
get :index
|
||||
around do |example|
|
||||
previous = Setting.trends
|
||||
example.run
|
||||
Setting.trends = previous
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
expect(response).to have_http_status(200)
|
||||
context 'when trends are disabled' do
|
||||
before { Setting.trends = false }
|
||||
|
||||
it 'returns http success' do
|
||||
get :index
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response.headers).to_not include('Link')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when trends are enabled' do
|
||||
before { Setting.trends = true }
|
||||
|
||||
it 'returns http success' do
|
||||
prepare_trends
|
||||
stub_const('Api::V1::Trends::TagsController::DEFAULT_TAGS_LIMIT', 2)
|
||||
get :index
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response.headers).to include('Link')
|
||||
end
|
||||
|
||||
def prepare_trends
|
||||
Fabricate.times(3, :tag, trendable: true).each do |tag|
|
||||
2.times { |i| Trends.tags.add(tag, i) }
|
||||
end
|
||||
Trends::Tags.new(threshold: 1).refresh
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -49,10 +49,12 @@ describe MediaComponentHelper do
|
|||
end
|
||||
|
||||
describe 'render_card_component' do
|
||||
let(:status) { Fabricate(:status, preview_cards: [Fabricate(:preview_card)]) }
|
||||
let(:status) { Fabricate(:status) }
|
||||
let(:result) { helper.render_card_component(status) }
|
||||
|
||||
before do
|
||||
PreviewCardsStatus.create(status: status, preview_card: Fabricate(:preview_card))
|
||||
|
||||
without_partial_double_verification do
|
||||
allow(helper).to receive(:current_account).and_return(status.account)
|
||||
end
|
||||
|
|
|
@ -5,6 +5,37 @@ require 'rails_helper'
|
|||
RSpec.describe Webhook do
|
||||
let(:webhook) { Fabricate(:webhook) }
|
||||
|
||||
describe 'Validations' do
|
||||
it 'requires presence of events' do
|
||||
record = described_class.new(events: nil)
|
||||
record.valid?
|
||||
|
||||
expect(record).to model_have_error_on_field(:events)
|
||||
end
|
||||
|
||||
it 'requires non-empty events value' do
|
||||
record = described_class.new(events: [])
|
||||
record.valid?
|
||||
|
||||
expect(record).to model_have_error_on_field(:events)
|
||||
end
|
||||
|
||||
it 'requires valid events value from EVENTS' do
|
||||
record = described_class.new(events: ['account.invalid'])
|
||||
record.valid?
|
||||
|
||||
expect(record).to model_have_error_on_field(:events)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Normalizations' do
|
||||
it 'cleans up events values' do
|
||||
record = described_class.new(events: ['account.approved', 'account.created ', ''])
|
||||
|
||||
expect(record.events).to eq(%w(account.approved account.created))
|
||||
end
|
||||
end
|
||||
|
||||
describe '#rotate_secret!' do
|
||||
it 'changes the secret' do
|
||||
previous_value = webhook.secret
|
||||
|
|
27
spec/requests/invite_spec.rb
Normal file
27
spec/requests/invite_spec.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'invites' do
|
||||
let(:invite) { Fabricate(:invite) }
|
||||
|
||||
context 'when requesting a JSON document' do
|
||||
it 'returns a JSON document with expected attributes' do
|
||||
get "/invite/#{invite.code}", headers: { 'Accept' => 'application/activity+json' }
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response.media_type).to eq 'application/json'
|
||||
|
||||
expect(body_as_json[:invite_code]).to eq invite.code
|
||||
end
|
||||
end
|
||||
|
||||
context 'when not requesting a JSON document' do
|
||||
it 'returns an HTML page' do
|
||||
get "/invite/#{invite.code}"
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response.media_type).to eq 'text/html'
|
||||
end
|
||||
end
|
||||
end
|
|
@ -10,46 +10,72 @@ RSpec.describe AppSignUpService, type: :service do
|
|||
let(:remote_ip) { IPAddr.new('198.0.2.1') }
|
||||
|
||||
describe '#call' do
|
||||
it 'returns nil when registrations are closed' do
|
||||
tmp = Setting.registrations_mode
|
||||
Setting.registrations_mode = 'none'
|
||||
expect { subject.call(app, remote_ip, good_params) }.to raise_error Mastodon::NotPermittedError
|
||||
Setting.registrations_mode = tmp
|
||||
let(:params) { good_params }
|
||||
|
||||
shared_examples 'successful registration' do
|
||||
it 'creates an unconfirmed user with access token and the app\'s scope', :aggregate_failures do
|
||||
access_token = subject.call(app, remote_ip, params)
|
||||
expect(access_token).to_not be_nil
|
||||
expect(access_token.scopes.to_s).to eq 'read write'
|
||||
|
||||
user = User.find_by(id: access_token.resource_owner_id)
|
||||
expect(user).to_not be_nil
|
||||
expect(user.confirmed?).to be false
|
||||
|
||||
expect(user.account).to_not be_nil
|
||||
expect(user.invite_request).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'when registrations are closed' do
|
||||
around do |example|
|
||||
tmp = Setting.registrations_mode
|
||||
Setting.registrations_mode = 'none'
|
||||
|
||||
example.run
|
||||
|
||||
Setting.registrations_mode = tmp
|
||||
end
|
||||
|
||||
it 'raises an error', :aggregate_failures do
|
||||
expect { subject.call(app, remote_ip, good_params) }.to raise_error Mastodon::NotPermittedError
|
||||
end
|
||||
|
||||
context 'when using a valid invite' do
|
||||
let(:params) { good_params.merge({ invite_code: invite.code }) }
|
||||
let(:invite) { Fabricate(:invite) }
|
||||
|
||||
before do
|
||||
invite.user.approve!
|
||||
end
|
||||
|
||||
it_behaves_like 'successful registration'
|
||||
end
|
||||
|
||||
context 'when using an invalid invite' do
|
||||
let(:params) { good_params.merge({ invite_code: invite.code }) }
|
||||
let(:invite) { Fabricate(:invite, uses: 1, max_uses: 1) }
|
||||
|
||||
it 'raises an error', :aggregate_failures do
|
||||
expect { subject.call(app, remote_ip, params) }.to raise_error Mastodon::NotPermittedError
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it 'raises an error when params are missing' do
|
||||
expect { subject.call(app, remote_ip, {}) }.to raise_error ActiveRecord::RecordInvalid
|
||||
end
|
||||
|
||||
it 'creates an unconfirmed user with access token' do
|
||||
access_token = subject.call(app, remote_ip, good_params)
|
||||
expect(access_token).to_not be_nil
|
||||
user = User.find_by(id: access_token.resource_owner_id)
|
||||
expect(user).to_not be_nil
|
||||
expect(user.confirmed?).to be false
|
||||
end
|
||||
it_behaves_like 'successful registration'
|
||||
|
||||
it 'creates access token with the app\'s scopes' do
|
||||
access_token = subject.call(app, remote_ip, good_params)
|
||||
expect(access_token).to_not be_nil
|
||||
expect(access_token.scopes.to_s).to eq 'read write'
|
||||
end
|
||||
|
||||
it 'creates an account' do
|
||||
access_token = subject.call(app, remote_ip, good_params)
|
||||
expect(access_token).to_not be_nil
|
||||
user = User.find_by(id: access_token.resource_owner_id)
|
||||
expect(user).to_not be_nil
|
||||
expect(user.account).to_not be_nil
|
||||
expect(user.invite_request).to be_nil
|
||||
end
|
||||
|
||||
it 'creates an account with invite request text' do
|
||||
access_token = subject.call(app, remote_ip, good_params.merge(reason: 'Foo bar'))
|
||||
expect(access_token).to_not be_nil
|
||||
user = User.find_by(id: access_token.resource_owner_id)
|
||||
expect(user).to_not be_nil
|
||||
expect(user.invite_request&.text).to eq 'Foo bar'
|
||||
context 'when given an invite request text' do
|
||||
it 'creates an account with invite request text' do
|
||||
access_token = subject.call(app, remote_ip, good_params.merge(reason: 'Foo bar'))
|
||||
expect(access_token).to_not be_nil
|
||||
user = User.find_by(id: access_token.resource_owner_id)
|
||||
expect(user).to_not be_nil
|
||||
expect(user.invite_request&.text).to eq 'Foo bar'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -121,7 +121,7 @@ RSpec.describe FetchLinkCardService, type: :service do
|
|||
let(:status) { Fabricate(:status, text: 'Check out http://example.com/sjis') }
|
||||
|
||||
it 'decodes the HTML' do
|
||||
expect(status.preview_cards.first.title).to eq('SJISのページ')
|
||||
expect(status.preview_card.title).to eq('SJISのページ')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -129,7 +129,7 @@ RSpec.describe FetchLinkCardService, type: :service do
|
|||
let(:status) { Fabricate(:status, text: 'Check out http://example.com/sjis_with_wrong_charset') }
|
||||
|
||||
it 'decodes the HTML despite the wrong charset header' do
|
||||
expect(status.preview_cards.first.title).to eq('SJISのページ')
|
||||
expect(status.preview_card.title).to eq('SJISのページ')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -137,7 +137,7 @@ RSpec.describe FetchLinkCardService, type: :service do
|
|||
let(:status) { Fabricate(:status, text: 'Check out http://example.com/koi8-r') }
|
||||
|
||||
it 'decodes the HTML' do
|
||||
expect(status.preview_cards.first.title).to eq('Московя начинаетъ только въ XVI ст. привлекать внимане иностранцевъ.')
|
||||
expect(status.preview_card.title).to eq('Московя начинаетъ только въ XVI ст. привлекать внимане иностранцевъ.')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -145,7 +145,7 @@ RSpec.describe FetchLinkCardService, type: :service do
|
|||
let(:status) { Fabricate(:status, text: 'Check out http://example.com/windows-1251') }
|
||||
|
||||
it 'decodes the HTML' do
|
||||
expect(status.preview_cards.first.title).to eq('сэмпл текст')
|
||||
expect(status.preview_card.title).to eq('сэмпл текст')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -253,11 +253,21 @@ RSpec.describe FetchLinkCardService, type: :service do
|
|||
expect(status.preview_card.title).to eq 'Hello world'
|
||||
end
|
||||
end
|
||||
|
||||
context 'with URL but author is not allow preview card' do
|
||||
let(:account) { Fabricate(:user, settings: { link_preview: false }).account }
|
||||
let(:status) { Fabricate(:status, text: 'http://example.com/html', account: account) }
|
||||
|
||||
it 'not create preview card' do
|
||||
expect(status.preview_card).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a remote status' do
|
||||
let(:account) { Fabricate(:account, domain: 'example.com') }
|
||||
let(:status) do
|
||||
Fabricate(:status, account: Fabricate(:account, domain: 'example.com'), text: <<-TEXT)
|
||||
Fabricate(:status, account: account, text: <<-TEXT)
|
||||
Habt ihr ein paar gute Links zu <a>foo</a>
|
||||
#<span class="tag"><a href="https://quitter.se/tag/wannacry" target="_blank" rel="tag noopener noreferrer" title="https://quitter.se/tag/wannacry">Wannacry</a></span> herumfliegen?
|
||||
Ich will mal unter <br> <a href="http://example.com/not-found" target="_blank" rel="noopener noreferrer" title="http://example.com/not-found">http://example.com/not-found</a> was sammeln. !
|
||||
|
@ -272,6 +282,14 @@ RSpec.describe FetchLinkCardService, type: :service do
|
|||
it 'ignores URLs to hashtags' do
|
||||
expect(a_request(:get, 'https://quitter.se/tag/wannacry')).to_not have_been_made
|
||||
end
|
||||
|
||||
context 'with URL but author is not allow preview card' do
|
||||
let(:account) { Fabricate(:account, domain: 'example.com', settings: { link_preview: false }) }
|
||||
|
||||
it 'not create link preview' do
|
||||
expect(status.preview_card).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a remote status of reference' do
|
||||
|
|
|
@ -23,11 +23,11 @@ RSpec.describe UpdateStatusService, type: :service do
|
|||
end
|
||||
|
||||
context 'when text changes' do
|
||||
let!(:status) { Fabricate(:status, text: 'Foo') }
|
||||
let(:status) { Fabricate(:status, text: 'Foo') }
|
||||
let(:preview_card) { Fabricate(:preview_card) }
|
||||
|
||||
before do
|
||||
status.preview_cards << preview_card
|
||||
PreviewCardsStatus.create(status: status, preview_card: preview_card)
|
||||
subject.call(status, status.account_id, text: 'Bar')
|
||||
end
|
||||
|
||||
|
@ -45,11 +45,11 @@ RSpec.describe UpdateStatusService, type: :service do
|
|||
end
|
||||
|
||||
context 'when content warning changes' do
|
||||
let!(:status) { Fabricate(:status, text: 'Foo', spoiler_text: '') }
|
||||
let(:status) { Fabricate(:status, text: 'Foo', spoiler_text: '') }
|
||||
let(:preview_card) { Fabricate(:preview_card) }
|
||||
|
||||
before do
|
||||
status.preview_cards << preview_card
|
||||
PreviewCardsStatus.create(status: status, preview_card: preview_card)
|
||||
subject.call(status, status.account_id, text: 'Foo', spoiler_text: 'Bar')
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue