зеркало из
https://github.com/glebtv/telegram-bot.git
synced 2026-09-07 11:25:52 +03:00
Fix storing token in ClientStub when config hash is given
Этот коммит содержится в:
@@ -35,7 +35,7 @@ module Telegram
|
|||||||
end
|
end
|
||||||
|
|
||||||
def initialize(token = nil, username = nil, **options)
|
def initialize(token = nil, username = nil, **options)
|
||||||
@token = token
|
@token = token || options[:token]
|
||||||
@username = username || options[:username] || token
|
@username = username || options[:username] || token
|
||||||
reset
|
reset
|
||||||
end
|
end
|
||||||
|
|||||||
9
spec/integration/requests/named_bot_spec.rb
Обычный файл
9
spec/integration/requests/named_bot_spec.rb
Обычный файл
@@ -0,0 +1,9 @@
|
|||||||
|
require 'integration_helper'
|
||||||
|
|
||||||
|
RSpec.describe NamedBotController, :telegram_bot, type: :request do
|
||||||
|
let(:bot) { Telegram.bots[:named] }
|
||||||
|
describe '#start' do
|
||||||
|
subject { -> { dispatch_command :start } }
|
||||||
|
it { should respond_with_message 'from named' }
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -18,22 +18,20 @@ class TestApplication < Rails::Application
|
|||||||
bot: 'default_token',
|
bot: 'default_token',
|
||||||
bots: {
|
bots: {
|
||||||
other: {token: 'other_token'},
|
other: {token: 'other_token'},
|
||||||
|
named: {token: 'named_token', username: 'TestBot'},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
Rails.application.initialize!
|
Rails.application.initialize!
|
||||||
|
|
||||||
# # Controllers
|
# # Controllers
|
||||||
class DefaultBotController < Telegram::Bot::UpdatesController
|
%w(default other named).each do |bot_name|
|
||||||
def start(*)
|
controller = Class.new(Telegram::Bot::UpdatesController) do
|
||||||
respond_with :message, text: 'from default'
|
define_method :start do |*|
|
||||||
end
|
respond_with :message, text: "from #{bot_name}"
|
||||||
end
|
end
|
||||||
|
|
||||||
class OtherBotController < Telegram::Bot::UpdatesController
|
|
||||||
def start(*)
|
|
||||||
respond_with :message, text: 'from other'
|
|
||||||
end
|
end
|
||||||
|
Object.const_set("#{bot_name}_bot_controller".camelize, controller)
|
||||||
end
|
end
|
||||||
|
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
@@ -57,7 +55,8 @@ RSpec.configure do |config|
|
|||||||
extend Telegram::Bot::RoutesHelper
|
extend Telegram::Bot::RoutesHelper
|
||||||
|
|
||||||
telegram_webhooks default: DefaultBotController,
|
telegram_webhooks default: DefaultBotController,
|
||||||
other: OtherBotController
|
other: OtherBotController,
|
||||||
|
named: NamedBotController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -49,5 +49,11 @@ RSpec.describe Telegram::Bot::ClientStub do
|
|||||||
its(:token) { should eq args[0] }
|
its(:token) { should eq args[0] }
|
||||||
its(:username) { should eq args[1] }
|
its(:username) { should eq args[1] }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when hash config is given' do
|
||||||
|
let(:args) { [token: 'token', username: 'superbot'] }
|
||||||
|
its(:token) { should eq args[0][:token] }
|
||||||
|
its(:username) { should eq args[0][:username] }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user