-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
application_metal_controller_spec.rb
66 lines (51 loc) · 1.69 KB
/
application_metal_controller_spec.rb
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
57
58
59
60
61
62
63
64
65
66
# frozen_string_literal: true
require "spec_helper_integration"
RSpec.describe Doorkeeper::ApplicationMetalController, type: :controller do
render_views
controller(described_class) do
def index
render json: {}, status: 200
end
def create
render json: {}, status: 200
end
end
it "lazy run hooks" do
i = 0
ActiveSupport.on_load(:doorkeeper_metal_controller) { i += 1 }
expect(i).to eq 1
end
describe "enforce_content_type" do
before { allow(Doorkeeper.config).to receive(:enforce_content_type).and_return(flag) }
context "when enabled" do
let(:flag) { true }
it "returns a 200 for the requests without body" do
get :index, params: {}
expect(response).to have_http_status 200
end
it "returns a 200 for the requests with body and correct media type" do
post :create, params: {}, as: :url_encoded_form
expect(response).to have_http_status 200
end
it "returns a 415 for the requests with body and incorrect media type" do
post :create, params: {}, as: :json
expect(response).to have_http_status 415
end
end
context "when disabled" do
let(:flag) { false }
it "returns a 200 for the correct media type" do
get :index, as: :url_encoded_form
expect(response).to have_http_status 200
end
it "returns a 200 for an incorrect media type" do
get :index, as: :json
expect(response).to have_http_status 200
end
it "returns a 200 for the requests with body and incorrect media type" do
post :create, params: {}, as: :json
expect(response).to have_http_status 200
end
end
end
end