Add action Settings::TelegramContactsController#index
This commit is contained in:
parent
f97a0fb25e
commit
ed35b805a0
7 changed files with 105 additions and 0 deletions
|
@ -58,6 +58,7 @@ Style/AndOr:
|
|||
|
||||
Style/ClassAndModuleChildren:
|
||||
Exclude:
|
||||
- 'app/policies/**/*.rb'
|
||||
- 'app/controllers/**/*.rb'
|
||||
|
||||
Style/Documentation:
|
||||
|
|
13
app/controllers/settings/telegram_contacts_controller.rb
Normal file
13
app/controllers/settings/telegram_contacts_controller.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Settings::TelegramContactsController < ApplicationController
|
||||
# GET /settings/telegram_contacts
|
||||
def index
|
||||
authorize %i[settings account_telegram_contact]
|
||||
|
||||
@telegram_contacts = policy_scope(
|
||||
current_account.account_telegram_contacts,
|
||||
policy_scope_class: Settings::AccountTelegramContactPolicy::Scope,
|
||||
)
|
||||
end
|
||||
end
|
15
app/policies/settings/account_telegram_contact_policy.rb
Normal file
15
app/policies/settings/account_telegram_contact_policy.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Settings::AccountTelegramContactPolicy < ApplicationPolicy
|
||||
def index?
|
||||
!!context.guest_account
|
||||
end
|
||||
|
||||
class Scope < Scope
|
||||
def resolve
|
||||
return scope.none if context.guest_account.nil?
|
||||
|
||||
scope.where(account: context.guest_account)
|
||||
end
|
||||
end
|
||||
end
|
0
app/views/settings/telegram_contacts/index.html.erb
Normal file
0
app/views/settings/telegram_contacts/index.html.erb
Normal file
|
@ -25,4 +25,8 @@ Rails.application.routes.draw do
|
|||
end
|
||||
|
||||
resources :telegram_chats, only: %i[index show]
|
||||
|
||||
namespace :settings do
|
||||
resources :telegram_contacts, only: :index
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Settings::AccountTelegramContactPolicy do
|
||||
permissions '.scope' do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
|
||||
permissions :show? do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
|
||||
permissions :create? do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
|
||||
permissions :update? do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
|
||||
permissions :destroy? do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
end
|
47
spec/requests/settings/telegram_contacts/index_spec.rb
Normal file
47
spec/requests/settings/telegram_contacts/index_spec.rb
Normal file
|
@ -0,0 +1,47 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'GET /settings/telegram_contacts' do
|
||||
before do
|
||||
sign_in current_account.user if current_account&.user
|
||||
|
||||
if current_account
|
||||
create_list :account_telegram_contact, 5, account: current_account
|
||||
end
|
||||
|
||||
get '/settings/telegram_contacts'
|
||||
end
|
||||
|
||||
context 'when no account is authenticated' do
|
||||
let(:current_account) { nil }
|
||||
|
||||
specify do
|
||||
expect(response).to have_http_status :unauthorized
|
||||
end
|
||||
end
|
||||
|
||||
xcontext 'when guest account is authenticated' do
|
||||
let(:current_account) { create :guest_account }
|
||||
|
||||
specify do
|
||||
expect(response).to have_http_status :ok
|
||||
end
|
||||
end
|
||||
|
||||
context 'when usual account is authenticated' do
|
||||
let(:current_account) { create :usual_account }
|
||||
|
||||
specify do
|
||||
expect(response).to have_http_status :ok
|
||||
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
|
Reference in a new issue