1
0
Fork 0

Rename controller

This commit is contained in:
Alex Kotov 2018-12-07 07:43:30 +05:00
parent 8aefed8ff1
commit e1856eef0b
No known key found for this signature in database
GPG Key ID: 4E831250F47DE154
4 changed files with 17 additions and 20 deletions

View File

@ -1,12 +1,12 @@
# frozen_string_literal: true # frozen_string_literal: true
class TelegramBotUpdatesController < ApplicationController class TelegramBots::UpdatesController < ApplicationController
before_action :set_telegram_bot before_action :set_telegram_bot
before_action :verify_telegram_bot_secret before_action :verify_telegram_bot_secret
skip_after_action :verify_authorized skip_after_action :verify_authorized
# POST /telegram_bot_updates # POST /telegram_bots/:telegram_bot_id/updates
def create def create
logger.info params.inspect logger.info params.inspect

View File

@ -42,11 +42,11 @@ private
def webhook_url def webhook_url
telegram_bot_updates_url( telegram_bot_updates_url(
format: 'json', context.telegram_bot,
protocol: 'https', format: 'json',
host: Rails.application.config.site_domain, protocol: 'https',
telegram_bot_id: context.telegram_bot.id, host: Rails.application.config.site_domain,
secret: context.telegram_bot.secret, secret: context.telegram_bot.secret,
) )
end end
end end

View File

@ -20,7 +20,7 @@ Rails.application.routes.draw do
only: %i[index create] only: %i[index create]
end end
resources :telegram_bots, only: %i[index show] resources :telegram_bots, only: %i[index show] do
resources :updates, controller: 'telegram_bots/updates', only: :create
resources :telegram_bot_updates, only: :create end
end end

View File

@ -2,14 +2,13 @@
require 'rails_helper' 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 } let(:telegram_bot) { create :telegram_bot }
context 'with valid params' do context 'with valid params' do
before do before do
post '/telegram_bot_updates', post "/telegram_bots/#{telegram_bot.id}/updates",
params: { telegram_bot_id: telegram_bot.id, params: { secret: telegram_bot.secret }
secret: telegram_bot.secret }
end end
specify do specify do
@ -19,9 +18,8 @@ RSpec.describe 'POST /telegram_bot_updates' do
context 'when no telegram bot exist' do context 'when no telegram bot exist' do
before do before do
post '/telegram_bot_updates', post "/telegram_bots/#{rand(10_000..1_000_000)}/updates",
params: { telegram_bot_id: rand(10_000..1_000_000), params: { secret: telegram_bot.secret }
secret: telegram_bot.secret }
end end
specify do specify do
@ -31,9 +29,8 @@ RSpec.describe 'POST /telegram_bot_updates' do
context 'when secret is not valid' do context 'when secret is not valid' do
before do before do
post '/telegram_bot_updates', post "/telegram_bots/#{telegram_bot.id}/updates",
params: { telegram_bot_id: telegram_bot.id, params: { secret: SecureRandom.hex }
secret: SecureRandom.hex }
end end
specify do specify do