зеркало из
https://github.com/glebtv/telegram-bot.git
synced 2026-09-07 11:25:52 +03:00
Sessions for UpdatesController
Этот коммит содержится в:
43
spec/telegram/bot/updates_controller/session_spec.rb
Обычный файл
43
spec/telegram/bot/updates_controller/session_spec.rb
Обычный файл
@@ -0,0 +1,43 @@
|
||||
RSpec.describe Telegram::Bot::UpdatesController::Session do
|
||||
include_context 'telegram/bot/updates_controller'
|
||||
let(:controller_class) do
|
||||
described_class = self.described_class
|
||||
Class.new(Telegram::Bot::UpdatesController) do
|
||||
include described_class
|
||||
end
|
||||
end
|
||||
|
||||
describe '.action_methods' do
|
||||
subject { controller_class.action_methods }
|
||||
it { should be_empty }
|
||||
end
|
||||
|
||||
describe '.dispatch' do
|
||||
subject { ->(*args) { controller_class.dispatch(*args) } }
|
||||
let(:other_bot) { double(username: 'otherBot') }
|
||||
before do
|
||||
controller_class.class_eval do
|
||||
self.session_store = :memory_store
|
||||
|
||||
def write(text)
|
||||
session[:text] = text
|
||||
end
|
||||
|
||||
def read
|
||||
session[:text]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def build_message(text, from)
|
||||
{'message' => {'text' => text, 'from' => from.stringify_keys}}
|
||||
end
|
||||
|
||||
it 'stores session between requests' do
|
||||
subject.call(bot, build_message('/write test', id: 1))
|
||||
expect(subject.call(bot, build_message('/read', id: 1))).to eq 'test'
|
||||
expect(subject.call(bot, build_message('/read', id: 2))).to eq nil
|
||||
expect(subject.call(other_bot, build_message('/read', id: 1))).to eq nil
|
||||
end
|
||||
end
|
||||
end
|
||||
Ссылка в новой задаче
Block a user