1
0
зеркало из https://github.com/glebtv/telegram-bot.git synced 2026-08-28 15:26:18 +03:00

Сравнить коммиты

...

1 Коммитов

Автор SHA1 Сообщение Дата
Max Melentiev
48ff7a4f43 Fix poller for typed responses
Fixes: #22
2017-03-05 17:56:32 +03:00
5 изменённых файлов: 45 добавлений и 8 удалений

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

@@ -1,3 +1,7 @@
# 0.11.1
# Fixed poller for typed response.
# 0.11.0
- Remove Bot::StaleChat in favor of Bot::Forbidden, as Telegram adds more

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

@@ -65,14 +65,16 @@ module Telegram
def fetch_updates
response = bot.async(false) { bot.get_updates(offset: offset, timeout: timeout) }
return unless response['ok'] && response['result'].any?
updates = response.is_a?(Array) ? response : response['result']
return unless updates && updates.any?
reload! do
response['result'].each do |update|
updates.each do |update|
@offset = update['update_id'] + 1
yield update
end
end
rescue Timeout::Error # rubocop:disable HandleExceptions
rescue Timeout::Error
log { 'Fetch timeout' }
end
def reload!

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

@@ -1,6 +1,6 @@
module Telegram
module Bot
VERSION = '0.11.0'.freeze
VERSION = '0.11.1'.freeze
def self.gem_version
Gem::Version.new VERSION

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

@@ -16,6 +16,7 @@ $LOAD_PATH.unshift GEM_ROOT.join('lib')
require 'telegram/bot'
require 'telegram/bot/updates_controller/rspec_helpers'
require 'telegram/bot/types'
require 'active_support/core_ext/object/json'
Dir[GEM_ROOT.join('spec/support/**/*.rb')].each { |f| require f }

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

@@ -1,9 +1,39 @@
RSpec.describe Telegram::Bot::UpdatesPoller do
describe '#initialize' do
subject { described_class.new bot, controller }
let(:bot) { double }
let(:controller) { double }
let(:instance) { described_class.new(bot, controller) }
let(:bot) { Telegram::Bot::Client.new('token') }
let(:controller) { double(:controller) }
describe '#initialize' do
subject { instance }
it { should be }
end
describe '#fetch_updates' do
subject { -> { instance.fetch_updates(&block) } }
let(:block) { ->(x) { expect(x).to eq expected_results.shift } }
let(:results) { [{update_id: 12}, {update_id: 34}] }
let(:expected_results) { results.as_json }
let(:request_result) { {ok: true, result: results}.as_json }
before do
allow(bot).to receive(:get_updates) do
expect(bot.async).to be_falsy
request_result
end
end
it { should change(instance, :offset).to(results.last[:update_id] + 1) }
it { should change { expected_results }.to([]) }
context 'with typed response' do
let(:request_result) { results.as_json.map { |x| Telegram::Bot::Types::Update.new(x) } }
let(:expected_results) { request_result.dup }
it { should change(instance, :offset).to(results.last[:update_id] + 1) }
it { should change { expected_results }.to([]) }
end
context 'when bot is in async mode' do
let(:bot) { Telegram::Bot::Client.new('token', async: Class.new) }
it { should change { expected_results }.to([]) }
end
end
end