Merge remote-tracking branch 'tootsuite/master' into glitchsoc/master

This commit is contained in:
Jenkins
2018-03-09 00:17:17 +00:00
206 changed files with 2401 additions and 737 deletions

View File

@@ -16,49 +16,24 @@ describe ApplicationController, type: :controller do
end
shared_examples 'default locale' do
context 'when DEFAULT_LOCALE environment variable is set' do
around do |example|
ClimateControl.modify 'DEFAULT_LOCALE' => 'ca', &example.method(:run)
I18n.locale = I18n.default_locale
end
after { I18n.locale = I18n.default_locale }
it 'sets language specified by ENV if preferred' do
request.headers['Accept-Language'] = 'ca, fa'
get 'success'
expect(I18n.locale).to eq :ca
end
it 'sets available and preferred language if language specified by ENV is not preferred' do
request.headers['Accept-Language'] = 'ca-ES, fa'
get 'success'
expect(I18n.locale).to eq :fa
end
it 'sets language specified by ENV if it is compatible and none of available languages are preferred' do
request.headers['Accept-Language'] = 'ca-ES, fa-IR'
get 'success'
expect(I18n.locale).to eq :ca
end
it 'sets available and compatible langauge if language specified by ENV is not compatible none of available languages are preferred' do
request.headers['Accept-Language'] = 'fa-IR'
get 'success'
expect(I18n.locale).to eq :fa
end
it 'sets language specified by ENV if none of available languages are compatible' do
request.headers['Accept-Language'] = ''
get 'success'
expect(I18n.locale).to eq :ca
end
it 'sets available and preferred language' do
request.headers['Accept-Language'] = 'ca-ES, fa'
get 'success'
expect(I18n.locale).to eq :fa
end
context 'when DEFAULT_LOCALE environment variable is not set' do
it 'sets default locale if none of available languages are compatible' do
request.headers['Accept-Language'] = ''
get 'success'
expect(I18n.locale).to eq :en
end
it 'sets available and compatible langauge if none of available languages are preferred' do
request.headers['Accept-Language'] = 'fa-IR'
get 'success'
expect(I18n.locale).to eq :fa
end
it 'sets default locale if none of available languages are compatible' do
request.headers['Accept-Language'] = ''
get 'success'
expect(I18n.locale).to eq :en
end
end

View File

@@ -4,21 +4,24 @@ RSpec.describe HomeController, type: :controller do
render_views
describe 'GET #index' do
subject { get :index }
context 'when not signed in' do
context 'when requested path is tag timeline' do
before { @request.path = '/web/timelines/tag/name' }
it { is_expected.to redirect_to '/tags/name' }
end
it 'redirects to about page' do
@request.path = '/'
get :index
expect(response).to redirect_to(about_path)
is_expected.to redirect_to(about_path)
end
end
context 'when signed in' do
let(:user) { Fabricate(:user) }
subject do
sign_in(user)
get :index
end
before { sign_in(user) }
it 'assigns @body_classes' do
subject

View File

@@ -15,12 +15,6 @@ describe InstanceHelper do
expect(helper.site_title).to eq 'New site title'
end
it 'returns empty string when Setting.site_title is nil' do
Setting.site_title = nil
expect(helper.site_title).to eq 'cb6e6126.ngrok.io'
end
end
describe 'site_hostname' do

View File

@@ -0,0 +1,29 @@
require 'rails_helper'
RSpec.describe ActivityPub::Activity::Add do
let(:sender) { Fabricate(:account, featured_collection_url: 'https://example.com/featured') }
let(:status) { Fabricate(:status, account: sender) }
let(:json) do
{
'@context': 'https://www.w3.org/ns/activitystreams',
id: 'foo',
type: 'Add',
actor: ActivityPub::TagManager.instance.uri_for(sender),
object: ActivityPub::TagManager.instance.uri_for(status),
target: sender.featured_collection_url,
}.with_indifferent_access
end
describe '#perform' do
subject { described_class.new(json, sender) }
before do
subject.perform
end
it 'creates a pin' do
expect(sender.pinned?(status)).to be true
end
end
end

View File

@@ -202,7 +202,7 @@ RSpec.describe ActivityPub::Activity::Create do
attachment: [
{
type: 'Document',
mime_type: 'image/png',
mediaType: 'image/png',
url: 'http://example.com/attachment.png',
},
],
@@ -217,6 +217,31 @@ RSpec.describe ActivityPub::Activity::Create do
end
end
context 'with media attachments with focal points' do
let(:object_json) do
{
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
type: 'Note',
content: 'Lorem ipsum',
attachment: [
{
type: 'Document',
mediaType: 'image/png',
url: 'http://example.com/attachment.png',
focalPoint: [0.5, -0.7],
},
],
}
end
it 'creates status' do
status = sender.statuses.first
expect(status).to_not be_nil
expect(status.media_attachments.map(&:focus)).to include('0.5,-0.7')
end
end
context 'with media attachments missing url' do
let(:object_json) do
{
@@ -226,7 +251,7 @@ RSpec.describe ActivityPub::Activity::Create do
attachment: [
{
type: 'Document',
mime_type: 'image/png',
mediaType: 'image/png',
},
],
}

View File

@@ -0,0 +1,30 @@
require 'rails_helper'
RSpec.describe ActivityPub::Activity::Remove do
let(:sender) { Fabricate(:account, featured_collection_url: 'https://example.com/featured') }
let(:status) { Fabricate(:status, account: sender) }
let(:json) do
{
'@context': 'https://www.w3.org/ns/activitystreams',
id: 'foo',
type: 'Add',
actor: ActivityPub::TagManager.instance.uri_for(sender),
object: ActivityPub::TagManager.instance.uri_for(status),
target: sender.featured_collection_url,
}.with_indifferent_access
end
describe '#perform' do
subject { described_class.new(json, sender) }
before do
StatusPin.create!(account: sender, status: status)
subject.perform
end
it 'removes a pin' do
expect(sender.pinned?(status)).to be false
end
end
end

View File

@@ -7,6 +7,7 @@ RSpec.describe ActivityPub::Activity::Update do
stub_request(:get, actor_json[:outbox]).to_return(status: 404)
stub_request(:get, actor_json[:followers]).to_return(status: 404)
stub_request(:get, actor_json[:following]).to_return(status: 404)
stub_request(:get, actor_json[:featured]).to_return(status: 404)
sender.update!(uri: ActivityPub::TagManager.instance.uri_for(sender))
end