Merge branch 'master' into glitch-soc/merge-upstream

Conflicts manually resolved:
- app/services/post_status_service.rb
- config/locales/simple_form.pl.yml
- config/routes.rb
- config/webpack/loaders/sass.js
- config/webpack/shared.js
- package.json
- yarn.lock
This commit is contained in:
Thibaut Girka
2019-01-02 13:45:18 +01:00
180 changed files with 3933 additions and 3622 deletions

View File

@@ -0,0 +1,31 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe BlacklistedEmailValidator, type: :validator do
describe '#validate' do
let(:user) { double(email: 'info@mail.com', errors: errors) }
let(:errors) { double(add: nil) }
before do
allow_any_instance_of(described_class).to receive(:blocked_email?) { blocked_email }
described_class.new.validate(user)
end
context 'blocked_email?' do
let(:blocked_email) { true }
it 'calls errors.add' do
expect(errors).to have_received(:add).with(:email, I18n.t('users.invalid_email'))
end
end
context '!blocked_email?' do
let(:blocked_email) { false }
it 'not calls errors.add' do
expect(errors).not_to have_received(:add).with(:email, I18n.t('users.invalid_email'))
end
end
end
end

View File

@@ -0,0 +1,46 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe DisallowedHashtagsValidator, type: :validator do
describe '#validate' do
before do
allow_any_instance_of(described_class).to receive(:select_tags) { tags }
described_class.new.validate(status)
end
let(:status) { double(errors: errors, local?: local, reblog?: reblog, text: '') }
let(:errors) { double(add: nil) }
context 'unless status.local? && !status.reblog?' do
let(:local) { false }
let(:reblog) { true }
it 'not calls errors.add' do
expect(errors).not_to have_received(:add).with(:text, any_args)
end
end
context 'status.local? && !status.reblog?' do
let(:local) { true }
let(:reblog) { false }
context 'tags.empty?' do
let(:tags) { [] }
it 'not calls errors.add' do
expect(errors).not_to have_received(:add).with(:text, any_args)
end
end
context '!tags.empty?' do
let(:tags) { %w(a b c) }
it 'calls errors.add' do
expect(errors).to have_received(:add)
.with(:text, I18n.t('statuses.disallowed_hashtags', tags: tags.join(', '), count: tags.size))
end
end
end
end
end

View File

@@ -0,0 +1,51 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe FollowLimitValidator, type: :validator do
describe '#validate' do
before do
allow_any_instance_of(described_class).to receive(:limit_reached?).with(account) do
limit_reached
end
described_class.new.validate(follow)
end
let(:follow) { double(account: account, errors: errors) }
let(:errors) { double(add: nil) }
let(:account) { double(nil?: _nil, local?: local, following_count: 0, followers_count: 0) }
let(:_nil) { true }
let(:local) { false }
context 'follow.account.nil? || !follow.account.local?' do
let(:_nil) { true }
it 'not calls errors.add' do
expect(errors).not_to have_received(:add).with(:base, any_args)
end
end
context '!(follow.account.nil? || !follow.account.local?)' do
let(:_nil) { false }
let(:local) { true }
context 'limit_reached?' do
let(:limit_reached) { true }
it 'calls errors.add' do
expect(errors).to have_received(:add)
.with(:base, I18n.t('users.follow_limit_reached', limit: FollowLimitValidator::LIMIT))
end
end
context '!limit_reached?' do
let(:limit_reached) { false }
it 'not calls errors.add' do
expect(errors).not_to have_received(:add).with(:base, any_args)
end
end
end
end
end

View File

@@ -4,8 +4,17 @@ require 'rails_helper'
describe StatusLengthValidator do
describe '#validate' do
it 'does not add errors onto remote statuses'
it 'does not add errors onto local reblogs'
it 'does not add errors onto remote statuses' do
status = double(local?: false)
subject.validate(status)
expect(status).not_to receive(:errors)
end
it 'does not add errors onto local reblogs' do
status = double(local?: false, reblog?: true)
subject.validate(status)
expect(status).not_to receive(:errors)
end
it 'adds an error when content warning is over MAX_CHARS characters' do
chars = StatusLengthValidator::MAX_CHARS + 1

View File

@@ -0,0 +1,57 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe StatusPinValidator, type: :validator do
describe '#validate' do
before do
subject.validate(pin)
end
let(:pin) { double(account: account, errors: errors, status: status, account_id: pin_account_id) }
let(:status) { double(reblog?: reblog, account_id: status_account_id, visibility: visibility) }
let(:account) { double(status_pins: status_pins, local?: local) }
let(:status_pins) { double(count: count) }
let(:errors) { double(add: nil) }
let(:pin_account_id) { 1 }
let(:status_account_id) { 1 }
let(:visibility) { 'public' }
let(:local) { false }
let(:reblog) { false }
let(:count) { 0 }
context 'pin.status.reblog?' do
let(:reblog) { true }
it 'calls errors.add' do
expect(errors).to have_received(:add).with(:base, I18n.t('statuses.pin_errors.reblog'))
end
end
context 'pin.account_id != pin.status.account_id' do
let(:pin_account_id) { 1 }
let(:status_account_id) { 2 }
it 'calls errors.add' do
expect(errors).to have_received(:add).with(:base, I18n.t('statuses.pin_errors.ownership'))
end
end
context 'unless %w(public unlisted).include?(pin.status.visibility)' do
let(:visibility) { '' }
it 'calls errors.add' do
expect(errors).to have_received(:add).with(:base, I18n.t('statuses.pin_errors.private'))
end
end
context 'pin.account.status_pins.count > 4 && pin.account.local?' do
let(:count) { 5 }
let(:local) { true }
it 'calls errors.add' do
expect(errors).to have_received(:add).with(:base, I18n.t('statuses.pin_errors.limit'))
end
end
end
end