Sha256: 947b741911ee38fb0e86154c4fec5a17502d4574ba3f74b89443c119fdeb1bc3

Contents?: true

Size: 988 Bytes

Versions: 3

Compression:

Stored size: 988 Bytes

Contents

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 Virtus::Attribute::Boolean' 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 Virtus::Attribute::Boolean' do
        is_expected.to eq 'Virtus::Attribute::Boolean'
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/grape-1.2.5/spec/grape/api/defines_boolean_in_params_spec.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/grape-1.2.5/spec/grape/api/defines_boolean_in_params_spec.rb
grape-1.2.5 spec/grape/api/defines_boolean_in_params_spec.rb