File: shared_helpers_spec.rb

package info (click to toggle)
ruby-grape 1.6.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,156 kB
  • sloc: ruby: 25,265; makefile: 7
file content (38 lines) | stat: -rw-r--r-- 697 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# frozen_string_literal: true

require 'spec_helper'

describe Grape::API::Helpers do
  subject do
    shared_params = Module.new do
      extend Grape::API::Helpers

      params :pagination do
        optional :page, type: Integer
        optional :size, type: Integer
      end
    end

    Class.new(Grape::API) do
      helpers shared_params
      format :json

      params do
        use :pagination
      end
      get do
        declared(params, include_missing: true)
      end
    end
  end

  def app
    subject
  end

  it 'defines parameters' do
    get '/'
    expect(last_response.status).to eq 200
    expect(last_response.body).to eq({ page: nil, size: nil }.to_json)
  end
end