Sha256: f68cb358fd0a66352f590d9a6c5e44a3e4769ae1a390aa4733a50336142f4778

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

describe Grape::ExtraValidators::MinimumValue do
  module ValidationsSpec
    module MinimumValueValidatorSpec
      class API < Grape::API
        default_format :json

        params do
          optional :number, type: Integer, minimum_value: 10
        end
        post "/" do
          body false
        end
      end
    end
  end

  def app
    ValidationsSpec::MinimumValueValidatorSpec::API
  end

  let(:params) { { number: number } }
  let(:number) { nil }
  before { post "/", params }
  subject { last_response.status }

  context "when the value is less than the configured minimum value" do
    let(:number) { 9 }

    it { is_expected.to eq(400) }
  end

  context "when the value is equal to the configured minimum value" do
    let(:number) { 10 }

    it { is_expected.to eq(204) }
  end

  context "when the value is more than the configured minimum value" do
    let(:number) { 11 }

    it { is_expected.to eq(204) }
  end

  context "when the parameter is nil" do
    it { is_expected.to eq(204) }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
grape-extra_validators-1.0.0 spec/grape/extra_validators/minimum_value_spec.rb