Sha256: 20b595027620df5fbfa14c65ea8c38be02c00995486724face3dc791137d78b3

Contents?: true

Size: 1.1 KB

Versions: 9

Compression:

Stored size: 1.1 KB

Contents

require 'spec_helper'

describe GrapePathHelpers::AllRoutes do
  Grape::API.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.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.all_routes
        expect(all_routes.map(&:path)).to include(*expected_routes)
      end
    end
    # rubocop:enable Metrics/LineLength
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
grape-path-helpers-1.2.0 spec/grape_path_helpers/all_routes_spec.rb
grape-path-helpers-1.1.0 spec/grape_path_helpers/all_routes_spec.rb
grape-path-helpers-1.0.6 spec/grape_path_helpers/all_routes_spec.rb
grape-path-helpers-1.0.5 spec/grape_path_helpers/all_routes_spec.rb
grape-path-helpers-1.0.4 spec/grape_path_helpers/all_routes_spec.rb
grape-path-helpers-1.0.3 spec/grape_path_helpers/all_routes_spec.rb
grape-path-helpers-1.0.2 spec/grape_path_helpers/all_routes_spec.rb
grape-path-helpers-1.0.1 spec/grape_path_helpers/all_routes_spec.rb
grape-path-helpers-1.0.0 spec/grape_path_helpers/all_routes_spec.rb