зеркало из
https://github.com/glebtv/telegram-bot.git
synced 2026-09-04 10:15:50 +03:00
Fix codeclimate issues
Этот коммит содержится в:
@@ -24,8 +24,8 @@ class TestApplication < Rails::Application
|
||||
},
|
||||
}
|
||||
|
||||
if Rails.application.respond_to?(:credentials)
|
||||
Rails.application.credentials.config[:telegram] = telegram_config
|
||||
if respond_to?(:credentials)
|
||||
credentials.config[:telegram] = telegram_config
|
||||
else
|
||||
secrets[:secret_key_base] = 'test'
|
||||
secrets[:telegram] = telegram_config
|
||||
|
||||
@@ -16,7 +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'
|
||||
require 'active_support/json'
|
||||
|
||||
Dir[GEM_ROOT.join('spec/support/**/*.rb')].each { |f| require f }
|
||||
|
||||
|
||||
@@ -8,12 +8,32 @@ RSpec.describe Telegram::Bot::UpdatesPoller do
|
||||
it { should be }
|
||||
end
|
||||
|
||||
describe '#fetch_updates' do
|
||||
subject { -> { instance.fetch_updates(&block) } }
|
||||
describe '#process_updates' do
|
||||
subject { -> { instance.process_updates(updates) } }
|
||||
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 }
|
||||
let(:updates) { [{update_id: 12}, {update_id: 34}].as_json }
|
||||
let(:processed_updates) { [] }
|
||||
before do
|
||||
allow(controller).to receive(:dispatch) do |bot, update|
|
||||
expect(bot).to eq self.bot
|
||||
processed_updates << update
|
||||
end
|
||||
end
|
||||
|
||||
it { should change(instance, :offset).to(updates.last['update_id'] + 1) }
|
||||
it { should change(self, :processed_updates).to(updates) }
|
||||
|
||||
context 'with typed response' do
|
||||
let(:updates) { super().map { |x| Telegram::Bot::Types::Update.new(x) } }
|
||||
it { should change(instance, :offset).to(updates.last['update_id'] + 1) }
|
||||
it { should change(self, :processed_updates).to(updates) }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#fetch_updates' do
|
||||
subject { instance.fetch_updates }
|
||||
let(:updates) { [{update_id: 12}, {update_id: 34}] }
|
||||
let(:request_result) { {ok: true, result: updates}.as_json }
|
||||
before do
|
||||
allow(bot).to receive(:get_updates) do
|
||||
expect(bot.async).to be_falsy
|
||||
@@ -21,19 +41,17 @@ RSpec.describe Telegram::Bot::UpdatesPoller do
|
||||
end
|
||||
end
|
||||
|
||||
it { should change(instance, :offset).to(results.last[:update_id] + 1) }
|
||||
it { should change { expected_results }.to([]) }
|
||||
it { should eq updates.as_json }
|
||||
|
||||
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([]) }
|
||||
let(:updates) { super().map { |x| Telegram::Bot::Types::Update.new(x.as_json) } }
|
||||
let(:request_result) { updates }
|
||||
it { should eq updates }
|
||||
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([]) }
|
||||
it { should eq updates.as_json }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Ссылка в новой задаче
Block a user