Merge remote-tracking branch 'parent/main' into upstream-20240828
This commit is contained in:
commit
b39054ff3c
136 changed files with 1803 additions and 977 deletions
|
@ -1,17 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe AboutController do
|
||||
render_views
|
||||
|
||||
describe 'GET #show' do
|
||||
before do
|
||||
get :show
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -6,19 +6,30 @@ describe Admin::DashboardController do
|
|||
render_views
|
||||
|
||||
describe 'GET #index' do
|
||||
let(:user) { Fabricate(:user, role: UserRole.find_by(name: 'Owner')) }
|
||||
|
||||
before do
|
||||
allow(Admin::SystemCheck).to receive(:perform).and_return([
|
||||
Admin::SystemCheck::Message.new(:database_schema_check),
|
||||
Admin::SystemCheck::Message.new(:rules_check, nil, admin_rules_path),
|
||||
Admin::SystemCheck::Message.new(:sidekiq_process_check, 'foo, bar'),
|
||||
])
|
||||
sign_in Fabricate(:user, role: UserRole.find_by(name: 'Admin'))
|
||||
stub_system_checks
|
||||
Fabricate :software_update
|
||||
sign_in(user)
|
||||
end
|
||||
|
||||
it 'returns 200' do
|
||||
it 'returns http success and body with system check messages' do
|
||||
get :index
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response)
|
||||
.to have_http_status(200)
|
||||
.and have_attributes(
|
||||
body: include(I18n.t('admin.system_checks.software_version_patch_check.message_html'))
|
||||
)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def stub_system_checks
|
||||
stub_const 'Admin::SystemCheck::ACTIVE_CHECKS', [
|
||||
Admin::SystemCheck::SoftwareVersionCheck,
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Api::OEmbedController do
|
||||
render_views
|
||||
|
||||
let(:alice) { Fabricate(:account, username: 'alice') }
|
||||
let(:status) { Fabricate(:status, text: 'Hello world', account: alice) }
|
||||
|
||||
describe 'GET #show' do
|
||||
before do
|
||||
request.host = Rails.configuration.x.local_domain
|
||||
get :show, params: { url: short_account_status_url(alice, status) }, format: :json
|
||||
end
|
||||
|
||||
it 'returns private cache control headers', :aggregate_failures do
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response.headers['Cache-Control']).to include('private, no-store')
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,24 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Api::Web::SettingsController do
|
||||
render_views
|
||||
|
||||
let!(:user) { Fabricate(:user) }
|
||||
|
||||
describe 'PATCH #update' do
|
||||
it 'redirects to about page' do
|
||||
sign_in(user)
|
||||
patch :update, format: :json, params: { data: { 'onboarded' => true } }
|
||||
|
||||
user.reload
|
||||
expect(response).to have_http_status(200)
|
||||
expect(user_web_setting.data['onboarded']).to eq('true')
|
||||
end
|
||||
|
||||
def user_web_setting
|
||||
Web::Setting.where(user: user).first
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,19 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe CustomCssController do
|
||||
render_views
|
||||
|
||||
describe 'GET #show' do
|
||||
before do
|
||||
get :show
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
|
||||
it_behaves_like 'cacheable response'
|
||||
end
|
||||
end
|
|
@ -1,18 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe EmojisController do
|
||||
render_views
|
||||
|
||||
let(:emoji) { Fabricate(:custom_emoji, shortcode: 'coolcat') }
|
||||
|
||||
describe 'GET #show' do
|
||||
let(:response) { get :show, params: { id: emoji.id, format: :json } }
|
||||
|
||||
it 'returns the right response' do
|
||||
expect(response).to have_http_status 200
|
||||
expect(body_as_json[:name]).to eq ':coolcat:'
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,14 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe HealthController do
|
||||
render_views
|
||||
|
||||
describe 'GET #show' do
|
||||
it 'returns http success' do
|
||||
get :show
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,30 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe HomeController do
|
||||
render_views
|
||||
|
||||
describe 'GET #index' do
|
||||
subject { get :index }
|
||||
|
||||
context 'when not signed in' do
|
||||
it 'returns http success' do
|
||||
request.path = '/'
|
||||
expect(subject).to have_http_status(:success)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when signed in' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
|
||||
before do
|
||||
sign_in(user)
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
expect(subject).to have_http_status(:success)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,54 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe InstanceActorsController do
|
||||
describe 'GET #show' do
|
||||
context 'with JSON' do
|
||||
let(:format) { 'json' }
|
||||
|
||||
shared_examples 'shared behavior' do
|
||||
before do
|
||||
get :show, params: { format: format }
|
||||
end
|
||||
|
||||
it 'returns http success with correct media type and body' do
|
||||
expect(response)
|
||||
.to have_http_status(200)
|
||||
.and have_attributes(
|
||||
media_type: eq('application/activity+json')
|
||||
)
|
||||
|
||||
expect(body_as_json)
|
||||
.to include(:id, :type, :preferredUsername, :inbox, :publicKey, :inbox, :outbox, :url)
|
||||
end
|
||||
|
||||
it_behaves_like 'cacheable response'
|
||||
end
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:authorized_fetch_mode?).and_return(authorized_fetch_mode)
|
||||
end
|
||||
|
||||
context 'without authorized fetch mode' do
|
||||
let(:authorized_fetch_mode) { false }
|
||||
|
||||
it_behaves_like 'shared behavior'
|
||||
end
|
||||
|
||||
context 'with authorized fetch mode' do
|
||||
let(:authorized_fetch_mode) { true }
|
||||
|
||||
it_behaves_like 'shared behavior'
|
||||
end
|
||||
|
||||
context 'with a suspended instance actor' do
|
||||
let(:authorized_fetch_mode) { false }
|
||||
|
||||
before { Account.representative.update(suspended_at: 10.days.ago) }
|
||||
|
||||
it_behaves_like 'shared behavior'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,19 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe ManifestsController do
|
||||
render_views
|
||||
|
||||
describe 'GET #show' do
|
||||
before do
|
||||
get :show
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
|
||||
it_behaves_like 'cacheable response'
|
||||
end
|
||||
end
|
|
@ -1,42 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe MediaProxyController do
|
||||
render_views
|
||||
|
||||
before do
|
||||
stub_request(:get, 'http://example.com/attachment.png').to_return(request_fixture('avatar.txt'))
|
||||
end
|
||||
|
||||
describe '#show' do
|
||||
it 'redirects when attached to a status' do
|
||||
status = Fabricate(:status)
|
||||
media_attachment = Fabricate(:media_attachment, status: status, remote_url: 'http://example.com/attachment.png')
|
||||
get :show, params: { id: media_attachment.id }
|
||||
|
||||
expect(response).to have_http_status(302)
|
||||
end
|
||||
|
||||
it 'responds with missing when there is not an attached status' do
|
||||
media_attachment = Fabricate(:media_attachment, status: nil, remote_url: 'http://example.com/attachment.png')
|
||||
get :show, params: { id: media_attachment.id }
|
||||
|
||||
expect(response).to have_http_status(404)
|
||||
end
|
||||
|
||||
it 'raises when id cant be found' do
|
||||
get :show, params: { id: 'missing' }
|
||||
|
||||
expect(response).to have_http_status(404)
|
||||
end
|
||||
|
||||
it 'raises when not permitted to view' do
|
||||
status = Fabricate(:status, visibility: :direct)
|
||||
media_attachment = Fabricate(:media_attachment, status: status, remote_url: 'http://example.com/attachment.png')
|
||||
get :show, params: { id: media_attachment.id }
|
||||
|
||||
expect(response).to have_http_status(404)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,14 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe PrivacyController do
|
||||
render_views
|
||||
|
||||
describe 'GET #show' do
|
||||
it 'returns http success' do
|
||||
get :show
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,19 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Settings::Exports::BlockedAccountsController do
|
||||
render_views
|
||||
|
||||
describe 'GET #index' do
|
||||
it 'returns a csv of the blocking accounts' do
|
||||
user = Fabricate(:user)
|
||||
user.account.block!(Fabricate(:account, username: 'username', domain: 'domain'))
|
||||
|
||||
sign_in user, scope: :user
|
||||
get :index, format: :csv
|
||||
|
||||
expect(response.body).to eq "username@domain\n"
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,20 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Settings::Exports::BlockedDomainsController do
|
||||
render_views
|
||||
|
||||
describe 'GET #index' do
|
||||
it 'returns a csv of the domains' do
|
||||
account = Fabricate(:account, domain: 'example.com')
|
||||
user = Fabricate(:user, account: account)
|
||||
Fabricate(:account_domain_block, domain: 'example.com', account: account)
|
||||
|
||||
sign_in user, scope: :user
|
||||
get :index, format: :csv
|
||||
|
||||
expect(response.body).to eq "example.com\n"
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,24 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Settings::Exports::BookmarksController do
|
||||
render_views
|
||||
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:account) { Fabricate(:account, domain: 'foo.bar') }
|
||||
let(:status) { Fabricate(:status, account: account, uri: 'https://foo.bar/statuses/1312') }
|
||||
|
||||
describe 'GET #index' do
|
||||
before do
|
||||
user.account.bookmarks.create!(status: status)
|
||||
end
|
||||
|
||||
it 'returns a csv of the bookmarked toots' do
|
||||
sign_in user, scope: :user
|
||||
get :index, format: :csv
|
||||
|
||||
expect(response.body).to eq "https://foo.bar/statuses/1312\n"
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,19 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Settings::Exports::FollowingAccountsController do
|
||||
render_views
|
||||
|
||||
describe 'GET #index' do
|
||||
it 'returns a csv of the following accounts' do
|
||||
user = Fabricate(:user)
|
||||
user.account.follow!(Fabricate(:account, username: 'username', domain: 'domain'))
|
||||
|
||||
sign_in user, scope: :user
|
||||
get :index, format: :csv
|
||||
|
||||
expect(response.body).to eq "Account address,Show boosts,Notify on new posts,Languages\nusername@domain,true,false,\n"
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,21 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Settings::Exports::ListsController do
|
||||
render_views
|
||||
|
||||
describe 'GET #index' do
|
||||
it 'returns a csv of the domains' do
|
||||
account = Fabricate(:account)
|
||||
user = Fabricate(:user, account: account)
|
||||
list = Fabricate(:list, account: account, title: 'The List')
|
||||
Fabricate(:list_account, list: list, account: account)
|
||||
|
||||
sign_in user, scope: :user
|
||||
get :index, format: :csv
|
||||
|
||||
expect(response.body).to match 'The List'
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,19 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Settings::Exports::MutedAccountsController do
|
||||
render_views
|
||||
|
||||
describe 'GET #index' do
|
||||
it 'returns a csv of the muting accounts' do
|
||||
user = Fabricate(:user)
|
||||
user.account.mute!(Fabricate(:account, username: 'username', domain: 'domain'))
|
||||
|
||||
sign_in user, scope: :user
|
||||
get :index, format: :csv
|
||||
|
||||
expect(response.body).to eq "Account address,Hide notifications\nusername@domain,true\n"
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,22 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe SharesController do
|
||||
render_views
|
||||
|
||||
let(:user) { Fabricate(:user) }
|
||||
|
||||
before { sign_in user }
|
||||
|
||||
describe 'GET #show' do
|
||||
subject(:body_classes) { assigns(:body_classes) }
|
||||
|
||||
before { get :show, params: { title: 'test title', text: 'test text', url: 'url1 url2' } }
|
||||
|
||||
it 'returns http success' do
|
||||
expect(response).to have_http_status 200
|
||||
expect(body_classes).to eq 'modal-layout compose-standalone'
|
||||
end
|
||||
end
|
||||
end
|
|
@ -44,7 +44,7 @@ require 'chewy/rspec'
|
|||
require 'email_spec/rspec'
|
||||
require 'test_prof/recipes/rspec/before_all'
|
||||
|
||||
Dir[Rails.root.join('spec', 'support', '**', '*.rb')].each { |f| require f }
|
||||
Rails.root.glob('spec/support/**/*.rb').each { |f| require f }
|
||||
|
||||
ActiveRecord::Migration.maintain_test_schema!
|
||||
WebMock.disable_net_connect!(
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
context 'when visited anonymously' do
|
||||
describe 'Anonymous visits' do
|
||||
around do |example|
|
||||
old = ActionController::Base.allow_forgery_protection
|
||||
ActionController::Base.allow_forgery_protection = true
|
||||
|
|
33
spec/requests/api/oembed_spec.rb
Normal file
33
spec/requests/api/oembed_spec.rb
Normal file
|
@ -0,0 +1,33 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'API OEmbed' do
|
||||
describe 'GET /api/oembed' do
|
||||
before { host! Rails.configuration.x.local_domain }
|
||||
|
||||
context 'when status is public' do
|
||||
let(:status) { Fabricate(:status, visibility: :public) }
|
||||
|
||||
it 'returns success with private cache control headers' do
|
||||
get '/api/oembed', params: { url: short_account_status_url(status.account, status) }
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(200)
|
||||
expect(response.headers['Cache-Control'])
|
||||
.to include('private, no-store')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when status is not public' do
|
||||
let(:status) { Fabricate(:status, visibility: :direct) }
|
||||
|
||||
it 'returns not found' do
|
||||
get '/api/oembed', params: { url: short_account_status_url(status.account, status) }
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(404)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
41
spec/requests/api/web/settings_spec.rb
Normal file
41
spec/requests/api/web/settings_spec.rb
Normal file
|
@ -0,0 +1,41 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe '/api/web/settings' do
|
||||
describe 'PATCH /api/web/settings' do
|
||||
let(:user) { Fabricate :user }
|
||||
|
||||
context 'when signed in' do
|
||||
before { sign_in(user) }
|
||||
|
||||
it 'updates setting and responds with success' do
|
||||
patch '/api/web/settings', params: { data: { 'onboarded' => true } }
|
||||
|
||||
expect(user_web_setting.data)
|
||||
.to include('onboarded' => 'true')
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(200)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when not signed in' do
|
||||
it 'responds with unprocessable and does not modify setting' do
|
||||
patch '/api/web/settings', params: { data: { 'onboarded' => true } }
|
||||
|
||||
expect(user_web_setting)
|
||||
.to be_nil
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(422)
|
||||
end
|
||||
end
|
||||
|
||||
def user_web_setting
|
||||
Web::Setting
|
||||
.where(user: user)
|
||||
.first
|
||||
end
|
||||
end
|
||||
end
|
19
spec/requests/custom_stylesheets_spec.rb
Normal file
19
spec/requests/custom_stylesheets_spec.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'Custom stylesheets' do
|
||||
describe 'GET /custom.css' do
|
||||
before { get '/custom.css' }
|
||||
|
||||
it 'returns http success' do
|
||||
expect(response)
|
||||
.to have_http_status(200)
|
||||
.and have_attributes(
|
||||
content_type: match('text/css')
|
||||
)
|
||||
end
|
||||
|
||||
it_behaves_like 'cacheable response'
|
||||
end
|
||||
end
|
21
spec/requests/emojis_spec.rb
Normal file
21
spec/requests/emojis_spec.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'Emojis' do
|
||||
describe 'GET /emojis/:id' do
|
||||
let(:emoji) { Fabricate(:custom_emoji, shortcode: 'coolcat') }
|
||||
|
||||
it 'returns http success with correct json' do
|
||||
get "/emojis/#{emoji.id}"
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(200)
|
||||
expect(body_as_json)
|
||||
.to include(
|
||||
name: ':coolcat:',
|
||||
type: 'Emoji'
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
16
spec/requests/health_spec.rb
Normal file
16
spec/requests/health_spec.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'Health check endpoint' do
|
||||
describe 'GET /health' do
|
||||
it 'returns http success when server is functioning' do
|
||||
get '/health'
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(200)
|
||||
expect(response.body)
|
||||
.to include('OK')
|
||||
end
|
||||
end
|
||||
end
|
71
spec/requests/instance_actor_spec.rb
Normal file
71
spec/requests/instance_actor_spec.rb
Normal file
|
@ -0,0 +1,71 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Instance actor endpoint' do
|
||||
describe 'GET /actor' do
|
||||
before do
|
||||
integration_session.https! # TODO: Move to global rails_helper for all request specs?
|
||||
host! Rails.configuration.x.local_domain # TODO: Move to global rails_helper for all request specs?
|
||||
end
|
||||
|
||||
let!(:original_federation_mode) { Rails.configuration.x.limited_federation_mode }
|
||||
|
||||
shared_examples 'instance actor endpoint' do
|
||||
before { get instance_actor_path(format: :json) }
|
||||
|
||||
it 'returns http success with correct media type and body' do
|
||||
expect(response)
|
||||
.to have_http_status(200)
|
||||
expect(response.content_type)
|
||||
.to start_with('application/activity+json')
|
||||
expect(body_as_json)
|
||||
.to include(
|
||||
id: instance_actor_url,
|
||||
type: 'Application',
|
||||
preferredUsername: 'mastodon.internal',
|
||||
inbox: instance_actor_inbox_url,
|
||||
outbox: instance_actor_outbox_url,
|
||||
publicKey: include(
|
||||
id: instance_actor_url(anchor: 'main-key')
|
||||
),
|
||||
url: about_more_url(instance_actor: true)
|
||||
)
|
||||
end
|
||||
|
||||
it_behaves_like 'cacheable response'
|
||||
end
|
||||
|
||||
context 'with limited federation mode disabled' do
|
||||
before { Rails.configuration.x.limited_federation_mode = false }
|
||||
after { Rails.configuration.x.limited_federation_mode = original_federation_mode }
|
||||
|
||||
it_behaves_like 'instance actor endpoint'
|
||||
|
||||
context 'with a disabled instance actor' do
|
||||
before { disable_instance_actor }
|
||||
|
||||
it_behaves_like 'instance actor endpoint'
|
||||
end
|
||||
end
|
||||
|
||||
context 'with limited federation mode enabled' do
|
||||
before { Rails.configuration.x.limited_federation_mode = true }
|
||||
after { Rails.configuration.x.limited_federation_mode = original_federation_mode }
|
||||
|
||||
it_behaves_like 'instance actor endpoint'
|
||||
|
||||
context 'with a disabled instance actor' do
|
||||
before { disable_instance_actor }
|
||||
|
||||
it_behaves_like 'instance actor endpoint'
|
||||
end
|
||||
end
|
||||
|
||||
def disable_instance_actor
|
||||
Account
|
||||
.representative
|
||||
.update(suspended_at: 10.days.ago)
|
||||
end
|
||||
end
|
||||
end
|
24
spec/requests/manifest_spec.rb
Normal file
24
spec/requests/manifest_spec.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'Manifest' do
|
||||
describe 'GET /manifest' do
|
||||
before { get '/manifest' }
|
||||
|
||||
it 'returns http success' do
|
||||
expect(response)
|
||||
.to have_http_status(200)
|
||||
.and have_attributes(
|
||||
content_type: match('application/json')
|
||||
)
|
||||
expect(body_as_json)
|
||||
.to include(
|
||||
id: '/home',
|
||||
name: 'Mastodon'
|
||||
)
|
||||
end
|
||||
|
||||
it_behaves_like 'cacheable response'
|
||||
end
|
||||
end
|
67
spec/requests/media_proxy_spec.rb
Normal file
67
spec/requests/media_proxy_spec.rb
Normal file
|
@ -0,0 +1,67 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'Media Proxy' do
|
||||
describe 'GET /media_proxy/:id' do
|
||||
before do
|
||||
integration_session.https! # TODO: Move to global rails_helper for all request specs?
|
||||
host! Rails.configuration.x.local_domain # TODO: Move to global rails_helper for all request specs?
|
||||
|
||||
stub_request(:get, 'http://example.com/attachment.png').to_return(request_fixture('avatar.txt'))
|
||||
end
|
||||
|
||||
context 'when attached to a status' do
|
||||
let(:status) { Fabricate(:status) }
|
||||
let(:media_attachment) { Fabricate(:media_attachment, status: status, remote_url: 'http://example.com/attachment.png') }
|
||||
|
||||
it 'redirects to correct original url' do
|
||||
get "/media_proxy/#{media_attachment.id}"
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(302)
|
||||
.and redirect_to media_attachment.file.url(:original)
|
||||
end
|
||||
|
||||
it 'redirects to small style url' do
|
||||
get "/media_proxy/#{media_attachment.id}/small"
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(302)
|
||||
.and redirect_to media_attachment.file.url(:small)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when there is not an attached status' do
|
||||
let(:media_attachment) { Fabricate(:media_attachment, status: status, remote_url: 'http://example.com/attachment.png') }
|
||||
|
||||
it 'responds with missing' do
|
||||
get "/media_proxy/#{media_attachment.id}"
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(404)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when id cannot be found' do
|
||||
it 'responds with missing' do
|
||||
get '/media_proxy/missing'
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(404)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when not permitted to view' do
|
||||
let(:status) { Fabricate(:status, visibility: :direct) }
|
||||
let(:media_attachment) { Fabricate(:media_attachment, status: status, remote_url: 'http://example.com/attachment.png') }
|
||||
|
||||
it 'responds with missing' do
|
||||
get "/media_proxy/#{media_attachment.id}"
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(404)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
42
spec/requests/settings/exports/blocked_accounts_spec.rb
Normal file
42
spec/requests/settings/exports/blocked_accounts_spec.rb
Normal file
|
@ -0,0 +1,42 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'Settings / Exports / Blocked Accounts' do
|
||||
describe 'GET /settings/exports/blocks' do
|
||||
context 'with a signed in user who has blocked accounts' do
|
||||
let(:user) { Fabricate :user }
|
||||
|
||||
before do
|
||||
Fabricate(
|
||||
:block,
|
||||
account: user.account,
|
||||
target_account: Fabricate(:account, username: 'username', domain: 'domain')
|
||||
)
|
||||
sign_in user
|
||||
end
|
||||
|
||||
it 'returns a CSV with the blocking accounts' do
|
||||
get '/settings/exports/blocks.csv'
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(200)
|
||||
expect(response.content_type)
|
||||
.to eq('text/csv')
|
||||
expect(response.body)
|
||||
.to eq(<<~CSV)
|
||||
username@domain
|
||||
CSV
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when signed out' do
|
||||
it 'returns unauthorized' do
|
||||
get '/settings/exports/blocks.csv'
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(401)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
39
spec/requests/settings/exports/blocked_domains_spec.rb
Normal file
39
spec/requests/settings/exports/blocked_domains_spec.rb
Normal file
|
@ -0,0 +1,39 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'Settings / Exports / Blocked Domains' do
|
||||
describe 'GET /settings/exports/domain_blocks' do
|
||||
context 'with a signed in user who has blocked domains' do
|
||||
let(:account) { Fabricate :account, domain: 'example.com' }
|
||||
let(:user) { Fabricate :user, account: account }
|
||||
|
||||
before do
|
||||
Fabricate(:account_domain_block, domain: 'example.com', account: account)
|
||||
sign_in user
|
||||
end
|
||||
|
||||
it 'returns a CSV with the domains' do
|
||||
get '/settings/exports/domain_blocks.csv'
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(200)
|
||||
expect(response.content_type)
|
||||
.to eq('text/csv')
|
||||
expect(response.body)
|
||||
.to eq(<<~CSV)
|
||||
example.com
|
||||
CSV
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when signed out' do
|
||||
it 'returns unauthorized' do
|
||||
get '/settings/exports/domain_blocks.csv'
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(401)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
44
spec/requests/settings/exports/bookmarks_spec.rb
Normal file
44
spec/requests/settings/exports/bookmarks_spec.rb
Normal file
|
@ -0,0 +1,44 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'Settings / Exports / Bookmarks' do
|
||||
describe 'GET /settings/exports/bookmarks' do
|
||||
context 'with a signed in user who has bookmarks' do
|
||||
let(:account) { Fabricate(:account, domain: 'foo.bar') }
|
||||
let(:status) { Fabricate(:status, account: account, uri: 'https://foo.bar/statuses/1312') }
|
||||
let(:user) { Fabricate(:user) }
|
||||
|
||||
before do
|
||||
Fabricate(
|
||||
:bookmark,
|
||||
account: user.account,
|
||||
status: status
|
||||
)
|
||||
sign_in user
|
||||
end
|
||||
|
||||
it 'returns a CSV with the bookmarked statuses' do
|
||||
get '/settings/exports/bookmarks.csv'
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(200)
|
||||
expect(response.content_type)
|
||||
.to eq('text/csv')
|
||||
expect(response.body)
|
||||
.to eq(<<~CSV)
|
||||
https://foo.bar/statuses/1312
|
||||
CSV
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when signed out' do
|
||||
it 'returns unauthorized' do
|
||||
get '/settings/exports/bookmarks.csv'
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(401)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
44
spec/requests/settings/exports/following_accounts_spec.rb
Normal file
44
spec/requests/settings/exports/following_accounts_spec.rb
Normal file
|
@ -0,0 +1,44 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'Settings / Exports / Following Accounts' do
|
||||
describe 'GET /settings/exports/follows' do
|
||||
context 'with a signed in user who is following accounts' do
|
||||
let(:user) { Fabricate :user }
|
||||
|
||||
before do
|
||||
Fabricate(
|
||||
:follow,
|
||||
account: user.account,
|
||||
target_account: Fabricate(:account, username: 'username', domain: 'domain'),
|
||||
languages: ['en']
|
||||
)
|
||||
sign_in user
|
||||
end
|
||||
|
||||
it 'returns a CSV with the accounts' do
|
||||
get '/settings/exports/follows.csv'
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(200)
|
||||
expect(response.content_type)
|
||||
.to eq('text/csv')
|
||||
expect(response.body)
|
||||
.to eq(<<~CSV)
|
||||
Account address,Show boosts,Notify on new posts,Languages
|
||||
username@domain,true,false,en
|
||||
CSV
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when signed out' do
|
||||
it 'returns unauthorized' do
|
||||
get '/settings/exports/follows.csv'
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(401)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
40
spec/requests/settings/exports/lists_spec.rb
Normal file
40
spec/requests/settings/exports/lists_spec.rb
Normal file
|
@ -0,0 +1,40 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'Settings / Exports / Lists' do
|
||||
describe 'GET /settings/exports/lists' do
|
||||
context 'with a signed in user who has lists' do
|
||||
let(:account) { Fabricate(:account, username: 'test', domain: 'example.com') }
|
||||
let(:list) { Fabricate :list, account: account, title: 'The List' }
|
||||
let(:user) { Fabricate(:user, account: account) }
|
||||
|
||||
before do
|
||||
Fabricate(:list_account, list: list, account: account)
|
||||
sign_in user
|
||||
end
|
||||
|
||||
it 'returns a CSV with the list' do
|
||||
get '/settings/exports/lists.csv'
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(200)
|
||||
expect(response.content_type)
|
||||
.to eq('text/csv')
|
||||
expect(response.body)
|
||||
.to eq(<<~CSV)
|
||||
The List,test@example.com
|
||||
CSV
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when signed out' do
|
||||
it 'returns unauthorized' do
|
||||
get '/settings/exports/lists.csv'
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(401)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
43
spec/requests/settings/exports/muted_accounts_spec.rb
Normal file
43
spec/requests/settings/exports/muted_accounts_spec.rb
Normal file
|
@ -0,0 +1,43 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'Settings / Exports / Muted Accounts' do
|
||||
describe 'GET /settings/exports/mutes' do
|
||||
context 'with a signed in user who has muted accounts' do
|
||||
let(:user) { Fabricate :user }
|
||||
|
||||
before do
|
||||
Fabricate(
|
||||
:mute,
|
||||
account: user.account,
|
||||
target_account: Fabricate(:account, username: 'username', domain: 'domain')
|
||||
)
|
||||
sign_in user
|
||||
end
|
||||
|
||||
it 'returns a CSV with the muted accounts' do
|
||||
get '/settings/exports/mutes.csv'
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(200)
|
||||
expect(response.content_type)
|
||||
.to eq('text/csv')
|
||||
expect(response.body)
|
||||
.to eq(<<~CSV)
|
||||
Account address,Hide notifications
|
||||
username@domain,true
|
||||
CSV
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when signed out' do
|
||||
it 'returns unauthorized' do
|
||||
get '/settings/exports/mutes.csv'
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(401)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -28,7 +28,7 @@ RSpec.configure do |config|
|
|||
end
|
||||
|
||||
config.after :suite do
|
||||
FileUtils.rm_rf(Dir[Rails.root.join('spec', 'test_files')])
|
||||
FileUtils.rm_rf(Rails.root.glob('spec/test_files'))
|
||||
end
|
||||
|
||||
# Use the GitHub Annotations formatter for CI
|
||||
|
|
12
spec/system/about_spec.rb
Normal file
12
spec/system/about_spec.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'About page' do
|
||||
it 'visits the about page and renders the web app' do
|
||||
visit about_path
|
||||
|
||||
expect(page)
|
||||
.to have_css('noscript', text: /Mastodon/)
|
||||
end
|
||||
end
|
25
spec/system/home_spec.rb
Normal file
25
spec/system/home_spec.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'Home page' do
|
||||
context 'when signed in' do
|
||||
before { sign_in Fabricate(:user) }
|
||||
|
||||
it 'visits the homepage and renders the web app' do
|
||||
visit root_path
|
||||
|
||||
expect(page)
|
||||
.to have_css('noscript', text: /Mastodon/)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when not signed in' do
|
||||
it 'visits the homepage and renders the web app' do
|
||||
visit root_path
|
||||
|
||||
expect(page)
|
||||
.to have_css('noscript', text: /Mastodon/)
|
||||
end
|
||||
end
|
||||
end
|
12
spec/system/privacy_spec.rb
Normal file
12
spec/system/privacy_spec.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'Privacy policy page' do
|
||||
it 'visits the privacy policy page and renders the web app' do
|
||||
visit privacy_policy_path
|
||||
|
||||
expect(page)
|
||||
.to have_css('noscript', text: /Mastodon/)
|
||||
end
|
||||
end
|
|
@ -2,32 +2,45 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'ShareEntrypoint', :js, :streaming do
|
||||
describe 'Share page', :js, :streaming do
|
||||
include ProfileStories
|
||||
|
||||
subject { page }
|
||||
|
||||
let(:email) { 'test@example.com' }
|
||||
let(:password) { 'password' }
|
||||
let(:confirmed_at) { Time.zone.now }
|
||||
let(:finished_onboarding) { true }
|
||||
|
||||
before do
|
||||
as_a_logged_in_user
|
||||
before { as_a_logged_in_user }
|
||||
|
||||
it 'allows posting a new status' do
|
||||
visit share_path
|
||||
|
||||
expect(page)
|
||||
.to have_css('.modal-layout__mastodon')
|
||||
.and have_css('div#mastodon-compose')
|
||||
.and have_css('.compose-form__submit')
|
||||
|
||||
fill_in_form
|
||||
|
||||
expect(page)
|
||||
.to have_css('.notification-bar-message', text: translations['compose.published.body'])
|
||||
end
|
||||
|
||||
it 'can be used to post a new status' do
|
||||
expect(subject).to have_css('div#mastodon-compose')
|
||||
expect(subject).to have_css('.compose-form__submit')
|
||||
|
||||
status_text = 'This is a new status!'
|
||||
|
||||
def fill_in_form
|
||||
within('.compose-form') do
|
||||
fill_in "What's on your mind?", with: status_text
|
||||
click_on 'Post'
|
||||
fill_in translations['compose_form.placeholder'],
|
||||
with: 'This is a new status!'
|
||||
click_on translations['compose_form.publish']
|
||||
end
|
||||
end
|
||||
|
||||
expect(subject).to have_css('.notification-bar-message', text: 'Post published.')
|
||||
def translations
|
||||
# TODO: Extract to system spec helper for re-use?
|
||||
JSON.parse(
|
||||
Rails
|
||||
.root
|
||||
.join('app', 'javascript', 'mastodon', 'locales', 'en.json')
|
||||
.read
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue