Rename
This commit is contained in:
parent
77331530cb
commit
30359399b9
|
@ -1,22 +1,22 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class FederalSubjectsController < ApplicationController
|
||||
before_action :set_country_state, except: :index
|
||||
before_action :set_federal_subject, except: :index
|
||||
|
||||
# GET /country_states
|
||||
# GET /federal_subjects
|
||||
def index
|
||||
authorize :country_state
|
||||
@country_states = policy_scope(FederalSubject)
|
||||
authorize :federal_subject
|
||||
@federal_subjects = policy_scope(FederalSubject)
|
||||
end
|
||||
|
||||
# GET /country_states/:id
|
||||
# GET /federal_subjects/:id
|
||||
def show
|
||||
authorize @country_state
|
||||
authorize @federal_subject
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_country_state
|
||||
@country_state = FederalSubject.find params[:id]
|
||||
def set_federal_subject
|
||||
@federal_subject = FederalSubject.find params[:id]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,8 +6,8 @@ module ApplicationHelper
|
|||
pills: 'nav nav-pills d-flex d-sm-none flex-column',
|
||||
}.freeze
|
||||
|
||||
def country_states_controller?
|
||||
controller_path == 'country_states'
|
||||
def federal_subjects_controller?
|
||||
controller_path == 'federal_subjects'
|
||||
end
|
||||
|
||||
def staff_controller?
|
||||
|
|
|
@ -5,7 +5,7 @@ class RegionalOffice < ApplicationRecord
|
|||
# Associations #
|
||||
################
|
||||
|
||||
belongs_to :country_state
|
||||
belongs_to :federal_subject
|
||||
|
||||
has_many :people, dependent: :restrict_with_exception
|
||||
|
||||
|
@ -15,5 +15,5 @@ class RegionalOffice < ApplicationRecord
|
|||
# Validations #
|
||||
###############
|
||||
|
||||
validates :country_state, uniqueness: true
|
||||
validates :federal_subject, uniqueness: true
|
||||
end
|
||||
|
|
|
@ -15,8 +15,8 @@
|
|||
<div class="mb-2">
|
||||
<i class="fas fa-map-marker-alt"></i>
|
||||
<%= link_to(
|
||||
@account.person.regional_office.country_state.display_name,
|
||||
@account.person.regional_office.country_state,
|
||||
@account.person.regional_office.federal_subject.display_name,
|
||||
@account.person.regional_office.federal_subject,
|
||||
) %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
|
|
@ -15,9 +15,9 @@
|
|||
|
||||
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
||||
<ul class="navbar-nav mr-auto">
|
||||
<% if policy(:country_state).index? %>
|
||||
<li class="nav-item <%= :active if country_states_controller? %>">
|
||||
<%= link_to country_states_path, class: 'nav-link' do %>
|
||||
<% if policy(:federal_subject).index? %>
|
||||
<li class="nav-item <%= :active if federal_subjects_controller? %>">
|
||||
<%= link_to federal_subjects_path, class: 'nav-link' do %>
|
||||
<%= FederalSubject.model_name.human count: 0 %>
|
||||
<% end %>
|
||||
</li>
|
||||
|
|
|
@ -13,13 +13,13 @@
|
|||
</thead>
|
||||
|
||||
<tbody>
|
||||
<% @country_states.each do |country_state| %>
|
||||
<% @federal_subjects.each do |federal_subject| %>
|
||||
<tr>
|
||||
<td><%= country_state.english_name %></td>
|
||||
<td><%= country_state.native_name %></td>
|
||||
<td><%= federal_subject.english_name %></td>
|
||||
<td><%= federal_subject.native_name %></td>
|
||||
<td>
|
||||
<% if policy(country_state).show? %>
|
||||
<%= link_to country_state,
|
||||
<% if policy(federal_subject).show? %>
|
||||
<%= link_to federal_subject,
|
||||
role: :button,
|
||||
class: 'btn btn-light btn-sm' do %>
|
||||
<i class="far fa-eye"></i>
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<div class="container">
|
||||
<h1><%= @country_state.native_name %></h1>
|
||||
<h1><%= @federal_subject.native_name %></h1>
|
||||
<p class="h1">
|
||||
<small class="text-muted">
|
||||
<%= @country_state.english_name %>
|
||||
<%= @federal_subject.english_name %>
|
||||
</small>
|
||||
</p>
|
||||
</div>
|
||||
|
|
|
@ -24,8 +24,8 @@
|
|||
<dd>
|
||||
<% if @person.regional_office %>
|
||||
<%= link_to(
|
||||
@person.regional_office.country_state.display_name,
|
||||
@person.regional_office.country_state,
|
||||
@person.regional_office.federal_subject.display_name,
|
||||
@person.regional_office.federal_subject,
|
||||
) %>
|
||||
<% else %>
|
||||
<%= translate :none %>
|
||||
|
|
|
@ -4,7 +4,7 @@ en:
|
|||
account:
|
||||
one: Account
|
||||
many: Accounts
|
||||
country_state:
|
||||
federal_subject:
|
||||
one: State
|
||||
many: States
|
||||
passport:
|
||||
|
@ -35,7 +35,7 @@ en:
|
|||
public_name: Public name
|
||||
biography: Bio
|
||||
avatar: Avatar
|
||||
country_state:
|
||||
federal_subject:
|
||||
id: ID
|
||||
english_name: Name
|
||||
native_name: Name
|
||||
|
|
|
@ -4,7 +4,7 @@ ru:
|
|||
account:
|
||||
one: Аккаунт
|
||||
many: Аккаунты
|
||||
country_state:
|
||||
federal_subject:
|
||||
one: Регион
|
||||
many: Регионы
|
||||
passport:
|
||||
|
@ -35,7 +35,7 @@ ru:
|
|||
public_name: Публичное имя
|
||||
biography: Биография
|
||||
avatar: Аватар
|
||||
country_state:
|
||||
federal_subject:
|
||||
id: ID
|
||||
english_name: Название
|
||||
native_name: Название
|
||||
|
|
|
@ -11,7 +11,7 @@ Rails.application.routes.draw do
|
|||
|
||||
resources :accounts, param: :nickname, only: :show
|
||||
|
||||
resources :country_states, only: %i[index show]
|
||||
resources :federal_subjects, only: %i[index show]
|
||||
|
||||
###############
|
||||
# User routes #
|
||||
|
|
|
@ -2,16 +2,16 @@
|
|||
|
||||
require 'csv'
|
||||
|
||||
country_states_filename = Rails.root.join 'config', 'country_states.csv'
|
||||
federal_subjects_filename = Rails.root.join 'config', 'federal_subjects.csv'
|
||||
|
||||
CSV.foreach country_states_filename,
|
||||
CSV.foreach federal_subjects_filename,
|
||||
col_sep: '|' do |(english_name, native_name)|
|
||||
native_name.strip!
|
||||
english_name.strip!
|
||||
|
||||
FederalSubject.where(english_name: english_name)
|
||||
.first_or_create! do |new_country_state|
|
||||
new_country_state.native_name = native_name
|
||||
.first_or_create! do |new_federal_subject|
|
||||
new_federal_subject.native_name = native_name
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
FactoryBot.define do
|
||||
factory :country_state do
|
||||
factory :federal_subject do
|
||||
initialize_with do
|
||||
FederalSubject.find_or_initialize_by english_name: english_name
|
||||
end
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
FactoryBot.define do
|
||||
factory :regional_office do
|
||||
initialize_with do
|
||||
RegionalOffice.find_or_initialize_by country_state: country_state
|
||||
RegionalOffice.find_or_initialize_by federal_subject: federal_subject
|
||||
end
|
||||
|
||||
association :country_state
|
||||
association :federal_subject
|
||||
end
|
||||
end
|
||||
|
|
|
@ -12,10 +12,10 @@ Feature: Account
|
|||
|
||||
Scenario: of a supporter
|
||||
Given there is a supporter account with the following data:
|
||||
| nickname | kotovalexarian |
|
||||
| public_name | Alex Kotov |
|
||||
| biography | Hi there :) |
|
||||
| country_state | Москва |
|
||||
| nickname | kotovalexarian |
|
||||
| public_name | Alex Kotov |
|
||||
| biography | Hi there :) |
|
||||
| federal_subject | Москва |
|
||||
When I visit "/accounts/kotovalexarian"
|
||||
Then I see text "kotovalexarian"
|
||||
And I see text "Alex Kotov"
|
||||
|
@ -25,10 +25,10 @@ Feature: Account
|
|||
|
||||
Scenario: of a member
|
||||
Given there is a member account with the following data:
|
||||
| nickname | kotovalexarian |
|
||||
| public_name | Alex Kotov |
|
||||
| biography | Hi there :) |
|
||||
| country_state | Москва |
|
||||
| nickname | kotovalexarian |
|
||||
| public_name | Alex Kotov |
|
||||
| biography | Hi there :) |
|
||||
| federal_subject | Москва |
|
||||
When I visit "/accounts/kotovalexarian"
|
||||
Then I see text "kotovalexarian"
|
||||
And I see text "Alex Kotov"
|
||||
|
@ -38,10 +38,10 @@ Feature: Account
|
|||
|
||||
Scenario: of an excluded member
|
||||
Given there is an excluded member account with the following data:
|
||||
| nickname | kotovalexarian |
|
||||
| public_name | Alex Kotov |
|
||||
| biography | Hi there :) |
|
||||
| country_state | Москва |
|
||||
| nickname | kotovalexarian |
|
||||
| public_name | Alex Kotov |
|
||||
| biography | Hi there :) |
|
||||
| federal_subject | Москва |
|
||||
When I visit "/accounts/kotovalexarian"
|
||||
Then I see text "kotovalexarian"
|
||||
And I see text "Alex Kotov"
|
||||
|
|
|
@ -12,8 +12,8 @@ end
|
|||
When 'there is a supporter account with the following data:' do |table|
|
||||
options = table.raw.map { |(k, v)| [k.to_sym, v] }.to_h
|
||||
|
||||
country_state = create :country_state, english_name: options[:country_state]
|
||||
regional_office = create :regional_office, country_state: country_state
|
||||
federal_subject = create :federal_subject, english_name: options[:federal_subject]
|
||||
regional_office = create :regional_office, federal_subject: federal_subject
|
||||
person = create :supporter_person, regional_office: regional_office
|
||||
|
||||
create :personal_account,
|
||||
|
@ -26,8 +26,8 @@ end
|
|||
When 'there is a member account with the following data:' do |table|
|
||||
options = table.raw.map { |(k, v)| [k.to_sym, v] }.to_h
|
||||
|
||||
country_state = create :country_state, english_name: options[:country_state]
|
||||
regional_office = create :regional_office, country_state: country_state
|
||||
federal_subject = create :federal_subject, english_name: options[:federal_subject]
|
||||
regional_office = create :regional_office, federal_subject: federal_subject
|
||||
person = create :member_person, regional_office: regional_office
|
||||
|
||||
create :personal_account,
|
||||
|
@ -40,8 +40,8 @@ end
|
|||
When 'there is an excluded member account with the following data:' do |table|
|
||||
options = table.raw.map { |(k, v)| [k.to_sym, v] }.to_h
|
||||
|
||||
country_state = create :country_state, english_name: options[:country_state]
|
||||
regional_office = create :regional_office, country_state: country_state
|
||||
federal_subject = create :federal_subject, english_name: options[:federal_subject]
|
||||
regional_office = create :regional_office, federal_subject: federal_subject
|
||||
person = create :excluded_person, regional_office: regional_office
|
||||
|
||||
create :personal_account,
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe FederalSubject do
|
||||
subject { create :country_state }
|
||||
subject { create :federal_subject }
|
||||
|
||||
it do
|
||||
is_expected.to \
|
||||
|
@ -20,7 +20,9 @@ RSpec.describe FederalSubject do
|
|||
it { is_expected.to validate_uniqueness_of :native_name }
|
||||
|
||||
describe '#display_name' do
|
||||
subject { create :country_state, native_name: Faker::Address.unique.state }
|
||||
subject do
|
||||
create :federal_subject, native_name: Faker::Address.unique.state
|
||||
end
|
||||
|
||||
around do |example|
|
||||
I18n.with_locale locale do
|
||||
|
|
|
@ -5,7 +5,7 @@ require 'rails_helper'
|
|||
RSpec.describe RegionalOffice do
|
||||
subject { create :regional_office }
|
||||
|
||||
it { is_expected.to belong_to :country_state }
|
||||
it { is_expected.to belong_to :federal_subject }
|
||||
|
||||
it { is_expected.to have_many(:people).dependent(:restrict_with_exception) }
|
||||
|
||||
|
@ -17,9 +17,9 @@ RSpec.describe RegionalOffice do
|
|||
|
||||
it do
|
||||
is_expected.to \
|
||||
validate_presence_of(:country_state)
|
||||
validate_presence_of(:federal_subject)
|
||||
.with_message(:required)
|
||||
end
|
||||
|
||||
it { is_expected.to validate_uniqueness_of :country_state }
|
||||
it { is_expected.to validate_uniqueness_of :federal_subject }
|
||||
end
|
||||
|
|
|
@ -9,10 +9,10 @@ RSpec.describe FederalSubjectPolicy do
|
|||
described_class::Scope.new(current_account, FederalSubject.all).resolve
|
||||
end
|
||||
|
||||
let!(:record) { create :country_state }
|
||||
let!(:other_record) { create :country_state }
|
||||
let!(:record) { create :federal_subject }
|
||||
let!(:other_record) { create :federal_subject }
|
||||
|
||||
before { create_list :country_state, 3 }
|
||||
before { create_list :federal_subject, 3 }
|
||||
|
||||
for_account_types nil, :guest, :usual, :superuser do
|
||||
it { is_expected.to permit_actions %i[index show] }
|
||||
|
|
|
@ -2,13 +2,13 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'GET /country_states' do
|
||||
RSpec.describe 'GET /federal_subjects' do
|
||||
before do
|
||||
sign_in current_account.user if current_account&.user
|
||||
|
||||
create_list :country_state, 5
|
||||
create_list :federal_subject, 5
|
||||
|
||||
get '/country_states'
|
||||
get '/federal_subjects'
|
||||
end
|
||||
|
||||
for_account_types nil, :guest, :usual, :superuser do
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'GET /country_states/:id' do
|
||||
let!(:country_state) { create :country_state }
|
||||
RSpec.describe 'GET /federal_subjects/:id' do
|
||||
let!(:federal_subject) { create :federal_subject }
|
||||
|
||||
before do
|
||||
sign_in current_account.user if current_account&.user
|
||||
get "/country_states/#{country_state.id}"
|
||||
get "/federal_subjects/#{federal_subject.id}"
|
||||
end
|
||||
|
||||
for_account_types nil, :guest, :usual, :superuser do
|
||||
|
|
Reference in New Issue