Sha256: f84043f0898ce3e129cec7aaf71286cce7975d3c7b124c1f74dd448079713935

Contents?: true

Size: 1.98 KB

Versions: 5

Compression:

Stored size: 1.98 KB

Contents

require 'spec_helper'

module Grape
  module DSL
    module ValidationsSpec
      class Dummy
        include Grape::DSL::Validations
      end
    end

    describe Validations do
      subject { ValidationsSpec::Dummy }

      describe '.reset_validations!' do
        before do
          subject.namespace_stackable :declared_params, ['dummy']
          subject.namespace_stackable :validations, ['dummy']
          subject.namespace_stackable :params, ['dummy']
          subject.route_setting :description, description: 'lol', params: ['dummy']
          subject.reset_validations!
        end

        after do
          subject.unset_route_setting :description
        end

        it 'resets declared params' do
          expect(subject.namespace_stackable(:declared_params)).to eq []
        end

        it 'resets validations' do
          expect(subject.namespace_stackable(:validations)).to eq []
        end

        it 'resets params' do
          expect(subject.namespace_stackable(:params)).to eq []
        end

        it 'resets documentation params' do
          expect(subject.route_setting(:description)[:params]).to be_nil
        end

        it 'does not reset documentation description' do
          expect(subject.route_setting(:description)[:description]).to eq 'lol'
        end
      end

      describe '.params' do
        it 'returns a ParamsScope' do
          expect(subject.params).to be_a Grape::Validations::ParamsScope
        end

        it 'evaluates block' do
          expect { subject.params { fail 'foo' } }.to raise_error RuntimeError, 'foo'
        end
      end

      describe '.document_attribute' do
        before do
          subject.document_attribute([full_name: 'xxx'], foo: 'bar')
        end

        it 'creates a param documentation' do
          expect(subject.namespace_stackable(:params)).to eq(['xxx' => { foo: 'bar' }])
          expect(subject.route_setting(:description)).to eq(params: { 'xxx' => { foo: 'bar' } })
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
grape-0.16.2 spec/grape/dsl/validations_spec.rb
grape-0.16.1 spec/grape/dsl/validations_spec.rb
grape-0.15.0 spec/grape/dsl/validations_spec.rb
grape-0.14.0 spec/grape/dsl/validations_spec.rb
grape-0.13.0 spec/grape/dsl/validations_spec.rb