@@ -1023,7 +1023,7 @@ def validate_param!(attr_name, params)
10231023 end
10241024
10251025 it "with valid data" do
1026- data_without_errors = {
1026+ data = {
10271027 top : [
10281028 { top_id : 1 , middle_1 : [
10291029 { middle_1_id : 11 } , { middle_1_id : 12 , middle_2 : [
@@ -1037,7 +1037,7 @@ def validate_param!(attr_name, params)
10371037 ]
10381038 }
10391039
1040- get '/multi_level' , data_without_errors
1040+ get '/multi_level' , data
10411041 expect ( last_response . body ) . to eq ( "multi_level works!" )
10421042 expect ( last_response . status ) . to eq ( 200 )
10431043 end
@@ -1067,6 +1067,90 @@ def validate_param!(attr_name, params)
10671067 end
10681068 end
10691069 end
1070+
1071+ it "exactly_one_of" do
1072+ subject . params do
1073+ requires :orders , type : Array do
1074+ requires :id , type : Integer
1075+ optional :drugs , type : Hash do
1076+ optional :batch_no , type : String
1077+ optional :batch_id , type : String
1078+ exactly_one_of :batch_no , :batch_id
1079+ end
1080+ end
1081+ end
1082+
1083+ subject . get '/exactly_one_of' do
1084+ 'exactly_one_of works!'
1085+ end
1086+
1087+ data = {
1088+ orders : [
1089+ { id : 77 , drugs : { batch_no : "A1234567" } } ,
1090+ { id : 70 }
1091+ ]
1092+ }
1093+
1094+ get '/exactly_one_of' , data
1095+ expect ( last_response . body ) . to eq ( "exactly_one_of works!" )
1096+ expect ( last_response . status ) . to eq ( 200 )
1097+ end
1098+
1099+ it "at_least_one_of" do
1100+ subject . params do
1101+ requires :orders , type : Array do
1102+ requires :id , type : Integer
1103+ optional :drugs , type : Hash do
1104+ optional :batch_no , type : String
1105+ optional :batch_id , type : String
1106+ at_least_one_of :batch_no , :batch_id
1107+ end
1108+ end
1109+ end
1110+
1111+ subject . get '/at_least_one_of' do
1112+ 'at_least_one_of works!'
1113+ end
1114+
1115+ data = {
1116+ orders : [
1117+ { id : 77 , drugs : { batch_no : "A1234567" } } ,
1118+ { id : 70 }
1119+ ]
1120+ }
1121+
1122+ get '/at_least_one_of' , data
1123+ expect ( last_response . body ) . to eq ( "at_least_one_of works!" )
1124+ expect ( last_response . status ) . to eq ( 200 )
1125+ end
1126+
1127+ it "all_or_none_of" do
1128+ subject . params do
1129+ requires :orders , type : Array do
1130+ requires :id , type : Integer
1131+ optional :drugs , type : Hash do
1132+ optional :batch_no , type : String
1133+ optional :batch_id , type : String
1134+ all_or_none_of :batch_no , :batch_id
1135+ end
1136+ end
1137+ end
1138+
1139+ subject . get '/all_or_none_of' do
1140+ 'all_or_none_of works!'
1141+ end
1142+
1143+ data = {
1144+ orders : [
1145+ { id : 77 , drugs : { batch_no : "A1234567" , batch_id : "12" } } ,
1146+ { id : 70 }
1147+ ]
1148+ }
1149+
1150+ get '/all_or_none_of' , data
1151+ expect ( last_response . body ) . to eq ( "all_or_none_of works!" )
1152+ expect ( last_response . status ) . to eq ( 200 )
1153+ end
10701154 end
10711155
10721156 context 'multiple validation errors' do
0 commit comments