Sha256: ecb18fb14b00eeaf77a3c763cbd03e0b42cd3774ebc2bd526f68e41afe2df083

Contents?: true

Size: 1.07 KB

Versions: 2

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe Grape::API::Helpers do
  let(:app) do
    Class.new(Grape::API) do
      helpers Module.new do
        extend Grape::API::Helpers

        params :drink do
          optional :beer
          optional :wine
          exactly_one_of :beer, :wine
        end
      end
      format :json

      params do
        requires :orderType, type: String, values: %w[food drink]
        given orderType: ->(val) { val == 'food' } do
          optional :pasta
          optional :pizza
          exactly_one_of :pasta, :pizza
        end
        given orderType: ->(val) { val == 'drink' } do
          use :drink
        end
      end
      get do
        declared(params, include_missing: true)
      end
    end
  end

  it 'defines parameters' do
    get '/', orderType: 'food', pizza: 'mista'
    expect(last_response.status).to eq 200
    expect(last_response.body).to eq({ orderType: 'food',
                                       pasta: nil, pizza: 'mista',
                                       beer: nil, wine: nil }.to_json)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
grape-1.6.2 spec/grape/api/shared_helpers_exactly_one_of_spec.rb
grape-1.6.1 spec/grape/api/shared_helpers_exactly_one_of_spec.rb