Skip to content

Commit

Permalink
Merge 253ffb7 into 1147658
Browse files Browse the repository at this point in the history
  • Loading branch information
myxoh committed Jun 22, 2023
2 parents 1147658 + 253ffb7 commit 41a6c40
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -12,6 +12,7 @@

#### Fixes

* [#2339](https://github.com/ruby-grape/grape/pull/2339): Documentation and specs for remountable configuration in params - [@myxoh](https://github.com/myxoh).
* [#2328](https://github.com/ruby-grape/grape/pull/2328): Don't cache Class.instance_methods - [@byroot](https://github.com/byroot).
* [#2337](https://github.com/ruby-grape/grape/pull/2337): Fix: allow custom validators that do not end with _validator - [@ericproulx](https://github.com/ericproulx).
* Your contribution here.
Expand Down
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -526,15 +526,15 @@ end
```ruby
class BasicAPI < Grape::API
desc 'Statuses index' do
params: mounted { configuration[:entity] || API::Entities::Status }.documentation
params: (configuration[:entity] || API::Entities::Status).documentation
end
params do
requires :all, using: mounted { configuration[:entity] || API::Entities::Status }.documentation
requires :all, using: (configuration[:entity] || API::Entities::Status).documentation
end
get '/statuses' do
statuses = Status.all
type = current_user.admin? ? :full : :default
present statuses, with: mounted { configuration[:entity] || API::Entities::Status }, type: type
present statuses, with: (configuration[:entity] || API::Entities::Status), type: type
end
end

Expand Down
36 changes: 36 additions & 0 deletions spec/grape/api_remount_spec.rb
Expand Up @@ -147,6 +147,42 @@ def app
end
end

context 'when the params are configured via a configuration' do
subject(:a_remounted_api) do
Class.new(described_class) do
params do
requires configuration[:required_attr_name], type: String
end

get(mounted { configuration[:endpoint] }) do
status 200
end
end
end

context 'when the configured param is my_attr' do
it 'requires the configured params' do
root_api.mount a_remounted_api, with: {
required_attr_name: 'my_attr',
endpoint: 'test'
}
get 'test?another_attr=1'
expect(last_response.status).to eq 400
get 'test?my_attr=1'
expect(last_response.status).to eq 200

root_api.mount a_remounted_api, with: {
required_attr_name: 'another_attr',
endpoint: 'test_b'
}
get 'test_b?another_attr=1'
expect(last_response.status).to eq 200
get 'test_b?my_attr=1'
expect(last_response.status).to eq 400
end
end
end

context 'when executing a standard block within a `mounted` block with all dynamic params' do
subject(:a_remounted_api) do
Class.new(described_class) do
Expand Down

0 comments on commit 41a6c40

Please sign in to comment.