Skip to content

Commit

Permalink
Change Grape::API's @setup var to an Array (from a Set) (#2529)
Browse files Browse the repository at this point in the history
  • Loading branch information
Haerezis authored Feb 2, 2025
1 parent 2e0d33b commit af1a6a2
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* [#2525](https://github.com/ruby-grape/grape/pull/2525): Require logger before active_support - [@ericproulx](https://github.com/ericproulx).
* [#2524](https://github.com/ruby-grape/grape/pull/2524): Fix validators bad encoding - [@ericproulx](https://github.com/ericproulx).
* [#2530](https://github.com/ruby-grape/grape/pull/2530): Fix endpoint's status when rescue_from without a block - [@ericproulx](https://github.com/ericproulx).
* [#2529](https://github.com/ruby-grape/grape/pull/2529): Fix missing settings on mounted routes (when settings are identical) - [@Haerezis](https://github.com/Haerezis).
* Your contribution here.

### 2.2.0 (2024-09-14)
Expand Down
2 changes: 1 addition & 1 deletion lib/grape/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def inherited(api)
# an instance that will be used to create the set up but will not be mounted
def initial_setup(base_instance_parent)
@instances = []
@setup = Set.new
@setup = []
@base_parent = base_instance_parent
@base_instance = mount_instance
end
Expand Down
60 changes: 60 additions & 0 deletions spec/grape/api_remount_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -505,5 +505,65 @@ def printed_response
end
end
end

context 'with route settings' do
before do
a_remounted_api.desc 'Identical description'
a_remounted_api.route_setting :custom, key: 'value'
a_remounted_api.route_setting :custom_diff, key: 'foo'
a_remounted_api.get '/api1' do
status 200
end

a_remounted_api.desc 'Identical description'
a_remounted_api.route_setting :custom, key: 'value'
a_remounted_api.route_setting :custom_diff, key: 'bar'
a_remounted_api.get '/api2' do
status 200
end
end

it 'has all the settings for both routes' do
expect(a_remounted_api.routes.count).to be(2)
expect(a_remounted_api.routes[0].settings).to include(
{
description: { description: 'Identical description' },
custom: { key: 'value' },
custom_diff: { key: 'foo' }
}
)
expect(a_remounted_api.routes[1].settings).to include(
{
description: { description: 'Identical description' },
custom: { key: 'value' },
custom_diff: { key: 'bar' }
}
)
end

context 'when mounting it' do
before do
root_api.mount a_remounted_api
end

it 'still has all the settings for both routes' do
expect(root_api.routes.count).to be(2)
expect(root_api.routes[0].settings).to include(
{
description: { description: 'Identical description' },
custom: { key: 'value' },
custom_diff: { key: 'foo' }
}
)
expect(root_api.routes[1].settings).to include(
{
description: { description: 'Identical description' },
custom: { key: 'value' },
custom_diff: { key: 'bar' }
}
)
end
end
end
end
end

0 comments on commit af1a6a2

Please sign in to comment.