Sha256: d7cc63d7122247037332624c380058b4e7da9875cf32cf46fc339a8d6632f070

Contents?: true

Size: 1.33 KB

Versions: 10

Compression:

Stored size: 1.33 KB

Contents

require 'spec_helper'

describe Apipie::Generator::Swagger::PathDecorator do
  let(:decorated_path) { described_class.new(path) }

  describe '#param_names' do
    subject { decorated_path.param_names }

    context 'when path does not contain any params' do
      let(:path) { 'some/path/without_params' }

      it { is_expected.to be_empty }
    end

    context 'when path has a param' do
      let(:path) { '/:resource_id/custom' }

      it { is_expected.to eq([:resource_id]) }
    end
  end

  describe '#param?' do
    subject { decorated_path.param?(param) }

    context 'when path has params' do
      let(:path) { '/:resource_id/custom' }

      context 'when param to check is in the path' do
        let(:param) { :resource_id }

        it { is_expected.to be(true) }
      end

      context 'when param to check is not in the path' do
        let(:param) { :some_param }

        it { is_expected.to be(false) }
      end
    end
  end

  describe '#swagger_path' do
    subject(:swagger_path) { decorated_path.swagger_path }

    let(:path) { '/some/custom/path' }

    it { is_expected.to eq('/some/custom/path') }

    context 'when path does not start with slash' do
      let(:path) { ':resource_id/custom' }

      it 'adds the slash in the beginning' do
        expect(swagger_path).to eq('/{resource_id}/custom')
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
apipie-rails-1.4.2 spec/lib/apipie/generator/swagger/path_decorator_spec.rb
apipie-rails-1.4.1 spec/lib/apipie/generator/swagger/path_decorator_spec.rb
apipie-rails-1.4.0 spec/lib/apipie/generator/swagger/path_decorator_spec.rb
apipie-rails-1.3.0 spec/lib/apipie/generator/swagger/path_decorator_spec.rb
apipie-rails-1.2.3 spec/lib/apipie/generator/swagger/path_decorator_spec.rb
apipie-rails-1.2.2 spec/lib/apipie/generator/swagger/path_decorator_spec.rb
apipie-rails-1.2.1 spec/lib/apipie/generator/swagger/path_decorator_spec.rb
apipie-rails-1.2.0 spec/lib/apipie/generator/swagger/path_decorator_spec.rb
apipie-rails-1.1.0 spec/lib/apipie/generator/swagger/path_decorator_spec.rb
apipie-rails-1.0.0 spec/lib/apipie/generator/swagger/path_decorator_spec.rb