Merge tag 'v3.1.1' into instance_only_statuses

This commit is contained in:
Renato "Lond" Cerqueira
2020-02-21 14:21:59 +01:00
1431 changed files with 34462 additions and 10030 deletions

View File

@ -215,13 +215,6 @@ RSpec.describe Account, type: :model do
end
end
describe '#subscription' do
it 'returns an OStatus subscription' do
account = Fabricate(:account)
expect(account.subscription('')).to be_instance_of OStatus2::Subscription
end
end
describe '#object_type' do
it 'is always a person' do
account = Fabricate(:account)
@ -626,18 +619,18 @@ RSpec.describe Account, type: :model do
end
context 'when is remote' do
it 'is invalid if the username is not unique in case-sensitive comparison among accounts in the same normalized domain' do
it 'is invalid if the username is same among accounts in the same normalized domain' do
Fabricate(:account, domain: 'にゃん', username: 'username')
account = Fabricate.build(:account, domain: 'xn--r9j5b5b', username: 'username')
account.valid?
expect(account).to model_have_error_on_field(:username)
end
it 'is valid even if the username is unique only in case-sensitive comparison among accounts in the same normalized domain' do
it 'is invalid if the username is not unique in case-insensitive comparison among accounts in the same normalized domain' do
Fabricate(:account, domain: 'にゃん', username: 'username')
account = Fabricate.build(:account, domain: 'xn--r9j5b5b', username: 'Username')
account.valid?
expect(account).not_to model_have_error_on_field(:username)
expect(account).to model_have_error_on_field(:username)
end
it 'is valid even if the username contains hyphens' do
@ -823,4 +816,5 @@ RSpec.describe Account, type: :model do
end
include_examples 'AccountAvatar', :account
include_examples 'AccountHeader', :account
end

View File

@ -0,0 +1,4 @@
require 'rails_helper'
RSpec.describe AnnouncementMute, type: :model do
end

View File

@ -0,0 +1,4 @@
require 'rails_helper'
RSpec.describe AnnouncementReaction, type: :model do
end

View File

@ -0,0 +1,4 @@
require 'rails_helper'
RSpec.describe Announcement, type: :model do
end

View File

@ -52,6 +52,16 @@ RSpec.describe DomainBlock, type: :model do
block = Fabricate(:domain_block, domain: 'sub.example.com')
expect(DomainBlock.rule_for('sub.example.com')).to eq block
end
it 'returns a rule matching a blocked TLD' do
block = Fabricate(:domain_block, domain: 'google')
expect(DomainBlock.rule_for('google')).to eq block
end
it 'returns a rule matching a subdomain of a blocked TLD' do
block = Fabricate(:domain_block, domain: 'google')
expect(DomainBlock.rule_for('maps.google')).to eq block
end
end
describe '#stricter_than?' do

View File

@ -31,14 +31,6 @@ RSpec.describe MediaAttachment, type: :model do
context 'file is blank' do
let(:file) { nil }
context 'remote_url is blank' do
let(:remote_url) { '' }
it 'returns false' do
is_expected.to be false
end
end
context 'remote_url is present' do
let(:remote_url) { 'remote_url' }
@ -133,13 +125,36 @@ RSpec.describe MediaAttachment, type: :model do
expect(media.file.meta["small"]["height"]).to eq 327
expect(media.file.meta["small"]["aspect"]).to eq 490.0 / 327
end
it 'gives the file a random name' do
expect(media.file_file_name).to_not eq 'attachment.jpg'
end
end
describe 'base64-encoded jpeg' do
let(:base64_attachment) { "data:image/jpeg;base64,#{Base64.encode64(attachment_fixture('attachment.jpg').read)}" }
let(:media) { MediaAttachment.create(account: Fabricate(:account), file: base64_attachment) }
it 'saves media attachment' do
expect(media.persisted?).to be true
expect(media.file).to_not be_nil
end
it 'gives the file a file name' do
expect(media.file_file_name).to_not be_blank
end
end
it 'is invalid without file' do
media = MediaAttachment.new(account: Fabricate(:account))
expect(media.valid?).to be false
end
describe 'descriptions for remote attachments' do
it 'are cut off at 140 characters' do
it 'are cut off at 1500 characters' do
media = Fabricate(:media_attachment, description: 'foo' * 1000, remote_url: 'http://example.com/blah.jpg')
expect(media.description.size).to be <= 420
expect(media.description.size).to be <= 1_500
end
end
end

View File

@ -34,32 +34,6 @@ RSpec.describe Notification, type: :model do
end
end
describe '#browserable?' do
let(:notification) { Fabricate(:notification) }
subject { notification.browserable? }
context 'type is :follow_request' do
before do
allow(notification).to receive(:type).and_return(:follow_request)
end
it 'returns false' do
is_expected.to be false
end
end
context 'type is not :follow_request' do
before do
allow(notification).to receive(:type).and_return(:else)
end
it 'returns true' do
is_expected.to be true
end
end
end
describe '#type' do
it 'returns :reblog for a Status' do
notification = Notification.new(activity: Status.new)

View File

@ -96,16 +96,20 @@ RSpec.describe Status, type: :model do
context 'unless destroyed?' do
context 'if reblog?' do
it 'returns "#{account.acct} shared a status by #{reblog.account.acct}"' do
it 'returns "#{account.acct} shared #{reblog.account.acct}\'s: #{preview}"' do
reblog = subject.reblog = other
expect(subject.title).to eq "#{account.acct} shared a status by #{reblog.account.acct}"
preview = subject.text.slice(0, 10).split("\n")[0]
expect(subject.title).to(
eq "#{account.acct} shared #{reblog.account.acct}'s: #{preview}"
)
end
end
context 'unless reblog?' do
it 'returns "New status by #{account.acct}"' do
it 'returns "#{account.acct}: #{preview}"' do
subject.reblog = nil
expect(subject.title).to eq "New status by #{account.acct}"
preview = subject.text.slice(0, 20).split("\n")[0]
expect(subject.title).to eq "#{account.acct}: #{preview}"
end
end
end

View File

@ -322,20 +322,7 @@ RSpec.describe User, type: :model do
end
it 'disables user' do
expect(user).to have_attributes(disabled: true, current_sign_in_at: nil, last_sign_in_at: current_sign_in_at)
end
end
describe '#disable!' do
subject(:user) { Fabricate(:user, disabled: false, current_sign_in_at: current_sign_in_at, last_sign_in_at: nil) }
let(:current_sign_in_at) { Time.zone.now }
before do
user.disable!
end
it 'disables user' do
expect(user).to have_attributes(disabled: true, current_sign_in_at: nil, last_sign_in_at: current_sign_in_at)
expect(user).to have_attributes(disabled: true)
end
end