From 55e44b154d8988500d1e11aa2abebca25d8cde8a Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Wed, 12 Dec 2018 08:08:42 +0500 Subject: [PATCH] Mount Sidekiq web interface --- config/routes.rb | 8 +++++ spec/requests/staff/sidekiq/show_spec.rb | 43 ++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 spec/requests/staff/sidekiq/show_spec.rb diff --git a/config/routes.rb b/config/routes.rb index dae9712..5b3a49e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require 'sidekiq/web' + Rails.application.routes.draw do root to: 'home#show' @@ -25,6 +27,12 @@ Rails.application.routes.draw do end namespace :staff do + authenticate :user, ->(user) { user.account.is_superuser? } do + mount Sidekiq::Web, at: '/sidekiq', as: :sidekiq + end + + get '/sidekiq', to: redirect('/', status: 307), as: :forbidden_sidekiq + resources :telegram_chats, only: %i[index show] end diff --git a/spec/requests/staff/sidekiq/show_spec.rb b/spec/requests/staff/sidekiq/show_spec.rb new file mode 100644 index 0000000..c2185e7 --- /dev/null +++ b/spec/requests/staff/sidekiq/show_spec.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe 'GET /staff/sidekiq' do + before do + @new_user_session_url = new_user_session_url + sign_in current_account.user if current_account&.user + get '/staff/sidekiq' + end + + context 'when no account is authenticated' do + let(:current_account) { nil } + + specify do + expect(response).to redirect_to @new_user_session_url + end + end + + context 'when guest account is authenticated' do + let(:current_account) { create :guest_account } + + specify do + expect(response).to redirect_to @new_user_session_url + end + end + + context 'when usual account is authenticated' do + let(:current_account) { create :usual_account } + + specify do + expect(response).to redirect_to root_url + end + end + + context 'when superuser account is authenticated' do + let(:current_account) { create :superuser_account } + + specify do + expect(response).to have_http_status :ok + end + end +end