зеркало из
https://github.com/glebtv/telegram-bot.git
synced 2026-09-03 09:46:17 +03:00
36 строки
1.1 KiB
Ruby
36 строки
1.1 KiB
Ruby
require 'rack/mock'
|
|
|
|
RSpec.describe Telegram::Bot::Middleware do
|
|
let(:instance) { described_class.new bot, controller }
|
|
let(:bot) { double(:bot) }
|
|
let(:controller) { double(:controller, dispatch: :dispatch_result) }
|
|
|
|
describe '#call' do
|
|
subject { instance.call(env) }
|
|
let(:env) { {'action_dispatch.request.request_parameters' => json_body} }
|
|
let(:update) { {'message' => {'id' => 1}} }
|
|
let(:env) do
|
|
Rack::MockRequest.env_for('/',
|
|
method: :post,
|
|
input: JSON.dump(update),
|
|
'CONTENT_TYPE' => 'application/json',
|
|
)
|
|
end
|
|
|
|
require 'action_pack/version'
|
|
if ActionPack::VERSION::MAJOR < 5
|
|
# Before Rails 5, params are parsed in middleware.
|
|
# In Rails 5, they are parsed in Request#request_parameters.
|
|
require 'action_dispatch/middleware/params_parser'
|
|
let(:instance) { ActionDispatch::ParamsParser.new(super()) }
|
|
end
|
|
|
|
it 'calls dispatch on controller' do
|
|
expect(controller).to receive(:dispatch).with(bot, update)
|
|
subject
|
|
end
|
|
|
|
it { should eq [200, {}, ['']] }
|
|
end
|
|
end
|