mirror of
https://git.kescher.at/CatCatNya/catstodon.git
synced 2024-11-25 16:41:36 +01:00
Simplify model validation spec in AccountModerationNote/ReportNote (#31792)
This commit is contained in:
parent
dea6c454fd
commit
37bcbeab4a
2 changed files with 26 additions and 36 deletions
|
@ -3,29 +3,24 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe AccountModerationNote do
|
RSpec.describe AccountModerationNote do
|
||||||
describe 'chronological scope' do
|
describe 'Scopes' do
|
||||||
it 'returns account moderation notes oldest to newest' do
|
describe '.chronological' do
|
||||||
account = Fabricate(:account)
|
it 'returns account moderation notes oldest to newest' do
|
||||||
note1 = Fabricate(:account_moderation_note, target_account: account)
|
account = Fabricate(:account)
|
||||||
note2 = Fabricate(:account_moderation_note, target_account: account)
|
note1 = Fabricate(:account_moderation_note, target_account: account)
|
||||||
|
note2 = Fabricate(:account_moderation_note, target_account: account)
|
||||||
|
|
||||||
expect(account.targeted_moderation_notes.chronological).to eq [note1, note2]
|
expect(account.targeted_moderation_notes.chronological).to eq [note1, note2]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'validations' do
|
describe 'Validations' do
|
||||||
it 'is invalid if the content is empty' do
|
subject { Fabricate.build :account_moderation_note }
|
||||||
report = Fabricate.build(:account_moderation_note, content: '')
|
|
||||||
expect(report.valid?).to be false
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'is invalid if content is longer than character limit' do
|
describe 'content' do
|
||||||
report = Fabricate.build(:account_moderation_note, content: comment_over_limit)
|
it { is_expected.to_not allow_value('').for(:content) }
|
||||||
expect(report.valid?).to be false
|
it { is_expected.to validate_length_of(:content).is_at_most(described_class::CONTENT_SIZE_LIMIT) }
|
||||||
end
|
|
||||||
|
|
||||||
def comment_over_limit
|
|
||||||
Faker::Lorem.paragraph_by_chars(number: described_class::CONTENT_SIZE_LIMIT * 2)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,29 +3,24 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe ReportNote do
|
RSpec.describe ReportNote do
|
||||||
describe 'chronological scope' do
|
describe 'Scopes' do
|
||||||
it 'returns report notes oldest to newest' do
|
describe '.chronological' do
|
||||||
report = Fabricate(:report)
|
it 'returns report notes oldest to newest' do
|
||||||
note1 = Fabricate(:report_note, report: report)
|
report = Fabricate(:report)
|
||||||
note2 = Fabricate(:report_note, report: report)
|
note1 = Fabricate(:report_note, report: report)
|
||||||
|
note2 = Fabricate(:report_note, report: report)
|
||||||
|
|
||||||
expect(report.notes.chronological).to eq [note1, note2]
|
expect(report.notes.chronological).to eq [note1, note2]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'validations' do
|
describe 'Validations' do
|
||||||
it 'is invalid if the content is empty' do
|
subject { Fabricate.build :report_note }
|
||||||
report = Fabricate.build(:report_note, content: '')
|
|
||||||
expect(report.valid?).to be false
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'is invalid if content is longer than character limit' do
|
describe 'content' do
|
||||||
report = Fabricate.build(:report_note, content: comment_over_limit)
|
it { is_expected.to_not allow_value('').for(:content) }
|
||||||
expect(report.valid?).to be false
|
it { is_expected.to validate_length_of(:content).is_at_most(described_class::CONTENT_SIZE_LIMIT) }
|
||||||
end
|
|
||||||
|
|
||||||
def comment_over_limit
|
|
||||||
Faker::Lorem.paragraph_by_chars(number: described_class::CONTENT_SIZE_LIMIT * 2)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue