Sha256: b34a97a6489d83e86e4b224dcfecd1c2fecd721e5bef7e900d74bd32a68a56b7

Contents?: true

Size: 1.69 KB

Versions: 16

Compression:

Stored size: 1.69 KB

Contents

require 'spec_helper'

describe Grape::API::Helpers do
  module PatchHelpersSpec
    class PatchPublic < Grape::API
      format :json
      version 'public-v1', using: :header, vendor: 'grape'

      get do
        { ok: 'public' }
      end
    end

    module AuthMethods
      def authenticate!; end
    end

    class PatchPrivate < Grape::API
      format :json
      version 'private-v1', using: :header, vendor: 'grape'

      helpers AuthMethods

      before do
        authenticate!
      end

      get do
        { ok: 'private' }
      end
    end

    class Main < Grape::API
      mount PatchPublic
      mount PatchPrivate
    end
  end

  def app
    PatchHelpersSpec::Main
  end

  context 'patch' do
    it 'public' do
      patch '/', {}, 'HTTP_ACCEPT' => 'application/vnd.grape-public-v1+json'
      expect(last_response.status).to eq 405
    end

    it 'private' do
      patch '/', {}, 'HTTP_ACCEPT' => 'application/vnd.grape-private-v1+json'
      expect(last_response.status).to eq 405
    end

    it 'default' do
      patch '/'
      expect(last_response.status).to eq 405
    end
  end

  context 'default' do
    it 'public' do
      get '/', {}, 'HTTP_ACCEPT' => 'application/vnd.grape-public-v1+json'
      expect(last_response.status).to eq 200
      expect(last_response.body).to eq({ ok: 'public' }.to_json)
    end

    it 'private' do
      get '/', {}, 'HTTP_ACCEPT' => 'application/vnd.grape-private-v1+json'
      expect(last_response.status).to eq 200
      expect(last_response.body).to eq({ ok: 'private' }.to_json)
    end

    it 'default' do
      get '/'
      expect(last_response.status).to eq 200
      expect(last_response.body).to eq({ ok: 'public' }.to_json)
    end
  end
end

Version data entries

16 entries across 16 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/patch_method_helpers_spec.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/grape-1.2.5/spec/grape/api/patch_method_helpers_spec.rb
grape-1.2.5 spec/grape/api/patch_method_helpers_spec.rb
grape-1.2.4 spec/grape/api/patch_method_helpers_spec.rb
grape-1.2.3 spec/grape/api/patch_method_helpers_spec.rb
grape-1.2.2 spec/grape/api/patch_method_helpers_spec.rb
grape-1.2.1 spec/grape/api/patch_method_helpers_spec.rb
grape-1.2.0 spec/grape/api/patch_method_helpers_spec.rb
grape-1.1.0 spec/grape/api/patch_method_helpers_spec.rb
grape-1.0.3 spec/grape/api/patch_method_helpers_spec.rb
grape-1.0.2 spec/grape/api/patch_method_helpers_spec.rb
grape-1.0.1 spec/grape/api/patch_method_helpers_spec.rb
grape-1.0.0 spec/grape/api/patch_method_helpers_spec.rb
grape-0.19.2 spec/grape/api/patch_method_helpers_spec.rb
grape-0.19.1 spec/grape/api/patch_method_helpers_spec.rb
grape-0.19.0 spec/grape/api/patch_method_helpers_spec.rb