Merge commit '877090518682b6c77ba9bdfa0231afd56daec44d' into glitch-soc/merge-upstream

Conflicts:
- `app/models/concerns/user/has_settings.rb`:
  Not a real conflict, upstream added a setting textually close to a glitch-soc one.
  Added upstream's new setting.
- `app/views/settings/preferences/appearance/show.html.haml`:
  Not a real conflict, upstream added a setting textually close to a glitch-soc one.
  Added upstream's new setting.
- `config/routes.rb`:
  Upstream moved web app routes to `config/routes/web_app.rb`, while glitch-soc had
  an extra route.
  Moved the extra route to `config/routes/web_app.rb`.
- `spec/controllers/settings/preferences/appearance_controller_spec.rb`:
  This spec got converted to a system spec upstream.
  However, the theme setting works differently in glitch-soc, so the spec had been
  changed.
  Changed the corresponding system spec as well.
This commit is contained in:
Claire committed 2024-12-25 18:01:37 +01:00
commit 0aa69487a2
759 files changed
+13447 -7221

No files matched your search

+33
View File
@@ -0,0 +1,33 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe AccountPin do
describe 'Associations' do
it { is_expected.to belong_to(:account).required }
it { is_expected.to belong_to(:target_account).required }
end
describe 'Validations' do
describe 'the follow relationship' do
subject { Fabricate.build :account_pin, account: account }
let(:account) { Fabricate :account }
let(:target_account) { Fabricate :account }
context 'when account is following target account' do
before { account.follow!(target_account) }
it { is_expected.to allow_value(target_account).for(:target_account).against(:base) }
end
context 'when account is not following target account' do
it { is_expected.to_not allow_value(target_account).for(:target_account).against(:base).with_message(not_following_message) }
def not_following_message
I18n.t('accounts.pin_errors.following')
end
end
end
end
end
@@ -129,8 +129,8 @@ RSpec.describe AccountStatusesCleanupPolicy do
let(:account_statuses_cleanup_policy) { Fabricate(:account_statuses_cleanup_policy, account: account) }
it 'records the given id' do
account_statuses_cleanup_policy.record_last_inspected(42)
expect(account_statuses_cleanup_policy.last_inspected).to eq 42
expect { account_statuses_cleanup_policy.record_last_inspected(42) }
.to change(account_statuses_cleanup_policy, :last_inspected).from(nil).to(42)
end
end
@@ -153,8 +153,8 @@ RSpec.describe AccountStatusesCleanupPolicy do
end
it 'does not change the recorded id' do
subject
expect(account_statuses_cleanup_policy.last_inspected).to eq 42
expect { subject }
.to_not change(account_statuses_cleanup_policy, :last_inspected).from(42)
end
end
@@ -164,8 +164,8 @@ RSpec.describe AccountStatusesCleanupPolicy do
end
it 'records the older id' do
subject
expect(account_statuses_cleanup_policy.last_inspected).to eq 10
expect { subject }
.to change(account_statuses_cleanup_policy, :last_inspected).from(42).to(10)
end
end
end
@@ -179,8 +179,8 @@ RSpec.describe AccountStatusesCleanupPolicy do
end
it 'does not change the recorded id' do
subject
expect(account_statuses_cleanup_policy.last_inspected).to eq 42
expect { subject }
.to_not change(account_statuses_cleanup_policy, :last_inspected).from(42)
end
end
@@ -190,8 +190,8 @@ RSpec.describe AccountStatusesCleanupPolicy do
end
it 'records the older id' do
subject
expect(account_statuses_cleanup_policy.last_inspected).to eq 10
expect { subject }
.to change(account_statuses_cleanup_policy, :last_inspected).from(42).to(10)
end
end
end
@@ -205,8 +205,8 @@ RSpec.describe AccountStatusesCleanupPolicy do
end
it 'does not change the recorded id' do
subject
expect(account_statuses_cleanup_policy.last_inspected).to eq 42
expect { subject }
.to_not change(account_statuses_cleanup_policy, :last_inspected).from(42)
end
end
@@ -216,8 +216,8 @@ RSpec.describe AccountStatusesCleanupPolicy do
end
it 'records the older id' do
subject
expect(account_statuses_cleanup_policy.last_inspected).to eq 10
expect { subject }
.to change(account_statuses_cleanup_policy, :last_inspected).from(42).to(10)
end
end
end
@@ -227,8 +227,8 @@ RSpec.describe AccountStatusesCleanupPolicy do
let(:status) { Fabricate(:status, account: account) }
it 'does not change the recorded id' do
subject
expect(account_statuses_cleanup_policy.last_inspected).to eq 42
expect { subject }
.to_not change(account_statuses_cleanup_policy, :last_inspected).from(42)
end
end
end
+28 -13
View File
@@ -3,23 +3,14 @@
require 'rails_helper'
RSpec.describe CustomFilter do
include_examples 'Expireable'
describe 'Validations' do
it { is_expected.to validate_presence_of(:title) }
it { is_expected.to validate_presence_of(:context) }
it 'requires non-empty of context' do
record = described_class.new(context: [])
record.valid?
expect(record).to model_have_error_on_field(:context)
end
it 'requires valid context value' do
record = described_class.new(context: ['invalid'])
record.valid?
expect(record).to model_have_error_on_field(:context)
end
it { is_expected.to_not allow_values([], %w(invalid)).for(:context) }
it { is_expected.to allow_values(%w(home)).for(:context) }
end
describe 'Normalizations' do
@@ -27,4 +18,28 @@ RSpec.describe CustomFilter do
it { is_expected.to normalize(:context).from(['home', 'notifications', 'public ', '']).to(%w(home notifications public)) }
end
end
describe '#expires_in' do
subject { custom_filter.expires_in }
let(:custom_filter) { Fabricate.build(:custom_filter, expires_at: expires_at) }
context 'when expires_at is nil' do
let(:expires_at) { nil }
it { is_expected.to be_nil }
end
context 'when expires is beyond the end of the range' do
let(:expires_at) { described_class::EXPIRATION_DURATIONS.last.from_now + 2.days }
it { is_expected.to be_nil }
end
context 'when expires is before the start of the range' do
let(:expires_at) { described_class::EXPIRATION_DURATIONS.first.from_now - 10.minutes }
it { is_expected.to eq(described_class::EXPIRATION_DURATIONS.first) }
end
end
end
+1 -4
View File
@@ -61,10 +61,7 @@ RSpec.describe Form::Import do
let(:import_type) { 'following' }
let(:import_file) { 'boop.ogg' }
it 'has errors' do
# NOTE: not testing more specific error because we don't know the string to match
expect(subject).to model_have_error_on_field(:data)
end
it { is_expected.to_not allow_value(data).for(:data) }
end
context 'when importing more follows than allowed' do
+2
View File
@@ -3,6 +3,8 @@
require 'rails_helper'
RSpec.describe Invite do
include_examples 'Expireable'
describe '#valid_for_use?' do
it 'returns true when there are no limitations' do
invite = Fabricate(:invite, max_uses: nil, expires_at: nil)
+2
View File
@@ -3,6 +3,8 @@
require 'rails_helper'
RSpec.describe IpBlock do
include_examples 'Expireable'
describe 'Validations' do
subject { Fabricate.build :ip_block }
+7 -1
View File
@@ -3,8 +3,14 @@
require 'rails_helper'
RSpec.describe Mention do
describe 'validations' do
describe 'Associations' do
it { is_expected.to belong_to(:account).required }
it { is_expected.to belong_to(:status).required }
end
describe 'Validations' do
subject { Fabricate.build :mention }
it { is_expected.to validate_uniqueness_of(:account_id).scoped_to(:status_id) }
end
end
+18
View File
@@ -0,0 +1,18 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Mute do
include_examples 'Expireable'
describe 'Associations' do
it { is_expected.to belong_to(:account).required }
it { is_expected.to belong_to(:target_account).required }
end
describe 'Validations' do
subject { Fabricate.build :mute }
it { is_expected.to validate_uniqueness_of(:account_id).scoped_to(:target_account_id) }
end
end
+1 -26
View File
@@ -3,32 +3,7 @@
require 'rails_helper'
RSpec.describe Poll do
describe 'Scopes' do
let(:status) { Fabricate(:status) }
let(:attached_poll) { Fabricate(:poll, status: status) }
let(:not_attached_poll) do
Fabricate(:poll).tap do |poll|
poll.status = nil
poll.save(validate: false)
end
end
describe '.attached' do
it 'finds the correct records' do
results = described_class.attached
expect(results).to eq([attached_poll])
end
end
describe '.unattached' do
it 'finds the correct records' do
results = described_class.unattached
expect(results).to eq([not_attached_poll])
end
end
end
include_examples 'Expireable'
describe '#reset_votes!' do
let(:poll) { Fabricate :poll, cached_tallies: [2, 3], votes_count: 5, voters_count: 5 }
+50 -21
View File
@@ -105,35 +105,64 @@ RSpec.describe Report do
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(:report) { Fabricate(:report, target_account_id: target_account.id, status_ids: [status.id]) }
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
let!(:matched_type_account_warning) { Fabricate(:action_log, target_type: 'AccountWarning', target_id: account_warning.id) }
let!(:matched_type_account) { Fabricate(:action_log, target_type: 'Account', target_id: report.target_account_id) }
let!(:matched_type_report) { Fabricate(:action_log, target_type: 'Report', target_id: report.id) }
let!(:matched_type_status) { Fabricate(:action_log, target_type: 'Status', target_id: status.id) }
let!(:unmatched_type_account_warning) { Fabricate(:action_log, target_type: 'AccountWarning') }
let!(:unmatched_type_account) { Fabricate(:action_log, target_type: 'Account') }
let!(:unmatched_type_report) { Fabricate(:action_log, target_type: 'Report') }
let!(:unmatched_type_status) { Fabricate(:action_log, target_type: 'Status') }
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'))
.and include(matched_type_account_warning)
.and include(matched_type_account)
.and include(matched_type_report)
.and include(matched_type_status)
.and not_include(unmatched_type_account_warning)
.and not_include(unmatched_type_account)
.and not_include(unmatched_type_report)
.and not_include(unmatched_type_status)
end
end
describe 'validations' do
describe '#unresolved_siblings?' do
subject { Fabricate :report }
context 'when the target account has other unresolved reports' do
before { Fabricate :report, action_taken_at: nil, target_account: subject.target_account }
it { is_expected.to be_unresolved_siblings }
end
context 'when the target account has a resolved report' do
before { Fabricate :report, action_taken_at: 3.days.ago, target_account: subject.target_account }
it { is_expected.to_not be_unresolved_siblings }
end
context 'when the target account has no other reports' do
before { described_class.where(target_account: subject.target_account).destroy_all }
it { is_expected.to_not be_unresolved_siblings }
end
end
describe 'Validations' do
let(:remote_account) { Fabricate(:account, domain: 'example.com', protocol: :activitypub, inbox_url: 'http://example.com/inbox') }
it 'is invalid if comment is longer than character limit and reporter is local' do
report = Fabricate.build(:report, comment: comment_over_limit)
expect(report.valid?).to be false
expect(report).to model_have_error_on_field(:comment)
report = Fabricate.build(:report)
expect(report).to_not allow_value(comment_over_limit).for(:comment)
end
it 'is valid if comment is longer than character limit and reporter is not local' do
@@ -142,16 +171,16 @@ RSpec.describe Report do
end
it 'is invalid if it references invalid rules' do
report = Fabricate.build(:report, category: :violation, rule_ids: [-1])
expect(report.valid?).to be false
expect(report).to model_have_error_on_field(:rule_ids)
report = Fabricate.build(:report, category: :violation)
expect(report).to_not allow_value([-1]).for(:rule_ids)
end
it 'is invalid if it references rules but category is not "violation"' do
rule = Fabricate(:rule)
report = Fabricate.build(:report, category: :spam, rule_ids: rule.id)
expect(report.valid?).to be false
expect(report).to model_have_error_on_field(:rule_ids)
report = Fabricate.build(:report, category: :spam)
expect(report).to_not allow_value(rule.id).for(:rule_ids)
end
def comment_over_limit
+33 -1
View File
@@ -5,7 +5,39 @@ require 'rails_helper'
RSpec.describe Tag do
include_examples 'Reviewable'
describe 'validations' do
describe 'Validations' do
describe 'name' do
context 'with a new record' do
subject { Fabricate.build :tag, name: 'original' }
it { is_expected.to allow_value('changed').for(:name) }
end
context 'with an existing record' do
subject { Fabricate :tag, name: 'original' }
it { is_expected.to_not allow_value('changed').for(:name).with_message(previous_name_error_message) }
end
end
describe 'display_name' do
context 'with a new record' do
subject { Fabricate.build :tag, name: 'original', display_name: 'OriginalDisplayName' }
it { is_expected.to allow_value('ChangedDisplayName').for(:display_name) }
end
context 'with an existing record' do
subject { Fabricate :tag, name: 'original', display_name: 'OriginalDisplayName' }
it { is_expected.to_not allow_value('ChangedDisplayName').for(:display_name).with_message(previous_name_error_message) }
end
end
def previous_name_error_message
I18n.t('tags.does_not_match_previous_name')
end
it 'invalid with #' do
expect(described_class.new(name: '#hello_world')).to_not be_valid
end
+11
View File
@@ -0,0 +1,11 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe TagTrend do
include_examples 'RankedTrend'
describe 'Associations' do
it { is_expected.to belong_to(:tag).required }
end
end
+27
View File
@@ -0,0 +1,27 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe TermsOfService do
describe '#scope_for_notification' do
subject { terms_of_service.scope_for_notification }
let(:published_at) { Time.now.utc }
let(:terms_of_service) { Fabricate(:terms_of_service, published_at: published_at) }
let(:user_before) { Fabricate(:user, created_at: published_at - 2.days) }
let(:user_before_unconfirmed) { Fabricate(:user, created_at: published_at - 2.days, confirmed_at: nil) }
let(:user_before_suspended) { Fabricate(:user, created_at: published_at - 2.days) }
let(:user_after) { Fabricate(:user, created_at: published_at + 1.hour) }
before do
user_before_suspended.account.suspend!
user_before_unconfirmed
user_before
user_after
end
it 'includes only users created before the terms of service were published' do
expect(subject.pluck(:id)).to match_array(user_before.id)
end
end
end
+2 -2
View File
@@ -61,10 +61,10 @@ RSpec.describe Trends::Tags do
it 'decays scores' do
subject.refresh(yesterday + 12.hours)
original_score = subject.score(tag_ocs.id)
original_score = TagTrend.find_by(tag: tag_ocs).score
expect(original_score).to eq 144.0
subject.refresh(yesterday + 12.hours + subject.options[:max_score_halflife])
decayed_score = subject.score(tag_ocs.id)
decayed_score = TagTrend.find_by(tag: tag_ocs).score
expect(decayed_score).to be <= original_score / 2
end
end
+8
View File
@@ -18,6 +18,14 @@ RSpec.describe UserRole do
end
end
describe 'position' do
subject { Fabricate.build :user_role }
let(:limit) { described_class::POSITION_LIMIT }
it { is_expected.to validate_numericality_of(:position).is_in(-limit..limit) }
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) }