Skip to content

Commit 384d203

Browse files
committed
Fix spec helpers for callback queries
1 parent 9e396ca commit 384d203

File tree

4 files changed

+49
-3
lines changed

4 files changed

+49
-3
lines changed

CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Unreleased
22

3-
# 0.12.2
3+
# 0.12.4
4+
5+
- Fix spec helpers for callback queries.
6+
7+
# 0.12.3
48

59
- New methods from Bot API v3.5
610
- Collect all api helper-methods in Client::ApiHelper module.

lib/telegram/bot/rspec/integration.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
RSpec.shared_context 'telegram/bot/integration' do
22
let(:bot) { Telegram.bot }
3+
let(:default_message_options) { {from: from, chat: chat} }
4+
let(:from) { {id: from_id} }
35
let(:from_id) { 123 }
6+
let(:chat) { {id: chat_id} }
47
let(:chat_id) { 456 }
5-
let(:default_message_options) { {from: {id: from_id}, chat: {id: chat_id}} }
68
let(:controller_path) do
79
route_name = Telegram::Bot::RoutesHelper.route_name_for_bot(bot)
810
Rails.application.routes.url_helpers.public_send("#{route_name}_path")

lib/telegram/bot/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Telegram
22
module Bot
3-
VERSION = '0.12.3'.freeze
3+
VERSION = '0.12.4'.freeze
44

55
def self.gem_version
66
Gem::Version.new VERSION

spec/telegram/bot/rspec/integration_spec.rb

+40
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,44 @@ def start(*args)
6969
it { should respond_with_message "Start: #{args[0...-1].inspect}, option: 1" }
7070
end
7171
end
72+
73+
describe 'callback queries', :callback_query do
74+
let(:controller) do
75+
Class.new(Telegram::Bot::UpdatesController) do
76+
include Telegram::Bot::UpdatesController::CallbackQueryContext
77+
78+
def callback_query(data = nil, *)
79+
answer_callback_query "data: #{data}"
80+
end
81+
82+
def context_callback_query(data = nil, *)
83+
answer_callback_query "data: #{data}", extra: :param
84+
end
85+
86+
def answer_and_edit_callback_query(data = nil, *)
87+
answer_callback_query "data: #{data}"
88+
edit_message :text, text: 'edited-text', extra: :param
89+
end
90+
end
91+
end
92+
93+
describe '#callback_query' do
94+
let(:data) { 'unknown:command' }
95+
it { should answer_callback_query("data: #{data}") }
96+
end
97+
98+
describe '#context_callback_query' do
99+
let(:data) { 'context:test:payload' }
100+
it { should answer_callback_query('data: test:payload', extra: :param) }
101+
it { should_not edit_current_message(:text) }
102+
end
103+
104+
describe '#answer_and_edit_callback_query' do
105+
let(:data) { 'answer_and_edit:test:payload' }
106+
it do
107+
should answer_callback_query(/test:payload/).
108+
and edit_current_message(:text, text: /edited/, extra: :param)
109+
end
110+
end
111+
end
72112
end

0 commit comments

Comments
 (0)