mirror of
https://github.com/mastodon/mastodon.git
synced 2026-03-21 18:05:23 -05:00
Some checks are pending
Check i18n / check-i18n (push) Waiting to run
Chromatic / Check for relevant changes (push) Waiting to run
Chromatic / Run Chromatic (push) Blocked by required conditions
CodeQL / Analyze (actions) (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
CodeQL / Analyze (ruby) (push) Waiting to run
Check formatting / lint (push) Waiting to run
Ruby Linting / lint (push) Waiting to run
Historical data migration test / test (14-alpine) (push) Waiting to run
Historical data migration test / test (15-alpine) (push) Waiting to run
Historical data migration test / test (16-alpine) (push) Waiting to run
Historical data migration test / test (17-alpine) (push) Waiting to run
Ruby Testing / build (production) (push) Waiting to run
Ruby Testing / build (test) (push) Waiting to run
Ruby Testing / test (.ruby-version) (push) Blocked by required conditions
Ruby Testing / test (3.2) (push) Blocked by required conditions
Ruby Testing / test (3.3) (push) Blocked by required conditions
Ruby Testing / End to End testing (.ruby-version) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.2) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.3) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.19.2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.2, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.3, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Blocked by required conditions
64 lines
1.3 KiB
Ruby
64 lines
1.3 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
RSpec.describe NoteLengthValidator do
|
|
subject { record_class.new }
|
|
|
|
let(:record_class) do
|
|
Class.new do
|
|
include ActiveModel::Validations
|
|
|
|
def self.name = 'Record'
|
|
|
|
attr_accessor :note
|
|
|
|
validates :note, note_length: { maximum: 100 }
|
|
end
|
|
end
|
|
|
|
context 'when note is too long' do
|
|
let(:too_long) { 'a' * 200 }
|
|
|
|
it { is_expected.to_not allow_value(too_long).for(:note).with_message(too_long_message) }
|
|
end
|
|
|
|
context 'when note has space separated linkable URLs' do
|
|
let(:text) { [starting_string, example_link].join(' ') }
|
|
|
|
it { is_expected.to allow_value(text).for(:note) }
|
|
end
|
|
|
|
context 'when note has non-separated URLs' do
|
|
let(:text) { [starting_string, example_link].join }
|
|
|
|
it { is_expected.to_not allow_value(text).for(:note).with_message(too_long_message) }
|
|
end
|
|
|
|
context 'with multi-byte emoji' do
|
|
let(:text) { '✨' * 100 }
|
|
|
|
it { is_expected.to allow_value(text).for(:note) }
|
|
end
|
|
|
|
context 'with ZWJ sequence emoji' do
|
|
let(:text) { '🏳️⚧️' * 100 }
|
|
|
|
it { is_expected.to allow_value(text).for(:note) }
|
|
end
|
|
|
|
private
|
|
|
|
def too_long_message
|
|
I18n.t('errors.messages.too_long', count: 100)
|
|
end
|
|
|
|
def starting_string
|
|
'a' * 76
|
|
end
|
|
|
|
def example_link
|
|
"http://#{'b' * 30}.com/example"
|
|
end
|
|
end
|