@@ -582,6 +582,79 @@ def app
582
582
end
583
583
end
584
584
585
+ describe '#declared; with multiple route_param' do
586
+ before do
587
+ mounted = Class . new ( Grape ::API )
588
+ mounted . namespace :albums do
589
+ get do
590
+ declared ( params )
591
+ end
592
+ end
593
+
594
+ subject . format :json
595
+ subject . namespace :artists do
596
+ route_param :id , type : Integer do
597
+ get do
598
+ declared ( params )
599
+ end
600
+
601
+ params do
602
+ requires :filter , type : String
603
+ end
604
+ get :some_route do
605
+ declared ( params )
606
+ end
607
+ end
608
+
609
+ route_param :artist_id , type : Integer do
610
+ namespace :compositions do
611
+ get do
612
+ declared ( params )
613
+ end
614
+ end
615
+ end
616
+
617
+ route_param :compositor_id , type : Integer do
618
+ mount mounted
619
+ end
620
+ end
621
+ end
622
+
623
+ it 'return only :id without :artist_id' do
624
+ get '/artists/1'
625
+ json = JSON . parse ( last_response . body , symbolize_names : true )
626
+
627
+ expect ( json . key? ( :id ) ) . to be_truthy
628
+ expect ( json . key? ( :artist_id ) ) . not_to be_truthy
629
+ end
630
+
631
+ it 'return only :artist_id without :id' do
632
+ get '/artists/1/compositions'
633
+ json = JSON . parse ( last_response . body , symbolize_names : true )
634
+
635
+ expect ( json . key? ( :artist_id ) ) . to be_truthy
636
+ expect ( json . key? ( :id ) ) . not_to be_truthy
637
+ end
638
+
639
+ it 'return :filter and :id parameters in declared for second enpoint inside route_param' do
640
+ get '/artists/1/some_route' , filter : 'some_filter'
641
+ json = JSON . parse ( last_response . body , symbolize_names : true )
642
+
643
+ expect ( json . key? ( :filter ) ) . to be_truthy
644
+ expect ( json . key? ( :id ) ) . to be_truthy
645
+ expect ( json . key? ( :artist_id ) ) . not_to be_truthy
646
+ end
647
+
648
+ it 'return :compositor_id for mounter in route_param' do
649
+ get '/artists/1/albums'
650
+ json = JSON . parse ( last_response . body , symbolize_names : true )
651
+
652
+ expect ( json . key? ( :compositor_id ) ) . to be_truthy
653
+ expect ( json . key? ( :id ) ) . not_to be_truthy
654
+ expect ( json . key? ( :artist_id ) ) . not_to be_truthy
655
+ end
656
+ end
657
+
585
658
describe '#params' do
586
659
it 'is available to the caller' do
587
660
subject . get ( '/hey' ) do
0 commit comments