Skip to content

Commit af1a6a2

Browse files
authored
Change Grape::API's @setup var to an Array (from a Set) (#2529)
1 parent 2e0d33b commit af1a6a2

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
* [#2525](https://github.com/ruby-grape/grape/pull/2525): Require logger before active_support - [@ericproulx](https://github.com/ericproulx).
2424
* [#2524](https://github.com/ruby-grape/grape/pull/2524): Fix validators bad encoding - [@ericproulx](https://github.com/ericproulx).
2525
* [#2530](https://github.com/ruby-grape/grape/pull/2530): Fix endpoint's status when rescue_from without a block - [@ericproulx](https://github.com/ericproulx).
26+
* [#2529](https://github.com/ruby-grape/grape/pull/2529): Fix missing settings on mounted routes (when settings are identical) - [@Haerezis](https://github.com/Haerezis).
2627
* Your contribution here.
2728

2829
### 2.2.0 (2024-09-14)

lib/grape/api.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def inherited(api)
4040
# an instance that will be used to create the set up but will not be mounted
4141
def initial_setup(base_instance_parent)
4242
@instances = []
43-
@setup = Set.new
43+
@setup = []
4444
@base_parent = base_instance_parent
4545
@base_instance = mount_instance
4646
end

spec/grape/api_remount_spec.rb

+60
Original file line numberDiff line numberDiff line change
@@ -505,5 +505,65 @@ def printed_response
505505
end
506506
end
507507
end
508+
509+
context 'with route settings' do
510+
before do
511+
a_remounted_api.desc 'Identical description'
512+
a_remounted_api.route_setting :custom, key: 'value'
513+
a_remounted_api.route_setting :custom_diff, key: 'foo'
514+
a_remounted_api.get '/api1' do
515+
status 200
516+
end
517+
518+
a_remounted_api.desc 'Identical description'
519+
a_remounted_api.route_setting :custom, key: 'value'
520+
a_remounted_api.route_setting :custom_diff, key: 'bar'
521+
a_remounted_api.get '/api2' do
522+
status 200
523+
end
524+
end
525+
526+
it 'has all the settings for both routes' do
527+
expect(a_remounted_api.routes.count).to be(2)
528+
expect(a_remounted_api.routes[0].settings).to include(
529+
{
530+
description: { description: 'Identical description' },
531+
custom: { key: 'value' },
532+
custom_diff: { key: 'foo' }
533+
}
534+
)
535+
expect(a_remounted_api.routes[1].settings).to include(
536+
{
537+
description: { description: 'Identical description' },
538+
custom: { key: 'value' },
539+
custom_diff: { key: 'bar' }
540+
}
541+
)
542+
end
543+
544+
context 'when mounting it' do
545+
before do
546+
root_api.mount a_remounted_api
547+
end
548+
549+
it 'still has all the settings for both routes' do
550+
expect(root_api.routes.count).to be(2)
551+
expect(root_api.routes[0].settings).to include(
552+
{
553+
description: { description: 'Identical description' },
554+
custom: { key: 'value' },
555+
custom_diff: { key: 'foo' }
556+
}
557+
)
558+
expect(root_api.routes[1].settings).to include(
559+
{
560+
description: { description: 'Identical description' },
561+
custom: { key: 'value' },
562+
custom_diff: { key: 'bar' }
563+
}
564+
)
565+
end
566+
end
567+
end
508568
end
509569
end

0 commit comments

Comments
 (0)