1
0
зеркало из https://github.com/glebtv/telegram-bot.git synced 2026-09-04 02:05:52 +03:00

Add UpdatesController#webhook_request

Этот коммит содержится в:
Max Melentiev
2023-04-16 20:15:45 +01:00
родитель ca20bb0533
Коммит cbe7186c44
12 изменённых файлов: 76 добавлений и 12 удалений

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

@@ -24,7 +24,8 @@ RSpec.describe Telegram::Bot::Middleware do
end
it 'calls dispatch on controller' do
expect(controller).to receive(:dispatch).with(bot, update)
expect(controller).to receive(:dispatch).
with(bot, update, instance_of(ActionDispatch::Request))
subject
end

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

@@ -2,4 +2,13 @@ require 'telegram/bot/rspec/integration/poller'
RSpec.describe 'Poller integration spec', telegram_bot: :poller do
include_examples 'shared integration examples'
describe '#dispatch' do
it 'doesn`t provide webhook_request' do
expect(controller_class).to receive(:dispatch).
with(bot, hash_including('message')).
and_call_original
dispatch_message :test
end
end
end

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

@@ -17,4 +17,13 @@ RSpec.describe 'Rack integration spec', telegram_bot: :rack do
ActionDispatch::ParamsParser.new(app)
end
end
describe '#dispatch' do
it 'provides webhook_request' do
expect(controller_class).to receive(:dispatch).
with(bot, hash_including('message'), instance_of(ActionDispatch::Request)).
and_call_original
dispatch_message :test
end
end
end

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

@@ -1,3 +1,5 @@
require 'action_dispatch'
RSpec.describe Telegram::Bot::UpdatesController::Testing do
include_context 'telegram/bot/updates_controller'
let(:controller_class) do
@@ -24,4 +26,27 @@ RSpec.describe Telegram::Bot::UpdatesController::Testing do
it { should_not change { controller.send(:session)[:key] }.from 'sval' }
end
end
describe '#dispatch' do
it 'doesn`t provide webhook_request' do
dispatch
expect(controller.webhook_request).to eq nil
end
context 'when webhook_request is set' do
let(:webhook_request) { ActionDispatch::Request.new({}) }
it 'passes it to controller' do
dispatch
expect(controller.webhook_request).to eq webhook_request
end
end
context 'when webhook_request is given' do
it 'passes it to controller' do
webhook_request = ::ActionDispatch::Request.new({})
dispatch(update, bot, webhook_request)
expect(controller.webhook_request).to eq webhook_request
end
end
end
end