Sha256: c07cfd424da434354d624dd0af0b3cc82373654a7aa7650ce51e1c0fec708bca

Contents?: true

Size: 1.04 KB

Versions: 2

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

describe Grape::ExtraValidators::MinimumLength do
  module ValidationsSpec
    module MinimumLengthValidatorSpec
      class API < Grape::API
        default_format :json

        params do
          optional :text, type: String, minimum_length: 4
        end
        post "/" do
          body false
        end
      end
    end
  end

  def app
    ValidationsSpec::MinimumLengthValidatorSpec::API
  end

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

  context "when the length is less than the configured minimum length" do
    let(:text) { "123" }

    it { is_expected.to eq(400) }
  end

  context "when the length is equal to the configured minimum length" do
    let(:text) { "1234" }

    it { is_expected.to eq(204) }
  end

  context "when the length is more than the configured minimum length" do
    let(:text) { "12345" }

    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

2 entries across 2 versions & 1 rubygems

Version Path
grape-extra_validators-2.0.0 spec/grape/extra_validators/minimum_length_spec.rb
grape-extra_validators-1.0.0 spec/grape/extra_validators/minimum_length_spec.rb