Welcome to mirror list, hosted at ThFree Co, Russian Federation.

iso8601_date_validator_spec.rb « validators « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8b9b8a5bb8f472a533decb5cc0f498fa07b35612 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Iso8601DateValidator do
  subject do
    Class.new(ActiveRecord::Base) do
      self.table_name = 'deploy_tokens'

      attribute :expires_at

      validates :expires_at, iso8601_date: true

      def self.name
        "DeployToken"
      end
    end.new
  end

  it 'passes a valid date' do
    subject.expires_at = DateTime.now

    expect(subject.valid?).to be_truthy
  end

  it 'errors on an invalid date' do
    subject.expires_at = '2-12-2022'

    expect(subject.valid?).to be_falsy
    expect(subject.errors.full_messages).to include('Expires at must be in ISO 8601 format')
  end
end