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