1
0
зеркало из https://github.com/glebtv/telegram-bot.git synced 2026-09-03 17:55:52 +03:00
Files
telegram-bot/spec/telegram/bot/updates_controller/session_spec.rb
2016-02-28 21:51:59 +06:00

44 строки
1.2 KiB
Ruby

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