1
0
зеркало из https://github.com/glebtv/telegram-bot.git synced 2026-08-28 15:26:18 +03:00
Этот коммит содержится в:
Max Melentiev
2018-01-05 14:04:20 +03:00
родитель 45e8a7283f
Коммит 707e532963
3 изменённых файлов: 94 добавлений и 6 удалений

Просмотреть файл

@@ -81,7 +81,8 @@ module Telegram
include AbstractController::Translation
include Rescue
include ReplyHelpers
prepend Instrumentation
include Instrumentation
extend Session::ConfigMethods
PAYLOAD_TYPES = %w[

Просмотреть файл

@@ -4,12 +4,13 @@ module Telegram
# Most methods are taken from ActionController::Instrumentation,
# some are slightly modified.
module Instrumentation
class << self
def prepended(base)
base.send :config_accessor, :logger
base.extend ClassMethods
end
extend ActiveSupport::Concern
included do
config_accessor :logger
end
class << self
def instrument(action, *args, &block)
ActiveSupport::Notifications.instrument(
"#{action}.updates_controller.bot.telegram",

Просмотреть файл

@@ -0,0 +1,86 @@
RSpec.describe Telegram::Bot::UpdatesController::Instrumentation do
include_context 'telegram/bot/updates_controller'
subject { -> { dispatch } }
let(:update) do
build_update :message, default_message_options.merge(text: '/start')
end
let(:controller_class) do
Class.new(Telegram::Bot::UpdatesController) do
def start(*)
end
end
end
let(:action_scope) { 'updates_controller.bot.telegram' }
let(:events) { Hash.new { |h, k| h[k] = [] } }
let!(:subscriber) do
ActiveSupport::Notifications.subscribe(/#{action_scope}/) do |action, *args|
events[action] << args
end
end
after { ActiveSupport::Notifications.unsubscribe(subscriber) }
def actions_list(*prefixes)
prefixes.map { |x| action_name(x) }
end
def action_name(prefix)
"#{prefix}.#{action_scope}"
end
describe '#process_action' do
it 'fires start_processing and process_action events' do
should change(events, :keys).by(actions_list(:start_processing, :process_action))
action = action_name(:start_processing)
expect(events[action].size).to eq(1)
expect(events[action][0].last).to include(update: update)
action = action_name(:process_action)
expect(events[action].size).to eq(1)
expect(events[action][0].last).to include(update: update)
end
end
describe '#halted_callback_hook' do
let(:controller_class) do
super().try(:class_eval) do |x|
x.before_action :halter_method
def halter_method
throw :abort
end
self
end
end
it 'fires halted_callback event' do
should change(events, :keys).
by(actions_list(:start_processing, :halted_callback, :process_action))
action = action_name(:halted_callback)
expect(events[action].size).to eq(1)
expect(events[action][0].last).to include(filter: :halter_method)
end
end
describe '#respond_with' do
before do
def controller.start(*)
respond_with :message, text: 'sample response'
end
end
it 'fires respond_with event' do
should change(events, :keys).
by(actions_list(:start_processing, :respond_with, :process_action))
action = action_name(:respond_with)
expect(events[action].size).to eq(1)
expect(events[action][0].last).to include(type: :message)
end
end
end