Sha256: 9870cfcbaad1766652a0ac8f41852dc3461cd44f7ff3159908f081fa3c1506c4

Contents?: true

Size: 971 Bytes

Versions: 11

Compression:

Stored size: 971 Bytes

Contents

# frozen_string_literal: true

require 'spec_helper'

describe Grape::API::Instance do
  describe 'boolean constant' do
    module DefinesBooleanInstanceSpec
      class API < Grape::API
        params do
          requires :message, type: Boolean
        end
        post :echo do
          { class: params[:message].class.name, value: params[:message] }
        end
      end
    end

    def app
      DefinesBooleanInstanceSpec::API
    end

    let(:expected_body) do
      { class: 'TrueClass', value: true }.to_s
    end

    it 'sets Boolean as a type' do
      post '/echo?message=true'
      expect(last_response.status).to eq(201)
      expect(last_response.body).to eq expected_body
    end

    context 'Params endpoint type' do
      subject { DefinesBooleanInstanceSpec::API.new.router.map['POST'].first.options[:params]['message'][:type] }
      it 'params type is a boolean' do
        is_expected.to eq 'Grape::API::Boolean'
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
grape-1.6.0 spec/grape/api/defines_boolean_in_params_spec.rb
grape-1.5.3 spec/grape/api/defines_boolean_in_params_spec.rb
grape-1.5.2 spec/grape/api/defines_boolean_in_params_spec.rb
grape-1.5.1 spec/grape/api/defines_boolean_in_params_spec.rb
grape-1.5.0 spec/grape/api/defines_boolean_in_params_spec.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/grape-1.4.0/spec/grape/api/defines_boolean_in_params_spec.rb
grape-1.4.0 spec/grape/api/defines_boolean_in_params_spec.rb
grape-1.3.3 spec/grape/api/defines_boolean_in_params_spec.rb
grape-1.3.2 spec/grape/api/defines_boolean_in_params_spec.rb
grape-1.3.1 spec/grape/api/defines_boolean_in_params_spec.rb
grape-1.3.0 spec/grape/api/defines_boolean_in_params_spec.rb