File: deeply_included_options_spec.rb

package info (click to toggle)
ruby-grape 1.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,488 kB
  • sloc: ruby: 21,014; makefile: 6
file content (56 lines) | stat: -rw-r--r-- 1,140 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require 'spec_helper'

module DeeplyIncludedOptionsSpec
  module Defaults
    extend ActiveSupport::Concern
    included do
      format :json
    end
  end

  module Admin
    module Defaults
      extend ActiveSupport::Concern
      include DeeplyIncludedOptionsSpec::Defaults
    end

    class Users < Grape::API
      include DeeplyIncludedOptionsSpec::Admin::Defaults

      resource :users do
        get do
          status 200
        end
      end
    end
  end

  class Main < Grape::API
    mount DeeplyIncludedOptionsSpec::Admin::Users
  end
end

describe Grape::API do
  subject { DeeplyIncludedOptionsSpec::Main }

  def app
    subject
  end

  it 'works for unspecified format' do
    get '/users'
    expect(last_response.status).to eql 200
    expect(last_response.content_type).to eql 'application/json'
  end

  it 'works for specified format' do
    get '/users.json'
    expect(last_response.status).to eql 200
    expect(last_response.content_type).to eql 'application/json'
  end

  it "doesn't work for format different than specified" do
    get '/users.txt'
    expect(last_response.status).to eql 404
  end
end