Merge commit '6c4c72497a5722870e4432ef41dd4c9ec36a8928' into glitch-soc/merge-upstream
Conflicts: - `.github/workflows/build-releases.yml`: Upstream changed comments close to a line we modified to account for different container image repositories. Updated the comments as upstream did.
This commit is contained in:
@@ -5,36 +5,66 @@ require 'rails_helper'
|
||||
describe Api::V1::Timelines::TagController do
|
||||
render_views
|
||||
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read:statuses') }
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:doorkeeper_token) { token }
|
||||
end
|
||||
|
||||
context 'with a user context' do
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id) }
|
||||
describe 'GET #show' do
|
||||
subject do
|
||||
get :show, params: { id: 'test' }
|
||||
end
|
||||
|
||||
describe 'GET #show' do
|
||||
before do
|
||||
PostStatusService.new.call(user.account, text: 'It is a #test')
|
||||
before do
|
||||
PostStatusService.new.call(user.account, text: 'It is a #test')
|
||||
end
|
||||
|
||||
context 'when the instance allows public preview' do
|
||||
context 'when the user is not authenticated' do
|
||||
let(:token) { nil }
|
||||
|
||||
it 'returns http success', :aggregate_failures do
|
||||
subject
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response.headers['Link'].links.size).to eq(2)
|
||||
end
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
get :show, params: { id: 'test' }
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response.headers['Link'].links.size).to eq(2)
|
||||
context 'when the user is authenticated' do
|
||||
it 'returns http success', :aggregate_failures do
|
||||
subject
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response.headers['Link'].links.size).to eq(2)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'without a user context' do
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: nil) }
|
||||
context 'when the instance does not allow public preview' do
|
||||
before do
|
||||
Form::AdminSettings.new(timeline_preview: false).save
|
||||
end
|
||||
|
||||
describe 'GET #show' do
|
||||
it 'returns http success' do
|
||||
get :show, params: { id: 'test' }
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response.headers['Link']).to be_nil
|
||||
context 'when the user is not authenticated' do
|
||||
let(:token) { nil }
|
||||
|
||||
it 'returns http unauthorized' do
|
||||
subject
|
||||
|
||||
expect(response).to have_http_status(401)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the user is authenticated' do
|
||||
it 'returns http success', :aggregate_failures do
|
||||
subject
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response.headers['Link'].links.size).to eq(2)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe WellKnown::WebfingerController do
|
||||
include RoutingHelper
|
||||
|
||||
render_views
|
||||
|
||||
describe 'GET #show' do
|
||||
@@ -167,5 +169,67 @@ describe WellKnown::WebfingerController do
|
||||
expect(response).to have_http_status(400)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when an account has an avatar' do
|
||||
let(:alice) { Fabricate(:account, username: 'alice', avatar: attachment_fixture('attachment.jpg')) }
|
||||
let(:resource) { alice.to_webfinger_s }
|
||||
|
||||
it 'returns avatar in response' do
|
||||
perform_show!
|
||||
|
||||
avatar_link = get_avatar_link(body_as_json)
|
||||
expect(avatar_link).to_not be_nil
|
||||
expect(avatar_link[:type]).to eq alice.avatar.content_type
|
||||
expect(avatar_link[:href]).to eq full_asset_url(alice.avatar)
|
||||
end
|
||||
|
||||
context 'with limited federation mode' do
|
||||
before do
|
||||
allow(Rails.configuration.x).to receive(:limited_federation_mode).and_return(true)
|
||||
end
|
||||
|
||||
it 'does not return avatar in response' do
|
||||
perform_show!
|
||||
|
||||
avatar_link = get_avatar_link(body_as_json)
|
||||
expect(avatar_link).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'when enabling DISALLOW_UNAUTHENTICATED_API_ACCESS' do
|
||||
around do |example|
|
||||
ClimateControl.modify DISALLOW_UNAUTHENTICATED_API_ACCESS: 'true' do
|
||||
example.run
|
||||
end
|
||||
end
|
||||
|
||||
it 'does not return avatar in response' do
|
||||
perform_show!
|
||||
|
||||
avatar_link = get_avatar_link(body_as_json)
|
||||
expect(avatar_link).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when an account does not have an avatar' do
|
||||
let(:alice) { Fabricate(:account, username: 'alice', avatar: nil) }
|
||||
let(:resource) { alice.to_webfinger_s }
|
||||
|
||||
before do
|
||||
perform_show!
|
||||
end
|
||||
|
||||
it 'does not return avatar in response' do
|
||||
avatar_link = get_avatar_link(body_as_json)
|
||||
expect(avatar_link).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_avatar_link(json)
|
||||
json[:links].find { |link| link[:rel] == 'http://webfinger.net/rel/avatar' }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
require 'parslet/rig/rspec'
|
||||
|
||||
describe SearchQueryParser do
|
||||
let(:parser) { described_class.new }
|
||||
|
||||
context 'with term' do
|
||||
it 'consumes "hello"' do
|
||||
expect(parser.term).to parse('hello')
|
||||
end
|
||||
end
|
||||
|
||||
context 'with prefix' do
|
||||
it 'consumes "foo:"' do
|
||||
expect(parser.prefix).to parse('foo:')
|
||||
end
|
||||
end
|
||||
|
||||
context 'with operator' do
|
||||
it 'consumes "+"' do
|
||||
expect(parser.operator).to parse('+')
|
||||
end
|
||||
|
||||
it 'consumes "-"' do
|
||||
expect(parser.operator).to parse('-')
|
||||
end
|
||||
end
|
||||
|
||||
context 'with shortcode' do
|
||||
it 'consumes ":foo:"' do
|
||||
expect(parser.shortcode).to parse(':foo:')
|
||||
end
|
||||
end
|
||||
|
||||
context 'with phrase' do
|
||||
it 'consumes "hello world"' do
|
||||
expect(parser.phrase).to parse('"hello world"')
|
||||
end
|
||||
end
|
||||
|
||||
context 'with clause' do
|
||||
it 'consumes "foo"' do
|
||||
expect(parser.clause).to parse('foo')
|
||||
end
|
||||
|
||||
it 'consumes "-foo"' do
|
||||
expect(parser.clause).to parse('-foo')
|
||||
end
|
||||
|
||||
it 'consumes "foo:bar"' do
|
||||
expect(parser.clause).to parse('foo:bar')
|
||||
end
|
||||
|
||||
it 'consumes "-foo:bar"' do
|
||||
expect(parser.clause).to parse('-foo:bar')
|
||||
end
|
||||
|
||||
it 'consumes \'foo:"hello world"\'' do
|
||||
expect(parser.clause).to parse('foo:"hello world"')
|
||||
end
|
||||
|
||||
it 'consumes \'-foo:"hello world"\'' do
|
||||
expect(parser.clause).to parse('-foo:"hello world"')
|
||||
end
|
||||
|
||||
it 'consumes "foo:"' do
|
||||
expect(parser.clause).to parse('foo:')
|
||||
end
|
||||
|
||||
it 'consumes \'"\'' do
|
||||
expect(parser.clause).to parse('"')
|
||||
end
|
||||
end
|
||||
|
||||
context 'with query' do
|
||||
it 'consumes "hello -world"' do
|
||||
expect(parser.query).to parse('hello -world')
|
||||
end
|
||||
|
||||
it 'consumes \'foo "hello world"\'' do
|
||||
expect(parser.query).to parse('foo "hello world"')
|
||||
end
|
||||
|
||||
it 'consumes "foo:bar hello"' do
|
||||
expect(parser.query).to parse('foo:bar hello')
|
||||
end
|
||||
|
||||
it 'consumes \'"hello" world "\'' do
|
||||
expect(parser.query).to parse('"hello" world "')
|
||||
end
|
||||
|
||||
it 'consumes "foo:bar bar: hello"' do
|
||||
expect(parser.query).to parse('foo:bar bar: hello')
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -3,16 +3,57 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe SearchQueryTransformer do
|
||||
describe 'initialization' do
|
||||
let(:parser) { SearchQueryParser.new.parse('query') }
|
||||
subject { described_class.new.apply(parser, current_account: nil) }
|
||||
|
||||
it 'sets attributes' do
|
||||
transformer = described_class.new.apply(parser)
|
||||
let(:parser) { SearchQueryParser.new.parse(query) }
|
||||
|
||||
expect(transformer.should_clauses.first).to be_nil
|
||||
expect(transformer.must_clauses.first).to be_a(SearchQueryTransformer::TermClause)
|
||||
expect(transformer.must_not_clauses.first).to be_nil
|
||||
expect(transformer.filter_clauses.first).to be_nil
|
||||
context 'with "hello world"' do
|
||||
let(:query) { 'hello world' }
|
||||
|
||||
it 'transforms clauses' do
|
||||
expect(subject.must_clauses.map(&:term)).to match_array %w(hello world)
|
||||
expect(subject.must_not_clauses).to be_empty
|
||||
expect(subject.filter_clauses).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
context 'with "hello -world"' do
|
||||
let(:query) { 'hello -world' }
|
||||
|
||||
it 'transforms clauses' do
|
||||
expect(subject.must_clauses.map(&:term)).to match_array %w(hello)
|
||||
expect(subject.must_not_clauses.map(&:term)).to match_array %w(world)
|
||||
expect(subject.filter_clauses).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
context 'with "hello is:reply"' do
|
||||
let(:query) { 'hello is:reply' }
|
||||
|
||||
it 'transforms clauses' do
|
||||
expect(subject.must_clauses.map(&:term)).to match_array %w(hello)
|
||||
expect(subject.must_not_clauses).to be_empty
|
||||
expect(subject.filter_clauses.map(&:term)).to match_array %w(reply)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with "foo: bar"' do
|
||||
let(:query) { 'foo: bar' }
|
||||
|
||||
it 'transforms clauses' do
|
||||
expect(subject.must_clauses.map(&:term)).to match_array %w(foo bar)
|
||||
expect(subject.must_not_clauses).to be_empty
|
||||
expect(subject.filter_clauses).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
context 'with "foo:bar"' do
|
||||
let(:query) { 'foo:bar' }
|
||||
|
||||
it 'transforms clauses' do
|
||||
expect(subject.must_clauses.map(&:term)).to contain_exactly('foo bar')
|
||||
expect(subject.must_not_clauses).to be_empty
|
||||
expect(subject.filter_clauses).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user