spec/grape/validations_spec.rb in grape-1.3.0 vs spec/grape/validations_spec.rb in grape-1.3.1

- old
+ new

@@ -9,36 +9,32 @@ subject end describe 'params' do context 'optional' do - it 'validates when params is present' do + before do subject.params do optional :a_number, regexp: /^[0-9]+$/ + optional :attachment, type: File end subject.get '/optional' do 'optional works!' end + end + it 'validates when params is present' do get '/optional', a_number: 'string' expect(last_response.status).to eq(400) expect(last_response.body).to eq('a_number is invalid') get '/optional', a_number: 45 expect(last_response.status).to eq(200) expect(last_response.body).to eq('optional works!') end it "doesn't validate when param not present" do - subject.params do - optional :a_number, regexp: /^[0-9]+$/ - end - subject.get '/optional' do - 'optional works!' - end - - get '/optional' + get '/optional', a_number: nil, attachment: nil expect(last_response.status).to eq(200) expect(last_response.body).to eq('optional works!') end it 'adds to declared parameters' do @@ -1420,11 +1416,11 @@ end it 'errors when two or more are present' do get '/custom_message/exactly_one_of', beer: 'string', wine: 'anotherstring' expect(last_response.status).to eq(400) - expect(last_response.body).to eq 'beer, wine, juice are missing, exactly one parameter is required' + expect(last_response.body).to eq 'beer, wine are missing, exactly one parameter is required' end end it 'errors when none are present' do get '/exactly_one_of' @@ -1439,11 +1435,11 @@ end it 'errors when two or more are present' do get '/exactly_one_of', beer: 'string', wine: 'anotherstring' expect(last_response.status).to eq(400) - expect(last_response.body).to eq 'beer, wine, juice are missing, exactly one parameter must be provided' + expect(last_response.body).to eq 'beer, wine are mutually exclusive' end end context 'nested params' do before :each do @@ -1479,10 +1475,10 @@ end it 'errors when two or more are present' do get '/exactly_one_of_nested', nested: { beer_nested: 'string' }, nested2: [{ beer_nested2: 'string', wine_nested2: 'anotherstring' }] expect(last_response.status).to eq(400) - expect(last_response.body).to eq 'nested2[0][beer_nested2], nested2[0][wine_nested2], nested2[0][juice_nested2] are missing, exactly one parameter must be provided' + expect(last_response.body).to eq 'nested2[0][beer_nested2], nested2[0][wine_nested2] are mutually exclusive' end end end context 'at least one of' do