Merge upstream 2.0ish #165
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Admin::AccountModerationNotesController, type: :controller do
|
||||
end
|
||||
@@ -0,0 +1,59 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Admin::EmailDomainBlocksController, type: :controller do
|
||||
render_views
|
||||
|
||||
before do
|
||||
sign_in Fabricate(:user, admin: true), scope: :user
|
||||
end
|
||||
|
||||
describe 'GET #index' do
|
||||
around do |example|
|
||||
default_per_page = EmailDomainBlock.default_per_page
|
||||
EmailDomainBlock.paginates_per 1
|
||||
example.run
|
||||
EmailDomainBlock.paginates_per default_per_page
|
||||
end
|
||||
|
||||
it 'renders email blacks' do
|
||||
2.times { Fabricate(:email_domain_block) }
|
||||
|
||||
get :index, params: { page: 2 }
|
||||
|
||||
assigned = assigns(:email_domain_blocks)
|
||||
expect(assigned.count).to eq 1
|
||||
expect(assigned.klass).to be EmailDomainBlock
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET #new' do
|
||||
it 'assigns a new email black' do
|
||||
get :new
|
||||
|
||||
expect(assigns(:email_domain_block)).to be_instance_of(EmailDomainBlock)
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #create' do
|
||||
it 'blocks the domain when succeeded to save' do
|
||||
post :create, params: { email_domain_block: { domain: 'example.com'} }
|
||||
|
||||
expect(flash[:notice]).to eq I18n.t('admin.email_domain_blocks.created_msg')
|
||||
expect(response).to redirect_to(admin_email_domain_blocks_path)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE #destroy' do
|
||||
it 'unblocks the domain' do
|
||||
email_domain_block = Fabricate(:email_domain_block)
|
||||
delete :destroy, params: { id: email_domain_block.id }
|
||||
|
||||
expect(flash[:notice]).to eq I18n.t('admin.email_domain_blocks.destroyed_msg')
|
||||
expect(response).to redirect_to(admin_email_domain_blocks_path)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -46,8 +46,8 @@ RSpec.describe Api::SalmonController, type: :controller do
|
||||
post :update, params: { id: account.id }
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
expect(response).to have_http_status(202)
|
||||
it 'returns http client error' do
|
||||
expect(response).to have_http_status(400)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
43
spec/controllers/api/v1/apps/credentials_controller_spec.rb
Normal file
43
spec/controllers/api/v1/apps/credentials_controller_spec.rb
Normal file
@@ -0,0 +1,43 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe Api::V1::Apps::CredentialsController do
|
||||
render_views
|
||||
|
||||
let(:token) { Fabricate(:accessible_access_token, scopes: 'read', application: Fabricate(:application)) }
|
||||
|
||||
context 'with an oauth token' do
|
||||
before do
|
||||
allow(controller).to receive(:doorkeeper_token) { token }
|
||||
end
|
||||
|
||||
describe 'GET #show' do
|
||||
before do
|
||||
get :show
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
|
||||
it 'does not contain client credentials' do
|
||||
json = body_as_json
|
||||
|
||||
expect(json).to_not have_key(:client_secret)
|
||||
expect(json).to_not have_key(:client_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'without an oauth token' do
|
||||
before do
|
||||
allow(controller).to receive(:doorkeeper_token) { nil }
|
||||
end
|
||||
|
||||
describe 'GET #show' do
|
||||
it 'returns http unauthorized' do
|
||||
get :show
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -6,15 +6,47 @@ RSpec.describe Api::V1::BlocksController, type: :controller do
|
||||
let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'follow') }
|
||||
|
||||
before do
|
||||
Fabricate(:block, account: user.account)
|
||||
allow(controller).to receive(:doorkeeper_token) { token }
|
||||
end
|
||||
before { allow(controller).to receive(:doorkeeper_token) { token } }
|
||||
|
||||
describe 'GET #index' do
|
||||
it 'returns http success' do
|
||||
it 'limits according to limit parameter' do
|
||||
2.times.map { Fabricate(:block, account: user.account) }
|
||||
get :index, params: { limit: 1 }
|
||||
expect(body_as_json.size).to eq 1
|
||||
end
|
||||
|
||||
it 'queries blocks in range according to max_id' do
|
||||
blocks = 2.times.map { Fabricate(:block, account: user.account) }
|
||||
|
||||
get :index, params: { max_id: blocks[1] }
|
||||
|
||||
expect(body_as_json.size).to eq 1
|
||||
expect(body_as_json[0][:id]).to eq blocks[0].target_account_id.to_s
|
||||
end
|
||||
|
||||
it 'queries blocks in range according to since_id' do
|
||||
blocks = 2.times.map { Fabricate(:block, account: user.account) }
|
||||
|
||||
get :index, params: { since_id: blocks[0] }
|
||||
|
||||
expect(body_as_json.size).to eq 1
|
||||
expect(body_as_json[0][:id]).to eq blocks[1].target_account_id.to_s
|
||||
end
|
||||
|
||||
it 'sets pagination header for next path' do
|
||||
blocks = 2.times.map { Fabricate(:block, account: user.account) }
|
||||
get :index, params: { limit: 1, since_id: blocks[0] }
|
||||
expect(response.headers['Link'].find_link(['rel', 'next']).href).to eq api_v1_blocks_url(limit: 1, max_id: blocks[1])
|
||||
end
|
||||
|
||||
it 'sets pagination header for previous path' do
|
||||
block = Fabricate(:block, account: user.account)
|
||||
get :index
|
||||
expect(response.headers['Link'].find_link(['rel', 'prev']).href).to eq api_v1_blocks_url(since_id: block)
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
get :index
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -101,4 +101,33 @@ RSpec.describe Api::V1::MediaController, type: :controller do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'PUT #update' do
|
||||
context 'when somebody else\'s' do
|
||||
let(:media) { Fabricate(:media_attachment, status: nil) }
|
||||
|
||||
it 'returns http not found' do
|
||||
put :update, params: { id: media.id, description: 'Lorem ipsum!!!' }
|
||||
expect(response).to have_http_status(:not_found)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when not attached to a status' do
|
||||
let(:media) { Fabricate(:media_attachment, status: nil, account: user.account) }
|
||||
|
||||
it 'updates the description' do
|
||||
put :update, params: { id: media.id, description: 'Lorem ipsum!!!' }
|
||||
expect(media.reload.description).to eq 'Lorem ipsum!!!'
|
||||
end
|
||||
end
|
||||
|
||||
context 'when attached to a status' do
|
||||
let(:media) { Fabricate(:media_attachment, status: Fabricate(:status), account: user.account) }
|
||||
|
||||
it 'returns http not found' do
|
||||
put :update, params: { id: media.id, description: 'Lorem ipsum!!!' }
|
||||
expect(response).to have_http_status(:not_found)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -8,10 +8,6 @@ describe ManifestsController do
|
||||
get :show, format: :json
|
||||
end
|
||||
|
||||
it 'assigns @instance_presenter' do
|
||||
expect(assigns(:instance_presenter)).to be_kind_of InstancePresenter
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
|
||||
@@ -5,15 +5,41 @@ describe Settings::FollowerDomainsController do
|
||||
|
||||
let(:user) { Fabricate(:user) }
|
||||
|
||||
before do
|
||||
sign_in user, scope: :user
|
||||
shared_examples 'authenticate user' do
|
||||
it 'redirects when not signed in' do
|
||||
is_expected.to redirect_to '/auth/sign_in'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET #show' do
|
||||
subject { get :show, params: { page: 2 } }
|
||||
|
||||
it 'assigns @account' do
|
||||
sign_in user, scope: :user
|
||||
subject
|
||||
expect(assigns(:account)).to eq user.account
|
||||
end
|
||||
|
||||
it 'assigns @domains' do
|
||||
Fabricate(:account, domain: 'old').follow!(user.account)
|
||||
Fabricate(:account, domain: 'recent').follow!(user.account)
|
||||
|
||||
sign_in user, scope: :user
|
||||
subject
|
||||
|
||||
assigned = assigns(:domains).per(1).to_a
|
||||
expect(assigned.size).to eq 1
|
||||
expect(assigned[0].accounts_from_domain).to eq 1
|
||||
expect(assigned[0].domain).to eq 'old'
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
get :show
|
||||
sign_in user, scope: :user
|
||||
subject
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
|
||||
include_examples 'authenticate user'
|
||||
end
|
||||
|
||||
describe 'PATCH #update' do
|
||||
@@ -21,16 +47,39 @@ describe Settings::FollowerDomainsController do
|
||||
|
||||
before do
|
||||
stub_request(:post, 'http://example.com/salmon').to_return(status: 200)
|
||||
poopfeast.follow!(user.account)
|
||||
patch :update, params: { select: ['example.com'] }
|
||||
end
|
||||
|
||||
it 'redirects back to followers page' do
|
||||
expect(response).to redirect_to(settings_follower_domains_path)
|
||||
shared_examples 'redirects back to followers page' do |notice|
|
||||
it 'redirects back to followers page' do
|
||||
poopfeast.follow!(user.account)
|
||||
|
||||
sign_in user, scope: :user
|
||||
subject
|
||||
|
||||
expect(flash[:notice]).to eq notice
|
||||
expect(response).to redirect_to(settings_follower_domains_path)
|
||||
end
|
||||
end
|
||||
|
||||
it 'soft-blocks followers from selected domains' do
|
||||
expect(poopfeast.following?(user.account)).to be false
|
||||
context 'when select parameter is not provided' do
|
||||
subject { patch :update }
|
||||
include_examples 'redirects back to followers page', 'In the process of soft-blocking followers from 0 domains...'
|
||||
end
|
||||
|
||||
context 'when select parameter is provided' do
|
||||
subject { patch :update, params: { select: ['example.com'] } }
|
||||
|
||||
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
|
||||
|
||||
include_examples 'authenticate user'
|
||||
include_examples 'redirects back to followers page', 'In the process of soft-blocking followers from one domain...'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
37
spec/controllers/settings/notifications_controller_spec.rb
Normal file
37
spec/controllers/settings/notifications_controller_spec.rb
Normal file
@@ -0,0 +1,37 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe Settings::NotificationsController do
|
||||
render_views
|
||||
|
||||
let(:user) { Fabricate(:user) }
|
||||
|
||||
before do
|
||||
sign_in user, scope: :user
|
||||
end
|
||||
|
||||
describe 'GET #show' do
|
||||
it 'returns http success' do
|
||||
get :show
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'PUT #update' do
|
||||
it 'updates notifications settings' do
|
||||
user.settings['notification_emails'] = user.settings['notification_emails'].merge('follow' => false)
|
||||
user.settings['interactions'] = user.settings['interactions'].merge('must_be_follower' => true)
|
||||
|
||||
put :update, params: {
|
||||
user: {
|
||||
notification_emails: { follow: '1' },
|
||||
interactions: { must_be_follower: '0' },
|
||||
}
|
||||
}
|
||||
|
||||
expect(response).to redirect_to(settings_notifications_path)
|
||||
user.reload
|
||||
expect(user.settings['notification_emails']['follow']).to be true
|
||||
expect(user.settings['interactions']['must_be_follower']).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -29,15 +29,11 @@ describe Settings::PreferencesController do
|
||||
it 'updates user settings' do
|
||||
user.settings['boost_modal'] = false
|
||||
user.settings['delete_modal'] = true
|
||||
user.settings['notification_emails'] = user.settings['notification_emails'].merge('follow' => false)
|
||||
user.settings['interactions'] = user.settings['interactions'].merge('must_be_follower' => true)
|
||||
|
||||
put :update, params: {
|
||||
user: {
|
||||
setting_boost_modal: '1',
|
||||
setting_delete_modal: '0',
|
||||
notification_emails: { follow: '1' },
|
||||
interactions: { must_be_follower: '0' },
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,8 +41,6 @@ describe Settings::PreferencesController do
|
||||
user.reload
|
||||
expect(user.settings['boost_modal']).to be true
|
||||
expect(user.settings['delete_modal']).to be false
|
||||
expect(user.settings['notification_emails']['follow']).to be true
|
||||
expect(user.settings['interactions']['must_be_follower']).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,9 +5,9 @@ RSpec.describe TagsController, type: :controller do
|
||||
|
||||
describe 'GET #show' do
|
||||
let!(:tag) { Fabricate(:tag, name: 'test') }
|
||||
let!(:local) { Fabricate(:status, tags: [ tag ], text: 'local #test') }
|
||||
let!(:remote) { Fabricate(:status, tags: [ tag ], text: 'remote #test', account: Fabricate(:account, domain: 'remote')) }
|
||||
let!(:late) { Fabricate(:status, tags: [ tag ], text: 'late #test') }
|
||||
let!(:local) { Fabricate(:status, tags: [tag], text: 'local #test') }
|
||||
let!(:remote) { Fabricate(:status, tags: [tag], text: 'remote #test', account: Fabricate(:account, domain: 'remote')) }
|
||||
let!(:late) { Fabricate(:status, tags: [tag], text: 'late #test') }
|
||||
|
||||
context 'when tag exists' do
|
||||
it 'returns http success' do
|
||||
@@ -15,41 +15,9 @@ RSpec.describe TagsController, type: :controller do
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
|
||||
it 'renders public layout' do
|
||||
it 'renders application layout' do
|
||||
get :show, params: { id: 'test', max_id: late.id }
|
||||
expect(response).to render_template layout: 'public'
|
||||
end
|
||||
|
||||
it 'renders only local statuses if local parameter is specified' do
|
||||
get :show, params: { id: 'test', local: true, max_id: late.id }
|
||||
|
||||
expect(assigns(:tag)).to eq tag
|
||||
statuses = assigns(:statuses).to_a
|
||||
expect(statuses.size).to eq 1
|
||||
expect(statuses[0]).to eq local
|
||||
end
|
||||
|
||||
it 'renders local and remote statuses if local parameter is not specified' do
|
||||
get :show, params: { id: 'test', max_id: late.id }
|
||||
|
||||
expect(assigns(:tag)).to eq tag
|
||||
statuses = assigns(:statuses).to_a
|
||||
expect(statuses.size).to eq 2
|
||||
expect(statuses[0]).to eq remote
|
||||
expect(statuses[1]).to eq local
|
||||
end
|
||||
|
||||
it 'filters statuses by the current account' do
|
||||
user = Fabricate(:user)
|
||||
user.account.block!(remote.account)
|
||||
|
||||
sign_in(user)
|
||||
get :show, params: { id: 'test', max_id: late.id }
|
||||
|
||||
expect(assigns(:tag)).to eq tag
|
||||
statuses = assigns(:statuses).to_a
|
||||
expect(statuses.size).to eq 1
|
||||
expect(statuses[0]).to eq local
|
||||
expect(response).to render_template layout: 'application'
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user