Sha256: d27bc669bbd865401504c2ead0fb6edfea57fc9775ee2c6f57d80ddeba2f7cfe

Contents?: true

Size: 832 Bytes

Versions: 1

Compression:

Stored size: 832 Bytes

Contents

require 'test_helper'
ActiveValidators.activate(:regexp)

describe "Regexp Validation" do
  let(:invalid_message) { subject.errors.generate_message(:redirect_rule, :invalid) }

  subject { TestRecord.new }

  before do
    TestRecord.reset_callbacks(:validate)
    TestRecord.validates :redirect_rule, :regexp => true
  end

  it "accepts blank value" do
    subject.redirect_rule = ''

    _(subject).must_be(:valid?)
    _(subject.errors).must_be(:empty?)
  end

  it "rejects malformed regular expressions" do
    subject.redirect_rule = '['

    _(subject).must_be(:invalid?)
    _(subject.errors[:redirect_rule]).must_include(invalid_message)
  end

  it "allow proper regular expressions" do
    subject.redirect_rule = '^/vanity-url(-2014)?'

    _(subject).must_be(:valid?)
    _(subject.errors).must_be(:empty?)
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
activevalidators-6.0.0 test/validations/regexp_test.rb