зеркало из
https://github.com/glebtv/telegram-bot.git
synced 2026-09-04 02:05:52 +03:00
Testing: run multiple dispatches on same instance
Этот коммит содержится в:
47
lib/telegram/bot/updates_controller/testing.rb
Обычный файл
47
lib/telegram/bot/updates_controller/testing.rb
Обычный файл
@@ -0,0 +1,47 @@
|
||||
module Telegram
|
||||
module Bot
|
||||
class UpdatesController
|
||||
module Testing
|
||||
IVARS_TO_KEEP = %i(@_session).freeze
|
||||
|
||||
# Perform multiple dispatches on same instance.
|
||||
def dispatch_again(bot = nil, update = nil)
|
||||
recycle!
|
||||
initialize(bot, update)
|
||||
dispatch
|
||||
end
|
||||
|
||||
# Cleans controller between dispatches.
|
||||
# Seems like there is nothing to clean between requests for now:
|
||||
# everything will be rewriten with #initialize.
|
||||
#
|
||||
# With `full` set to `true` it'll clear all cached instance variables.
|
||||
def recycle!(full = false)
|
||||
return unless full
|
||||
(instance_variables - IVARS_TO_KEEP).each do |ivar|
|
||||
remove_instance_variable(ivar)
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
# Stubs session.
|
||||
def session
|
||||
@_session ||= Testing::SessionHash.new
|
||||
end
|
||||
|
||||
class SessionHash < Session::SessionHash
|
||||
def initialize
|
||||
@data = {}
|
||||
@loaded = true
|
||||
@exists = true
|
||||
end
|
||||
|
||||
alias_method :destroy, :clear
|
||||
alias_method :load!, :id
|
||||
alias_method :commit, :id
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Ссылка в новой задаче
Block a user