Skip to content

Upgrading to 0.14

printercu edited this page Jun 7, 2018 · 2 revisions

Gem's API getting more stable with every minor update and I expect next version be a major release. However there was some issues that had to be addressed before first major release. So 0.14 version goes with some breaking changes. This update is going to make bots more secure and source-code more consistent, trying to keep code clean and simple - this is what we like Ruby for.

See upgrade commit in example app.

Commands now use bang-methods as action names

Please see #85 for rationale and discussion.

Change method names for command to their bang-version. Make sure to update save_context if you used command name as context name.

# was
def start(*)
end

def rename(name = nil, *)
  if name
  else
    save_context :rename
  end
end

# becomes
def start!(*)
end

def rename!(name = nil, *)
  if name
  else
    save_context :rename!
  end
end

context_to_action! is enabled by default, context_handler is removed

Because of using bang-methods for commands, there are no more name conflicts. Change all context_handlers to usual ruby methods, remove context_to_action! calls.

# was
context_to_action!
context_handler :rename do |name, *|
end

# becomes
def rename(name, *)
end

:telegram_bot RSpec tag is replaced with telegram_bot: :rails

0.14 brings RSpec contexts for testing bots in poller mode and in rack applications without Rails. To make it consistent, it's required to specify exact context type.

# was
RSpec.describe BotController, :telegram_bot do

# becomes
RSpec.describe BotController, telegram_bot: :rails do

Breaking changes in controller specs

Controller specs getting consistent with integration specs, so dispatch method changed it's signature. To simplify API build_update is dropped in favour of deep_stringify. In this update controller specs receives all matchers and helpers available in request specs.

# was
dispatch(bot, update)
build_update(type, data)

# becomes
dispatch(update, bot)
deep_stringify(type => data)