Merge tag 'v4.4.0-rc.1' into chinwag-next
This commit is contained in:
commit
fbbcaf4efd
2660 changed files with 83548 additions and 52192 deletions
51
spec/validators/date_of_birth_validator_spec.rb
Normal file
51
spec/validators/date_of_birth_validator_spec.rb
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe DateOfBirthValidator do
|
||||
let(:record_class) do
|
||||
Class.new do
|
||||
include ActiveModel::Validations
|
||||
|
||||
attr_accessor :date_of_birth
|
||||
|
||||
validates :date_of_birth, date_of_birth: true
|
||||
end
|
||||
end
|
||||
|
||||
let(:record) { record_class.new }
|
||||
|
||||
before do
|
||||
Setting.min_age = 16
|
||||
end
|
||||
|
||||
describe '#validate_each' do
|
||||
context 'with an invalid date' do
|
||||
it 'adds errors' do
|
||||
record.date_of_birth = '76.830.10'
|
||||
|
||||
expect(record).to_not be_valid
|
||||
expect(record.errors.first.attribute).to eq(:date_of_birth)
|
||||
expect(record.errors.first.type).to eq(:invalid)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a date below age limit' do
|
||||
it 'adds errors' do
|
||||
record.date_of_birth = 13.years.ago.strftime('%d.%m.%Y')
|
||||
|
||||
expect(record).to_not be_valid
|
||||
expect(record.errors.first.attribute).to eq(:date_of_birth)
|
||||
expect(record.errors.first.type).to eq(:below_limit)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a date above age limit' do
|
||||
it 'does not add errors' do
|
||||
record.date_of_birth = 16.years.ago.strftime('%d.%m.%Y')
|
||||
|
||||
expect(record).to be_valid
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe LinesValidator do
|
||||
let(:record_class) do
|
||||
Class.new do
|
||||
include ActiveModel::Validations
|
||||
|
||||
attr_accessor :text
|
||||
|
||||
validates :text, lines: { maximum: 5 }
|
||||
end
|
||||
end
|
||||
|
||||
let(:record) { record_class.new }
|
||||
|
||||
describe '#validate_each' do
|
||||
context 'with a nil value' do
|
||||
it 'does not add errors' do
|
||||
record.text = nil
|
||||
|
||||
expect(record).to be_valid
|
||||
expect(record.errors).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
context 'with lines below the limit' do
|
||||
it 'does not add errors' do
|
||||
record.text = "hoge\n" * 5
|
||||
|
||||
expect(record).to be_valid
|
||||
expect(record.errors).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
context 'with more lines than limit' do
|
||||
it 'adds an error' do
|
||||
record.text = "hoge\n" * 6
|
||||
|
||||
expect(record).to_not be_valid
|
||||
expect(record.errors.where(:text)).to_not be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -30,6 +30,22 @@ RSpec.describe NoteLengthValidator do
|
|||
expect(account.errors).to have_received(:add)
|
||||
end
|
||||
|
||||
it 'counts multi byte emoji as single character' do
|
||||
text = '✨' * 500
|
||||
account = instance_double(Account, note: text, errors: activemodel_errors)
|
||||
|
||||
subject.validate_each(account, 'note', text)
|
||||
expect(account.errors).to_not have_received(:add)
|
||||
end
|
||||
|
||||
it 'counts ZWJ sequence emoji as single character' do
|
||||
text = '🏳️⚧️' * 500
|
||||
account = instance_double(Account, note: text, errors: activemodel_errors)
|
||||
|
||||
subject.validate_each(account, 'note', text)
|
||||
expect(account.errors).to_not have_received(:add)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def starting_string
|
||||
|
|
|
|||
|
|
@ -41,5 +41,31 @@ RSpec.describe PollOptionsValidator do
|
|||
expect(errors).to have_received(:add)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'character length of poll options' do
|
||||
context 'when poll has acceptable length options' do
|
||||
let(:options) { %w(test this) }
|
||||
|
||||
it 'has no errors' do
|
||||
expect(errors).to_not have_received(:add)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when poll has multibyte and ZWJ emoji options' do
|
||||
let(:options) { ['✨' * described_class::MAX_OPTION_CHARS, '🏳️⚧️' * described_class::MAX_OPTION_CHARS] }
|
||||
|
||||
it 'has no errors' do
|
||||
expect(errors).to_not have_received(:add)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when poll has options that are too long' do
|
||||
let(:options) { ['ok', 'a' * (described_class::MAX_OPTION_CHARS**2)] }
|
||||
|
||||
it 'has errors' do
|
||||
expect(errors).to have_received(:add)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -80,6 +80,22 @@ RSpec.describe StatusLengthValidator do
|
|||
subject.validate(status)
|
||||
expect(status.errors).to have_received(:add)
|
||||
end
|
||||
|
||||
it 'counts multi byte emoji as single character' do
|
||||
text = '✨' * 500
|
||||
status = status_double(text: text)
|
||||
|
||||
subject.validate(status)
|
||||
expect(status.errors).to_not have_received(:add)
|
||||
end
|
||||
|
||||
it 'counts ZWJ sequence emoji as single character' do
|
||||
text = '🏳️⚧️' * 500
|
||||
status = status_double(text: text)
|
||||
|
||||
subject.validate(status)
|
||||
expect(status.errors).to_not have_received(:add)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue