1
0
зеркало из https://github.com/glebtv/telegram-bot.git synced 2026-09-03 17:55:52 +03:00

Fixed Readme, added spec for protected methods in controller

Этот коммит содержится в:
Max Melentiev
2016-03-14 14:20:16 +06:00
родитель c04884040d
Коммит 9fe4c6bcae
2 изменённых файлов: 35 добавлений и 19 удалений

Просмотреть файл

@@ -142,7 +142,7 @@ You can enable typecasting of `update` with `telegram-bot-types` by including
```ruby
class Telegram::WebhookController < Telegram::Bot::UpdatesController
include Telegram::Bot::UpdatesPoller::TypedUpdate
include Telegram::Bot::UpdatesController::TypedUpdate
def message(message)
message.class # => Telegram::Bot::Types::Message
@@ -205,7 +205,7 @@ class Telegram::WebhookController < Telegram::Bot::UpdatesController
# You can do it in other way:
def rename(name = nil, *)
if name
update_name message[:text]
update_name name
reply_with :message, text: 'Renamed!'
else
save_context :rename

Просмотреть файл

@@ -147,17 +147,41 @@ RSpec.describe Telegram::Bot::UpdatesController do
describe '#process' do
subject { -> { controller.process(:action, *args) } }
let(:args) { [:arg1, :arg2] }
let(:controller_class) do
Class.new(described_class) do
attr_reader :acted, :hooked
def action(*args)
@acted = true
[from, chat, args]
end
end
end
context 'when action is protected' do
before { controller_class.send :protected, :action }
its(:call) { should eq nil }
context 'when action_missing defined' do
before do
controller.class_eval do
protected
def action_missing(*args)
args
end
end
end
its(:call) { should eq ['action', *args] }
end
end
context 'when callbacks are defined' do
let(:controller_class) do
Class.new(described_class) do
before do
controller_class.class_eval do
before_action :hook, only: :action
attr_reader :acted, :hooked
def action(*args)
@acted = true
args
end
attr_reader :hooked
private
@@ -169,7 +193,7 @@ RSpec.describe Telegram::Bot::UpdatesController do
it { should change(controller, :hooked).to true }
it { should change(controller, :acted).to true }
its(:call) { should eq args }
its(:call) { should eq [nil, nil, args] }
context 'when callback returns false' do
before do
@@ -191,14 +215,6 @@ RSpec.describe Telegram::Bot::UpdatesController do
let(:controller) { controller_class.new(bot, from: from, chat: chat) }
let(:from) { {'id' => 'user_id'} }
let(:chat) { {'id' => 'chat_id'} }
let(:controller_class) do
Class.new(described_class) do
def action(*args)
[from, chat, args]
end
end
end
its(:call) { should eq [from, chat, args] }
end
end