Sha256: 1cc47defc1fd753ac64666f4a5836631ff23fe9d33abab1480012d8a1bf69c84

Contents?: true

Size: 1.98 KB

Versions: 23

Compression:

Stored size: 1.98 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe Praxis::ApiGeneralInfo do
  subject(:info) { Praxis::ApiGeneralInfo.new }

  before do
    allow(Praxis::Application.instance).to receive(:versioning_scheme=).with(%i[header params])
  end

  let(:info_block) do
    proc do
      name 'Name'
      title 'Title'
      description 'Description'
      endpoint 'api.example.com'
      base_path '/base'

      consumes 'json'
      produces 'json'

      base_params do
        attribute :name, String
      end
    end
  end

  context 'setting' do
    it 'accepts the appropriate DSLs' do
      expect do
        info.instance_exec(&info_block)
      end.to_not raise_error
    end
  end

  context 'getting values' do
    before do
      info.instance_exec(&info_block)
    end

    its(:name) { should eq 'Name' }
    its(:consumes) { should eq ['json'] }
    its(:produces) { should eq ['json'] }
  end

  context '.describe' do
    before do
      info.instance_exec(&info_block)
    end

    subject(:output) { info.describe }
    its([:schema_version]) { should eq '1.0' }
    its([:name]) { should eq 'Name' }
    its([:title]) { should eq 'Title' }
    its([:description]) { should eq 'Description' }
    its([:base_path]) { should eq '/base' }
    its([:base_params]) { should have_key :name }
    its(%i[base_params name type name]) { should eq 'String' }
    its([:version_with]) { should eq(%i[header params]) }
    its([:endpoint]) { should eq 'api.example.com' }
    its([:consumes]) { should eq ['json'] }
    its([:produces]) { should eq ['json'] }
  end

  context 'base_path with versioning' do
    let(:global_info) { Praxis::ApiGeneralInfo.new }
    subject(:info) { Praxis::ApiGeneralInfo.new(global_info, version: '1.0') }

    before do
      global_info

      expect(Praxis::Application.instance).to receive(:versioning_scheme=).with(:path)

      global_info.version_with :path
      global_info.base_path '/api/v:api_version'
    end

    its(:base_path) { should eq '/api/v1.0' }
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
praxis-2.0.0 spec/praxis/api_general_info_spec.rb
praxis-2.0.pre.40 spec/praxis/api_general_info_spec.rb
praxis-2.0.pre.39 spec/praxis/api_general_info_spec.rb
praxis-2.0.pre.38 spec/praxis/api_general_info_spec.rb
praxis-2.0.pre.37 spec/praxis/api_general_info_spec.rb
praxis-2.0.pre.36 spec/praxis/api_general_info_spec.rb
praxis-2.0.pre.35 spec/praxis/api_general_info_spec.rb
praxis-2.0.pre.34 spec/praxis/api_general_info_spec.rb
praxis-2.0.pre.33 spec/praxis/api_general_info_spec.rb
praxis-2.0.pre.32 spec/praxis/api_general_info_spec.rb
praxis-2.0.pre.31 spec/praxis/api_general_info_spec.rb
praxis-2.0.pre.30 spec/praxis/api_general_info_spec.rb
praxis-2.0.pre.29 spec/praxis/api_general_info_spec.rb
praxis-2.0.pre.28 spec/praxis/api_general_info_spec.rb
praxis-2.0.pre.27 spec/praxis/api_general_info_spec.rb
praxis-2.0.pre.26 spec/praxis/api_general_info_spec.rb
praxis-2.0.pre.25 spec/praxis/api_general_info_spec.rb
praxis-2.0.pre.24 spec/praxis/api_general_info_spec.rb
praxis-2.0.pre.23 spec/praxis/api_general_info_spec.rb
praxis-2.0.pre.22 spec/praxis/api_general_info_spec.rb