Merge remote-tracking branch 'origin/master' into gs-master

Conflicts:
 	.travis.yml
 	Gemfile.lock
 	README.md
 	app/controllers/settings/follower_domains_controller.rb
 	app/controllers/statuses_controller.rb
 	app/javascript/mastodon/locales/ja.json
 	app/lib/feed_manager.rb
 	app/models/media_attachment.rb
 	app/models/mute.rb
 	app/models/status.rb
 	app/services/mute_service.rb
 	app/views/home/index.html.haml
 	app/views/stream_entries/_simple_status.html.haml
 	config/locales/ca.yml
 	config/locales/en.yml
 	config/locales/es.yml
 	config/locales/fr.yml
 	config/locales/nl.yml
 	config/locales/pl.yml
 	config/locales/pt-BR.yml
 	config/themes.yml
This commit is contained in:
David Yip
2018-05-03 17:23:44 -05:00
437 changed files with 5999 additions and 1848 deletions

View File

@ -94,14 +94,14 @@ RSpec.describe Account, type: :model do
describe '#save_with_optional_media!' do
before do
stub_request(:get, 'https://remote/valid_avatar').to_return(request_fixture('avatar.txt'))
stub_request(:get, 'https://remote/invalid_avatar').to_return(request_fixture('feed.txt'))
stub_request(:get, 'https://remote.test/valid_avatar').to_return(request_fixture('avatar.txt'))
stub_request(:get, 'https://remote.test/invalid_avatar').to_return(request_fixture('feed.txt'))
end
let(:account) do
Fabricate(:account,
avatar_remote_url: 'https://remote/valid_avatar',
header_remote_url: 'https://remote/valid_avatar')
avatar_remote_url: 'https://remote.test/valid_avatar',
header_remote_url: 'https://remote.test/valid_avatar')
end
let!(:expectation) { account.dup }
@ -121,7 +121,7 @@ RSpec.describe Account, type: :model do
context 'with invalid properties' do
before do
account.avatar_remote_url = 'https://remote/invalid_avatar'
account.avatar_remote_url = 'https://remote.test/invalid_avatar'
account.save_with_optional_media!
end
@ -815,7 +815,8 @@ RSpec.describe Account, type: :model do
end
context 'when is local' do
it 'generates keys' do
# Test disabled because test environment omits autogenerating keys for performance
xit 'generates keys' do
account = Account.create!(domain: nil, username: Faker::Internet.user_name(nil, ['_']))
expect(account.keypair.private?).to eq true
end

View File

@ -115,13 +115,15 @@ describe AccountInteractions do
end
describe '#mute!' do
subject { account.mute!(target_account, notifications: arg_notifications) }
context 'Mute does not exist yet' do
context 'arg :notifications is nil' do
let(:arg_notifications) { nil }
it 'creates Mute, and returns nil' do
it 'creates Mute, and returns Mute' do
expect do
expect(account.mute!(target_account, notifications: arg_notifications)).to be nil
expect(subject).to be_kind_of Mute
end.to change { account.mute_relationships.count }.by 1
end
end
@ -129,9 +131,9 @@ describe AccountInteractions do
context 'arg :notifications is false' do
let(:arg_notifications) { false }
it 'creates Mute, and returns nil' do
it 'creates Mute, and returns Mute' do
expect do
expect(account.mute!(target_account, notifications: arg_notifications)).to be nil
expect(subject).to be_kind_of Mute
end.to change { account.mute_relationships.count }.by 1
end
end
@ -139,9 +141,9 @@ describe AccountInteractions do
context 'arg :notifications is true' do
let(:arg_notifications) { true }
it 'creates Mute, and returns nil' do
it 'creates Mute, and returns Mute' do
expect do
expect(account.mute!(target_account, notifications: arg_notifications)).to be nil
expect(subject).to be_kind_of Mute
end.to change { account.mute_relationships.count }.by 1
end
end
@ -165,36 +167,30 @@ describe AccountInteractions do
context 'arg :notifications is nil' do
let(:arg_notifications) { nil }
it 'returns nil without updating mute.hide_notifications' do
it 'returns Mute without updating mute.hide_notifications' do
expect do
expect(account.mute!(target_account, notifications: arg_notifications)).to be nil
mute = account.mute_relationships.find_by(target_account: target_account)
expect(mute.hide_notifications?).to be true
end
expect(subject).to be_kind_of Mute
end.not_to change { mute.reload.hide_notifications? }.from(true)
end
end
context 'arg :notifications is false' do
let(:arg_notifications) { false }
it 'returns true, and updates mute.hide_notifications false' do
it 'returns Mute, and updates mute.hide_notifications false' do
expect do
expect(account.mute!(target_account, notifications: arg_notifications)).to be true
mute = account.mute_relationships.find_by(target_account: target_account)
expect(mute.hide_notifications?).to be false
end
expect(subject).to be_kind_of Mute
end.to change { mute.reload.hide_notifications? }.from(true).to(false)
end
end
context 'arg :notifications is true' do
let(:arg_notifications) { true }
it 'returns nil without updating mute.hide_notifications' do
it 'returns Mute without updating mute.hide_notifications' do
expect do
expect(account.mute!(target_account, notifications: arg_notifications)).to be nil
mute = account.mute_relationships.find_by(target_account: target_account)
expect(mute.hide_notifications?).to be true
end
expect(subject).to be_kind_of Mute
end.not_to change { mute.reload.hide_notifications? }.from(true)
end
end
end
@ -205,36 +201,30 @@ describe AccountInteractions do
context 'arg :notifications is nil' do
let(:arg_notifications) { nil }
it 'returns true, and updates mute.hide_notifications true' do
it 'returns Mute, and updates mute.hide_notifications true' do
expect do
expect(account.mute!(target_account, notifications: arg_notifications)).to be true
mute = account.mute_relationships.find_by(target_account: target_account)
expect(mute.hide_notifications?).to be true
end
expect(subject).to be_kind_of Mute
end.to change { mute.reload.hide_notifications? }.from(false).to(true)
end
end
context 'arg :notifications is false' do
let(:arg_notifications) { false }
it 'returns nil without updating mute.hide_notifications' do
it 'returns Mute without updating mute.hide_notifications' do
expect do
expect(account.mute!(target_account, notifications: arg_notifications)).to be nil
mute = account.mute_relationships.find_by(target_account: target_account)
expect(mute.hide_notifications?).to be false
end
expect(subject).to be_kind_of Mute
end.not_to change { mute.reload.hide_notifications? }.from(false)
end
end
context 'arg :notifications is true' do
let(:arg_notifications) { true }
it 'returns true, and updates mute.hide_notifications true' do
it 'returns Mute, and updates mute.hide_notifications true' do
expect do
expect(account.mute!(target_account, notifications: arg_notifications)).to be true
mute = account.mute_relationships.find_by(target_account: target_account)
expect(mute.hide_notifications?).to be true
end
expect(subject).to be_kind_of Mute
end.to change { mute.reload.hide_notifications? }.from(false).to(true)
end
end
end

View File

@ -89,34 +89,34 @@ describe StatusThreadingConcern do
let!(:viewer) { Fabricate(:account, username: 'viewer') }
it 'returns replies' do
expect(status.descendants).to include(reply1, reply2, reply3)
expect(status.descendants(4)).to include(reply1, reply2, reply3)
end
it 'does not return replies user is not allowed to see' do
reply1.update(visibility: :private)
reply3.update(visibility: :direct)
expect(status.descendants(viewer)).to_not include(reply1, reply3)
expect(status.descendants(4, viewer)).to_not include(reply1, reply3)
end
it 'does not return replies from blocked users' do
viewer.block!(jeff)
expect(status.descendants(viewer)).to_not include(reply3)
expect(status.descendants(4, viewer)).to_not include(reply3)
end
it 'does not return replies from muted users' do
viewer.mute!(jeff)
expect(status.descendants(viewer)).to_not include(reply3)
expect(status.descendants(4, viewer)).to_not include(reply3)
end
it 'does not return replies from silenced and not followed users' do
jeff.update(silenced: true)
expect(status.descendants(viewer)).to_not include(reply3)
expect(status.descendants(4, viewer)).to_not include(reply3)
end
it 'does not return replies from blocked domains' do
viewer.block_domain!('example.com')
expect(status.descendants(viewer)).to_not include(reply2)
expect(status.descendants(4, viewer)).to_not include(reply2)
end
end
end

View File

@ -22,6 +22,101 @@ describe Report do
end
end
describe 'assign_to_self!' do
subject { report.assigned_account_id }
let(:report) { Fabricate(:report, assigned_account_id: original_account) }
let(:original_account) { Fabricate(:account) }
let(:current_account) { Fabricate(:account) }
before do
report.assign_to_self!(current_account)
end
it 'assigns to a given account' do
is_expected.to eq current_account.id
end
end
describe 'unassign!' do
subject { report.assigned_account_id }
let(:report) { Fabricate(:report, assigned_account_id: account.id) }
let(:account) { Fabricate(:account) }
before do
report.unassign!
end
it 'unassigns' do
is_expected.to be_nil
end
end
describe 'resolve!' do
subject(:report) { Fabricate(:report, action_taken: false, action_taken_by_account_id: nil) }
let(:acting_account) { Fabricate(:account) }
before do
report.resolve!(acting_account)
end
it 'records action taken' do
expect(report).to have_attributes(action_taken: true, action_taken_by_account_id: acting_account.id)
end
end
describe 'unresolve!' do
subject(:report) { Fabricate(:report, action_taken: true, action_taken_by_account_id: acting_account.id) }
let(:acting_account) { Fabricate(:account) }
before do
report.unresolve!
end
it 'unresolves' do
expect(report).to have_attributes(action_taken: false, action_taken_by_account_id: nil)
end
end
describe 'unresolved?' do
subject { report.unresolved? }
let(:report) { Fabricate(:report, action_taken: action_taken) }
context 'if action is taken' do
let(:action_taken) { true }
it { is_expected.to be false }
end
context 'if action not is taken' do
let(:action_taken) { false }
it { is_expected.to be true }
end
end
describe 'history' do
subject(:action_logs) { report.history }
let(:report) { Fabricate(:report, target_account_id: target_account.id, status_ids: [status.id], created_at: 3.days.ago, updated_at: 1.day.ago) }
let(:target_account) { Fabricate(:account) }
let(:status) { Fabricate(:status) }
before do
Fabricate('Admin::ActionLog', target_type: 'Report', account_id: target_account.id, target_id: report.id, created_at: 2.days.ago)
Fabricate('Admin::ActionLog', target_type: 'Account', account_id: target_account.id, target_id: report.target_account_id, created_at: 2.days.ago)
Fabricate('Admin::ActionLog', target_type: 'Status', account_id: target_account.id, target_id: status.id, created_at: 2.days.ago)
end
it 'returns right logs' do
expect(action_logs.count).to eq 3
end
end
describe 'validatiions' do
it 'has a valid fabricator' do
report = Fabricate(:report)

View File

@ -55,7 +55,7 @@ RSpec.describe StatusPin, type: :model do
end
it 'allows pins above the max for remote accounts' do
account = Fabricate(:account, domain: 'remote', username: 'bob', url: 'https://remote/')
account = Fabricate(:account, domain: 'remote.test', username: 'bob', url: 'https://remote.test/')
status = []
(max_pins + 1).times do |i|

View File

@ -324,4 +324,218 @@ RSpec.describe User, type: :model do
expect(admin.role?('moderator')).to be true
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)
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)
end
end
describe '#enable!' do
subject(:user) { Fabricate(:user, disabled: true) }
before do
user.enable!
end
it 'enables user' do
expect(user).to have_attributes(disabled: false)
end
end
describe '#confirm!' do
subject(:user) { Fabricate(:user, confirmed_at: confirmed_at) }
before do
ActionMailer::Base.deliveries.clear
user.confirm!
end
after { ActionMailer::Base.deliveries.clear }
context 'when user is new' do
let(:confirmed_at) { nil }
it 'confirms user' do
expect(user.confirmed_at).to be_present
end
it 'delivers mails' do
expect(ActionMailer::Base.deliveries.count).to eq 2
end
end
context 'when user is not new' do
let(:confirmed_at) { Time.zone.now }
it 'confirms user' do
expect(user.confirmed_at).to be_present
end
it 'does not deliver mail' do
expect(ActionMailer::Base.deliveries.count).to eq 0
end
end
end
describe '#promote!' do
subject(:user) { Fabricate(:user, admin: is_admin, moderator: is_moderator) }
before do
user.promote!
end
context 'when user is an admin' do
let(:is_admin) { true }
context 'when user is a moderator' do
let(:is_moderator) { true }
it 'changes moderator filed false' do
expect(user).to be_admin
expect(user).not_to be_moderator
end
end
context 'when user is not a moderator' do
let(:is_moderator) { false }
it 'does not change status' do
expect(user).to be_admin
expect(user).not_to be_moderator
end
end
end
context 'when user is not admin' do
let(:is_admin) { false }
context 'when user is a moderator' do
let(:is_moderator) { true }
it 'changes user into an admin' do
expect(user).to be_admin
expect(user).not_to be_moderator
end
end
context 'when user is not a moderator' do
let(:is_moderator) { false }
it 'changes user into a moderator' do
expect(user).not_to be_admin
expect(user).to be_moderator
end
end
end
end
describe '#demote!' do
subject(:user) { Fabricate(:user, admin: admin, moderator: moderator) }
before do
user.demote!
end
context 'when user is an admin' do
let(:admin) { true }
context 'when user is a moderator' do
let(:moderator) { true }
it 'changes user into a moderator' do
expect(user).not_to be_admin
expect(user).to be_moderator
end
end
context 'when user is not a moderator' do
let(:moderator) { false }
it 'changes user into a moderator' do
expect(user).not_to be_admin
expect(user).to be_moderator
end
end
end
context 'when user is not an admin' do
let(:admin) { false }
context 'when user is a moderator' do
let(:moderator) { true }
it 'changes user into a plain user' do
expect(user).not_to be_admin
expect(user).not_to be_moderator
end
end
context 'when user is not a moderator' do
let(:moderator) { false }
it 'does not change any fields' do
expect(user).not_to be_admin
expect(user).not_to be_moderator
end
end
end
end
describe '#active_for_authentication?' do
subject { user.active_for_authentication? }
let(:user) { Fabricate(:user, disabled: disabled, confirmed_at: confirmed_at) }
context 'when user is disabled' do
let(:disabled) { true }
context 'when user is confirmed' do
let(:confirmed_at) { Time.zone.now }
it { is_expected.to be false }
end
context 'when user is not confirmed' do
let(:confirmed_at) { nil }
it { is_expected.to be false }
end
end
context 'when user is not disabled' do
let(:disabled) { false }
context 'when user is confirmed' do
let(:confirmed_at) { Time.zone.now }
it { is_expected.to be true }
end
context 'when user is not confirmed' do
let(:confirmed_at) { nil }
it { is_expected.to be false }
end
end
end
end