Merge remote-tracking branch 'parent/main' into upstream-20240201
This commit is contained in:
commit
92ef42d697
179 changed files with 1218 additions and 2902 deletions
|
@ -153,13 +153,9 @@ RSpec.describe Admin::AccountsController do
|
|||
context 'when user is admin' do
|
||||
let(:role) { UserRole.find_by(name: 'Admin') }
|
||||
|
||||
it 'succeeds in approving account' do
|
||||
it 'succeeds in approving account and logs action' do
|
||||
expect(subject).to redirect_to admin_accounts_path(status: 'pending')
|
||||
expect(user.reload).to be_approved
|
||||
end
|
||||
|
||||
it 'logs action' do
|
||||
expect(subject).to have_http_status 302
|
||||
|
||||
expect(latest_admin_action_log)
|
||||
.to be_present
|
||||
|
@ -195,12 +191,8 @@ RSpec.describe Admin::AccountsController do
|
|||
context 'when user is admin' do
|
||||
let(:role) { UserRole.find_by(name: 'Admin') }
|
||||
|
||||
it 'succeeds in rejecting account' do
|
||||
it 'succeeds in rejecting account and logs action' do
|
||||
expect(subject).to redirect_to admin_accounts_path(status: 'pending')
|
||||
end
|
||||
|
||||
it 'logs action' do
|
||||
expect(subject).to have_http_status 302
|
||||
|
||||
expect(latest_admin_action_log)
|
||||
.to be_present
|
||||
|
@ -286,12 +278,9 @@ RSpec.describe Admin::AccountsController do
|
|||
context 'when user is admin' do
|
||||
let(:role) { UserRole.find_by(name: 'Admin') }
|
||||
|
||||
it 'succeeds in removing email blocks' do
|
||||
it 'succeeds in removing email blocks and redirects to admin account path' do
|
||||
expect { subject }.to change { CanonicalEmailBlock.where(reference_account: account).count }.from(1).to(0)
|
||||
end
|
||||
|
||||
it 'redirects to admin account path' do
|
||||
subject
|
||||
expect(response).to redirect_to admin_account_path(account.id)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -60,16 +60,14 @@ describe Admin::StatusesController do
|
|||
shared_examples 'when action is report' do
|
||||
let(:action) { 'report' }
|
||||
|
||||
it 'creates a report' do
|
||||
it 'creates a report and redirects to report page' do
|
||||
subject
|
||||
|
||||
report = Report.last
|
||||
expect(report.target_account_id).to eq account.id
|
||||
expect(report.status_ids).to eq status_ids
|
||||
end
|
||||
|
||||
it 'redirects to report page' do
|
||||
subject
|
||||
expect(Report.last)
|
||||
.to have_attributes(
|
||||
target_account_id: eq(account.id),
|
||||
status_ids: eq(status_ids)
|
||||
)
|
||||
|
||||
expect(response).to redirect_to(admin_report_path(Report.last.id))
|
||||
end
|
||||
|
|
|
@ -39,11 +39,14 @@ describe Api::V1::Accounts::StatusesController do
|
|||
end
|
||||
|
||||
it 'returns posts along with self replies', :aggregate_failures do
|
||||
json = body_as_json
|
||||
post_ids = json.map { |item| item[:id].to_i }.sort
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(post_ids).to eq [status.id, status_self_reply.id]
|
||||
expect(response)
|
||||
.to have_http_status(200)
|
||||
expect(body_as_json)
|
||||
.to have_attributes(size: 2)
|
||||
.and contain_exactly(
|
||||
include(id: status.id.to_s),
|
||||
include(id: status_self_reply.id.to_s)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,78 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Api::V1::Statuses::MentionedAccountsController do
|
||||
render_views
|
||||
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:app) { Fabricate(:application, name: 'Test app', website: 'http://testapp.com') }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, application: app, scopes: 'read:accounts') }
|
||||
let(:alice) { Fabricate(:account) }
|
||||
let(:bob) { Fabricate(:account) }
|
||||
let(:ohagi) { Fabricate(:account) }
|
||||
|
||||
context 'with an oauth token' do
|
||||
before do
|
||||
allow(controller).to receive(:doorkeeper_token) { token }
|
||||
end
|
||||
|
||||
describe 'GET #index' do
|
||||
let(:status) { Fabricate(:status, account: user.account) }
|
||||
|
||||
before do
|
||||
Mention.create!(account: bob, status: status)
|
||||
Mention.create!(account: ohagi, status: status)
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
get :index, params: { status_id: status.id, limit: 2 }
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response.headers['Link'].links.size).to eq(2)
|
||||
end
|
||||
|
||||
it 'returns accounts who favorited the status' do
|
||||
get :index, params: { status_id: status.id, limit: 2 }
|
||||
expect(body_as_json.size).to eq 2
|
||||
expect([body_as_json[0][:id], body_as_json[1][:id]]).to contain_exactly(bob.id.to_s, ohagi.id.to_s)
|
||||
end
|
||||
|
||||
it 'does not return blocked users' do
|
||||
user.account.block!(ohagi)
|
||||
get :index, params: { status_id: status.id, limit: 2 }
|
||||
expect(body_as_json.size).to eq 1
|
||||
expect(body_as_json[0][:id]).to eq bob.id.to_s
|
||||
end
|
||||
|
||||
context 'when other accounts status' do
|
||||
let(:status) { Fabricate(:status, account: alice) }
|
||||
|
||||
it 'returns http unauthorized' do
|
||||
get :index, params: { status_id: status.id }
|
||||
expect(response).to have_http_status(404)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'without an oauth token' do
|
||||
before do
|
||||
allow(controller).to receive(:doorkeeper_token).and_return(nil)
|
||||
end
|
||||
|
||||
context 'with a public status' do
|
||||
let(:status) { Fabricate(:status, account: user.account, visibility: :public) }
|
||||
|
||||
describe 'GET #index' do
|
||||
before do
|
||||
Mention.create!(account: bob, status: status)
|
||||
end
|
||||
|
||||
it 'returns http unauthorized' do
|
||||
get :index, params: { status_id: status.id }
|
||||
expect(response).to have_http_status(404)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,78 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Api::V1::Timelines::PublicController do
|
||||
render_views
|
||||
|
||||
let!(:account) { Fabricate(:account) }
|
||||
let!(:user) { Fabricate(:user, account: account) }
|
||||
let!(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read') }
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:doorkeeper_token) { token }
|
||||
end
|
||||
|
||||
describe 'GET #show' do
|
||||
subject do
|
||||
get :show
|
||||
body_as_json
|
||||
end
|
||||
|
||||
let!(:local_account) { Fabricate(:account, domain: nil) }
|
||||
let!(:remote_account) { Fabricate(:account, domain: 'test.com') }
|
||||
let!(:local_status) { Fabricate(:status, account: local_account, text: 'ohagi is good') }
|
||||
let!(:remote_status) { Fabricate(:status, account: remote_account, text: 'ohagi is ohagi') }
|
||||
|
||||
it 'load statuses', :aggregate_failures do
|
||||
json = subject
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(json).to be_an Array
|
||||
expect(json.any? { |status| status[:id] == local_status.id.to_s }).to be true
|
||||
expect(json.any? { |status| status[:id] == remote_status.id.to_s }).to be true
|
||||
end
|
||||
|
||||
context 'with filter' do
|
||||
subject do
|
||||
get :show
|
||||
body_as_json.filter { |status| status[:filtered].empty? || status[:filtered][0][:filter][:id] != filter.id.to_s }.map { |status| status[:id].to_i }
|
||||
end
|
||||
|
||||
before do
|
||||
Fabricate(:custom_filter_keyword, custom_filter: filter, keyword: 'ohagi')
|
||||
Fabricate(:follow, account: account, target_account: remote_account)
|
||||
end
|
||||
|
||||
let(:exclude_follows) { false }
|
||||
let(:exclude_localusers) { false }
|
||||
let!(:filter) { Fabricate(:custom_filter, account: account, exclude_follows: exclude_follows, exclude_localusers: exclude_localusers) }
|
||||
|
||||
it 'load statuses', :aggregate_failures do
|
||||
ids = subject
|
||||
expect(ids).to_not include(local_status.id)
|
||||
expect(ids).to_not include(remote_status.id)
|
||||
end
|
||||
|
||||
context 'when exclude_followers' do
|
||||
let(:exclude_follows) { true }
|
||||
|
||||
it 'load statuses', :aggregate_failures do
|
||||
ids = subject
|
||||
expect(ids).to_not include(local_status.id)
|
||||
expect(ids).to include(remote_status.id)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when exclude_localusers' do
|
||||
let(:exclude_localusers) { true }
|
||||
|
||||
it 'load statuses', :aggregate_failures do
|
||||
ids = subject
|
||||
expect(ids).to include(local_status.id)
|
||||
expect(ids).to_not include(remote_status.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -22,13 +22,10 @@ describe ApplicationController do
|
|||
end
|
||||
|
||||
shared_examples 'respond_with_error' do |code|
|
||||
it "returns http #{code} for http" do
|
||||
subject
|
||||
expect(response).to have_http_status(code)
|
||||
end
|
||||
|
||||
it 'renders template for http' do
|
||||
it "returns http #{code} for http and renders template" do
|
||||
expect(subject).to render_template("errors/#{code}", layout: 'error')
|
||||
|
||||
expect(response).to have_http_status(code)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -49,22 +49,21 @@ describe AccountControllerConcern do
|
|||
end
|
||||
|
||||
context 'when account is not suspended' do
|
||||
it 'assigns @account' do
|
||||
account = Fabricate(:account)
|
||||
let(:account) { Fabricate(:account, username: 'username') }
|
||||
|
||||
it 'assigns @account, returns success, and sets link headers' do
|
||||
get 'success', params: { account_username: account.username }
|
||||
|
||||
expect(assigns(:account)).to eq account
|
||||
end
|
||||
|
||||
it 'sets link headers' do
|
||||
Fabricate(:account, username: 'username')
|
||||
get 'success', params: { account_username: 'username' }
|
||||
expect(response.headers['Link'].to_s).to eq '<http://test.host/.well-known/webfinger?resource=acct%3Ausername%40cb6e6126.ngrok.io>; rel="lrdd"; type="application/jrd+json", <https://cb6e6126.ngrok.io/users/username>; rel="alternate"; type="application/activity+json"'
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
account = Fabricate(:account)
|
||||
get 'success', params: { account_username: account.username }
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response.headers['Link'].to_s).to eq(expected_link_headers)
|
||||
end
|
||||
|
||||
def expected_link_headers
|
||||
[
|
||||
'<http://test.host/.well-known/webfinger?resource=acct%3Ausername%40cb6e6126.ngrok.io>; rel="lrdd"; type="application/jrd+json"',
|
||||
'<https://cb6e6126.ngrok.io/users/username>; rel="alternate"; type="application/activity+json"',
|
||||
].join(', ')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -12,30 +12,20 @@ RSpec.describe InstanceActorsController do
|
|||
get :show, params: { format: format }
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
it 'returns http success with correct media type, headers, and session values' do
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
|
||||
it 'returns application/activity+json' do
|
||||
expect(response.media_type).to eq 'application/activity+json'
|
||||
end
|
||||
|
||||
it 'does not set cookies' do
|
||||
expect(response.cookies).to be_empty
|
||||
expect(response.headers['Set-Cookies']).to be_nil
|
||||
end
|
||||
|
||||
it 'does not set sessions' do
|
||||
expect(session).to be_empty
|
||||
end
|
||||
|
||||
it 'returns public Cache-Control header' do
|
||||
expect(response.headers['Cache-Control']).to include 'public'
|
||||
end
|
||||
|
||||
it 'renders account' do
|
||||
json = body_as_json
|
||||
expect(json).to include(:id, :type, :preferredUsername, :inbox, :publicKey, :inbox, :outbox, :url)
|
||||
expect(body_as_json)
|
||||
.to include(:id, :type, :preferredUsername, :inbox, :publicKey, :inbox, :outbox, :url)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -46,22 +46,13 @@ RSpec.describe LinkDetailsExtractor do
|
|||
</html>
|
||||
HTML
|
||||
|
||||
describe '#title' do
|
||||
it 'returns the title from title tag' do
|
||||
expect(subject.title).to eq 'Man bites dog'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#description' do
|
||||
it 'returns the description from meta tag' do
|
||||
expect(subject.description).to eq "A dog's tale"
|
||||
end
|
||||
end
|
||||
|
||||
describe '#language' do
|
||||
it 'returns the language from lang attribute' do
|
||||
expect(subject.language).to eq 'en'
|
||||
end
|
||||
it 'extracts the expected values from html metadata' do
|
||||
expect(subject)
|
||||
.to have_attributes(
|
||||
title: eq('Man bites dog'),
|
||||
description: eq("A dog's tale"),
|
||||
language: eq('en')
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -90,40 +81,16 @@ RSpec.describe LinkDetailsExtractor do
|
|||
end
|
||||
|
||||
shared_examples 'structured data' do
|
||||
describe '#title' do
|
||||
it 'returns the title from structured data' do
|
||||
expect(subject.title).to eq 'Man bites dog'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#description' do
|
||||
it 'returns the description from structured data' do
|
||||
expect(subject.description).to eq "A dog's tale"
|
||||
end
|
||||
end
|
||||
|
||||
describe '#published_at' do
|
||||
it 'returns the publicaton time from structured data' do
|
||||
expect(subject.published_at).to eq '2022-01-31T19:53:00+00:00'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#author_name' do
|
||||
it 'returns the author name from structured data' do
|
||||
expect(subject.author_name).to eq 'Charlie Brown'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#provider_name' do
|
||||
it 'returns the provider name from structured data' do
|
||||
expect(subject.provider_name).to eq 'Pet News'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#language' do
|
||||
it 'returns the language from structured data' do
|
||||
expect(subject.language).to eq 'en'
|
||||
end
|
||||
it 'extracts the expected values from structured data' do
|
||||
expect(subject)
|
||||
.to have_attributes(
|
||||
title: eq('Man bites dog'),
|
||||
description: eq("A dog's tale"),
|
||||
published_at: eq('2022-01-31T19:53:00+00:00'),
|
||||
author_name: eq('Charlie Brown'),
|
||||
provider_name: eq('Pet News'),
|
||||
language: eq('en')
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -245,58 +212,19 @@ RSpec.describe LinkDetailsExtractor do
|
|||
</html>
|
||||
HTML
|
||||
|
||||
describe '#canonical_url' do
|
||||
it 'returns the URL from Open Graph protocol data' do
|
||||
expect(subject.canonical_url).to eq 'https://example.com/dog.html'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#title' do
|
||||
it 'returns the title from Open Graph protocol data' do
|
||||
expect(subject.title).to eq 'Man bites dog'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#description' do
|
||||
it 'returns the description from Open Graph protocol data' do
|
||||
expect(subject.description).to eq "A dog's tale"
|
||||
end
|
||||
end
|
||||
|
||||
describe '#published_at' do
|
||||
it 'returns the publicaton time from Open Graph protocol data' do
|
||||
expect(subject.published_at).to eq '2022-01-31T19:53:00+00:00'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#author_name' do
|
||||
it 'returns the author name from Open Graph protocol data' do
|
||||
expect(subject.author_name).to eq 'Charlie Brown'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#language' do
|
||||
it 'returns the language from Open Graph protocol data' do
|
||||
expect(subject.language).to eq 'en'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#image' do
|
||||
it 'returns the image from Open Graph protocol data' do
|
||||
expect(subject.image).to eq 'https://example.com/snoopy.jpg'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#image:alt' do
|
||||
it 'returns the image description from Open Graph protocol data' do
|
||||
expect(subject.image_alt).to eq 'A good boy'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#provider_name' do
|
||||
it 'returns the provider name from Open Graph protocol data' do
|
||||
expect(subject.provider_name).to eq 'Pet News'
|
||||
end
|
||||
it 'extracts the expected values from open graph data' do
|
||||
expect(subject)
|
||||
.to have_attributes(
|
||||
canonical_url: eq('https://example.com/dog.html'),
|
||||
title: eq('Man bites dog'),
|
||||
description: eq("A dog's tale"),
|
||||
published_at: eq('2022-01-31T19:53:00+00:00'),
|
||||
author_name: eq('Charlie Brown'),
|
||||
language: eq('en'),
|
||||
image: eq('https://example.com/snoopy.jpg'),
|
||||
image_alt: eq('A good boy'),
|
||||
provider_name: eq('Pet News')
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -65,8 +65,7 @@ describe Mastodon::CLI::Accounts do
|
|||
|
||||
it 'exits with an error message' do
|
||||
expect { subject }
|
||||
.to output_results('Failure/Error: email')
|
||||
.and raise_error(SystemExit)
|
||||
.to raise_error(Thor::Error, %r{Failure/Error: email})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -127,8 +126,7 @@ describe Mastodon::CLI::Accounts do
|
|||
|
||||
it 'exits with an error message indicating the role name was not found' do
|
||||
expect { subject }
|
||||
.to output_results('Cannot find user role with that name')
|
||||
.and raise_error(SystemExit)
|
||||
.to raise_error(Thor::Error, 'Cannot find user role with that name')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -191,8 +189,7 @@ describe Mastodon::CLI::Accounts do
|
|||
|
||||
it 'exits with an error message indicating the user was not found' do
|
||||
expect { subject }
|
||||
.to output_results('No user with such username')
|
||||
.and raise_error(SystemExit)
|
||||
.to raise_error(Thor::Error, 'No user with such username')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -214,8 +211,7 @@ describe Mastodon::CLI::Accounts do
|
|||
|
||||
it 'exits with an error message indicating the role was not found' do
|
||||
expect { subject }
|
||||
.to output_results('Cannot find user role with that name')
|
||||
.and raise_error(SystemExit)
|
||||
.to raise_error(Thor::Error, 'Cannot find user role with that name')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -364,8 +360,7 @@ describe Mastodon::CLI::Accounts do
|
|||
|
||||
it 'exits with an error message' do
|
||||
expect { subject }
|
||||
.to output_results('Failure/Error: email')
|
||||
.and raise_error(SystemExit)
|
||||
.to raise_error(Thor::Error, %r{Failure/Error: email})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -387,16 +382,14 @@ describe Mastodon::CLI::Accounts do
|
|||
|
||||
it 'exits with an error message indicating that only one should be used' do
|
||||
expect { subject }
|
||||
.to output_results('Use username or --email, not both')
|
||||
.and raise_error(SystemExit)
|
||||
.to raise_error(Thor::Error, 'Use username or --email, not both')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when neither username nor --email are provided' do
|
||||
it 'exits with an error message indicating that no username was provided' do
|
||||
expect { subject }
|
||||
.to output_results('No username provided')
|
||||
.and raise_error(SystemExit)
|
||||
.to raise_error(Thor::Error, 'No username provided')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -425,8 +418,7 @@ describe Mastodon::CLI::Accounts do
|
|||
|
||||
it 'exits with an error message indicating that no user was found' do
|
||||
expect { subject }
|
||||
.to output_results('No user with such username')
|
||||
.and raise_error(SystemExit)
|
||||
.to raise_error(Thor::Error, 'No user with such username')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -458,8 +450,7 @@ describe Mastodon::CLI::Accounts do
|
|||
|
||||
it 'exits with an error message indicating that no user was found' do
|
||||
expect { subject }
|
||||
.to output_results('No user with such email')
|
||||
.and raise_error(SystemExit)
|
||||
.to raise_error(Thor::Error, 'No user with such email')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -511,8 +502,7 @@ describe Mastodon::CLI::Accounts do
|
|||
|
||||
it 'exits with an error message indicating that the number must be positive' do
|
||||
expect { subject }
|
||||
.to output_results('Number must be positive')
|
||||
.and raise_error(SystemExit)
|
||||
.to raise_error(Thor::Error, 'Number must be positive')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -545,8 +535,7 @@ describe Mastodon::CLI::Accounts do
|
|||
|
||||
it 'exits with an error message indicating that no such account was found' do
|
||||
expect { subject }
|
||||
.to output_results('No such account')
|
||||
.and raise_error(SystemExit)
|
||||
.to raise_error(Thor::Error, 'No such account')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -560,8 +549,7 @@ describe Mastodon::CLI::Accounts do
|
|||
|
||||
it 'exits with an error message indicating that no account with the given username was found' do
|
||||
expect { subject }
|
||||
.to output_results('No such account')
|
||||
.and raise_error(SystemExit)
|
||||
.to raise_error(Thor::Error, 'No such account')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -596,8 +584,7 @@ describe Mastodon::CLI::Accounts do
|
|||
|
||||
it 'exits with an error message indicating that no account with the given username was found' do
|
||||
expect { subject }
|
||||
.to output_results('No such account')
|
||||
.and raise_error(SystemExit)
|
||||
.to raise_error(Thor::Error, 'No such account')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -634,8 +621,7 @@ describe Mastodon::CLI::Accounts do
|
|||
|
||||
it 'exits with an error message indicating that there is no such account' do
|
||||
expect { subject }
|
||||
.to output_results('No user with such username')
|
||||
.and raise_error(SystemExit)
|
||||
.to raise_error(Thor::Error, 'No user with such username')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -795,8 +781,7 @@ describe Mastodon::CLI::Accounts do
|
|||
allow(Account).to receive(:find_remote).with(account_example_com_b.username, account_example_com_b.domain).and_return(nil)
|
||||
|
||||
expect { subject }
|
||||
.to output_results('No such account')
|
||||
.and raise_error(SystemExit)
|
||||
.to raise_error(Thor::Error, 'No such account')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -892,8 +877,7 @@ describe Mastodon::CLI::Accounts do
|
|||
context 'when neither a list of accts nor options are provided' do
|
||||
it 'exits with an error message' do
|
||||
expect { subject }
|
||||
.to output_results('No account(s) given')
|
||||
.and raise_error(SystemExit)
|
||||
.to raise_error(Thor::Error, 'No account(s) given')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -904,8 +888,7 @@ describe Mastodon::CLI::Accounts do
|
|||
context 'when neither username nor --all option are given' do
|
||||
it 'exits with an error message' do
|
||||
expect { subject }
|
||||
.to output_results('No account(s) given')
|
||||
.and raise_error(SystemExit)
|
||||
.to raise_error(Thor::Error, 'No account(s) given')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -940,8 +923,7 @@ describe Mastodon::CLI::Accounts do
|
|||
|
||||
it 'exits with an error message when the specified username is not found' do
|
||||
expect { subject }
|
||||
.to output_results('No such account')
|
||||
.and raise_error(SystemExit)
|
||||
.to raise_error(Thor::Error, 'No such account')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -980,8 +962,7 @@ describe Mastodon::CLI::Accounts do
|
|||
shared_examples 'an account not found' do |acct|
|
||||
it 'exits with an error message indicating that there is no such account' do
|
||||
expect { subject }
|
||||
.to output_results("No such account (#{acct})")
|
||||
.and raise_error(SystemExit)
|
||||
.to raise_error(Thor::Error, "No such account (#{acct})")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1031,8 +1012,7 @@ describe Mastodon::CLI::Accounts do
|
|||
|
||||
it 'exits with an error message indicating that the accounts do not have the same pub key' do
|
||||
expect { subject }
|
||||
.to output_results("Accounts don't have the same public key, might not be duplicates!\nOverride with --force")
|
||||
.and raise_error(SystemExit)
|
||||
.to raise_error(Thor::Error, "Accounts don't have the same public key, might not be duplicates!\nOverride with --force\n")
|
||||
end
|
||||
|
||||
context 'with --force option' do
|
||||
|
@ -1200,8 +1180,7 @@ describe Mastodon::CLI::Accounts do
|
|||
context 'when no option is given' do
|
||||
it 'exits with an error message indicating that at least one option is required' do
|
||||
expect { subject }
|
||||
.to output_results('Please specify either --follows or --followers, or both')
|
||||
.and raise_error(SystemExit)
|
||||
.to raise_error(Thor::Error, 'Please specify either --follows or --followers, or both')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1211,8 +1190,7 @@ describe Mastodon::CLI::Accounts do
|
|||
|
||||
it 'exits with an error message indicating that there is no such account' do
|
||||
expect { subject }
|
||||
.to output_results('No such account')
|
||||
.and raise_error(SystemExit)
|
||||
.to raise_error(Thor::Error, 'No such account')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1348,18 +1326,16 @@ describe Mastodon::CLI::Accounts do
|
|||
end
|
||||
|
||||
shared_examples 'a successful migration' do
|
||||
it 'calls the MoveService for the last migration' do
|
||||
expect { subject }
|
||||
.to output_results('OK')
|
||||
|
||||
last_migration = source_account.migrations.last
|
||||
|
||||
expect(move_service).to have_received(:call).with(last_migration).once
|
||||
end
|
||||
|
||||
it 'displays a successful message' do
|
||||
it 'displays a success message and calls the MoveService for the last migration' do
|
||||
expect { subject }
|
||||
.to output_results("OK, migrated #{source_account.acct} to #{target_account.acct}")
|
||||
|
||||
expect(move_service)
|
||||
.to have_received(:call).with(last_migration).once
|
||||
end
|
||||
|
||||
def last_migration
|
||||
source_account.migrations.last
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1368,16 +1344,14 @@ describe Mastodon::CLI::Accounts do
|
|||
|
||||
it 'exits with an error message indicating that using both options is not possible' do
|
||||
expect { subject }
|
||||
.to output_results('Use --replay or --target, not both')
|
||||
.and raise_error(SystemExit)
|
||||
.to raise_error(Thor::Error, 'Use --replay or --target, not both')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when no option is given' do
|
||||
it 'exits with an error message indicating that at least one option must be used' do
|
||||
expect { subject }
|
||||
.to output_results('Use either --replay or --target')
|
||||
.and raise_error(SystemExit)
|
||||
.to raise_error(Thor::Error, 'Use either --replay or --target')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1387,8 +1361,7 @@ describe Mastodon::CLI::Accounts do
|
|||
|
||||
it 'exits with an error message indicating that there is no such account' do
|
||||
expect { subject }
|
||||
.to output_results("No such account: #{arguments.first}")
|
||||
.and raise_error(SystemExit)
|
||||
.to raise_error(Thor::Error, "No such account: #{arguments.first}")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1398,8 +1371,7 @@ describe Mastodon::CLI::Accounts do
|
|||
context 'when the specified account has no previous migrations' do
|
||||
it 'exits with an error message indicating that the given account has no previous migrations' do
|
||||
expect { subject }
|
||||
.to output_results('The specified account has not performed any migration')
|
||||
.and raise_error(SystemExit)
|
||||
.to raise_error(Thor::Error, 'The specified account has not performed any migration')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1421,8 +1393,7 @@ describe Mastodon::CLI::Accounts do
|
|||
|
||||
it 'exits with an error message' do
|
||||
expect { subject }
|
||||
.to output_results('The specified account is not redirecting to its last migration target. Use --force if you want to replay the migration anyway')
|
||||
.and raise_error(SystemExit)
|
||||
.to raise_error(Thor::Error, 'The specified account is not redirecting to its last migration target. Use --force if you want to replay the migration anyway')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1449,8 +1420,7 @@ describe Mastodon::CLI::Accounts do
|
|||
|
||||
it 'exits with an error message indicating that there is no such account' do
|
||||
expect { subject }
|
||||
.to output_results("The specified target account could not be found: #{options[:target]}")
|
||||
.and raise_error(SystemExit)
|
||||
.to raise_error(Thor::Error, "The specified target account could not be found: #{options[:target]}")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1474,8 +1444,7 @@ describe Mastodon::CLI::Accounts do
|
|||
context 'when the migration record is invalid' do
|
||||
it 'exits with an error indicating that the validation failed' do
|
||||
expect { subject }
|
||||
.to output_results('Error: Validation failed')
|
||||
.and raise_error(SystemExit)
|
||||
.to raise_error(Thor::Error, /Error: Validation failed/)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1486,8 +1455,7 @@ describe Mastodon::CLI::Accounts do
|
|||
|
||||
it 'exits with an error message' do
|
||||
expect { subject }
|
||||
.to output_results('The specified account is redirecting to a different target account. Use --force if you want to change the migration target')
|
||||
.and raise_error(SystemExit)
|
||||
.to raise_error(Thor::Error, 'The specified account is redirecting to a different target account. Use --force if you want to change the migration target')
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -64,8 +64,7 @@ describe Mastodon::CLI::Cache do
|
|||
|
||||
it 'Exits with an error message' do
|
||||
expect { subject }
|
||||
.to output_results('Unknown')
|
||||
.and raise_error(SystemExit)
|
||||
.to raise_error(Thor::Error, /Unknown/)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -35,8 +35,7 @@ describe Mastodon::CLI::EmailDomainBlocks do
|
|||
context 'without any options' do
|
||||
it 'warns about usage and exits' do
|
||||
expect { subject }
|
||||
.to output_results('No domain(s) given')
|
||||
.and raise_error(SystemExit)
|
||||
.to raise_error(Thor::Error, 'No domain(s) given')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -72,8 +71,7 @@ describe Mastodon::CLI::EmailDomainBlocks do
|
|||
context 'without any options' do
|
||||
it 'warns about usage and exits' do
|
||||
expect { subject }
|
||||
.to output_results('No domain(s) given')
|
||||
.and raise_error(SystemExit)
|
||||
.to raise_error(Thor::Error, 'No domain(s) given')
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -42,8 +42,7 @@ describe Mastodon::CLI::Feeds do
|
|||
|
||||
it 'displays an error and exits' do
|
||||
expect { subject }
|
||||
.to output_results('No such account')
|
||||
.and raise_error(SystemExit)
|
||||
.to raise_error(Thor::Error, 'No such account')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -144,8 +144,7 @@ describe Mastodon::CLI::IpBlocks do
|
|||
|
||||
it 'exits with an error message' do
|
||||
expect { subject }
|
||||
.to output_results('No IP(s) given')
|
||||
.and raise_error(SystemExit)
|
||||
.to raise_error(Thor::Error, 'No IP(s) given')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -235,8 +234,7 @@ describe Mastodon::CLI::IpBlocks do
|
|||
context 'when no IP address is provided' do
|
||||
it 'exits with an error message' do
|
||||
expect { subject }
|
||||
.to output_results('No IP(s) given')
|
||||
.and raise_error(SystemExit)
|
||||
.to raise_error(Thor::Error, 'No IP(s) given')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -104,9 +104,9 @@ describe Mastodon::CLI::Main do
|
|||
answer_hostname_incorrectly
|
||||
end
|
||||
|
||||
it 'exits silently' do
|
||||
it 'exits with mismatch error message' do
|
||||
expect { subject }
|
||||
.to raise_error(SystemExit)
|
||||
.to raise_error(Thor::Error, /Domains do not match/)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -119,7 +119,7 @@ describe Mastodon::CLI::Main do
|
|||
it 'passes first step but stops before instructions' do
|
||||
expect { subject }
|
||||
.to output_results('operation WILL NOT')
|
||||
.and raise_error(SystemExit)
|
||||
.and raise_error(Thor::Error, /Self-destruct will not begin/)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -22,8 +22,7 @@ describe Mastodon::CLI::Maintenance do
|
|||
|
||||
it 'Exits with error message' do
|
||||
expect { subject }
|
||||
.to output_results('is too old')
|
||||
.and raise_error(SystemExit)
|
||||
.to raise_error(Thor::Error, /is too old/)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -36,7 +35,7 @@ describe Mastodon::CLI::Maintenance do
|
|||
it 'Exits with error message' do
|
||||
expect { subject }
|
||||
.to output_results('more recent')
|
||||
.and raise_error(SystemExit)
|
||||
.and raise_error(Thor::Error, /more recent/)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -48,8 +47,7 @@ describe Mastodon::CLI::Maintenance do
|
|||
|
||||
it 'Exits with error message' do
|
||||
expect { subject }
|
||||
.to output_results('Sidekiq is running')
|
||||
.and raise_error(SystemExit)
|
||||
.to raise_error(Thor::Error, /Sidekiq is running/)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -20,8 +20,7 @@ describe Mastodon::CLI::Media do
|
|||
|
||||
it 'warns about usage and exits' do
|
||||
expect { subject }
|
||||
.to output_results('--prune-profiles and --remove-headers should not be specified simultaneously')
|
||||
.and raise_error(SystemExit)
|
||||
.to raise_error(Thor::Error, '--prune-profiles and --remove-headers should not be specified simultaneously')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -30,8 +29,7 @@ describe Mastodon::CLI::Media do
|
|||
|
||||
it 'warns about usage and exits' do
|
||||
expect { subject }
|
||||
.to output_results('--include-follows can only be used with --prune-profiles or --remove-headers')
|
||||
.and raise_error(SystemExit)
|
||||
.to raise_error(Thor::Error, '--include-follows can only be used with --prune-profiles or --remove-headers')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -98,8 +96,7 @@ describe Mastodon::CLI::Media do
|
|||
|
||||
it 'warns about url and exits' do
|
||||
expect { subject }
|
||||
.to output_results('Not a media URL')
|
||||
.and raise_error(SystemExit)
|
||||
.to raise_error(Thor::Error, 'Not a media URL')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -121,8 +118,7 @@ describe Mastodon::CLI::Media do
|
|||
context 'without any options' do
|
||||
it 'warns about usage and exits' do
|
||||
expect { subject }
|
||||
.to output_results('Specify the source')
|
||||
.and raise_error(SystemExit)
|
||||
.to raise_error(Thor::Error, /Specify the source/)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -147,8 +143,7 @@ describe Mastodon::CLI::Media do
|
|||
|
||||
it 'warns about usage and exits' do
|
||||
expect { subject }
|
||||
.to output_results('No such account')
|
||||
.and raise_error(SystemExit)
|
||||
.to raise_error(Thor::Error, 'No such account')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -221,8 +216,7 @@ describe Mastodon::CLI::Media do
|
|||
|
||||
it 'warns about usage and exits' do
|
||||
expect { subject }
|
||||
.to output_results('azure storage driver is not supported')
|
||||
.and raise_error(SystemExit)
|
||||
.to raise_error(Thor::Error, /azure storage driver is not supported/)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -233,8 +227,7 @@ describe Mastodon::CLI::Media do
|
|||
|
||||
it 'warns about usage and exits' do
|
||||
expect { subject }
|
||||
.to output_results('fog storage driver is not supported')
|
||||
.and raise_error(SystemExit)
|
||||
.to raise_error(Thor::Error, /fog storage driver is not supported/)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -20,8 +20,7 @@ describe Mastodon::CLI::Search do
|
|||
|
||||
it 'Exits with error message' do
|
||||
expect { subject }
|
||||
.to output_results('this concurrency setting')
|
||||
.and raise_error(SystemExit)
|
||||
.to raise_error(Thor::Error, /this concurrency setting/)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -30,8 +29,7 @@ describe Mastodon::CLI::Search do
|
|||
|
||||
it 'Exits with error message' do
|
||||
expect { subject }
|
||||
.to output_results('this batch_size setting')
|
||||
.and raise_error(SystemExit)
|
||||
.to raise_error(Thor::Error, /this batch_size setting/)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -20,8 +20,7 @@ describe Mastodon::CLI::Statuses do
|
|||
|
||||
it 'exits with error message' do
|
||||
expect { subject }
|
||||
.to output_results('Cannot run')
|
||||
.and raise_error(SystemExit)
|
||||
.to raise_error(Thor::Error, /Cannot run/)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -187,12 +187,9 @@ RSpec.describe User do
|
|||
context 'when the user is already confirmed' do
|
||||
let!(:user) { Fabricate(:user, confirmed_at: Time.now.utc, approved: true, unconfirmed_email: new_email) }
|
||||
|
||||
it 'sets email to unconfirmed_email' do
|
||||
it 'sets email to unconfirmed_email and does not trigger web hook' do
|
||||
expect { subject }.to change { user.reload.email }.to(new_email)
|
||||
end
|
||||
|
||||
it 'does not trigger the account.approved Web Hook' do
|
||||
subject
|
||||
expect(TriggerWebhookWorker).to_not have_received(:perform_async).with('account.approved', 'Account', user.account_id)
|
||||
end
|
||||
end
|
||||
|
@ -206,12 +203,9 @@ RSpec.describe User do
|
|||
user.approve!
|
||||
end
|
||||
|
||||
it 'sets email to unconfirmed_email' do
|
||||
it 'sets email to unconfirmed_email and triggers `account.approved` web hook' do
|
||||
expect { subject }.to change { user.reload.email }.to(new_email)
|
||||
end
|
||||
|
||||
it 'triggers the account.approved Web Hook' do
|
||||
user.confirm
|
||||
expect(TriggerWebhookWorker).to have_received(:perform_async).with('account.approved', 'Account', user.account_id).once
|
||||
end
|
||||
end
|
||||
|
@ -221,12 +215,9 @@ RSpec.describe User do
|
|||
Setting.registrations_mode = 'open'
|
||||
end
|
||||
|
||||
it 'sets email to unconfirmed_email' do
|
||||
it 'sets email to unconfirmed_email and triggers `account.approved` web hook' do
|
||||
expect { subject }.to change { user.reload.email }.to(new_email)
|
||||
end
|
||||
|
||||
it 'triggers the account.approved Web Hook' do
|
||||
user.confirm
|
||||
expect(TriggerWebhookWorker).to have_received(:perform_async).with('account.approved', 'Account', user.account_id).once
|
||||
end
|
||||
end
|
||||
|
@ -236,12 +227,9 @@ RSpec.describe User do
|
|||
Setting.registrations_mode = 'approved'
|
||||
end
|
||||
|
||||
it 'sets email to unconfirmed_email' do
|
||||
it 'sets email to unconfirmed_email and does not trigger web hook' do
|
||||
expect { subject }.to change { user.reload.email }.to(new_email)
|
||||
end
|
||||
|
||||
it 'does not trigger the account.approved Web Hook' do
|
||||
subject
|
||||
expect(TriggerWebhookWorker).to_not have_received(:perform_async).with('account.approved', 'Account', user.account_id)
|
||||
end
|
||||
end
|
||||
|
@ -259,12 +247,9 @@ RSpec.describe User do
|
|||
context 'when the user is already confirmed' do
|
||||
let(:user) { Fabricate(:user, confirmed_at: Time.now.utc, approved: false) }
|
||||
|
||||
it 'sets the approved flag' do
|
||||
it 'sets the approved flag and triggers `account.approved` web hook' do
|
||||
expect { subject }.to change { user.reload.approved? }.to(true)
|
||||
end
|
||||
|
||||
it 'triggers the account.approved Web Hook' do
|
||||
subject
|
||||
expect(TriggerWebhookWorker).to have_received(:perform_async).with('account.approved', 'Account', user.account_id).once
|
||||
end
|
||||
end
|
||||
|
@ -272,12 +257,9 @@ RSpec.describe User do
|
|||
context 'when the user is not confirmed' do
|
||||
let(:user) { Fabricate(:user, confirmed_at: nil, approved: false) }
|
||||
|
||||
it 'sets the approved flag' do
|
||||
it 'sets the approved flag and does not trigger web hook' do
|
||||
expect { subject }.to change { user.reload.approved? }.to(true)
|
||||
end
|
||||
|
||||
it 'does not trigger the account.approved Web Hook' do
|
||||
subject
|
||||
expect(TriggerWebhookWorker).to_not have_received(:perform_async).with('account.approved', 'Account', user.account_id)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,31 +2,26 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Api::V1::Admin::Trends::Links::PreviewCardProvidersController do
|
||||
render_views
|
||||
|
||||
describe 'API V1 Admin Trends Links Preview Card Providers' do
|
||||
let(:role) { UserRole.find_by(name: 'Admin') }
|
||||
let(:user) { Fabricate(:user, role: role) }
|
||||
let(:scopes) { 'admin:read admin:write' }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
||||
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
|
||||
let(:account) { Fabricate(:account) }
|
||||
let(:preview_card_provider) { Fabricate(:preview_card_provider) }
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:doorkeeper_token) { token }
|
||||
end
|
||||
|
||||
describe 'GET #index' do
|
||||
describe 'GET /api/v1/admin/trends/links/publishers' do
|
||||
it 'returns http success' do
|
||||
get :index, params: { account_id: account.id, limit: 2 }
|
||||
get '/api/v1/admin/trends/links/publishers', params: { account_id: account.id, limit: 2 }, headers: headers
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #approve' do
|
||||
describe 'POST /api/v1/admin/trends/links/publishers/:id/approve' do
|
||||
before do
|
||||
post :approve, params: { id: preview_card_provider.id }
|
||||
post "/api/v1/admin/trends/links/publishers/#{preview_card_provider.id}/approve", headers: headers
|
||||
end
|
||||
|
||||
it_behaves_like 'forbidden for wrong scope', 'write:statuses'
|
||||
|
@ -37,9 +32,9 @@ describe Api::V1::Admin::Trends::Links::PreviewCardProvidersController do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'POST #reject' do
|
||||
describe 'POST /api/v1/admin/trends/links/publishers/:id/reject' do
|
||||
before do
|
||||
post :reject, params: { id: preview_card_provider.id }
|
||||
post "/api/v1/admin/trends/links/publishers/#{preview_card_provider.id}/reject", headers: headers
|
||||
end
|
||||
|
||||
it_behaves_like 'forbidden for wrong scope', 'write:statuses'
|
|
@ -76,20 +76,14 @@ RSpec.describe 'Media' do
|
|||
let(:params) { {} }
|
||||
|
||||
shared_examples 'a successful media upload' do |media_type|
|
||||
it 'uploads the file successfully', :aggregate_failures do
|
||||
it 'uploads the file successfully and returns correct media content', :aggregate_failures do
|
||||
subject
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(MediaAttachment.first).to be_present
|
||||
expect(MediaAttachment.first).to have_attached_file(:file)
|
||||
end
|
||||
|
||||
it 'returns the correct media content' do
|
||||
subject
|
||||
|
||||
body = body_as_json
|
||||
|
||||
expect(body).to match(
|
||||
expect(body_as_json).to match(
|
||||
a_hash_including(id: MediaAttachment.first.id.to_s, description: params[:description], type: media_type)
|
||||
)
|
||||
end
|
||||
|
|
|
@ -2,23 +2,18 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Api::V1::Statuses::HistoriesController do
|
||||
render_views
|
||||
|
||||
describe 'API V1 Statuses Histories' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:app) { Fabricate(:application, name: 'Test app', website: 'http://testapp.com') }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read:statuses', application: app) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
||||
let(:scopes) { 'read:statuses' }
|
||||
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
|
||||
|
||||
context 'with an oauth token' do
|
||||
before do
|
||||
allow(controller).to receive(:doorkeeper_token) { token }
|
||||
end
|
||||
|
||||
describe 'GET #show' do
|
||||
describe 'GET /api/v1/statuses/:status_id/history' do
|
||||
let(:status) { Fabricate(:status, account: user.account) }
|
||||
|
||||
before do
|
||||
get :show, params: { status_id: status.id }
|
||||
get "/api/v1/statuses/#{status.id}/history", headers: headers
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
|
@ -2,23 +2,18 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Api::V1::Statuses::MutesController do
|
||||
render_views
|
||||
|
||||
describe 'API V1 Statuses Mutes' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:app) { Fabricate(:application, name: 'Test app', website: 'http://testapp.com') }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'write:mutes', application: app) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
||||
let(:scopes) { 'write:mutes' }
|
||||
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
|
||||
|
||||
context 'with an oauth token' do
|
||||
before do
|
||||
allow(controller).to receive(:doorkeeper_token) { token }
|
||||
end
|
||||
|
||||
describe 'POST #create' do
|
||||
describe 'POST /api/v1/statuses/:status_id/mute' do
|
||||
let(:status) { Fabricate(:status, account: user.account) }
|
||||
|
||||
before do
|
||||
post :create, params: { status_id: status.id }
|
||||
post "/api/v1/statuses/#{status.id}/mute", headers: headers
|
||||
end
|
||||
|
||||
it 'creates a conversation mute', :aggregate_failures do
|
||||
|
@ -27,12 +22,12 @@ describe Api::V1::Statuses::MutesController do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'POST #destroy' do
|
||||
describe 'POST /api/v1/statuses/:status_id/unmute' do
|
||||
let(:status) { Fabricate(:status, account: user.account) }
|
||||
|
||||
before do
|
||||
user.account.mute_conversation!(status.conversation)
|
||||
post :destroy, params: { status_id: status.id }
|
||||
post "/api/v1/statuses/#{status.id}/unmute", headers: headers
|
||||
end
|
||||
|
||||
it 'destroys the conversation mute', :aggregate_failures do
|
|
@ -2,23 +2,18 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Api::V1::Statuses::ReblogsController do
|
||||
render_views
|
||||
|
||||
describe 'API V1 Statuses Reblogs' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:app) { Fabricate(:application, name: 'Test app', website: 'http://testapp.com') }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'write:statuses', application: app) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
||||
let(:scopes) { 'write:statuses' }
|
||||
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
|
||||
|
||||
context 'with an oauth token' do
|
||||
before do
|
||||
allow(controller).to receive(:doorkeeper_token) { token }
|
||||
end
|
||||
|
||||
describe 'POST #create' do
|
||||
describe 'POST /api/v1/statuses/:status_id/reblog' do
|
||||
let(:status) { Fabricate(:status, account: user.account) }
|
||||
|
||||
before do
|
||||
post :create, params: { status_id: status.id }
|
||||
post "/api/v1/statuses/#{status.id}/reblog", headers: headers
|
||||
end
|
||||
|
||||
context 'with public status' do
|
||||
|
@ -46,13 +41,13 @@ describe Api::V1::Statuses::ReblogsController do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'POST #destroy', :sidekiq_inline do
|
||||
describe 'POST /api/v1/statuses/:status_id/unreblog', :sidekiq_inline do
|
||||
context 'with public status' do
|
||||
let(:status) { Fabricate(:status, account: user.account) }
|
||||
|
||||
before do
|
||||
ReblogService.new.call(user.account, status)
|
||||
post :destroy, params: { status_id: status.id }
|
||||
post "/api/v1/statuses/#{status.id}/unreblog", headers: headers
|
||||
end
|
||||
|
||||
it 'destroys the reblog', :aggregate_failures do
|
||||
|
@ -76,7 +71,7 @@ describe Api::V1::Statuses::ReblogsController do
|
|||
before do
|
||||
ReblogService.new.call(user.account, status)
|
||||
status.account.block!(user.account)
|
||||
post :destroy, params: { status_id: status.id }
|
||||
post "/api/v1/statuses/#{status.id}/unreblog", headers: headers
|
||||
end
|
||||
|
||||
it 'destroys the reblog', :aggregate_failures do
|
||||
|
@ -98,7 +93,7 @@ describe Api::V1::Statuses::ReblogsController do
|
|||
let(:status) { Fabricate(:status, visibility: :private) }
|
||||
|
||||
before do
|
||||
post :destroy, params: { status_id: status.id }
|
||||
post "/api/v1/statuses/#{status.id}/unreblog", headers: headers
|
||||
end
|
||||
|
||||
it 'returns http not found' do
|
|
@ -2,19 +2,14 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Api::V1::Statuses::TranslationsController do
|
||||
render_views
|
||||
|
||||
describe 'API V1 Statuses Translations' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:app) { Fabricate(:application, name: 'Test app', website: 'http://testapp.com') }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read:statuses', application: app) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
||||
let(:scopes) { 'read:statuses' }
|
||||
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
|
||||
|
||||
context 'with an oauth token' do
|
||||
before do
|
||||
allow(controller).to receive(:doorkeeper_token) { token }
|
||||
end
|
||||
|
||||
describe 'POST #create' do
|
||||
describe 'POST /api/v1/statuses/:status_id/translate' do
|
||||
let(:status) { Fabricate(:status, account: user.account, text: 'Hola', language: 'es') }
|
||||
|
||||
before do
|
||||
|
@ -22,7 +17,7 @@ describe Api::V1::Statuses::TranslationsController do
|
|||
service = instance_double(TranslationService::DeepL, translate: [translation])
|
||||
allow(TranslationService).to receive_messages(configured?: true, configured: service)
|
||||
Rails.cache.write('translation_service/languages', { 'es' => ['en'] })
|
||||
post :create, params: { status_id: status.id }
|
||||
post "/api/v1/statuses/#{status.id}/translate", headers: headers
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
|
@ -2,28 +2,26 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Api::V1::Timelines::AntennaController do
|
||||
render_views
|
||||
|
||||
describe 'API V1 Timelines Antenna' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:scopes) { 'read:statuses' }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
||||
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
|
||||
let(:antenna) { Fabricate(:antenna, account: user.account) }
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:doorkeeper_token) { token }
|
||||
end
|
||||
|
||||
context 'with a user context' do
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read:lists') }
|
||||
|
||||
describe 'GET #show' do
|
||||
describe 'GET /api/v1/timelines/antenna/:id' do
|
||||
before do
|
||||
account = Fabricate(:account)
|
||||
antenna.antenna_accounts.create!(account: account)
|
||||
PostStatusService.new.call(account, text: 'New status for user home timeline.')
|
||||
subscribe = Fabricate(:antenna_account)
|
||||
antenna.antenna_accounts << subscribe
|
||||
PostStatusService.new.call(subscribe.account, text: 'New status for user home timeline.')
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
get :show, params: { id: antenna.id }
|
||||
get "/api/v1/timelines/antenna/#{antenna.id}", headers: headers
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
|
@ -35,7 +33,8 @@ describe Api::V1::Timelines::AntennaController do
|
|||
|
||||
describe 'GET #show' do
|
||||
it 'returns http not found' do
|
||||
get :show, params: { id: antenna.id }
|
||||
get "/api/v1/timelines/antenna/#{antenna.id}", headers: headers
|
||||
|
||||
expect(response).to have_http_status(404)
|
||||
end
|
||||
end
|
||||
|
@ -46,7 +45,7 @@ describe Api::V1::Timelines::AntennaController do
|
|||
|
||||
describe 'GET #show' do
|
||||
it 'returns http unprocessable entity' do
|
||||
get :show, params: { id: antenna.id }
|
||||
get "/api/v1/timelines/antenna/#{antenna.id}", headers: headers
|
||||
|
||||
expect(response).to have_http_status(422)
|
||||
expect(response.headers['Link']).to be_nil
|
|
@ -2,20 +2,17 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Api::V1::Timelines::ListController do
|
||||
render_views
|
||||
|
||||
describe 'API V1 Timelines List' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:scopes) { 'read:statuses' }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
||||
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
|
||||
let(:list) { Fabricate(:list, account: user.account) }
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:doorkeeper_token) { token }
|
||||
end
|
||||
|
||||
context 'with a user context' do
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read:lists') }
|
||||
|
||||
describe 'GET #show' do
|
||||
describe 'GET /api/v1/timelines/list/:id' do
|
||||
before do
|
||||
follow = Fabricate(:follow, account: user.account)
|
||||
list.accounts << follow.target_account
|
||||
|
@ -23,7 +20,8 @@ describe Api::V1::Timelines::ListController do
|
|||
end
|
||||
|
||||
it 'returns http success' do
|
||||
get :show, params: { id: list.id }
|
||||
get "/api/v1/timelines/list/#{list.id}", headers: headers
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
|
@ -35,7 +33,8 @@ describe Api::V1::Timelines::ListController do
|
|||
|
||||
describe 'GET #show' do
|
||||
it 'returns http not found' do
|
||||
get :show, params: { id: list.id }
|
||||
get "/api/v1/timelines/list/#{list.id}", headers: headers
|
||||
|
||||
expect(response).to have_http_status(404)
|
||||
end
|
||||
end
|
||||
|
@ -46,7 +45,7 @@ describe Api::V1::Timelines::ListController do
|
|||
|
||||
describe 'GET #show' do
|
||||
it 'returns http unprocessable entity' do
|
||||
get :show, params: { id: list.id }
|
||||
get "/api/v1/timelines/list/#{list.id}", headers: headers
|
||||
|
||||
expect(response).to have_http_status(422)
|
||||
expect(response.headers['Link']).to be_nil
|
|
@ -25,10 +25,10 @@ describe 'Public' do
|
|||
get '/api/v1/timelines/public', headers: headers, params: params
|
||||
end
|
||||
|
||||
let!(:private_status) { Fabricate(:status, visibility: :private) } # rubocop:disable RSpec/LetSetup
|
||||
let!(:local_status) { Fabricate(:status, account: Fabricate.build(:account, domain: nil)) }
|
||||
let!(:remote_status) { Fabricate(:status, account: Fabricate.build(:account, domain: 'example.com')) }
|
||||
let!(:media_status) { Fabricate(:status, media_attachments: [Fabricate.build(:media_attachment)]) }
|
||||
let!(:private_status) { Fabricate(:status, text: 'ohagi', visibility: :private) } # rubocop:disable RSpec/LetSetup
|
||||
let!(:local_status) { Fabricate(:status, text: 'ohagi', account: Fabricate.build(:account, domain: nil)) }
|
||||
let!(:remote_status) { Fabricate(:status, text: 'ohagi', account: Fabricate.build(:account, domain: 'example.com')) }
|
||||
let!(:media_status) { Fabricate(:status, text: 'ohagi', media_attachments: [Fabricate.build(:media_attachment)]) }
|
||||
|
||||
let(:params) { {} }
|
||||
|
||||
|
@ -134,5 +134,61 @@ describe 'Public' do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when user is setting filters' do
|
||||
subject do
|
||||
get '/api/v1/timelines/public', headers: headers, params: params
|
||||
body_as_json.filter { |status| status[:filtered].empty? || status[:filtered][0][:filter][:id] != filter.id.to_s }.map { |status| status[:id].to_i }
|
||||
end
|
||||
|
||||
before do
|
||||
Fabricate(:custom_filter_keyword, custom_filter: filter, keyword: 'ohagi')
|
||||
Fabricate(:follow, account: account, target_account: remote_account)
|
||||
end
|
||||
|
||||
let(:exclude_follows) { false }
|
||||
let(:exclude_localusers) { false }
|
||||
let(:include_quotes) { false }
|
||||
let(:account) { user.account }
|
||||
let(:remote_account) { remote_status.account }
|
||||
let!(:filter) { Fabricate(:custom_filter, account: account, exclude_follows: exclude_follows, exclude_localusers: exclude_localusers, with_quote: include_quotes) }
|
||||
let!(:quote_status) { Fabricate(:status, quote: Fabricate(:status, text: 'ohagi')) }
|
||||
|
||||
it 'load statuses', :aggregate_failures do
|
||||
ids = subject
|
||||
expect(ids).to_not include(local_status.id)
|
||||
expect(ids).to_not include(remote_status.id)
|
||||
end
|
||||
|
||||
context 'when exclude_followers' do
|
||||
let(:exclude_follows) { true }
|
||||
|
||||
it 'load statuses', :aggregate_failures do
|
||||
ids = subject
|
||||
expect(ids).to_not include(local_status.id)
|
||||
expect(ids).to include(remote_status.id)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when exclude_localusers' do
|
||||
let(:exclude_localusers) { true }
|
||||
|
||||
it 'load statuses', :aggregate_failures do
|
||||
ids = subject
|
||||
expect(ids).to include(local_status.id)
|
||||
expect(ids).to_not include(remote_status.id)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when include_quotes' do # rubocop:disable RSpec/MultipleMemoizedHelpers
|
||||
let(:with_quote) { true }
|
||||
|
||||
it 'load statuses', :aggregate_failures do
|
||||
ids = subject
|
||||
expect(ids).to_not include(local_status.id)
|
||||
expect(ids).to include(quote_status.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,15 +2,13 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Api::V1::Trends::LinksController do
|
||||
render_views
|
||||
|
||||
describe 'GET #index' do
|
||||
RSpec.describe 'API V1 Trends Links' do
|
||||
describe 'GET /api/v1/trends/links' do
|
||||
context 'when trends are disabled' do
|
||||
before { Setting.trends = false }
|
||||
|
||||
it 'returns http success' do
|
||||
get :index
|
||||
get '/api/v1/trends/links'
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
|
@ -22,7 +20,7 @@ RSpec.describe Api::V1::Trends::LinksController do
|
|||
it 'returns http success' do
|
||||
prepare_trends
|
||||
stub_const('Api::V1::Trends::LinksController::DEFAULT_LINKS_LIMIT', 2)
|
||||
get :index
|
||||
get '/api/v1/trends/links'
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response.headers).to include('Link')
|
|
@ -2,15 +2,13 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Api::V1::Trends::StatusesController do
|
||||
render_views
|
||||
|
||||
describe 'GET #index' do
|
||||
RSpec.describe 'API V1 Trends Statuses' do
|
||||
describe 'GET /api/v1/trends/statuses' do
|
||||
context 'when trends are disabled' do
|
||||
before { Setting.trends = false }
|
||||
|
||||
it 'returns http success' do
|
||||
get :index
|
||||
get '/api/v1/trends/statuses'
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
|
@ -22,7 +20,7 @@ RSpec.describe Api::V1::Trends::StatusesController do
|
|||
it 'returns http success' do
|
||||
prepare_trends
|
||||
stub_const('Api::BaseController::DEFAULT_STATUSES_LIMIT', 2)
|
||||
get :index
|
||||
get '/api/v1/trends/statuses'
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response.headers).to include('Link')
|
|
@ -2,15 +2,13 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Api::V1::Trends::TagsController do
|
||||
render_views
|
||||
|
||||
describe 'GET #index' do
|
||||
RSpec.describe 'API V1 Trends Tags' do
|
||||
describe 'GET /api/v1/trends/tags' do
|
||||
context 'when trends are disabled' do
|
||||
before { Setting.trends = false }
|
||||
|
||||
it 'returns http success' do
|
||||
get :index
|
||||
get '/api/v1/trends/tags'
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response.headers).to_not include('Link')
|
||||
|
@ -23,7 +21,7 @@ RSpec.describe Api::V1::Trends::TagsController do
|
|||
it 'returns http success' do
|
||||
prepare_trends
|
||||
stub_const('Api::V1::Trends::TagsController::DEFAULT_TAGS_LIMIT', 2)
|
||||
get :index
|
||||
get '/api/v1/trends/tags'
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response.headers).to include('Link')
|
|
@ -2,19 +2,14 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Api::V2::Admin::AccountsController do
|
||||
render_views
|
||||
|
||||
RSpec.describe 'API V2 Admin Accounts' do
|
||||
let(:role) { UserRole.find_by(name: 'Moderator') }
|
||||
let(:user) { Fabricate(:user, role: role) }
|
||||
let(:scopes) { 'admin:read admin:write' }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
||||
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
|
||||
let(:account) { Fabricate(:account) }
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:doorkeeper_token) { token }
|
||||
end
|
||||
|
||||
describe 'GET #index' do
|
||||
let!(:remote_account) { Fabricate(:account, domain: 'example.org') }
|
||||
let!(:other_remote_account) { Fabricate(:account, domain: 'foo.bar') }
|
||||
|
@ -28,7 +23,8 @@ RSpec.describe Api::V2::Admin::AccountsController do
|
|||
|
||||
before do
|
||||
pending_account.user.update(approved: false)
|
||||
get :index, params: params
|
||||
|
||||
get '/api/v2/admin/accounts', params: params, headers: headers
|
||||
end
|
||||
|
||||
it_behaves_like 'forbidden for wrong scope', 'write:statuses'
|
|
@ -17,22 +17,18 @@ describe 'The /.well-known/webfinger endpoint' do
|
|||
end
|
||||
|
||||
shared_examples 'a successful response' do
|
||||
it 'returns http success' do
|
||||
it 'returns http success with correct media type and headers and body json' do
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
|
||||
it 'sets only a Vary Origin header' do
|
||||
expect(response.headers['Vary']).to eq('Origin')
|
||||
end
|
||||
|
||||
it 'returns application/jrd+json' do
|
||||
expect(response.media_type).to eq 'application/jrd+json'
|
||||
end
|
||||
|
||||
it 'returns links for the account' do
|
||||
json = body_as_json
|
||||
expect(json[:subject]).to eq 'acct:alice@cb6e6126.ngrok.io'
|
||||
expect(json[:aliases]).to include('https://cb6e6126.ngrok.io/@alice', 'https://cb6e6126.ngrok.io/users/alice')
|
||||
expect(body_as_json)
|
||||
.to include(
|
||||
subject: eq('acct:alice@cb6e6126.ngrok.io'),
|
||||
aliases: include('https://cb6e6126.ngrok.io/@alice', 'https://cb6e6126.ngrok.io/users/alice')
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -21,20 +21,14 @@ RSpec.describe ActivityPub::FetchRemoteAccountService, type: :service do
|
|||
let(:account) { subject.call('https://example.com/alice', id: true) }
|
||||
|
||||
shared_examples 'sets profile data' do
|
||||
it 'returns an account' do
|
||||
expect(account).to be_an Account
|
||||
end
|
||||
|
||||
it 'sets display name' do
|
||||
expect(account.display_name).to eq 'Alice'
|
||||
end
|
||||
|
||||
it 'sets note' do
|
||||
expect(account.note).to eq 'Foo bar'
|
||||
end
|
||||
|
||||
it 'sets URL' do
|
||||
expect(account.url).to eq 'https://example.com/alice'
|
||||
it 'returns an account with expected details' do
|
||||
expect(account)
|
||||
.to be_an(Account)
|
||||
.and have_attributes(
|
||||
display_name: eq('Alice'),
|
||||
note: eq('Foo bar'),
|
||||
url: eq('https://example.com/alice')
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -49,18 +43,11 @@ RSpec.describe ActivityPub::FetchRemoteAccountService, type: :service do
|
|||
stub_request(:get, 'https://example.com/.well-known/nodeinfo').to_return(body: '{}')
|
||||
end
|
||||
|
||||
it 'fetches resource' do
|
||||
account
|
||||
expect(a_request(:get, 'https://example.com/alice')).to have_been_made.once
|
||||
end
|
||||
|
||||
it 'looks up webfinger' do
|
||||
account
|
||||
expect(a_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com')).to have_been_made.once
|
||||
end
|
||||
|
||||
it 'returns nil' do
|
||||
it 'fetches resource and looks up webfinger and returns nil' do
|
||||
expect(account).to be_nil
|
||||
|
||||
expect(a_request(:get, 'https://example.com/alice')).to have_been_made.once
|
||||
expect(a_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com')).to have_been_made.once
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -73,17 +60,12 @@ RSpec.describe ActivityPub::FetchRemoteAccountService, type: :service do
|
|||
stub_request(:get, 'https://example.com/.well-known/nodeinfo').to_return(body: '{}')
|
||||
end
|
||||
|
||||
it 'fetches resource' do
|
||||
it 'fetches resource and looks up webfinger and sets attributes' do
|
||||
account
|
||||
|
||||
expect(a_request(:get, 'https://example.com/alice')).to have_been_made.once
|
||||
end
|
||||
|
||||
it 'looks up webfinger' do
|
||||
account
|
||||
expect(a_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com')).to have_been_made.once
|
||||
end
|
||||
|
||||
it 'sets username and domain from webfinger' do
|
||||
expect(account.username).to eq 'alice'
|
||||
expect(account.domain).to eq 'example.com'
|
||||
end
|
||||
|
@ -101,22 +83,13 @@ RSpec.describe ActivityPub::FetchRemoteAccountService, type: :service do
|
|||
stub_request(:get, 'https://iscool.af/.well-known/nodeinfo').to_return(body: '{}')
|
||||
end
|
||||
|
||||
it 'fetches resource' do
|
||||
it 'fetches resource and looks up webfinger and follows redirection and sets attributes' do
|
||||
account
|
||||
|
||||
expect(a_request(:get, 'https://example.com/alice')).to have_been_made.once
|
||||
end
|
||||
|
||||
it 'looks up webfinger' do
|
||||
account
|
||||
expect(a_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com')).to have_been_made.once
|
||||
end
|
||||
|
||||
it 'looks up "redirected" webfinger' do
|
||||
account
|
||||
expect(a_request(:get, 'https://iscool.af/.well-known/webfinger?resource=acct:alice@iscool.af')).to have_been_made.once
|
||||
end
|
||||
|
||||
it 'sets username and domain from final webfinger' do
|
||||
expect(account.username).to eq 'alice'
|
||||
expect(account.domain).to eq 'iscool.af'
|
||||
end
|
||||
|
@ -133,18 +106,11 @@ RSpec.describe ActivityPub::FetchRemoteAccountService, type: :service do
|
|||
stub_request(:get, 'https://example.com/.well-known/nodeinfo').to_return(body: '{}')
|
||||
end
|
||||
|
||||
it 'fetches resource' do
|
||||
account
|
||||
expect(a_request(:get, 'https://example.com/alice')).to have_been_made.once
|
||||
end
|
||||
|
||||
it 'looks up webfinger' do
|
||||
account
|
||||
expect(a_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com')).to have_been_made.once
|
||||
end
|
||||
|
||||
it 'does not create account' do
|
||||
it 'fetches resource and looks up webfinger and does not create account' do
|
||||
expect(account).to be_nil
|
||||
|
||||
expect(a_request(:get, 'https://example.com/alice')).to have_been_made.once
|
||||
expect(a_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com')).to have_been_made.once
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -158,23 +124,12 @@ RSpec.describe ActivityPub::FetchRemoteAccountService, type: :service do
|
|||
stub_request(:get, 'https://iscool.af/.well-known/nodeinfo').to_return(body: '{}')
|
||||
end
|
||||
|
||||
it 'fetches resource' do
|
||||
account
|
||||
expect(a_request(:get, 'https://example.com/alice')).to have_been_made.once
|
||||
end
|
||||
|
||||
it 'looks up webfinger' do
|
||||
account
|
||||
expect(a_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com')).to have_been_made.once
|
||||
end
|
||||
|
||||
it 'looks up "redirected" webfinger' do
|
||||
account
|
||||
expect(a_request(:get, 'https://iscool.af/.well-known/webfinger?resource=acct:alice@iscool.af')).to have_been_made.once
|
||||
end
|
||||
|
||||
it 'does not create account' do
|
||||
it 'fetches resource and looks up webfinger and follows redirect and does not create account' do
|
||||
expect(account).to be_nil
|
||||
|
||||
expect(a_request(:get, 'https://example.com/alice')).to have_been_made.once
|
||||
expect(a_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com')).to have_been_made.once
|
||||
expect(a_request(:get, 'https://iscool.af/.well-known/webfinger?resource=acct:alice@iscool.af')).to have_been_made.once
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -21,20 +21,14 @@ RSpec.describe ActivityPub::FetchRemoteActorService, type: :service do
|
|||
let(:account) { subject.call('https://example.com/alice', id: true) }
|
||||
|
||||
shared_examples 'sets profile data' do
|
||||
it 'returns an account' do
|
||||
expect(account).to be_an Account
|
||||
end
|
||||
|
||||
it 'sets display name' do
|
||||
expect(account.display_name).to eq 'Alice'
|
||||
end
|
||||
|
||||
it 'sets note' do
|
||||
expect(account.note).to eq 'Foo bar'
|
||||
end
|
||||
|
||||
it 'sets URL' do
|
||||
expect(account.url).to eq 'https://example.com/alice'
|
||||
it 'returns an account and sets attributes' do
|
||||
expect(account)
|
||||
.to be_an(Account)
|
||||
.and have_attributes(
|
||||
display_name: eq('Alice'),
|
||||
note: eq('Foo bar'),
|
||||
url: eq('https://example.com/alice')
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -49,18 +43,11 @@ RSpec.describe ActivityPub::FetchRemoteActorService, type: :service do
|
|||
stub_request(:get, 'https://example.com/.well-known/nodeinfo').to_return(body: '{}')
|
||||
end
|
||||
|
||||
it 'fetches resource' do
|
||||
account
|
||||
expect(a_request(:get, 'https://example.com/alice')).to have_been_made.once
|
||||
end
|
||||
|
||||
it 'looks up webfinger' do
|
||||
account
|
||||
expect(a_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com')).to have_been_made.once
|
||||
end
|
||||
|
||||
it 'returns nil' do
|
||||
it 'fetches resource and looks up webfinger and returns nil' do
|
||||
expect(account).to be_nil
|
||||
|
||||
expect(a_request(:get, 'https://example.com/alice')).to have_been_made.once
|
||||
expect(a_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com')).to have_been_made.once
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -73,17 +60,12 @@ RSpec.describe ActivityPub::FetchRemoteActorService, type: :service do
|
|||
stub_request(:get, 'https://example.com/.well-known/nodeinfo').to_return(body: '{}')
|
||||
end
|
||||
|
||||
it 'fetches resource' do
|
||||
it 'fetches resource and looks up webfinger and sets values' do
|
||||
account
|
||||
|
||||
expect(a_request(:get, 'https://example.com/alice')).to have_been_made.once
|
||||
end
|
||||
|
||||
it 'looks up webfinger' do
|
||||
account
|
||||
expect(a_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com')).to have_been_made.once
|
||||
end
|
||||
|
||||
it 'sets username and domain from webfinger' do
|
||||
expect(account.username).to eq 'alice'
|
||||
expect(account.domain).to eq 'example.com'
|
||||
end
|
||||
|
@ -101,22 +83,13 @@ RSpec.describe ActivityPub::FetchRemoteActorService, type: :service do
|
|||
stub_request(:get, 'https://iscool.af/.well-known/nodeinfo').to_return(body: '{}')
|
||||
end
|
||||
|
||||
it 'fetches resource' do
|
||||
it 'fetches resource and looks up webfinger and follows redirect and sets values' do
|
||||
account
|
||||
|
||||
expect(a_request(:get, 'https://example.com/alice')).to have_been_made.once
|
||||
end
|
||||
|
||||
it 'looks up webfinger' do
|
||||
account
|
||||
expect(a_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com')).to have_been_made.once
|
||||
end
|
||||
|
||||
it 'looks up "redirected" webfinger' do
|
||||
account
|
||||
expect(a_request(:get, 'https://iscool.af/.well-known/webfinger?resource=acct:alice@iscool.af')).to have_been_made.once
|
||||
end
|
||||
|
||||
it 'sets username and domain from final webfinger' do
|
||||
expect(account.username).to eq 'alice'
|
||||
expect(account.domain).to eq 'iscool.af'
|
||||
end
|
||||
|
@ -133,18 +106,11 @@ RSpec.describe ActivityPub::FetchRemoteActorService, type: :service do
|
|||
stub_request(:get, 'https://example.com/.well-known/nodeinfo').to_return(body: '{}')
|
||||
end
|
||||
|
||||
it 'fetches resource' do
|
||||
account
|
||||
expect(a_request(:get, 'https://example.com/alice')).to have_been_made.once
|
||||
end
|
||||
|
||||
it 'looks up webfinger' do
|
||||
account
|
||||
expect(a_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com')).to have_been_made.once
|
||||
end
|
||||
|
||||
it 'does not create account' do
|
||||
it 'fetches resource and looks up webfinger and does not create account' do
|
||||
expect(account).to be_nil
|
||||
|
||||
expect(a_request(:get, 'https://example.com/alice')).to have_been_made.once
|
||||
expect(a_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com')).to have_been_made.once
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -158,23 +124,12 @@ RSpec.describe ActivityPub::FetchRemoteActorService, type: :service do
|
|||
stub_request(:get, 'https://iscool.af/.well-known/nodeinfo').to_return(body: '{}')
|
||||
end
|
||||
|
||||
it 'fetches resource' do
|
||||
account
|
||||
expect(a_request(:get, 'https://example.com/alice')).to have_been_made.once
|
||||
end
|
||||
|
||||
it 'looks up webfinger' do
|
||||
account
|
||||
expect(a_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com')).to have_been_made.once
|
||||
end
|
||||
|
||||
it 'looks up "redirected" webfinger' do
|
||||
account
|
||||
expect(a_request(:get, 'https://iscool.af/.well-known/webfinger?resource=acct:alice@iscool.af')).to have_been_made.once
|
||||
end
|
||||
|
||||
it 'does not create account' do
|
||||
it 'fetches resource and looks up webfinger and follows redirect and does not create account' do
|
||||
expect(account).to be_nil
|
||||
|
||||
expect(a_request(:get, 'https://example.com/alice')).to have_been_made.once
|
||||
expect(a_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com')).to have_been_made.once
|
||||
expect(a_request(:get, 'https://iscool.af/.well-known/webfinger?resource=acct:alice@iscool.af')).to have_been_made.once
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,22 +1,14 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
shared_examples 'cacheable response' do |expects_vary: false|
|
||||
it 'does not set cookies' do
|
||||
it 'sets correct cache and vary headers and does not set cookies or session' do
|
||||
expect(response.cookies).to be_empty
|
||||
expect(response.headers['Set-Cookies']).to be_nil
|
||||
end
|
||||
|
||||
it 'does not set sessions' do
|
||||
expect(session).to be_empty
|
||||
end
|
||||
|
||||
if expects_vary
|
||||
it 'returns Vary header' do
|
||||
expect(response.headers['Vary']).to include(expects_vary)
|
||||
end
|
||||
end
|
||||
expect(response.headers['Vary']).to include(expects_vary) if expects_vary
|
||||
|
||||
it 'returns public Cache-Control header' do
|
||||
expect(response.headers['Cache-Control']).to include('public')
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,7 +10,7 @@ module ProfileStories
|
|||
account: Fabricate(:account, username: 'bob')
|
||||
)
|
||||
|
||||
Web::Setting.where(user: bob).first_or_initialize(user: bob).update!(data: { introductionVersion: 201812160442020 }) if finished_onboarding # rubocop:disable Style/NumericLiterals
|
||||
Web::Setting.where(user: bob).first_or_initialize(user: bob).update!(data: { introductionVersion: 2018_12_16_044202 }) if finished_onboarding
|
||||
end
|
||||
|
||||
def as_a_logged_in_user
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue