2023-02-21 19:55:31 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-23 18:38:37 -04:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2019-03-16 06:23:22 -04:00
|
|
|
describe RelationshipsController do
|
2017-04-28 09:12:37 -04:00
|
|
|
render_views
|
|
|
|
|
2017-04-23 18:38:37 -04:00
|
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
|
2017-09-30 17:06:09 -04:00
|
|
|
shared_examples 'authenticate user' do
|
|
|
|
it 'redirects when not signed in' do
|
2023-02-19 23:00:48 -05:00
|
|
|
expect(subject).to redirect_to '/auth/sign_in'
|
2017-09-30 17:06:09 -04:00
|
|
|
end
|
2017-04-23 18:38:37 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #show' do
|
2019-03-16 06:23:22 -04:00
|
|
|
subject { get :show, params: { page: 2, relationship: 'followed_by' } }
|
2017-09-30 17:06:09 -04:00
|
|
|
|
2019-03-16 06:23:22 -04:00
|
|
|
it 'assigns @accounts' do
|
2017-09-30 17:06:09 -04:00
|
|
|
Fabricate(:account, domain: 'old').follow!(user.account)
|
|
|
|
Fabricate(:account, domain: 'recent').follow!(user.account)
|
|
|
|
|
|
|
|
sign_in user, scope: :user
|
|
|
|
subject
|
|
|
|
|
2019-03-16 06:23:22 -04:00
|
|
|
assigned = assigns(:accounts).per(1).to_a
|
2017-09-30 17:06:09 -04:00
|
|
|
expect(assigned.size).to eq 1
|
|
|
|
expect(assigned[0].domain).to eq 'old'
|
|
|
|
end
|
|
|
|
|
2017-04-23 18:38:37 -04:00
|
|
|
it 'returns http success' do
|
2017-09-30 17:06:09 -04:00
|
|
|
sign_in user, scope: :user
|
|
|
|
subject
|
2018-04-21 15:35:07 -04:00
|
|
|
expect(response).to have_http_status(200)
|
2017-04-23 18:38:37 -04:00
|
|
|
end
|
2017-09-30 17:06:09 -04:00
|
|
|
|
|
|
|
include_examples 'authenticate user'
|
2017-04-23 18:38:37 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'PATCH #update' do
|
2021-05-07 13:32:58 -04:00
|
|
|
let(:poopfeast) { Fabricate(:account, username: 'poopfeast', domain: 'example.com') }
|
2017-04-23 18:38:37 -04:00
|
|
|
|
2019-03-16 06:23:22 -04:00
|
|
|
shared_examples 'redirects back to followers page' do
|
2017-09-30 17:06:09 -04:00
|
|
|
it 'redirects back to followers page' do
|
|
|
|
poopfeast.follow!(user.account)
|
|
|
|
|
|
|
|
sign_in user, scope: :user
|
|
|
|
subject
|
|
|
|
|
2019-03-16 06:23:22 -04:00
|
|
|
expect(response).to redirect_to(relationships_path)
|
2017-09-30 17:06:09 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when select parameter is not provided' do
|
|
|
|
subject { patch :update }
|
2023-02-19 20:46:00 -05:00
|
|
|
|
2019-03-16 06:23:22 -04:00
|
|
|
include_examples 'redirects back to followers page'
|
2017-04-23 18:38:37 -04:00
|
|
|
end
|
|
|
|
|
2017-09-30 17:06:09 -04:00
|
|
|
context 'when select parameter is provided' do
|
2023-03-03 14:25:15 -05:00
|
|
|
subject { patch :update, params: { form_account_batch: { account_ids: [poopfeast.id] }, remove_domains_from_followers: '' } }
|
2017-09-30 17:06:09 -04:00
|
|
|
|
|
|
|
it 'soft-blocks followers from selected domains' do
|
|
|
|
poopfeast.follow!(user.account)
|
|
|
|
|
|
|
|
sign_in user, scope: :user
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(poopfeast.following?(user.account)).to be false
|
|
|
|
end
|
|
|
|
|
2023-03-03 14:25:15 -05:00
|
|
|
it 'does not unfollow users from selected domains' do
|
|
|
|
user.account.follow!(poopfeast)
|
|
|
|
|
|
|
|
sign_in user, scope: :user
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(user.account.following?(poopfeast)).to be true
|
|
|
|
end
|
|
|
|
|
2017-09-30 17:06:09 -04:00
|
|
|
include_examples 'authenticate user'
|
2019-03-16 06:23:22 -04:00
|
|
|
include_examples 'redirects back to followers page'
|
2017-04-23 18:38:37 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|