mirror of
https://github.com/glitch-soc/mastodon.git
synced 2025-12-15 16:59:41 +00:00
Implement Instance Moderation Notes (#31529)
This commit is contained in:
7
spec/fabricators/instance_moderation_note_fabricator.rb
Normal file
7
spec/fabricators/instance_moderation_note_fabricator.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
Fabricator(:instance_moderation_note) do
|
||||
domain { sequence(:domain) { |i| "#{i}#{Faker::Internet.domain_name}" } }
|
||||
account { Fabricate.build(:account) }
|
||||
content { Faker::Lorem.sentence }
|
||||
end
|
||||
37
spec/models/instance_moderation_note_spec.rb
Normal file
37
spec/models/instance_moderation_note_spec.rb
Normal file
@@ -0,0 +1,37 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe InstanceModerationNote do
|
||||
describe 'chronological' do
|
||||
it 'returns the instance notes sorted by oldest first' do
|
||||
instance = Instance.find_or_initialize_by(domain: TagManager.instance.normalize_domain('mastodon.example'))
|
||||
|
||||
note1 = Fabricate(:instance_moderation_note, domain: instance.domain)
|
||||
note2 = Fabricate(:instance_moderation_note, domain: instance.domain)
|
||||
|
||||
expect(instance.moderation_notes.chronological).to eq [note1, note2]
|
||||
end
|
||||
end
|
||||
|
||||
describe 'validations' do
|
||||
it 'is invalid if the content is empty' do
|
||||
note = Fabricate.build(:instance_moderation_note, domain: 'mastodon.example', content: '')
|
||||
expect(note.valid?).to be false
|
||||
end
|
||||
|
||||
it 'is invalid if content is longer than character limit' do
|
||||
note = Fabricate.build(:instance_moderation_note, domain: 'mastodon.example', content: comment_over_limit)
|
||||
expect(note.valid?).to be false
|
||||
end
|
||||
|
||||
it 'is valid even if the instance does not exist yet' do
|
||||
note = Fabricate.build(:instance_moderation_note, domain: 'non-existent.example', content: 'test comment')
|
||||
expect(note.valid?).to be true
|
||||
end
|
||||
|
||||
def comment_over_limit
|
||||
Faker::Lorem.paragraph_by_chars(number: described_class::CONTENT_SIZE_LIMIT * 2)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -3,9 +3,9 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Instance do
|
||||
describe 'Scopes' do
|
||||
before { described_class.refresh }
|
||||
before { described_class.refresh }
|
||||
|
||||
describe 'Scopes' do
|
||||
describe '#searchable' do
|
||||
let(:expected_domain) { 'host.example' }
|
||||
let(:blocked_domain) { 'other.example' }
|
||||
|
||||
16
spec/requests/admin/instances/moderation_notes_spec.rb
Normal file
16
spec/requests/admin/instances/moderation_notes_spec.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Admin Report Notes' do
|
||||
describe 'POST /admin/instance/moderation_notes' do
|
||||
before { sign_in Fabricate(:admin_user) }
|
||||
|
||||
it 'gracefully handles invalid nested params' do
|
||||
post admin_instance_moderation_notes_path(instance_id: 'mastodon.test', instance_note: 'invalid')
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(400)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -4,9 +4,9 @@ require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Admin Instances' do
|
||||
describe 'GET /admin/instances/:id' do
|
||||
context 'with an unknown domain' do
|
||||
before { sign_in Fabricate(:admin_user) }
|
||||
before { sign_in Fabricate(:admin_user) }
|
||||
|
||||
context 'with an unknown domain' do
|
||||
it 'returns http success' do
|
||||
get admin_instance_path(id: 'unknown.example')
|
||||
|
||||
@@ -14,5 +14,14 @@ RSpec.describe 'Admin Instances' do
|
||||
.to have_http_status(200)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with an invalid domain' do
|
||||
it 'returns http success' do
|
||||
get admin_instance_path(id: ' ')
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(200)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -35,7 +35,7 @@ RSpec.describe 'Admin::AccountModerationNotes' do
|
||||
end
|
||||
|
||||
def delete_note
|
||||
within('.report-notes__item__actions') do
|
||||
within('.report-notes__item:first-child .report-notes__item__actions') do
|
||||
click_on I18n.t('admin.reports.notes.delete')
|
||||
end
|
||||
end
|
||||
|
||||
51
spec/system/admin/instance/moderation_notes_spec.rb
Normal file
51
spec/system/admin/instance/moderation_notes_spec.rb
Normal file
@@ -0,0 +1,51 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Admin::Instances::ModerationNotesController' do
|
||||
let(:current_user) { Fabricate(:admin_user) }
|
||||
let(:instance_domain) { 'mastodon.example' }
|
||||
|
||||
before { sign_in current_user }
|
||||
|
||||
describe 'Managing instance moderation notes' do
|
||||
it 'saves and then deletes a record' do
|
||||
visit admin_instance_path(instance_domain)
|
||||
|
||||
fill_in 'instance_moderation_note_content', with: ''
|
||||
expect { submit_form }
|
||||
.to not_change(InstanceModerationNote, :count)
|
||||
expect(page)
|
||||
.to have_content(/error below/)
|
||||
|
||||
fill_in 'instance_moderation_note_content', with: 'Test message ' * InstanceModerationNote::CONTENT_SIZE_LIMIT
|
||||
expect { submit_form }
|
||||
.to not_change(InstanceModerationNote, :count)
|
||||
expect(page)
|
||||
.to have_content(/error below/)
|
||||
|
||||
fill_in 'instance_moderation_note_content', with: 'Test message'
|
||||
expect { submit_form }
|
||||
.to change(InstanceModerationNote, :count).by(1)
|
||||
expect(page)
|
||||
.to have_current_path(admin_instance_path(instance_domain))
|
||||
expect(page)
|
||||
.to have_content(I18n.t('admin.instances.moderation_notes.created_msg'))
|
||||
|
||||
expect { delete_note }
|
||||
.to change(InstanceModerationNote, :count).by(-1)
|
||||
expect(page)
|
||||
.to have_content(I18n.t('admin.instances.moderation_notes.destroyed_msg'))
|
||||
end
|
||||
|
||||
def submit_form
|
||||
click_on I18n.t('admin.instances.moderation_notes.create')
|
||||
end
|
||||
|
||||
def delete_note
|
||||
within('.report-notes__item:first-child .report-notes__item__actions') do
|
||||
click_on I18n.t('admin.reports.notes.delete')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user