2019-10-13 20:06:38 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-08-30 08:53:06 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe JsRegexValidator do
|
|
|
|
describe '#validates_each' do
|
|
|
|
using RSpec::Parameterized::TableSyntax
|
|
|
|
|
|
|
|
let(:validator) { described_class.new(attributes: [:user_default_internal_regex]) }
|
|
|
|
let(:application_setting) { build(:application_setting, user_default_external: true) }
|
|
|
|
|
|
|
|
where(:user_default_internal_regex, :result) do
|
|
|
|
nil | []
|
|
|
|
'' | []
|
|
|
|
'(?#comment)' | ['Regex Pattern (?#comment) can not be expressed in Javascript']
|
|
|
|
'(?(a)b|c)' | ['invalid conditional pattern: /(?(a)b|c)/i']
|
|
|
|
end
|
|
|
|
|
|
|
|
with_them do
|
|
|
|
it 'generates correct errors' do
|
|
|
|
validator.validate_each(application_setting, :user_default_internal_regex, user_default_internal_regex)
|
|
|
|
|
|
|
|
expect(application_setting.errors[:user_default_internal_regex]).to eq result
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|