Merge remote-tracking branch 'parent/main' into upstream-20241126
This commit is contained in:
commit
8a075ba4c6
303 changed files with 7495 additions and 4498 deletions
|
@ -30,7 +30,7 @@ RSpec.describe FollowRequest do
|
|||
follow_request.authorize!
|
||||
|
||||
expect(account).to have_received(:follow!).with(target_account, reblogs: true, notify: false, uri: follow_request.uri, languages: nil, bypass_limit: true)
|
||||
expect(MergeWorker).to have_received(:perform_async).with(target_account.id, account.id)
|
||||
expect(MergeWorker).to have_received(:perform_async).with(target_account.id, account.id, 'home')
|
||||
expect(follow_request).to have_received(:destroy!)
|
||||
end
|
||||
|
||||
|
|
17
spec/models/login_activity_spec.rb
Normal file
17
spec/models/login_activity_spec.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe LoginActivity do
|
||||
include_examples 'BrowserDetection'
|
||||
|
||||
describe 'Associations' do
|
||||
it { is_expected.to belong_to(:user).required }
|
||||
end
|
||||
|
||||
describe 'Validations' do
|
||||
subject { Fabricate.build :login_activity }
|
||||
|
||||
it { is_expected.to define_enum_for(:authentication_method).backed_by_column_of_type(:string) }
|
||||
end
|
||||
end
|
|
@ -108,15 +108,22 @@ RSpec.describe Report do
|
|||
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) }
|
||||
let(:account_warning) { Fabricate(:account_warning, report_id: report.id) }
|
||||
|
||||
before do
|
||||
Fabricate(:action_log, target_type: 'Report', account_id: target_account.id, target_id: report.id, created_at: 2.days.ago)
|
||||
Fabricate(:action_log, target_type: 'Account', account_id: target_account.id, target_id: report.target_account_id, created_at: 2.days.ago)
|
||||
Fabricate(:action_log, target_type: 'Status', account_id: target_account.id, target_id: status.id, created_at: 2.days.ago)
|
||||
Fabricate(:action_log, target_type: 'AccountWarning', account_id: target_account.id, target_id: account_warning.id, created_at: 2.days.ago)
|
||||
end
|
||||
|
||||
it 'returns right logs' do
|
||||
expect(action_logs.count).to eq 3
|
||||
it 'returns expected logs' do
|
||||
expect(action_logs)
|
||||
.to have_attributes(count: 4)
|
||||
.and include(have_attributes(target_type: 'Account'))
|
||||
.and include(have_attributes(target_type: 'AccountWarning'))
|
||||
.and include(have_attributes(target_type: 'Report'))
|
||||
.and include(have_attributes(target_type: 'Status'))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -3,39 +3,7 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe SessionActivation do
|
||||
describe '#detection' do
|
||||
let(:session_activation) { Fabricate(:session_activation, user_agent: 'Chrome/62.0.3202.89') }
|
||||
|
||||
it 'sets a Browser instance as detection' do
|
||||
expect(session_activation.detection).to be_a Browser::Chrome
|
||||
end
|
||||
end
|
||||
|
||||
describe '#browser' do
|
||||
before do
|
||||
allow(session_activation).to receive(:detection).and_return(detection)
|
||||
end
|
||||
|
||||
let(:detection) { instance_double(Browser::Chrome, id: 1) }
|
||||
let(:session_activation) { Fabricate(:session_activation) }
|
||||
|
||||
it 'returns detection.id' do
|
||||
expect(session_activation.browser).to be 1
|
||||
end
|
||||
end
|
||||
|
||||
describe '#platform' do
|
||||
before do
|
||||
allow(session_activation).to receive(:detection).and_return(detection)
|
||||
end
|
||||
|
||||
let(:session_activation) { Fabricate(:session_activation) }
|
||||
let(:detection) { instance_double(Browser::Chrome, platform: instance_double(Browser::Platform, id: 1)) }
|
||||
|
||||
it 'returns detection.platform.id' do
|
||||
expect(session_activation.platform).to be 1
|
||||
end
|
||||
end
|
||||
include_examples 'BrowserDetection'
|
||||
|
||||
describe '.active?' do
|
||||
subject { described_class.active?(id) }
|
||||
|
|
|
@ -3,9 +3,69 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe UserRole do
|
||||
subject { described_class.create(name: 'Foo', position: 1) }
|
||||
describe 'Validations' do
|
||||
describe 'name' do
|
||||
context 'when everyone' do
|
||||
subject { described_class.everyone }
|
||||
|
||||
it { is_expected.to_not validate_presence_of(:name) }
|
||||
end
|
||||
|
||||
context 'when not everyone' do
|
||||
subject { Fabricate.build :user_role }
|
||||
|
||||
it { is_expected.to validate_presence_of(:name) }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'color' do
|
||||
it { is_expected.to allow_values('#112233', '#aabbcc', '').for(:color) }
|
||||
it { is_expected.to_not allow_values('x', '112233445566', '#xxyyzz').for(:color) }
|
||||
end
|
||||
|
||||
context 'when current_account is set' do
|
||||
subject { Fabricate :user_role }
|
||||
|
||||
let(:account) { Fabricate :account }
|
||||
|
||||
before { subject.current_account = account }
|
||||
|
||||
it { is_expected.to_not allow_value(999_999).for(:position).with_message(:elevated) }
|
||||
|
||||
it { is_expected.to_not allow_value(999_999).for(:permissions).against(:permissions_as_keys).with_message(:elevated) }
|
||||
|
||||
context 'when current_account is changing their own role' do
|
||||
let(:account) { Fabricate :account, user: Fabricate(:user, role: subject) }
|
||||
|
||||
it { is_expected.to_not allow_value(100).for(:permissions).against(:permissions_as_keys).with_message(:own_role) }
|
||||
it { is_expected.to_not allow_value(100).for(:position).with_message(:own_role) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Callback for position' do
|
||||
context 'when everyone' do
|
||||
subject { Fabricate.build :user_role, id: described_class::EVERYONE_ROLE_ID }
|
||||
|
||||
it 'sets the position to nobody position' do
|
||||
expect { subject.valid? }
|
||||
.to change(subject, :position).to(described_class::NOBODY_POSITION)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when not everyone' do
|
||||
subject { Fabricate.build :user_role }
|
||||
|
||||
it 'does not change the position' do
|
||||
expect { subject.valid? }
|
||||
.to_not change(subject, :position)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#can?' do
|
||||
subject { Fabricate :user_role }
|
||||
|
||||
context 'with a single flag' do
|
||||
it 'returns true if any of them are present' do
|
||||
subject.permissions = described_class::FLAGS[:manage_reports]
|
||||
|
@ -92,6 +152,8 @@ RSpec.describe UserRole do
|
|||
end
|
||||
|
||||
describe '#computed_permissions' do
|
||||
subject { Fabricate :user_role }
|
||||
|
||||
context 'when the role is nobody' do
|
||||
subject { described_class.nobody }
|
||||
|
||||
|
|
|
@ -33,14 +33,12 @@ RSpec.describe User do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'validations' do
|
||||
describe 'Associations' do
|
||||
it { is_expected.to belong_to(:account).required }
|
||||
end
|
||||
|
||||
it 'is invalid without a valid email' do
|
||||
user = Fabricate.build(:user, email: 'john@')
|
||||
user.valid?
|
||||
expect(user).to model_have_error_on_field(:email)
|
||||
end
|
||||
describe 'Validations' do
|
||||
it { is_expected.to_not allow_value('john@').for(:email) }
|
||||
|
||||
it 'is valid with an invalid e-mail that has already been saved' do
|
||||
user = Fabricate.build(:user, email: 'invalid-email')
|
||||
|
@ -48,11 +46,7 @@ RSpec.describe User do
|
|||
expect(user.valid?).to be true
|
||||
end
|
||||
|
||||
it 'is valid with a localhost e-mail address' do
|
||||
user = Fabricate.build(:user, email: 'admin@localhost')
|
||||
user.valid?
|
||||
expect(user.valid?).to be true
|
||||
end
|
||||
it { is_expected.to allow_value('admin@localhost').for(:email) }
|
||||
end
|
||||
|
||||
describe 'Normalizations' do
|
||||
|
@ -183,6 +177,39 @@ RSpec.describe User do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#update_sign_in!' do
|
||||
context 'with an existing user' do
|
||||
let!(:user) { Fabricate :user, last_sign_in_at: 10.days.ago, current_sign_in_at: 1.hour.ago, sign_in_count: 123 }
|
||||
|
||||
context 'with new sign in false' do
|
||||
it 'updates timestamps but not counts' do
|
||||
expect { user.update_sign_in!(new_sign_in: false) }
|
||||
.to change(user, :last_sign_in_at)
|
||||
.and change(user, :current_sign_in_at)
|
||||
.and not_change(user, :sign_in_count)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with new sign in true' do
|
||||
it 'updates timestamps and counts' do
|
||||
expect { user.update_sign_in!(new_sign_in: true) }
|
||||
.to change(user, :last_sign_in_at)
|
||||
.and change(user, :current_sign_in_at)
|
||||
.and change(user, :sign_in_count).by(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a new user' do
|
||||
let(:user) { Fabricate.build :user }
|
||||
|
||||
it 'does not persist the user' do
|
||||
expect { user.update_sign_in! }
|
||||
.to_not change(user, :persisted?).from(false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#confirmed?' do
|
||||
it 'returns true when a confirmed_at is set' do
|
||||
user = Fabricate.build(:user, confirmed_at: Time.now.utc)
|
||||
|
|
|
@ -6,20 +6,28 @@ RSpec.describe Webhook do
|
|||
let(:webhook) { Fabricate(:webhook) }
|
||||
|
||||
describe 'Validations' do
|
||||
subject { Fabricate.build :webhook }
|
||||
|
||||
it { is_expected.to validate_presence_of(:events) }
|
||||
|
||||
it 'requires non-empty events value' do
|
||||
record = described_class.new(events: [])
|
||||
record.valid?
|
||||
it { is_expected.to_not allow_values([], %w(account.invalid)).for(:events) }
|
||||
|
||||
expect(record).to model_have_error_on_field(:events)
|
||||
end
|
||||
it { is_expected.to_not allow_values('{{account }').for(:template) }
|
||||
|
||||
it 'requires valid events value from EVENTS' do
|
||||
record = described_class.new(events: ['account.invalid'])
|
||||
record.valid?
|
||||
context 'when current_account is assigned' do
|
||||
subject { Fabricate.build :webhook, current_account: account }
|
||||
|
||||
expect(record).to model_have_error_on_field(:events)
|
||||
context 'with account that has permissions' do
|
||||
let(:account) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account }
|
||||
|
||||
it { is_expected.to allow_values(%w(account.created)).for(:events) }
|
||||
end
|
||||
|
||||
context 'with account lacking permissions' do
|
||||
let(:account) { Fabricate :account }
|
||||
|
||||
it { is_expected.to_not allow_values(%w(account.created)).for(:events) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -29,6 +37,96 @@ RSpec.describe Webhook do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'Callbacks' do
|
||||
describe 'Generating a secret' do
|
||||
context 'when secret exists already' do
|
||||
subject { described_class.new(secret: 'secret') }
|
||||
|
||||
it 'does not override' do
|
||||
expect { subject.valid? }
|
||||
.to_not change(subject, :secret)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when secret does not exist' do
|
||||
subject { described_class.new(secret: nil) }
|
||||
|
||||
it 'does not override' do
|
||||
expect { subject.valid? }
|
||||
.to change(subject, :secret)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '.permission_for_event' do
|
||||
subject { described_class.permission_for_event(event) }
|
||||
|
||||
context 'with a nil value' do
|
||||
let(:event) { nil }
|
||||
|
||||
it { is_expected.to be_nil }
|
||||
end
|
||||
|
||||
context 'with an account approved event' do
|
||||
let(:event) { 'account.approved' }
|
||||
|
||||
it { is_expected.to eq(:manage_users) }
|
||||
end
|
||||
|
||||
context 'with an account created event' do
|
||||
let(:event) { 'account.created' }
|
||||
|
||||
it { is_expected.to eq(:manage_users) }
|
||||
end
|
||||
|
||||
context 'with an account updated event' do
|
||||
let(:event) { 'account.updated' }
|
||||
|
||||
it { is_expected.to eq(:manage_users) }
|
||||
end
|
||||
|
||||
context 'with an report created event' do
|
||||
let(:event) { 'report.created' }
|
||||
|
||||
it { is_expected.to eq(:manage_reports) }
|
||||
end
|
||||
|
||||
context 'with an report updated event' do
|
||||
let(:event) { 'report.updated' }
|
||||
|
||||
it { is_expected.to eq(:manage_reports) }
|
||||
end
|
||||
|
||||
context 'with an status created event' do
|
||||
let(:event) { 'status.created' }
|
||||
|
||||
it { is_expected.to eq(:view_devops) }
|
||||
end
|
||||
|
||||
context 'with an status updated event' do
|
||||
let(:event) { 'status.updated' }
|
||||
|
||||
it { is_expected.to eq(:view_devops) }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#required_permissions' do
|
||||
subject { described_class.new(events:).required_permissions }
|
||||
|
||||
context 'with empty events' do
|
||||
let(:events) { [] }
|
||||
|
||||
it { is_expected.to eq([]) }
|
||||
end
|
||||
|
||||
context 'with multiple event types' do
|
||||
let(:events) { %w(account.created account.updated status.created) }
|
||||
|
||||
it { is_expected.to eq %i(manage_users view_devops) }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#rotate_secret!' do
|
||||
it 'changes the secret' do
|
||||
expect { webhook.rotate_secret! }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue