Add namespace Callbacks
This commit is contained in:
parent
a606f72b0a
commit
c355d5f8f8
|
@ -1,12 +1,12 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class TelegramBots::UpdatesController < ApplicationController
|
||||
class Callbacks::TelegramBots::UpdatesController < ApplicationController
|
||||
before_action :set_telegram_bot
|
||||
before_action :verify_telegram_bot_secret
|
||||
|
||||
skip_after_action :verify_authorized
|
||||
|
||||
# POST /telegram_bots/:telegram_bot_id/updates
|
||||
# POST /callbacks/telegram_bots/:telegram_bot_id/updates
|
||||
def create
|
||||
handle_message params[:message]
|
||||
|
|
@ -29,7 +29,7 @@ private
|
|||
end
|
||||
|
||||
def webhook_url
|
||||
telegram_bot_updates_url(
|
||||
callbacks_telegram_bot_updates_url(
|
||||
context.telegram_bot,
|
||||
format: 'json',
|
||||
protocol: 'https',
|
||||
|
|
|
@ -38,10 +38,12 @@ Rails.application.routes.draw do
|
|||
# Callbacks for third-party services #
|
||||
######################################
|
||||
|
||||
resources :telegram_bots, only: [] do
|
||||
resources :updates,
|
||||
controller: 'telegram_bots/updates',
|
||||
only: :create
|
||||
namespace :callbacks do
|
||||
resources :telegram_bots, only: [] do
|
||||
resources :updates,
|
||||
controller: 'telegram_bots/updates',
|
||||
only: :create
|
||||
end
|
||||
end
|
||||
|
||||
#########################
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'POST /telegram_bots/:telegram_bot_id/updates' do
|
||||
RSpec.describe 'POST /callbacks/telegram_bots/:telegram_bot_id/updates' do
|
||||
let(:telegram_bot) { create :telegram_bot }
|
||||
|
||||
context 'with valid params' do
|
||||
before do
|
||||
post "/telegram_bots/#{telegram_bot.id}/updates",
|
||||
post "/callbacks/telegram_bots/#{telegram_bot.id}/updates",
|
||||
params: { secret: telegram_bot.secret }
|
||||
end
|
||||
|
||||
|
@ -18,7 +18,7 @@ RSpec.describe 'POST /telegram_bots/:telegram_bot_id/updates' do
|
|||
|
||||
context 'when no telegram bot exist' do
|
||||
before do
|
||||
post "/telegram_bots/#{rand(10_000..1_000_000)}/updates",
|
||||
post "/callbacks/telegram_bots/#{rand(10_000..1_000_000)}/updates",
|
||||
params: { secret: telegram_bot.secret }
|
||||
end
|
||||
|
||||
|
@ -29,7 +29,7 @@ RSpec.describe 'POST /telegram_bots/:telegram_bot_id/updates' do
|
|||
|
||||
context 'when secret is not valid' do
|
||||
before do
|
||||
post "/telegram_bots/#{telegram_bot.id}/updates",
|
||||
post "/callbacks/telegram_bots/#{telegram_bot.id}/updates",
|
||||
params: { secret: SecureRandom.hex }
|
||||
end
|
||||
|
Reference in New Issue