Skip to content

Commit

Permalink
Merge 1a84571 into 1147658
Browse files Browse the repository at this point in the history
  • Loading branch information
myxoh committed Jun 20, 2023
2 parents 1147658 + 1a84571 commit a8e8e3f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 a8e8e3f

Please sign in to comment.