Merge remote-tracking branch 'parent/main' into upstream-20240926
This commit is contained in:
commit
c905714459
517 changed files with 4284 additions and 3891 deletions
19
spec/models/account_deletion_request_spec.rb
Normal file
19
spec/models/account_deletion_request_spec.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe AccountDeletionRequest do
|
||||
describe 'Associations' do
|
||||
it { is_expected.to belong_to(:account).required }
|
||||
end
|
||||
|
||||
describe '#due_at' do
|
||||
before { stub_const 'AccountDeletionRequest::DELAY_TO_DELETION', 1.day }
|
||||
|
||||
it 'returns time from created at with delay added' do
|
||||
account_deletion_request = Fabricate :account_deletion_request, created_at: Date.current.at_midnight
|
||||
expect(account_deletion_request.due_at)
|
||||
.to be_within(0.1).of(Date.tomorrow.at_midnight)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -252,88 +252,83 @@ RSpec.describe Notification do
|
|||
]
|
||||
end
|
||||
|
||||
context 'with a preloaded target status' do
|
||||
it 'preloads mention' do
|
||||
expect(subject[0].type).to eq :mention
|
||||
expect(subject[0].association(:mention)).to be_loaded
|
||||
expect(subject[0].mention.association(:status)).to be_loaded
|
||||
context 'with a preloaded target status and a cached status' do
|
||||
it 'preloads association records and replaces association records' do
|
||||
expect(subject)
|
||||
.to contain_exactly(
|
||||
mention_attributes,
|
||||
status_attributes,
|
||||
reblog_attributes,
|
||||
follow_attributes,
|
||||
follow_request_attributes,
|
||||
favourite_attributes,
|
||||
poll_attributes
|
||||
)
|
||||
end
|
||||
|
||||
it 'preloads status' do
|
||||
expect(subject[1].type).to eq :status
|
||||
expect(subject[1].association(:status)).to be_loaded
|
||||
def mention_attributes
|
||||
have_attributes(
|
||||
type: :mention,
|
||||
target_status: eq(mention.status).and(have_loaded_association(:account)),
|
||||
mention: have_loaded_association(:status)
|
||||
).and(have_loaded_association(:mention))
|
||||
end
|
||||
|
||||
it 'preloads reblog' do
|
||||
expect(subject[2].type).to eq :reblog
|
||||
expect(subject[2].association(:status)).to be_loaded
|
||||
expect(subject[2].status.association(:reblog)).to be_loaded
|
||||
def status_attributes
|
||||
have_attributes(
|
||||
type: :status,
|
||||
target_status: eq(status).and(have_loaded_association(:account))
|
||||
).and(have_loaded_association(:status))
|
||||
end
|
||||
|
||||
it 'preloads follow as nil' do
|
||||
expect(subject[3].type).to eq :follow
|
||||
expect(subject[3].target_status).to be_nil
|
||||
def reblog_attributes
|
||||
have_attributes(
|
||||
type: :reblog,
|
||||
status: have_loaded_association(:reblog),
|
||||
target_status: eq(reblog.reblog).and(have_loaded_association(:account))
|
||||
).and(have_loaded_association(:status))
|
||||
end
|
||||
|
||||
it 'preloads follow_request as nill' do
|
||||
expect(subject[4].type).to eq :follow_request
|
||||
expect(subject[4].target_status).to be_nil
|
||||
def follow_attributes
|
||||
have_attributes(
|
||||
type: :follow,
|
||||
target_status: be_nil
|
||||
)
|
||||
end
|
||||
|
||||
it 'preloads favourite' do
|
||||
expect(subject[5].type).to eq :favourite
|
||||
expect(subject[5].association(:favourite)).to be_loaded
|
||||
expect(subject[5].favourite.association(:status)).to be_loaded
|
||||
def follow_request_attributes
|
||||
have_attributes(
|
||||
type: :follow_request,
|
||||
target_status: be_nil
|
||||
)
|
||||
end
|
||||
|
||||
it 'preloads poll' do
|
||||
expect(subject[6].type).to eq :poll
|
||||
expect(subject[6].association(:poll)).to be_loaded
|
||||
expect(subject[6].poll.association(:status)).to be_loaded
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a cached status' do
|
||||
it 'replaces mention' do
|
||||
expect(subject[0].type).to eq :mention
|
||||
expect(subject[0].target_status.association(:account)).to be_loaded
|
||||
expect(subject[0].target_status).to eq mention.status
|
||||
def favourite_attributes
|
||||
have_attributes(
|
||||
type: :favourite,
|
||||
favourite: have_loaded_association(:status),
|
||||
target_status: eq(favourite.status).and(have_loaded_association(:account))
|
||||
).and(have_loaded_association(:favourite))
|
||||
end
|
||||
|
||||
it 'replaces status' do
|
||||
expect(subject[1].type).to eq :status
|
||||
expect(subject[1].target_status.association(:account)).to be_loaded
|
||||
expect(subject[1].target_status).to eq status
|
||||
end
|
||||
|
||||
it 'replaces reblog' do
|
||||
expect(subject[2].type).to eq :reblog
|
||||
expect(subject[2].target_status.association(:account)).to be_loaded
|
||||
expect(subject[2].target_status).to eq reblog.reblog
|
||||
end
|
||||
|
||||
it 'replaces follow' do
|
||||
expect(subject[3].type).to eq :follow
|
||||
expect(subject[3].target_status).to be_nil
|
||||
end
|
||||
|
||||
it 'replaces follow_request' do
|
||||
expect(subject[4].type).to eq :follow_request
|
||||
expect(subject[4].target_status).to be_nil
|
||||
end
|
||||
|
||||
it 'replaces favourite' do
|
||||
expect(subject[5].type).to eq :favourite
|
||||
expect(subject[5].target_status.association(:account)).to be_loaded
|
||||
expect(subject[5].target_status).to eq favourite.status
|
||||
end
|
||||
|
||||
it 'replaces poll' do
|
||||
expect(subject[6].type).to eq :poll
|
||||
expect(subject[6].target_status.association(:account)).to be_loaded
|
||||
expect(subject[6].target_status).to eq poll.status
|
||||
def poll_attributes
|
||||
have_attributes(
|
||||
type: :poll,
|
||||
poll: have_loaded_association(:status),
|
||||
target_status: eq(poll.status).and(have_loaded_association(:account))
|
||||
).and(have_loaded_association(:poll))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
RSpec::Matchers.define :have_loaded_association do |association|
|
||||
match do |record|
|
||||
record.association(association).loaded?
|
||||
end
|
||||
|
||||
failure_message do |record|
|
||||
"expected #{record} to have loaded association #{association} but it did not."
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe OneTimeKey do
|
||||
describe 'validations' do
|
||||
context 'with an invalid signature' do
|
||||
let(:one_time_key) { Fabricate.build(:one_time_key, signature: 'wrong!') }
|
||||
|
||||
it 'is invalid' do
|
||||
expect(one_time_key).to_not be_valid
|
||||
end
|
||||
end
|
||||
|
||||
context 'with an invalid key' do
|
||||
let(:one_time_key) { Fabricate.build(:one_time_key, key: 'wrong!') }
|
||||
|
||||
it 'is invalid' do
|
||||
expect(one_time_key).to_not be_valid
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -24,21 +24,5 @@ RSpec.describe PreviewCardProvider do
|
|||
expect(results).to eq([not_trendable_and_not_reviewed])
|
||||
end
|
||||
end
|
||||
|
||||
describe 'reviewed' do
|
||||
it 'returns the relevant records' do
|
||||
results = described_class.reviewed
|
||||
|
||||
expect(results).to eq([trendable_and_reviewed])
|
||||
end
|
||||
end
|
||||
|
||||
describe 'pending_review' do
|
||||
it 'returns the relevant records' do
|
||||
results = described_class.pending_review
|
||||
|
||||
expect(results).to eq([not_trendable_and_not_reviewed])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,6 +4,8 @@ require 'rails_helper'
|
|||
require 'devise_two_factor/spec_helpers'
|
||||
|
||||
RSpec.describe User do
|
||||
subject { described_class.new(account: account) }
|
||||
|
||||
let(:password) { 'abcd1234' }
|
||||
let(:account) { Fabricate(:account, username: 'alice') }
|
||||
|
||||
|
@ -464,7 +466,9 @@ RSpec.describe User do
|
|||
end
|
||||
|
||||
describe '#reset_password!' do
|
||||
subject(:user) { Fabricate(:user, password: 'foobar12345') }
|
||||
subject(:user) { Fabricate(:user, password: original_password) }
|
||||
|
||||
let(:original_password) { 'foobar12345' }
|
||||
|
||||
let!(:session_activation) { Fabricate(:session_activation, user: user) }
|
||||
let!(:access_token) { Fabricate(:access_token, resource_owner_id: user.id) }
|
||||
|
@ -472,31 +476,40 @@ RSpec.describe User do
|
|||
|
||||
let(:redis_pipeline_stub) { instance_double(Redis::Namespace, publish: nil) }
|
||||
|
||||
before do
|
||||
allow(redis).to receive(:pipelined).and_yield(redis_pipeline_stub)
|
||||
user.reset_password!
|
||||
before { stub_redis }
|
||||
|
||||
it 'changes the password immediately and revokes related access' do
|
||||
expect { user.reset_password! }
|
||||
.to remove_activated_sessions
|
||||
.and remove_active_user_tokens
|
||||
.and remove_user_web_subscriptions
|
||||
|
||||
expect(user)
|
||||
.to_not be_external_or_valid_password(original_password)
|
||||
expect { session_activation.reload }
|
||||
.to raise_error(ActiveRecord::RecordNotFound)
|
||||
expect { web_push_subscription.reload }
|
||||
.to raise_error(ActiveRecord::RecordNotFound)
|
||||
expect(redis_pipeline_stub)
|
||||
.to have_received(:publish).with("timeline:access_token:#{access_token.id}", Oj.dump(event: :kill)).once
|
||||
end
|
||||
|
||||
it 'changes the password immediately' do
|
||||
expect(user.external_or_valid_password?('foobar12345')).to be false
|
||||
def remove_activated_sessions
|
||||
change(user.session_activations, :count).to(0)
|
||||
end
|
||||
|
||||
it 'deactivates all sessions' do
|
||||
expect(user.session_activations.count).to eq 0
|
||||
expect { session_activation.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
||||
def remove_active_user_tokens
|
||||
change { Doorkeeper::AccessToken.active_for(user).count }.to(0)
|
||||
end
|
||||
|
||||
it 'revokes all access tokens' do
|
||||
expect(Doorkeeper::AccessToken.active_for(user).count).to eq 0
|
||||
def remove_user_web_subscriptions
|
||||
change { Web::PushSubscription.where(user: user).or(Web::PushSubscription.where(access_token: access_token)).count }.to(0)
|
||||
end
|
||||
|
||||
it 'revokes streaming access for all access tokens' do
|
||||
expect(redis_pipeline_stub).to have_received(:publish).with("timeline:access_token:#{access_token.id}", Oj.dump(event: :kill)).once
|
||||
end
|
||||
|
||||
it 'removes push subscriptions' do
|
||||
expect(Web::PushSubscription.where(user: user).or(Web::PushSubscription.where(access_token: access_token)).count).to eq 0
|
||||
expect { web_push_subscription.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
||||
def stub_redis
|
||||
allow(redis)
|
||||
.to receive(:pipelined)
|
||||
.and_yield(redis_pipeline_stub)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue