зеркало из
https://github.com/glebtv/telegram-bot.git
synced 2026-09-07 19:35:52 +03:00
Fixed MessageContext for messages without text
Этот коммит содержится в:
@@ -24,7 +24,7 @@ module Telegram
|
|||||||
#
|
#
|
||||||
# # To run other action with all the callbacks:
|
# # To run other action with all the callbacks:
|
||||||
# context_handler :rename do |message|
|
# context_handler :rename do |message|
|
||||||
# process(:rename, *m['text'].split)
|
# process(:rename, *m['text'].try!(:split)) # Message can be without text
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# # Or just
|
# # Or just
|
||||||
@@ -32,7 +32,7 @@ module Telegram
|
|||||||
# context_handler :rename # to call :rename
|
# context_handler :rename # to call :rename
|
||||||
#
|
#
|
||||||
# # For messages without context use this instead of `message` method:
|
# # For messages without context use this instead of `message` method:
|
||||||
# context_handle do |message|
|
# context_handler do |message|
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
def context_handler(context = nil, action = nil, &block)
|
def context_handler(context = nil, action = nil, &block)
|
||||||
@@ -56,7 +56,7 @@ module Telegram
|
|||||||
if handler.respond_to?(:call)
|
if handler.respond_to?(:call)
|
||||||
instance_exec(message, &handler)
|
instance_exec(message, &handler)
|
||||||
else
|
else
|
||||||
process(handler, *message['text'].split)
|
process(handler, *message['text'].try!(:split))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -54,6 +54,11 @@ RSpec.describe Telegram::Bot::UpdatesController::MessageContext do
|
|||||||
its(:call) { should eq [:block_result, payload] }
|
its(:call) { should eq [:block_result, payload] }
|
||||||
it { should_not change(controller, :filter_done) }
|
it { should_not change(controller, :filter_done) }
|
||||||
it { should change { session[:context] }.to nil }
|
it { should change { session[:context] }.to nil }
|
||||||
|
|
||||||
|
context 'when message has no text' do
|
||||||
|
let(:payload) { {'audio' => {'file_id' => 123}} }
|
||||||
|
its(:call) { should eq [:block_result, payload] }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when context is handled by short redirect' do
|
context 'when context is handled by short redirect' do
|
||||||
@@ -61,6 +66,13 @@ RSpec.describe Telegram::Bot::UpdatesController::MessageContext do
|
|||||||
its(:call) { should eq [:method_result, *text.split] }
|
its(:call) { should eq [:method_result, *text.split] }
|
||||||
it { should change(controller, :filter_done).to true }
|
it { should change(controller, :filter_done).to true }
|
||||||
it { should change { session[:context] }.to nil }
|
it { should change { session[:context] }.to nil }
|
||||||
|
|
||||||
|
context 'when message has no text' do
|
||||||
|
let(:payload) { {'audio' => {'file_id' => 123}} }
|
||||||
|
its(:call) { should eq [:method_result] }
|
||||||
|
it { should change(controller, :filter_done).to true }
|
||||||
|
it { should change { session[:context] }.to nil }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when context is handled by custom redirect' do
|
context 'when context is handled by custom redirect' do
|
||||||
|
|||||||
@@ -109,6 +109,11 @@ RSpec.describe Telegram::Bot::UpdatesController do
|
|||||||
it { should eq [false, 'message', [payload]] }
|
it { should eq [false, 'message', [payload]] }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'without text' do
|
||||||
|
let(:payload) { {'audio' => {'file_id' => 123}} }
|
||||||
|
it { should eq [false, payload_type, [payload]] }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user