2023-02-22 11:55:31 +11:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-24 08:38:37 +10:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2024-09-04 15:12:25 +10:00
|
|
|
RSpec.describe RelationshipsController do
|
2017-04-28 23:12:37 +10:00
|
|
|
render_views
|
|
|
|
|
2017-04-24 08:38:37 +10:00
|
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
|
|
|
|
describe 'GET #show' do
|
2023-04-20 00:07:29 +10:00
|
|
|
context 'when signed in' do
|
|
|
|
before do
|
|
|
|
sign_in user, scope: :user
|
|
|
|
get :show, params: { page: 2, relationship: 'followed_by' }
|
|
|
|
end
|
2017-10-01 08:06:09 +11:00
|
|
|
|
2023-04-20 00:07:29 +10:00
|
|
|
it 'returns http success' do
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
end
|
2017-10-01 08:06:09 +11:00
|
|
|
|
2023-04-20 00:07:29 +10:00
|
|
|
it 'returns private cache control headers' do
|
|
|
|
expect(response.headers['Cache-Control']).to include('private, no-store')
|
|
|
|
end
|
2017-10-01 08:06:09 +11:00
|
|
|
end
|
|
|
|
|
2023-04-20 00:07:29 +10:00
|
|
|
context 'when not signed in' do
|
|
|
|
before do
|
|
|
|
get :show, params: { page: 2, relationship: 'followed_by' }
|
|
|
|
end
|
2017-10-01 08:06:09 +11:00
|
|
|
|
2023-04-20 00:07:29 +10:00
|
|
|
it 'redirects when not signed in' do
|
|
|
|
expect(response).to redirect_to '/auth/sign_in'
|
|
|
|
end
|
|
|
|
end
|
2017-04-24 08:38:37 +10:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'PATCH #update' do
|
2023-04-20 00:07:29 +10:00
|
|
|
let(:alice) { Fabricate(:account, username: 'alice', domain: 'example.com') }
|
2017-04-24 08:38:37 +10:00
|
|
|
|
2019-03-16 21:23:22 +11:00
|
|
|
shared_examples 'redirects back to followers page' do
|
2017-10-01 08:06:09 +11:00
|
|
|
it 'redirects back to followers page' do
|
2023-04-20 00:07:29 +10:00
|
|
|
alice.follow!(user.account)
|
2017-10-01 08:06:09 +11:00
|
|
|
|
|
|
|
sign_in user, scope: :user
|
|
|
|
subject
|
|
|
|
|
2019-03-16 21:23:22 +11:00
|
|
|
expect(response).to redirect_to(relationships_path)
|
2017-10-01 08:06:09 +11:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when select parameter is not provided' do
|
|
|
|
subject { patch :update }
|
2023-02-20 12:46:00 +11:00
|
|
|
|
2019-03-16 21:23:22 +11:00
|
|
|
include_examples 'redirects back to followers page'
|
2017-04-24 08:38:37 +10:00
|
|
|
end
|
|
|
|
|
2017-10-01 08:06:09 +11:00
|
|
|
context 'when select parameter is provided' do
|
2023-04-20 00:07:29 +10:00
|
|
|
subject { patch :update, params: { form_account_batch: { account_ids: [alice.id] }, remove_domains_from_followers: '' } }
|
2017-10-01 08:06:09 +11:00
|
|
|
|
|
|
|
it 'soft-blocks followers from selected domains' do
|
2023-04-20 00:07:29 +10:00
|
|
|
alice.follow!(user.account)
|
2017-10-01 08:06:09 +11:00
|
|
|
|
|
|
|
sign_in user, scope: :user
|
|
|
|
subject
|
|
|
|
|
2023-04-20 00:07:29 +10:00
|
|
|
expect(alice.following?(user.account)).to be false
|
2017-10-01 08:06:09 +11:00
|
|
|
end
|
|
|
|
|
2023-03-04 06:25:15 +11:00
|
|
|
it 'does not unfollow users from selected domains' do
|
2023-04-20 00:07:29 +10:00
|
|
|
user.account.follow!(alice)
|
2023-03-04 06:25:15 +11:00
|
|
|
|
|
|
|
sign_in user, scope: :user
|
|
|
|
subject
|
|
|
|
|
2023-04-20 00:07:29 +10:00
|
|
|
expect(user.account.following?(alice)).to be true
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when not signed in' do
|
|
|
|
before do
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'redirects when not signed in' do
|
|
|
|
expect(response).to redirect_to '/auth/sign_in'
|
|
|
|
end
|
2023-03-04 06:25:15 +11:00
|
|
|
end
|
|
|
|
|
2019-03-16 21:23:22 +11:00
|
|
|
include_examples 'redirects back to followers page'
|
2017-04-24 08:38:37 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|