зеркало из
https://github.com/glebtv/telegram-bot.git
synced 2026-09-03 09:46:17 +03:00
Make integration & controller specs consistent
Этот коммит содержится в:
@@ -7,7 +7,6 @@ RSpec.describe Telegram::Bot::Middleware do
|
||||
|
||||
describe '#call' do
|
||||
subject { instance.call(env) }
|
||||
let(:env) { {'action_dispatch.request.request_parameters' => json_body} }
|
||||
let(:update) { {'message' => {'id' => 1}} }
|
||||
let(:env) do
|
||||
Rack::MockRequest.env_for('/',
|
||||
|
||||
@@ -27,7 +27,7 @@ RSpec.describe Telegram::Bot::UpdatesController::CallbackQueryContext do
|
||||
describe '#dispatch' do
|
||||
subject { -> { dispatch } }
|
||||
let(:payload_type) { :callback_query }
|
||||
let(:payload) { {'data' => data} }
|
||||
let(:payload) { {data: data} }
|
||||
let(:data) { text }
|
||||
let(:text) { 'asd qwe zxc' }
|
||||
|
||||
|
||||
@@ -2,9 +2,7 @@ RSpec.describe Telegram::Bot::UpdatesController::Instrumentation do
|
||||
include_context 'telegram/bot/updates_controller'
|
||||
|
||||
subject { -> { dispatch } }
|
||||
let(:update) do
|
||||
build_update :message, default_message_options.merge(text: '/start')
|
||||
end
|
||||
let(:update) { {message: default_message_options.merge(text: '/start')} }
|
||||
|
||||
let(:controller_class) do
|
||||
Class.new(Telegram::Bot::UpdatesController) do
|
||||
@@ -36,11 +34,11 @@ RSpec.describe Telegram::Bot::UpdatesController::Instrumentation do
|
||||
|
||||
action = action_name(:start_processing)
|
||||
expect(events[action].size).to eq(1)
|
||||
expect(events[action][0].last).to include(update: update)
|
||||
expect(events[action][0].last).to include(update: deep_stringify(update))
|
||||
|
||||
action = action_name(:process_action)
|
||||
expect(events[action].size).to eq(1)
|
||||
expect(events[action][0].last).to include(update: update)
|
||||
expect(events[action][0].last).to include(update: deep_stringify(update))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ RSpec.describe Telegram::Bot::UpdatesController do
|
||||
let(:respond_type) { :photo }
|
||||
let(:result) { double(:result) }
|
||||
let(:payload_type) { :message }
|
||||
let(:payload) { {message_id: double(:message_id)} }
|
||||
let(:chat) { {'id' => double(:chat_id)} }
|
||||
let(:payload) { {message_id: double(:message_id), chat: chat} }
|
||||
let(:chat) { {id: double(:chat_id)} }
|
||||
|
||||
shared_examples 'missing chat' do
|
||||
context 'when chat is missing' do
|
||||
@@ -19,9 +19,8 @@ RSpec.describe Telegram::Bot::UpdatesController do
|
||||
include_examples 'missing chat'
|
||||
|
||||
it 'sets chat_id & reply_to_message_id' do
|
||||
expect(controller).to receive(:chat) { chat }
|
||||
expect(bot).to receive("send_#{respond_type}").
|
||||
with(params.merge(chat_id: chat['id'])) { result }
|
||||
with(params.merge(chat_id: chat[:id])) { result }
|
||||
should eq result
|
||||
end
|
||||
end
|
||||
@@ -31,19 +30,18 @@ RSpec.describe Telegram::Bot::UpdatesController do
|
||||
include_examples 'missing chat'
|
||||
|
||||
it 'sets chat_id & reply_to_message_id' do
|
||||
expect(controller).to receive(:chat) { chat }
|
||||
expect(bot).to receive("send_#{respond_type}").with(params.merge(
|
||||
chat_id: chat['id'],
|
||||
chat_id: chat[:id],
|
||||
reply_to_message_id: payload[:message_id],
|
||||
)) { result }
|
||||
should eq result
|
||||
end
|
||||
|
||||
context 'when update is not set' do
|
||||
let(:update) { {chat: chat} }
|
||||
let(:controller_args) { [bot, chat: deep_stringify(chat)] }
|
||||
it 'sets chat_id' do
|
||||
expect(bot).to receive("send_#{respond_type}").
|
||||
with(params.merge(chat_id: chat['id'])) { result }
|
||||
with(params.merge(chat_id: chat[:id])) { result }
|
||||
should eq result
|
||||
end
|
||||
end
|
||||
@@ -70,7 +68,7 @@ RSpec.describe Telegram::Bot::UpdatesController do
|
||||
it 'sets chat_id & message_id' do
|
||||
expect(bot).to receive("edit_message_#{type}").with(params.merge(
|
||||
message_id: payload[:message][:message_id],
|
||||
chat_id: payload[:message][:chat]['id'],
|
||||
chat_id: payload[:message][:chat][:id],
|
||||
)) { result }
|
||||
should eq result
|
||||
end
|
||||
|
||||
@@ -36,7 +36,7 @@ RSpec.describe Telegram::Bot::UpdatesController::Session do
|
||||
end
|
||||
|
||||
def build_message(text, from)
|
||||
{'message' => {'text' => text, 'from' => from.stringify_keys}}
|
||||
deep_stringify(message: {text: text, from: from})
|
||||
end
|
||||
|
||||
it 'stores session between requests' do
|
||||
|
||||
@@ -278,11 +278,13 @@ RSpec.describe Telegram::Bot::UpdatesController do
|
||||
instance_eval(&block)
|
||||
context 'when re-initialized' do
|
||||
let(:controller) do
|
||||
described_class.new(double(:other_bot), build_update(:message,
|
||||
initial_update = deep_stringify message: {
|
||||
text: 'original message',
|
||||
from: double(:original_from),
|
||||
chat: double(:original_chat),
|
||||
)).tap { |x| x.send(:initialize, bot, update) }
|
||||
}
|
||||
described_class.new(double(:other_bot), initial_update).
|
||||
tap { |x| x.send(:initialize, *controller_args) }
|
||||
end
|
||||
instance_eval(&block)
|
||||
end
|
||||
@@ -300,7 +302,7 @@ RSpec.describe Telegram::Bot::UpdatesController do
|
||||
end
|
||||
|
||||
context 'when options hash is given' do
|
||||
let(:update) { {from: from, chat: chat} }
|
||||
let(:controller_args) { [bot, from: from, chat: chat] }
|
||||
with_reinitialize do
|
||||
its(:bot) { should eq bot }
|
||||
its(:update) { should eq nil }
|
||||
|
||||
Ссылка в новой задаче
Block a user