Skip to content

Commit

Permalink
Fix spec helpers for callback queries
Browse files Browse the repository at this point in the history
  • Loading branch information
printercu committed Dec 4, 2017
1 parent 9e396ca commit 384d203
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 3 additions & 1 deletion lib/telegram/bot/rspec/integration.rb
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
2 changes: 1 addition & 1 deletion lib/telegram/bot/version.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
40 changes: 40 additions & 0 deletions spec/telegram/bot/rspec/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,44 @@ def start(*args)
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

0 comments on commit 384d203

Please sign in to comment.