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

integer_or_custom_value_spec.rb « validators « validations « api « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a04917736db54963828b0ff7e1bc62973b24edf9 (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe API::Validations::Validators::IntegerOrCustomValue do
  include ApiValidatorsHelpers

  let(:custom_values) { %w[None Any Started Current] }

  subject { described_class.new(['test'], { values: custom_values }, false, scope.new) }

  context 'valid parameters' do
    it 'does not raise a validation error' do
      expect_no_validation_error('test' => 2)
      expect_no_validation_error('test' => 100)
      expect_no_validation_error('test' => 'None')
      expect_no_validation_error('test' => 'Any')
      expect_no_validation_error('test' => 'none')
      expect_no_validation_error('test' => 'any')
      expect_no_validation_error('test' => 'started')
      expect_no_validation_error('test' => 'CURRENT')
    end

    context 'when custom values is empty and value is an integer' do
      let(:custom_values) { [] }

      it 'does not raise a validation error' do
        expect_no_validation_error({ 'test' => 5 })
      end
    end
  end

  context 'invalid parameters' do
    it 'raises a validation error' do
      expect_validation_error({ 'test' => 'Upcomming' })
    end

    context 'when custom values is empty and value is not an integer' do
      let(:custom_values) { [] }

      it 'raises a validation error' do
        expect_validation_error({ 'test' => '5' })
      end
    end
  end
end