You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mastodon/spec/validators/language_validator_spec.rb

36 lines
814 B
Ruby

# frozen_string_literal: true
require 'rails_helper'
RSpec.describe LanguageValidator do
subject { record_class.new }
let(:record_class) do
Class.new do
include ActiveModel::Validations
def self.name = 'Record'
attr_accessor :locale
validates :locale, language: true
end
end
context 'with a nil value' do
it { is_expected.to allow_value(nil).for(:locale) }
end
context 'with an array of values' do
it { is_expected.to allow_value(%w(en fr)).for(:locale) }
it { is_expected.to_not allow_value(%w(en fr missing)).for(:locale).with_message(:invalid) }
end
context 'with a locale string' do
it { is_expected.to allow_value('en').for(:locale) }
it { is_expected.to_not allow_value('missing').for(:locale).with_message(:invalid) }
end
end