1
0
Fork 0

Add action Staffs::RelationStatusesController#index

This commit is contained in:
Alex Kotov 2019-09-21 20:39:52 +05:00
parent f6d5bd981b
commit 17f8215d93
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
10 changed files with 163 additions and 0 deletions

View file

@ -0,0 +1,12 @@
# frozen_string_literal: true
class Staffs::RelationStatusesController < ApplicationController
# GET /staff/relation_statuses
def index
authorize [:staff, RelationStatus]
@relation_statuses = policy_scope(
RelationStatus.order(codename: :asc),
policy_scope_class: Staff::RelationStatusPolicy::Scope,
).page(params[:page])
end
end

View file

@ -0,0 +1,19 @@
# frozen_string_literal: true
class Staff::RelationStatusPolicy < ApplicationPolicy
def index?
return false if restricted?
account&.superuser?
end
class Scope < Scope
def resolve
return scope.none if restricted?
return scope.all if account&.superuser?
scope.none
end
end
end

View file

@ -26,5 +26,12 @@
staff_contact_networks_path %>
</li>
<% end %>
<% if policy([:staff, RelationStatus]).index? %>
<li>
<%= link_to RelationStatus.model_name.human(count: 0),
staff_relation_statuses_path %>
</li>
<% end %>
</ul>
</div>

View file

@ -0,0 +1,21 @@
<table class="table">
<thead>
<tr>
<th scope="col">
<%= RelationStatus.human_attribute_name :codename %>
</th>
<th scope="col">
<%= RelationStatus.human_attribute_name :name %>
</th>
</tr>
</thead>
<tbody>
<% relation_statuses.each do |relation_status| %>
<tr>
<td scope="row"><%= relation_status.codename %></td>
<td><%= relation_status.name %></td>
</tr>
<% end %>
</tbody>
</table>

View file

@ -0,0 +1,10 @@
<div class="container">
<%= nav_breadcrumb(
[translate(:staff_services), staff_root_path],
RelationStatus.model_name.human(count: 0),
) %>
<%= render partial: 'table',
locals: { relation_statuses: @relation_statuses } %>
<%= pagination @relation_statuses %>
</div>

View file

@ -26,6 +26,9 @@ en:
regional_office:
one: Regional office
many: Regional offices
relation_status:
one: Relation status
many: Relation statuses
relationship:
one: Party relation
many: Party relations
@ -93,6 +96,10 @@ en:
text: Text
regional_office:
id: ID
relation_status:
id: ID
codename: Codename
name: Name
relationship:
id: ID
regional_office: Regional department

View file

@ -26,6 +26,9 @@ ru:
regional_office:
one: Региональное отделение
many: Региональные отделения
relation_status:
one: Статус отношения
many: Статусы отношения
relationship:
one: Отношение с партией
one: Отношения с партией
@ -93,6 +96,10 @@ ru:
text: Текст
regional_office:
id: ID
relation_status:
id: ID
codename: Кодовое имя
name: Название
relationship:
id: ID
regional_office: Региональное отделение

View file

@ -59,6 +59,8 @@ Rails.application.routes.draw do
resources :contact_networks, only: :index
resources :relation_statuses, only: :index
resources :accounts, param: :nickname, only: %i[index show]
resources :people, only: %i[index show new create] do

View file

@ -0,0 +1,7 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Staff::RelationStatusPolicy do
pending "add some examples to (or delete) #{__FILE__}"
end

View file

@ -0,0 +1,71 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'GET /staff/relation_statuses' do
let(:current_account) { create :superuser_account }
let :relation_statuses_count do
[0, 1, rand(2..4), rand(5..10), rand(20..40)].sample
end
before do
sign_in current_account.user if current_account&.user
create_list :some_relation_status, relation_statuses_count
get '/staff/relation_statuses'
end
for_account_types nil, :usual do
specify do
expect(response).to have_http_status :forbidden
end
end
for_account_types :superuser do
specify do
expect(response).to have_http_status :ok
end
end
context 'when there are no relation statuses' do
let(:relation_statuses_count) { 0 }
specify do
expect(response).to have_http_status :ok
end
end
context 'when there is one relation status' do
let(:relation_statuses_count) { 1 }
specify do
expect(response).to have_http_status :ok
end
end
context 'when there are few relation statuses' do
let(:relation_statuses_count) { rand 2..4 }
specify do
expect(response).to have_http_status :ok
end
end
context 'when there are many relation statuses' do
let(:relation_statuses_count) { rand 5..10 }
specify do
expect(response).to have_http_status :ok
end
end
context 'when there are lot of relation statuses' do
let(:relation_statuses_count) { rand 20..40 }
specify do
expect(response).to have_http_status :ok
end
end
end