Sha256: af63e93432bc11aa8d314783a30c13212d5307fa3c8bb87253afa181603fe65f

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

describe Grape::ExtraValidators::MaximumValue do
  module ValidationsSpec
    module MaximumValueValidatorSpec
      class API < Grape::API
        default_format :json

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

  def app
    ValidationsSpec::MaximumValueValidatorSpec::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(204) }
  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(400) }
  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/maximum_value_spec.rb