Merge commit '55e7c08a83547424024bac311d5459cb82cf6dae' into glitch-soc/merge-upstream
Conflicts: - `app/models/user_settings.rb`: Upstream added a constraint on a setting textually close to glitch-soc-only settings. Applied upstream's change. - `lib/sanitize_ext/sanitize_config.rb`: Upstream added support for the `translate` attribute on a few elements, where glitch-soc had a different set of allowed elements and attributes. Extended glitch-soc's allowed attributes with `translate` as upstream did. - `spec/validators/status_length_validator_spec.rb`: Upstream refactored to use RSpec's `instance_double` instead of `double`, but glitch-soc had changes to tests due to configurable max toot chars. Applied upstream's changes while keeping tests against configurable max toot chars.
This commit is contained in:
@@ -1,55 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Api::V1::Admin::AccountActionsController do
|
||||
render_views
|
||||
|
||||
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(:account) { Fabricate(:account) }
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:doorkeeper_token) { token }
|
||||
end
|
||||
|
||||
describe 'POST #create' do
|
||||
context 'with type of disable' do
|
||||
before do
|
||||
post :create, params: { account_id: account.id, type: 'disable' }
|
||||
end
|
||||
|
||||
it_behaves_like 'forbidden for wrong scope', 'write:statuses'
|
||||
it_behaves_like 'forbidden for wrong role', ''
|
||||
|
||||
it 'returns http success' do
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
|
||||
it 'performs action against account' do
|
||||
expect(account.reload.user_disabled?).to be true
|
||||
end
|
||||
|
||||
it 'logs action' do
|
||||
log_item = Admin::ActionLog.last
|
||||
|
||||
expect(log_item).to_not be_nil
|
||||
expect(log_item.action).to eq :disable
|
||||
expect(log_item.account_id).to eq user.account_id
|
||||
expect(log_item.target_id).to eq account.user.id
|
||||
end
|
||||
end
|
||||
|
||||
context 'with no type' do
|
||||
before do
|
||||
post :create, params: { account_id: account.id }
|
||||
end
|
||||
|
||||
it 'returns http unprocessable entity' do
|
||||
expect(response).to have_http_status(422)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@@ -18,6 +18,7 @@ RSpec.describe Api::V1::ConversationsController do
|
||||
|
||||
before do
|
||||
PostStatusService.new.call(other.account, text: 'Hey @alice', visibility: 'direct')
|
||||
PostStatusService.new.call(user.account, text: 'Hey, nobody here', visibility: 'direct')
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
@@ -33,7 +34,8 @@ RSpec.describe Api::V1::ConversationsController do
|
||||
it 'returns conversations' do
|
||||
get :index
|
||||
json = body_as_json
|
||||
expect(json.size).to eq 1
|
||||
expect(json.size).to eq 2
|
||||
expect(json[0][:accounts].size).to eq 1
|
||||
end
|
||||
|
||||
context 'with since_id' do
|
||||
@@ -41,7 +43,7 @@ RSpec.describe Api::V1::ConversationsController do
|
||||
it 'returns conversations' do
|
||||
get :index, params: { since_id: Mastodon::Snowflake.id_at(1.hour.ago, with_random: false) }
|
||||
json = body_as_json
|
||||
expect(json.size).to eq 1
|
||||
expect(json.size).to eq 2
|
||||
end
|
||||
end
|
||||
|
||||
|
@@ -67,24 +67,13 @@ RSpec.describe Api::V1::NotificationsController do
|
||||
get :index
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
it 'returns expected notification types', :aggregate_failures do
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
|
||||
it 'includes reblog' do
|
||||
expect(body_as_json.pluck(:type)).to include 'reblog'
|
||||
end
|
||||
|
||||
it 'includes mention' do
|
||||
expect(body_as_json.pluck(:type)).to include 'mention'
|
||||
end
|
||||
|
||||
it 'includes favourite' do
|
||||
expect(body_as_json.pluck(:type)).to include 'favourite'
|
||||
end
|
||||
|
||||
it 'includes follow' do
|
||||
expect(body_as_json.pluck(:type)).to include 'follow'
|
||||
expect(body_json_types).to include 'reblog'
|
||||
expect(body_json_types).to include 'mention'
|
||||
expect(body_json_types).to include 'favourite'
|
||||
expect(body_json_types).to include 'follow'
|
||||
end
|
||||
end
|
||||
|
||||
@@ -93,12 +82,14 @@ RSpec.describe Api::V1::NotificationsController do
|
||||
get :index, params: { account_id: third.account.id }
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
it 'returns only notifications from specified user', :aggregate_failures do
|
||||
expect(response).to have_http_status(200)
|
||||
|
||||
expect(body_json_account_ids.uniq).to eq [third.account.id.to_s]
|
||||
end
|
||||
|
||||
it 'returns only notifications from specified user' do
|
||||
expect(body_as_json.map { |x| x[:account][:id] }.uniq).to eq [third.account.id.to_s]
|
||||
def body_json_account_ids
|
||||
body_as_json.map { |x| x[:account][:id] }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -107,27 +98,23 @@ RSpec.describe Api::V1::NotificationsController do
|
||||
get :index, params: { account_id: 'foo' }
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
it 'returns nothing', :aggregate_failures do
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
|
||||
it 'returns nothing' do
|
||||
expect(body_as_json.size).to eq 0
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with excluded_types param' do
|
||||
describe 'with exclude_types param' do
|
||||
before do
|
||||
get :index, params: { exclude_types: %w(mention) }
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
it 'returns everything but excluded type', :aggregate_failures do
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
|
||||
it 'returns everything but excluded type' do
|
||||
expect(body_as_json.size).to_not eq 0
|
||||
expect(body_as_json.pluck(:type).uniq).to_not include 'mention'
|
||||
expect(body_json_types.uniq).to_not include 'mention'
|
||||
end
|
||||
end
|
||||
|
||||
@@ -136,13 +123,15 @@ RSpec.describe Api::V1::NotificationsController do
|
||||
get :index, params: { types: %w(mention) }
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
it 'returns only requested type', :aggregate_failures do
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
|
||||
it 'returns only requested type' do
|
||||
expect(body_as_json.pluck(:type).uniq).to eq ['mention']
|
||||
expect(body_json_types.uniq).to eq ['mention']
|
||||
end
|
||||
end
|
||||
|
||||
def body_json_types
|
||||
body_as_json.pluck(:type)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@@ -23,7 +23,8 @@ RSpec.describe Api::V1::ReportsController do
|
||||
let(:rule_ids) { nil }
|
||||
|
||||
before do
|
||||
allow(AdminMailer).to receive(:new_report).and_return(double('email', deliver_later: nil))
|
||||
allow(AdminMailer).to receive(:new_report)
|
||||
.and_return(instance_double(ActionMailer::MessageDelivery, deliver_later: nil))
|
||||
post :create, params: { status_ids: [status.id], account_id: target_account.id, comment: 'reasons', category: category, rule_ids: rule_ids, forward: forward }
|
||||
end
|
||||
|
||||
|
@@ -23,6 +23,7 @@ describe Api::V1::Statuses::HistoriesController do
|
||||
|
||||
it 'returns http success' do
|
||||
expect(response).to have_http_status(200)
|
||||
expect(body_as_json.size).to_not be 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@@ -1,37 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Api::V1::SuggestionsController do
|
||||
render_views
|
||||
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read write') }
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:doorkeeper_token) { token }
|
||||
end
|
||||
|
||||
describe 'GET #index' do
|
||||
let(:bob) { Fabricate(:account) }
|
||||
let(:jeff) { Fabricate(:account) }
|
||||
|
||||
before do
|
||||
PotentialFriendshipTracker.record(user.account_id, bob.id, :reblog)
|
||||
PotentialFriendshipTracker.record(user.account_id, jeff.id, :favourite)
|
||||
|
||||
get :index
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
|
||||
it 'returns accounts' do
|
||||
json = body_as_json
|
||||
|
||||
expect(json.size).to be >= 1
|
||||
expect(json.pluck(:id)).to include(*[bob, jeff].map { |i| i.id.to_s })
|
||||
end
|
||||
end
|
||||
end
|
@@ -1,88 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Api::V1::TagsController do
|
||||
render_views
|
||||
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:scopes) { 'write:follows' }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
||||
|
||||
before { allow(controller).to receive(:doorkeeper_token) { token } }
|
||||
|
||||
describe 'GET #show' do
|
||||
before do
|
||||
get :show, params: { id: name }
|
||||
end
|
||||
|
||||
context 'with existing tag' do
|
||||
let!(:tag) { Fabricate(:tag) }
|
||||
let(:name) { tag.name }
|
||||
|
||||
it 'returns http success' do
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with non-existing tag' do
|
||||
let(:name) { 'hoge' }
|
||||
|
||||
it 'returns http success' do
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #follow' do
|
||||
let!(:unrelated_tag) { Fabricate(:tag) }
|
||||
|
||||
before do
|
||||
TagFollow.create!(account: user.account, tag: unrelated_tag)
|
||||
|
||||
post :follow, params: { id: name }
|
||||
end
|
||||
|
||||
context 'with existing tag' do
|
||||
let!(:tag) { Fabricate(:tag) }
|
||||
let(:name) { tag.name }
|
||||
|
||||
it 'returns http success' do
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
|
||||
it 'creates follow' do
|
||||
expect(TagFollow.where(tag: tag, account: user.account).exists?).to be true
|
||||
end
|
||||
end
|
||||
|
||||
context 'with non-existing tag' do
|
||||
let(:name) { 'hoge' }
|
||||
|
||||
it 'returns http success' do
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
|
||||
it 'creates follow' do
|
||||
expect(TagFollow.where(tag: Tag.find_by!(name: name), account: user.account).exists?).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #unfollow' do
|
||||
let!(:tag) { Fabricate(:tag, name: 'foo') }
|
||||
let!(:tag_follow) { Fabricate(:tag_follow, account: user.account, tag: tag) }
|
||||
|
||||
before do
|
||||
post :unfollow, params: { id: tag.name }
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
|
||||
it 'removes the follow' do
|
||||
expect(TagFollow.where(tag: tag, account: user.account).exists?).to be false
|
||||
end
|
||||
end
|
||||
end
|
@@ -55,5 +55,13 @@ RSpec.describe Api::V2::Admin::AccountsController do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with limit param' do
|
||||
let(:params) { { limit: 1 } }
|
||||
|
||||
it 'sets the correct pagination headers' do
|
||||
expect(response.headers['Link'].find_link(%w(rel next)).href).to eq api_v2_admin_accounts_url(limit: 1, max_id: admin_account.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@@ -26,7 +26,7 @@ describe Api::Web::EmbedsController do
|
||||
|
||||
context 'when fails to find status' do
|
||||
let(:url) { 'https://host.test/oembed.html' }
|
||||
let(:service_instance) { double('fetch_oembed_service') }
|
||||
let(:service_instance) { instance_double(FetchOEmbedService) }
|
||||
|
||||
before do
|
||||
allow(FetchOEmbedService).to receive(:new) { service_instance }
|
||||
|
Reference in New Issue
Block a user