diff --git a/app/controllers/telegram_bot_updates_controller.rb b/app/controllers/telegram_bots/updates_controller.rb similarity index 83% rename from app/controllers/telegram_bot_updates_controller.rb rename to app/controllers/telegram_bots/updates_controller.rb index f63c172..b924cf5 100644 --- a/app/controllers/telegram_bot_updates_controller.rb +++ b/app/controllers/telegram_bots/updates_controller.rb @@ -1,12 +1,12 @@ # frozen_string_literal: true -class TelegramBotUpdatesController < ApplicationController +class TelegramBots::UpdatesController < ApplicationController before_action :set_telegram_bot before_action :verify_telegram_bot_secret skip_after_action :verify_authorized - # POST /telegram_bot_updates + # POST /telegram_bots/:telegram_bot_id/updates def create logger.info params.inspect diff --git a/app/interactors/initialize_telegram_bot.rb b/app/interactors/initialize_telegram_bot.rb index 5361162..ec489c9 100644 --- a/app/interactors/initialize_telegram_bot.rb +++ b/app/interactors/initialize_telegram_bot.rb @@ -42,11 +42,11 @@ private def webhook_url telegram_bot_updates_url( - format: 'json', - protocol: 'https', - host: Rails.application.config.site_domain, - telegram_bot_id: context.telegram_bot.id, - secret: context.telegram_bot.secret, + context.telegram_bot, + format: 'json', + protocol: 'https', + host: Rails.application.config.site_domain, + secret: context.telegram_bot.secret, ) end end diff --git a/config/routes.rb b/config/routes.rb index cb8c70e..acd40a2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -20,7 +20,7 @@ Rails.application.routes.draw do only: %i[index create] end - resources :telegram_bots, only: %i[index show] - - resources :telegram_bot_updates, only: :create + resources :telegram_bots, only: %i[index show] do + resources :updates, controller: 'telegram_bots/updates', only: :create + end end diff --git a/spec/requests/telegram_bot_updates/create_spec.rb b/spec/requests/telegram_bots/updates/create_spec.rb similarity index 51% rename from spec/requests/telegram_bot_updates/create_spec.rb rename to spec/requests/telegram_bots/updates/create_spec.rb index 430819e..77ebe1b 100644 --- a/spec/requests/telegram_bot_updates/create_spec.rb +++ b/spec/requests/telegram_bots/updates/create_spec.rb @@ -2,14 +2,13 @@ require 'rails_helper' -RSpec.describe 'POST /telegram_bot_updates' do +RSpec.describe 'POST /telegram_bots/:telegram_bot_id/updates' do let(:telegram_bot) { create :telegram_bot } context 'with valid params' do before do - post '/telegram_bot_updates', - params: { telegram_bot_id: telegram_bot.id, - secret: telegram_bot.secret } + post "/telegram_bots/#{telegram_bot.id}/updates", + params: { secret: telegram_bot.secret } end specify do @@ -19,9 +18,8 @@ RSpec.describe 'POST /telegram_bot_updates' do context 'when no telegram bot exist' do before do - post '/telegram_bot_updates', - params: { telegram_bot_id: rand(10_000..1_000_000), - secret: telegram_bot.secret } + post "/telegram_bots/#{rand(10_000..1_000_000)}/updates", + params: { secret: telegram_bot.secret } end specify do @@ -31,9 +29,8 @@ RSpec.describe 'POST /telegram_bot_updates' do context 'when secret is not valid' do before do - post '/telegram_bot_updates', - params: { telegram_bot_id: telegram_bot.id, - secret: SecureRandom.hex } + post "/telegram_bots/#{telegram_bot.id}/updates", + params: { secret: SecureRandom.hex } end specify do