spec/grape/validations_spec.rb in grape-1.3.3 vs spec/grape/validations_spec.rb in grape-1.4.0
- old
+ new
@@ -7,10 +7,14 @@
def app
subject
end
+ def declared_params
+ subject.namespace_stackable(:declared_params).flatten
+ end
+
describe 'params' do
context 'optional' do
before do
subject.params do
optional :a_number, regexp: /^[0-9]+$/
@@ -39,11 +43,11 @@
it 'adds to declared parameters' do
subject.params do
optional :some_param
end
- expect(subject.route_setting(:declared_params)).to eq([:some_param])
+ expect(declared_params).to eq([:some_param])
end
end
context 'optional using Grape::Entity documentation' do
def define_optional_using
@@ -59,11 +63,11 @@
end
end
it 'adds entity documentation to declared params' do
define_optional_using
- expect(subject.route_setting(:declared_params)).to eq(%i[field_a field_b])
+ expect(declared_params).to eq(%i[field_a field_b])
end
it 'works when field_a and field_b are not present' do
get '/optional'
expect(last_response.status).to eq(200)
@@ -106,11 +110,11 @@
it 'adds to declared parameters' do
subject.params do
requires :some_param
end
- expect(subject.route_setting(:declared_params)).to eq([:some_param])
+ expect(declared_params).to eq([:some_param])
end
it 'works when required field is present but nil' do
put '/required', { key: nil }.to_json, 'CONTENT_TYPE' => 'application/json'
expect(last_response.status).to eq(200)
@@ -191,11 +195,11 @@
end
end
it 'adds entity documentation to declared params' do
define_requires_all
- expect(subject.route_setting(:declared_params)).to eq(%i[required_field optional_field])
+ expect(declared_params).to eq(%i[required_field optional_field])
end
it 'errors when required_field is not present' do
get '/required'
expect(last_response.status).to eq(400)
@@ -226,11 +230,11 @@
end
end
it 'adds entity documentation to declared params' do
define_requires_none
- expect(subject.route_setting(:declared_params)).to eq(%i[required_field optional_field])
+ expect(declared_params).to eq(%i[required_field optional_field])
end
it 'errors when required_field is not present' do
get '/required'
expect(last_response.status).to eq(400)
@@ -256,11 +260,11 @@
end
end
it 'adds only the entity documentation to declared params, nothing more' do
define_requires_all
- expect(subject.route_setting(:declared_params)).to eq(%i[required_field optional_field])
+ expect(declared_params).to eq(%i[required_field optional_field])
end
end
context 'requires :none' do
def define_requires_none
@@ -322,11 +326,11 @@
subject.params do
requires :items, type: Array do
requires :key
end
end
- expect(subject.route_setting(:declared_params)).to eq([items: [:key]])
+ expect(declared_params).to eq([items: [:key]])
end
end
# Ensure there is no leakage between declared Array types and
# subsequent Hash types
@@ -394,11 +398,11 @@
subject.params do
requires :items, type: Array do
requires :key
end
end
- expect(subject.route_setting(:declared_params)).to eq([items: [:key]])
+ expect(declared_params).to eq([items: [:key]])
end
end
context 'hash with a required param with validation' do
before do
@@ -457,11 +461,11 @@
subject.params do
group :items, type: Array do
requires :key
end
end
- expect(subject.route_setting(:declared_params)).to eq([items: [:key]])
+ expect(declared_params).to eq([items: [:key]])
end
end
context 'group params with nested params which has a type' do
let(:invalid_items) { { items: '' } }
@@ -811,11 +815,11 @@
subject.params do
optional :items, type: Array do
requires :key
end
end
- expect(subject.route_setting(:declared_params)).to eq([items: [:key]])
+ expect(declared_params).to eq([items: [:key]])
end
end
context 'nested optional Array blocks' do
before do
@@ -875,11 +879,11 @@
requires :key
optional(:optional_subitems, type: Array) { requires :value }
requires(:required_subitems, type: Array) { requires :value }
end
end
- expect(subject.route_setting(:declared_params)).to eq([items: [:key, { optional_subitems: [:value] }, { required_subitems: [:value] }]])
+ expect(declared_params).to eq([items: [:key, { optional_subitems: [:value] }, { required_subitems: [:value] }]])
end
end
context 'multiple validation errors' do
before do
@@ -1120,17 +1124,17 @@
it 'by #use' do
subject.params do
use :pagination
end
- expect(subject.route_setting(:declared_params)).to eq %i[page per_page]
+ expect(declared_params).to eq %i[page per_page]
end
it 'by #use with multiple params' do
subject.params do
use :pagination, :period
end
- expect(subject.route_setting(:declared_params)).to eq %i[page per_page start_date end_date]
+ expect(declared_params).to eq %i[page per_page start_date end_date]
end
end
context 'with block' do
before do