perf(benchmarks): ability to pass a params list to controller
This commit is contained in:
parent
3b9285a00b
commit
cd100bccdf
1 changed files with 12 additions and 0 deletions
|
@ -78,6 +78,11 @@ namespace :benchmarks do
|
|||
#
|
||||
# Attention : penser à refaire les étapes 1 et 2 sur la seconde branche !
|
||||
#
|
||||
# 5. Pour passer des paramètres d'urls, utiliser la variable d'environnement `PARAMS`
|
||||
# sous forme key=value, séparables par des virgules :
|
||||
#
|
||||
# rake benchmarks:action[Users::CommencerController,commencer,commencer] PARAMS=path=my-demarche,other=value
|
||||
#
|
||||
desc "Benchmark a Rails action"
|
||||
task :action, [:controller, :action1, :action2] => :environment do |_, args|
|
||||
require 'benchmark/ips'
|
||||
|
@ -97,6 +102,13 @@ namespace :benchmarks do
|
|||
controller.request = ActionDispatch::TestRequest.create
|
||||
controller.response = ActionDispatch::TestResponse.new
|
||||
controller.request.env['warden'] = warden
|
||||
|
||||
params = ENV.fetch("PARAMS") { "" }.split(",")
|
||||
params.each do |param|
|
||||
key, value = param.split("=")
|
||||
controller.params[key.strip] = value.strip
|
||||
end
|
||||
|
||||
controller
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue