diff --git a/CHANGELOG.md b/CHANGELOG.md index 83513fd..83d7f74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Unreleased -# 0.12.2 +# 0.12.4 + +- Fix spec helpers for callback queries. + +# 0.12.3 - New methods from Bot API v3.5 - Collect all api helper-methods in Client::ApiHelper module. diff --git a/lib/telegram/bot/rspec/integration.rb b/lib/telegram/bot/rspec/integration.rb index ab2e840..a6f9eda 100644 --- a/lib/telegram/bot/rspec/integration.rb +++ b/lib/telegram/bot/rspec/integration.rb @@ -1,8 +1,10 @@ RSpec.shared_context 'telegram/bot/integration' do let(:bot) { Telegram.bot } + let(:default_message_options) { {from: from, chat: chat} } + let(:from) { {id: from_id} } let(:from_id) { 123 } + let(:chat) { {id: chat_id} } let(:chat_id) { 456 } - let(:default_message_options) { {from: {id: from_id}, chat: {id: chat_id}} } let(:controller_path) do route_name = Telegram::Bot::RoutesHelper.route_name_for_bot(bot) Rails.application.routes.url_helpers.public_send("#{route_name}_path") diff --git a/lib/telegram/bot/version.rb b/lib/telegram/bot/version.rb index ffb1a9f..45854cf 100644 --- a/lib/telegram/bot/version.rb +++ b/lib/telegram/bot/version.rb @@ -1,6 +1,6 @@ module Telegram module Bot - VERSION = '0.12.3'.freeze + VERSION = '0.12.4'.freeze def self.gem_version Gem::Version.new VERSION diff --git a/spec/telegram/bot/rspec/integration_spec.rb b/spec/telegram/bot/rspec/integration_spec.rb index 8caa9bc..070947a 100644 --- a/spec/telegram/bot/rspec/integration_spec.rb +++ b/spec/telegram/bot/rspec/integration_spec.rb @@ -69,4 +69,44 @@ RSpec.describe 'Integrations helper', :telegram_bot do it { should respond_with_message "Start: #{args[0...-1].inspect}, option: 1" } end end + + describe 'callback queries', :callback_query do + let(:controller) do + Class.new(Telegram::Bot::UpdatesController) do + include Telegram::Bot::UpdatesController::CallbackQueryContext + + def callback_query(data = nil, *) + answer_callback_query "data: #{data}" + end + + def context_callback_query(data = nil, *) + answer_callback_query "data: #{data}", extra: :param + end + + def answer_and_edit_callback_query(data = nil, *) + answer_callback_query "data: #{data}" + edit_message :text, text: 'edited-text', extra: :param + end + end + end + + describe '#callback_query' do + let(:data) { 'unknown:command' } + it { should answer_callback_query("data: #{data}") } + end + + describe '#context_callback_query' do + let(:data) { 'context:test:payload' } + it { should answer_callback_query('data: test:payload', extra: :param) } + it { should_not edit_current_message(:text) } + end + + describe '#answer_and_edit_callback_query' do + let(:data) { 'answer_and_edit:test:payload' } + it do + should answer_callback_query(/test:payload/). + and edit_current_message(:text, text: /edited/, extra: :param) + end + end + end end