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
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

View File

@ -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

View File

@ -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

View File

@ -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