Sha256: 050b98edf7f51f28e7bb6a9079262d56809a04e318ea6121374734ab915173b1

Contents?: true

Size: 1.54 KB

Versions: 10

Compression:

Stored size: 1.54 KB

Contents

require 'spec_helper'

# rubocop:disable Metrics/BlockLength
describe GrapePathHelpers::AllRoutes do
  Grape::API::Instance.extend described_class

  describe '#all_routes' do
    context 'when API is mounted within another API' do
      let(:mounting_api) { Spec::Support::MountedAPI }

      it 'does not include the same route twice' do
        mounting_api

        # A route is unique if no other route shares the same set of options
        all_route_options = Grape::API::Instance.all_routes.map do |r|
          r.instance_variable_get(:@options).merge(path: r.path)
        end

        duplicates = all_route_options.select do |o|
          all_route_options.count(o) > 1
        end

        expect(duplicates).to be_empty
      end
    end

    # rubocop:disable Metrics/LineLength
    context 'when there are multiple POST routes with the same namespace in the same API' do
      it 'returns all POST routes' do
        expected_routes = Spec::Support::MultiplePostsAPI.routes.map(&:path)

        all_routes = Grape::API::Instance.all_routes
        expect(all_routes.map(&:path)).to include(*expected_routes)
      end
    end

    context 'when an API is created via an intermediate class' do
      it 'includes those routes on both Grape::API::Instance and the base class' do
        expect(Spec::Support::BaseAPI.all_routes.map(&:origin)).to include('/derived_ping')
        expect(Grape::API::Instance.all_routes.map(&:origin)).to include('/derived_ping')
      end
    end
    # rubocop:enable Metrics/LineLength
  end
end
# rubocop:enable Metrics/BlockLength

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
grape-path-helpers-2.0.1 spec/grape_path_helpers/all_routes_spec.rb
grape-path-helpers-2.0.0 spec/grape_path_helpers/all_routes_spec.rb
grape-path-helpers-1.7.1 spec/grape_path_helpers/all_routes_spec.rb
grape-path-helpers-1.7.0 spec/grape_path_helpers/all_routes_spec.rb
grape-path-helpers-1.6.3 spec/grape_path_helpers/all_routes_spec.rb
grape-path-helpers-1.6.2 spec/grape_path_helpers/all_routes_spec.rb
grape-path-helpers-1.6.1 spec/grape_path_helpers/all_routes_spec.rb
grape-path-helpers-1.6.0 spec/grape_path_helpers/all_routes_spec.rb
grape-path-helpers-1.5.0 spec/grape_path_helpers/all_routes_spec.rb
grape-path-helpers-1.4.0 spec/grape_path_helpers/all_routes_spec.rb