Sha256: f710fa874a6280ea43af48ee1e73360c2c65efcee78658e36da16936b54142e1

Contents?: true

Size: 1.21 KB

Versions: 4

Compression:

Stored size: 1.21 KB

Contents

# encoding: utf-8
require 'test_helper'

class BasicMultilingualPlaneValidatorTest < Minitest::Test

  class Model
    include ActiveModel::Validations

    attr_accessor :unicode
    validates :unicode, basic_multilingual_plane: true
  end

  def setup
    @model = Model.new
  end

  def test_basic_multilingual_plane_string
    @model.unicode = 'basic multilingual ünicode'
    assert @model.valid?

  end

  def test_emoji
    @model.unicode = '💩'
    assert @model.invalid?
    assert_equal ["contains characters outside Unicode's basic multilingual plane"], @model.errors[:unicode]
  end

  def test_nil
    @model.unicode = nil
    assert @model.valid?
  end

  def test_different_type
    @model.unicode = 1
    assert @model.valid?
  end

  def test_non_unicode_encoding
    @model.unicode = 'ü'.encode('ISO-8859-15')
    assert @model.valid?
  end

  def test_utf8mb3_japanese
    @model.unicode = 'これは普通なストリングです'
    assert @model.valid?
  end

  def test_utf8mb4_kanji
    @model.unicode = '𠜎𠜱𠝹𠱓𠱸𠲖𠳏𠳕𠴕𠵼𠵿𠸎𠸏𠹷'
    assert @model.invalid?
    assert_equal ["contains characters outside Unicode's basic multilingual plane"], @model.errors[:unicode]
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
activerecord-databasevalidations-0.5.1 test/basic_multilingual_plane_validator_test.rb
activerecord-databasevalidations-0.5.0 test/basic_multilingual_plane_validator_test.rb
activerecord-databasevalidations-0.4.0 test/basic_multilingual_plane_validator_test.rb
activerecord-databasevalidations-0.3.1 test/basic_multilingual_plane_validator_test.rb