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

Extract Botan-related code from Client to Botan::ClientHelpers

Этот коммит содержится в:
Max Melentiev
2016-08-09 15:27:27 +06:00
родитель 27602b20bd
Коммит 85ff07de9b
5 изменённых файлов: 44 добавлений и 13 удалений

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

@@ -3,6 +3,7 @@ module Telegram
class Botan
TRACK_URI = 'https://api.botan.io/track'.freeze
autoload :ClientHelpers, 'telegram/bot/botan/client_helpers'
autoload :ControllerHelpers, 'telegram/bot/botan/controller_helpers'
class Error < Bot::Error; end

15
lib/telegram/bot/botan/client_helpers.rb Обычный файл
Просмотреть файл

@@ -0,0 +1,15 @@
module Telegram
module Bot
class Botan
# Helpers for botan.io metrics.
module ClientHelpers
attr_reader :botan
def initialize(*, botan: nil, **)
super
@botan = Botan.wrap(botan) if botan
end
end
end
end
end

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

@@ -10,6 +10,7 @@ module Telegram
autoload :TypedResponse, 'telegram/bot/client/typed_response'
extend Initializers
prepend Botan::ClientHelpers
include DebugClient
class << self
@@ -31,9 +32,9 @@ module Telegram
end
end
attr_reader :client, :token, :username, :base_uri, :botan
attr_reader :client, :token, :username, :base_uri
def initialize(token = nil, username = nil, botan: nil, **options)
def initialize(token = nil, username = nil, **options)
@client = HTTPClient.new
@token = token || options[:token]
@username = username || options[:username]

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

@@ -0,0 +1,25 @@
RSpec.describe Telegram::Bot::Client do
let(:instance) { described_class.new(*client_args) }
let(:token) { 'token' }
let(:botan_token) { double(:botan_token) }
let(:client_id) { 'client_id' }
let(:client_args) { [token] }
describe '#botan' do
subject { instance.botan }
it { should eq nil }
context 'when botan token is set' do
let(:client_args) { [token, id: client_id, async: Class.new, botan: botan_token] }
it { should be_instance_of Telegram::Bot::Botan }
its(:token) { should eq botan_token }
end
context 'when botan is configured with hash' do
let(:client_args) { [token, id: client_id, async: Class.new, botan: botan_config] }
let(:botan_config) { {token: botan_token, async: Class.new} }
it { should be_instance_of Telegram::Bot::Botan }
its(:token) { should eq botan_token }
end
end
end

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

@@ -41,15 +41,4 @@ RSpec.describe Telegram::Bot::Client do
its(:base_uri) { should include args[0][:token] }
end
end
describe '#botan' do
subject { instance.botan }
it { should eq nil }
context 'when botan token is set' do
let(:instance) { described_class.new token, botan: botan_token }
it { should be_instance_of Telegram::Bot::Botan }
its(:token) { should eq botan_token }
end
end
end