Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset endpoint options between calls #918

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/grape/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -324,5 +324,10 @@ def after_validations
def afters
namespace_stackable(:afters) || []
end

def initialize_copy(other)
super
self.options = other.options.deep_dup
end
end
end
13 changes: 13 additions & 0 deletions spec/grape/endpoint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,19 @@ def memoized
expect(last_response.body).to eq('Hello')
end

it 'reset options between calls' do
subject.get('/options') do
if params[:rabl]
env['api.endpoint'].options[:route_options][:rabl] = params[:rabl]
end
end

get '/options?rabl=index'
expect(last_request.env['api.endpoint'].options[:route_options][:rabl]).to eq 'index'
get '/options'
expect(last_request.env['api.endpoint'].options[:route_options][:rabl]).to eq nil
end

describe '.generate_api_method' do
it 'raises NameError if the method name is already in use' do
expect do
Expand Down