1
0
Fork 0
forked from gitea/nas

Merge remote-tracking branch 'parent/main' into upstream-20231221

This commit is contained in:
KMY 2023-12-21 08:37:12 +09:00
commit a6b57e3890
154 changed files with 7762 additions and 1748 deletions

View file

@ -0,0 +1,210 @@
# frozen_string_literal: true
require 'rails_helper'
describe Announcement do
describe 'Scopes' do
context 'with published and unpublished records' do
let!(:published) { Fabricate(:announcement, published: true) }
let!(:unpublished) { Fabricate(:announcement, published: false, scheduled_at: 10.days.from_now) }
describe '#unpublished' do
it 'returns records with published false' do
results = described_class.unpublished
expect(results).to eq([unpublished])
end
end
describe '#published' do
it 'returns records with published true' do
results = described_class.published
expect(results).to eq([published])
end
end
end
describe '#without_muted' do
let!(:announcement) { Fabricate(:announcement) }
let(:account) { Fabricate(:account) }
let(:muted_announcement) { Fabricate(:announcement) }
before do
Fabricate(:announcement_mute, account: account, announcement: muted_announcement)
end
it 'returns the announcements not muted by the account' do
results = described_class.without_muted(account)
expect(results).to include(announcement)
expect(results).to_not include(muted_announcement)
end
end
context 'with timestamped announcements' do
let!(:adam_announcement) { Fabricate(:announcement, starts_at: 100.days.ago, scheduled_at: 10.days.ago, published_at: 10.days.ago, ends_at: 5.days.from_now) }
let!(:brenda_announcement) { Fabricate(:announcement, starts_at: 10.days.ago, scheduled_at: 100.days.ago, published_at: 10.days.ago, ends_at: 5.days.from_now) }
let!(:clara_announcement) { Fabricate(:announcement, starts_at: 10.days.ago, scheduled_at: 10.days.ago, published_at: 100.days.ago, ends_at: 5.days.from_now) }
let!(:darnelle_announcement) { Fabricate(:announcement, starts_at: 10.days.ago, scheduled_at: 10.days.ago, published_at: 10.days.ago, ends_at: 5.days.from_now, created_at: 100.days.ago) }
describe '#chronological' do
it 'orders the records correctly' do
results = described_class.chronological
expect(results).to eq(
[
adam_announcement,
brenda_announcement,
clara_announcement,
darnelle_announcement,
]
)
end
end
describe '#reverse_chronological' do
it 'orders the records correctly' do
results = described_class.reverse_chronological
expect(results).to eq(
[
darnelle_announcement,
clara_announcement,
brenda_announcement,
adam_announcement,
]
)
end
end
end
end
describe 'Validations' do
describe 'text' do
it 'validates presence of attribute' do
record = Fabricate.build(:announcement, text: nil)
expect(record).to_not be_valid
expect(record.errors[:text]).to be_present
end
end
describe 'ends_at' do
it 'validates presence when starts_at is present' do
record = Fabricate.build(:announcement, starts_at: 1.day.ago)
expect(record).to_not be_valid
expect(record.errors[:ends_at]).to be_present
end
it 'does not validate presence when starts_at is missing' do
record = Fabricate.build(:announcement, starts_at: nil)
expect(record).to be_valid
expect(record.errors[:ends_at]).to_not be_present
end
end
end
describe '#publish!' do
it 'publishes an unpublished record' do
announcement = Fabricate(:announcement, published: false, scheduled_at: 10.days.from_now)
announcement.publish!
expect(announcement).to be_published
expect(announcement.published_at).to_not be_nil
expect(announcement.scheduled_at).to be_nil
end
end
describe '#unpublish!' do
it 'unpublishes a published record' do
announcement = Fabricate(:announcement, published: true)
announcement.unpublish!
expect(announcement).to_not be_published
expect(announcement.scheduled_at).to be_nil
end
end
describe '#time_range?' do
it 'returns false when starts_at and ends_at are missing' do
record = Fabricate.build(:announcement, starts_at: nil, ends_at: nil)
expect(record.time_range?).to be(false)
end
it 'returns false when starts_at is present and ends_at is missing' do
record = Fabricate.build(:announcement, starts_at: 5.days.from_now, ends_at: nil)
expect(record.time_range?).to be(false)
end
it 'returns false when starts_at is missing and ends_at is present' do
record = Fabricate.build(:announcement, starts_at: nil, ends_at: 5.days.from_now)
expect(record.time_range?).to be(false)
end
it 'returns true when starts_at and ends_at are present' do
record = Fabricate.build(:announcement, starts_at: 5.days.from_now, ends_at: 10.days.from_now)
expect(record.time_range?).to be(true)
end
end
describe '#reactions' do
context 'with announcement_reactions present' do
let!(:account) { Fabricate(:account) }
let!(:announcement) { Fabricate(:announcement) }
let!(:announcement_reaction) { Fabricate(:announcement_reaction, announcement: announcement, created_at: 10.days.ago) }
let!(:announcement_reaction_account) { Fabricate(:announcement_reaction, announcement: announcement, created_at: 5.days.ago, account: account) }
before do
Fabricate(:announcement_reaction)
end
it 'returns the announcement reactions for the announcement' do
results = announcement.reactions
expect(results.first.name).to eq(announcement_reaction.name)
expect(results.last.name).to eq(announcement_reaction_account.name)
end
it 'returns the announcement reactions for the announcement limited to account' do
results = announcement.reactions(account)
expect(results.first.name).to eq(announcement_reaction.name)
end
end
end
describe '#statuses' do
let(:announcement) { Fabricate(:announcement, status_ids: status_ids) }
context 'with empty status_ids' do
let(:status_ids) { nil }
it 'returns empty array' do
results = announcement.statuses
expect(results).to eq([])
end
end
context 'with relevant status_ids' do
let(:status) { Fabricate(:status, visibility: :public) }
let(:direct_status) { Fabricate(:status, visibility: :direct) }
let(:status_ids) { [status.id, direct_status.id] }
it 'returns public and unlisted statuses' do
results = announcement.statuses
expect(results).to include(status)
expect(results).to_not include(direct_status)
end
end
end
end

View file

@ -178,11 +178,11 @@ RSpec.describe Remotable do
allow(foo).to receive(:public_send)
foo.hoge_remote_url = url
expect(foo).to have_received(:public_send).with("download_#{hoge}!", url)
expect(foo).to have_received(:public_send).with(:"download_#{hoge}!", url)
allow(foo).to receive(:public_send)
foo.download_hoge!(url)
expect(foo).to have_received(:public_send).with("#{hoge}=", response_with_limit)
expect(foo).to have_received(:public_send).with(:"#{hoge}=", response_with_limit)
end
end
end

View file

@ -59,7 +59,7 @@ RSpec.describe CustomEmoji do
describe '.from_text' do
subject { described_class.from_text(text, nil) }
let!(:emojo) { Fabricate(:custom_emoji) }
let!(:emojo) { Fabricate(:custom_emoji, shortcode: 'coolcat') }
context 'with plain text' do
let(:text) { 'Hello :coolcat:' }

View file

@ -0,0 +1,118 @@
# frozen_string_literal: true
require 'rails_helper'
describe Form::CustomEmojiBatch do
describe '#save' do
subject { described_class.new({ current_account: account }.merge(options)) }
let(:options) { {} }
let(:account) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account }
context 'with empty custom_emoji_ids' do
let(:options) { { custom_emoji_ids: [] } }
it 'does nothing if custom_emoji_ids is empty' do
expect(subject.save).to be_nil
end
end
describe 'the update action' do
let(:custom_emoji) { Fabricate(:custom_emoji, category: Fabricate(:custom_emoji_category)) }
let(:custom_emoji_category) { Fabricate(:custom_emoji_category) }
context 'without anything to change' do
let(:options) { { action: 'update' } }
it 'silently exits without updating any custom emojis' do
expect { subject.save }.to_not change(Admin::ActionLog, :count)
end
end
context 'with a category_id' do
let(:options) { { action: 'update', custom_emoji_ids: [custom_emoji.id], category_id: custom_emoji_category.id } }
it 'updates the category of the emoji' do
subject.save
expect(custom_emoji.reload.category).to eq(custom_emoji_category)
end
end
context 'with a category_name' do
let(:options) { { action: 'update', custom_emoji_ids: [custom_emoji.id], category_name: custom_emoji_category.name } }
it 'updates the category of the emoji' do
subject.save
expect(custom_emoji.reload.category).to eq(custom_emoji_category)
end
end
end
describe 'the list action' do
let(:custom_emoji) { Fabricate(:custom_emoji, visible_in_picker: false) }
let(:options) { { action: 'list', custom_emoji_ids: [custom_emoji.id] } }
it 'updates the picker visibility of the emoji' do
subject.save
expect(custom_emoji.reload.visible_in_picker).to be(true)
end
end
describe 'the unlist action' do
let(:custom_emoji) { Fabricate(:custom_emoji, visible_in_picker: true) }
let(:options) { { action: 'unlist', custom_emoji_ids: [custom_emoji.id] } }
it 'updates the picker visibility of the emoji' do
subject.save
expect(custom_emoji.reload.visible_in_picker).to be(false)
end
end
describe 'the enable action' do
let(:custom_emoji) { Fabricate(:custom_emoji, disabled: true) }
let(:options) { { action: 'enable', custom_emoji_ids: [custom_emoji.id] } }
it 'updates the disabled value of the emoji' do
subject.save
expect(custom_emoji.reload).to_not be_disabled
end
end
describe 'the disable action' do
let(:custom_emoji) { Fabricate(:custom_emoji, visible_in_picker: false) }
let(:options) { { action: 'disable', custom_emoji_ids: [custom_emoji.id] } }
it 'updates the disabled value of the emoji' do
subject.save
expect(custom_emoji.reload).to be_disabled
end
end
describe 'the copy action' do
let(:custom_emoji) { Fabricate(:custom_emoji) }
let(:options) { { action: 'copy', custom_emoji_ids: [custom_emoji.id] } }
it 'makes a copy of the emoji' do
expect { subject.save }
.to change(CustomEmoji, :count).by(1)
end
end
describe 'the delete action' do
let(:custom_emoji) { Fabricate(:custom_emoji) }
let(:options) { { action: 'delete', custom_emoji_ids: [custom_emoji.id] } }
it 'destroys the emoji' do
subject.save
expect { custom_emoji.reload }.to raise_error(ActiveRecord::RecordNotFound)
end
end
end
end

View file

@ -175,16 +175,8 @@ RSpec.describe User do
let(:user) { Fabricate(:user, confirmed_at: nil, unconfirmed_email: new_email) }
context 'when the user is already approved' do
around do |example|
registrations_mode = Setting.registrations_mode
Setting.registrations_mode = 'approved'
example.run
Setting.registrations_mode = registrations_mode
end
before do
Setting.registrations_mode = 'approved'
user.approve!
end
@ -199,13 +191,8 @@ RSpec.describe User do
end
context 'when the user does not require explicit approval' do
around do |example|
registrations_mode = Setting.registrations_mode
before do
Setting.registrations_mode = 'open'
example.run
Setting.registrations_mode = registrations_mode
end
it 'sets email to unconfirmed_email' do
@ -219,13 +206,8 @@ RSpec.describe User do
end
context 'when the user requires explicit approval but is not approved' do
around do |example|
registrations_mode = Setting.registrations_mode
before do
Setting.registrations_mode = 'approved'
example.run
Setting.registrations_mode = registrations_mode
end
it 'sets email to unconfirmed_email' do
@ -243,16 +225,8 @@ RSpec.describe User do
describe '#approve!' do
subject { user.approve! }
around do |example|
registrations_mode = Setting.registrations_mode
Setting.registrations_mode = 'approved'
example.run
Setting.registrations_mode = registrations_mode
end
before do
Setting.registrations_mode = 'approved'
allow(TriggerWebhookWorker).to receive(:perform_async)
end