Merge commit '1fc165de02d79294c8a218f5fa82bcd477484ca1' into glitch-soc/merge-upstream

Conflicts:
- `.env.production.sample`:
  Upstream added a block of three environment variables, while glitch-soc
  has a different version of the file overall.
  Added upstream's changes.
- `app/helpers/application_helper.rb`:
  Upstream added a helper, while glitch-soc had extra helpers.
  Added upstream's helper.
This commit is contained in:
Claire committed 2024-10-19 19:13:32 +02:00
commit 6281c4dedd
283 files changed
+2777 -1360

No files matched your search

@@ -16,6 +16,8 @@ RSpec.describe AccountStatusesCleanupPolicy do
describe 'save hooks' do
context 'when widening a policy' do
subject { account_statuses_cleanup_policy.last_inspected }
let!(:account_statuses_cleanup_policy) do
Fabricate(:account_statuses_cleanup_policy,
account: account,
@@ -33,64 +35,64 @@ RSpec.describe AccountStatusesCleanupPolicy do
account_statuses_cleanup_policy.record_last_inspected(42)
end
it 'invalidates last_inspected when widened because of keep_direct' do
account_statuses_cleanup_policy.keep_direct = false
account_statuses_cleanup_policy.save
expect(account_statuses_cleanup_policy.last_inspected).to be_nil
context 'when widened because of keep_direct' do
before { account_statuses_cleanup_policy.update(keep_direct: false) }
it { is_expected.to be_nil }
end
it 'invalidates last_inspected when widened because of keep_pinned' do
account_statuses_cleanup_policy.keep_pinned = false
account_statuses_cleanup_policy.save
expect(account_statuses_cleanup_policy.last_inspected).to be_nil
context 'when widened because of keep_pinned' do
before { account_statuses_cleanup_policy.update(keep_pinned: false) }
it { is_expected.to be_nil }
end
it 'invalidates last_inspected when widened because of keep_polls' do
account_statuses_cleanup_policy.keep_polls = false
account_statuses_cleanup_policy.save
expect(account_statuses_cleanup_policy.last_inspected).to be_nil
context 'when widened because of keep_polls' do
before { account_statuses_cleanup_policy.update(keep_polls: false) }
it { is_expected.to be_nil }
end
it 'invalidates last_inspected when widened because of keep_media' do
account_statuses_cleanup_policy.keep_media = false
account_statuses_cleanup_policy.save
expect(account_statuses_cleanup_policy.last_inspected).to be_nil
context 'when widened because of keep_media' do
before { account_statuses_cleanup_policy.update(keep_media: false) }
it { is_expected.to be_nil }
end
it 'invalidates last_inspected when widened because of keep_self_fav' do
account_statuses_cleanup_policy.keep_self_fav = false
account_statuses_cleanup_policy.save
expect(account_statuses_cleanup_policy.last_inspected).to be_nil
context 'when widened because of keep_self_fav' do
before { account_statuses_cleanup_policy.update(keep_self_fav: false) }
it { is_expected.to be_nil }
end
it 'invalidates last_inspected when widened because of keep_self_bookmark' do
account_statuses_cleanup_policy.keep_self_bookmark = false
account_statuses_cleanup_policy.save
expect(account_statuses_cleanup_policy.last_inspected).to be_nil
context 'when widened because of keep_self_bookmark' do
before { account_statuses_cleanup_policy.update(keep_self_bookmark: false) }
it { is_expected.to be_nil }
end
it 'invalidates last_inspected when widened because of higher min_favs' do
account_statuses_cleanup_policy.min_favs = 5
account_statuses_cleanup_policy.save
expect(account_statuses_cleanup_policy.last_inspected).to be_nil
context 'when widened because of higher min_favs' do
before { account_statuses_cleanup_policy.update(min_favs: 5) }
it { is_expected.to be_nil }
end
it 'invalidates last_inspected when widened because of disabled min_favs' do
account_statuses_cleanup_policy.min_favs = nil
account_statuses_cleanup_policy.save
expect(account_statuses_cleanup_policy.last_inspected).to be_nil
context 'when widened because of disabled min_favs' do
before { account_statuses_cleanup_policy.update(min_favs: nil) }
it { is_expected.to be_nil }
end
it 'invalidates last_inspected when widened because of higher min_reblogs' do
account_statuses_cleanup_policy.min_reblogs = 5
account_statuses_cleanup_policy.save
expect(account_statuses_cleanup_policy.last_inspected).to be_nil
context 'when widened because of higher min_reblogs' do
before { account_statuses_cleanup_policy.update(min_reblogs: 5) }
it { is_expected.to be_nil }
end
it 'invalidates last_inspected when widened because of disable min_reblogs' do
account_statuses_cleanup_policy.min_reblogs = nil
account_statuses_cleanup_policy.save
expect(account_statuses_cleanup_policy.last_inspected).to be_nil
context 'when widened because of disable min_reblogs' do
before { account_statuses_cleanup_policy.update(min_reblogs: nil) }
it { is_expected.to be_nil }
end
end
+27 -1
View File
@@ -3,11 +3,37 @@
require 'rails_helper'
RSpec.describe Block do
describe 'validations' do
describe 'Associations' do
it { is_expected.to belong_to(:account).required }
it { is_expected.to belong_to(:target_account).required }
end
describe '#local?' do
it { is_expected.to_not be_local }
end
describe 'Callbacks' do
describe 'Setting a URI' do
context 'when URI exists' do
subject { Fabricate.build :block, uri: 'https://uri/value' }
it 'does not change' do
expect { subject.save }
.to not_change(subject, :uri)
end
end
context 'when URI is blank' do
subject { Fabricate.build :follow, uri: nil }
it 'populates the value' do
expect { subject.save }
.to change(subject, :uri).to(be_present)
end
end
end
end
it 'removes blocking cache after creation' do
account = Fabricate(:account)
target_account = Fabricate(:account)
+19 -7
View File
@@ -3,7 +3,7 @@
require 'rails_helper'
RSpec.describe Poll do
describe 'scopes' do
describe 'Scopes' do
let(:status) { Fabricate(:status) }
let(:attached_poll) { Fabricate(:poll, status: status) }
let(:not_attached_poll) do
@@ -13,7 +13,7 @@ RSpec.describe Poll do
end
end
describe 'attached' do
describe '.attached' do
it 'finds the correct records' do
results = described_class.attached
@@ -21,7 +21,7 @@ RSpec.describe Poll do
end
end
describe 'unattached' do
describe '.unattached' do
it 'finds the correct records' do
results = described_class.unattached
@@ -30,11 +30,23 @@ RSpec.describe Poll do
end
end
describe 'validations' do
context 'when not valid' do
subject { Fabricate.build(:poll) }
describe '#reset_votes!' do
let(:poll) { Fabricate :poll, cached_tallies: [2, 3], votes_count: 5, voters_count: 5 }
let!(:vote) { Fabricate :poll_vote, poll: }
it { is_expected.to validate_presence_of(:expires_at) }
it 'resets vote data and deletes votes' do
expect { poll.reset_votes! }
.to change(poll, :cached_tallies).to([0, 0])
.and change(poll, :votes_count).to(0)
.and(change(poll, :voters_count).to(0))
expect { vote.reload }
.to raise_error(ActiveRecord::RecordNotFound)
end
end
describe 'Validations' do
subject { Fabricate.build(:poll) }
it { is_expected.to validate_presence_of(:expires_at) }
end
end
+8 -12
View File
@@ -55,12 +55,10 @@ RSpec.describe PublicFeed do
context 'without a viewer' do
let(:viewer) { nil }
it 'includes remote instances statuses' do
expect(subject).to include(remote_status.id)
end
it 'includes local statuses' do
expect(subject).to include(local_status.id)
it 'includes remote instances statuses and local statuses' do
expect(subject)
.to include(remote_status.id)
.and include(local_status.id)
end
it 'does not include local-only statuses' do
@@ -71,12 +69,10 @@ RSpec.describe PublicFeed do
context 'with a viewer' do
let(:viewer) { Fabricate(:account, username: 'viewer') }
it 'includes remote instances statuses' do
expect(subject).to include(remote_status.id)
end
it 'includes local statuses' do
expect(subject).to include(local_status.id)
it 'includes remote instances statuses and local statuses' do
expect(subject)
.to include(remote_status.id)
.and include(local_status.id)
end
it 'does not include local-only statuses' do
+30 -10
View File
@@ -387,23 +387,43 @@ RSpec.describe User do
end
end
describe 'token_for_app' do
describe '#token_for_app' do
let(:user) { Fabricate(:user) }
let(:app) { Fabricate(:application, owner: user) }
it 'returns a token' do
expect(user.token_for_app(app)).to be_a(Doorkeeper::AccessToken)
context 'when user owns app but does not have tokens' do
let(:app) { Fabricate(:application, owner: user) }
it 'creates and returns a persisted token' do
expect { user.token_for_app(app) }
.to change(Doorkeeper::AccessToken.where(resource_owner_id: user.id, application: app), :count).by(1)
end
end
it 'persists a token' do
t = user.token_for_app(app)
expect(user.token_for_app(app)).to eql(t)
context 'when user owns app and already has tokens' do
let(:app) { Fabricate(:application, owner: user) }
let!(:token) { Fabricate :access_token, application: app, resource_owner_id: user.id }
it 'returns a persisted token' do
expect(user.token_for_app(app))
.to be_a(Doorkeeper::AccessToken)
.and eq(token)
end
end
it 'is nil if user does not own app' do
app.update!(owner: nil)
context 'when user does not own app' do
let(:app) { Fabricate(:application) }
expect(user.token_for_app(app)).to be_nil
it 'returns nil' do
expect(user.token_for_app(app))
.to be_nil
end
end
context 'when app is nil' do
it 'returns nil' do
expect(user.token_for_app(nil))
.to be_nil
end
end
end