Sha256: 9344024ce147a3fce46a00a624cb5a8d0cd223228b748c6e0f630e52a778095b

Contents?: true

Size: 1.67 KB

Versions: 15

Compression:

Stored size: 1.67 KB

Contents

# frozen_string_literal: true

require "spec_helper_integration"

describe Doorkeeper::ApplicationMetalController do
  controller(Doorkeeper::ApplicationMetalController) 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.configuration).to receive(:enforce_content_type).and_return(flag) }

    context "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 "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

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
doorkeeper-5.1.2 spec/controllers/application_metal_controller_spec.rb
doorkeeper-5.2.6 spec/controllers/application_metal_controller_spec.rb
doorkeeper-5.1.1 spec/controllers/application_metal_controller_spec.rb
doorkeeper-5.2.5 spec/controllers/application_metal_controller_spec.rb
doorkeeper-sequel-2.2.0 spec/controllers/application_metal_controller_spec.rb
doorkeeper-5.2.4 spec/controllers/application_metal_controller_spec.rb
doorkeeper-5.2.3 spec/controllers/application_metal_controller_spec.rb
doorkeeper-5.2.2 spec/controllers/application_metal_controller_spec.rb
doorkeeper-sequel-2.1.0 spec/controllers/application_metal_controller_spec.rb
doorkeeper-5.2.1 spec/controllers/application_metal_controller_spec.rb
doorkeeper-5.2.0 spec/controllers/application_metal_controller_spec.rb
doorkeeper-5.2.0.rc3 spec/controllers/application_metal_controller_spec.rb
doorkeeper-5.2.0.rc2 spec/controllers/application_metal_controller_spec.rb
doorkeeper-5.2.0.rc1 spec/controllers/application_metal_controller_spec.rb
doorkeeper-5.1.0 spec/controllers/application_metal_controller_spec.rb