Sha256: 32897568d352b6f2b55615fba4a6d9c29797da1067c87e5da25ab82ba317471e

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

require 'spec_helper'

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
    # rubocop:enable Metrics/LineLength
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
grape-path-helpers-1.3.0 spec/grape_path_helpers/all_routes_spec.rb